心连心鲜花网 加入收藏  -  设为首页
您的位置:心连心鲜花网 > 知识百科 > 正文

目录

1,oracle 中SQL 语句开发语法 SELECT INTO含义

oracle 中SQL 语句开发语法 SELECT INTO含义

和sqlserver的不一样
sqlserver或者access中select into 是通过查询数据来建表
oracle中,这个select into不能在语句中执行,必须要放到存储过程,函数等等里边执行
譬如select to_char(sysdate,'yyyy-mm-dd') into v_date from dual;
这个v_date是用来放变量的,在后续的过程中来调用这个变量
但是这个一次只能放一个值,如果值过多的话需要用到游标


你说的非维护语法是啥意思啊?你要有不懂的可以继续问,但是资料的确不多,都是自己写的被我放论坛上了

2,SQL:select into写法

在oracle中
可以是可以,但是,变量的话最好用个特殊点的符号
v_c varchar2(10);
v_d varchar2(10);
SELECT Column1,Column2 into v_c,v_d
FROM table where rownum<=1;

怕真有c和d字段的时候混淆了,同时,每个sql语句执行的最后要有个分号,否则下一句就执行不过去了
-------------补充-----------
你俩就别误导人了,人家不是要建表,是在存储过程里调用变量的,oracle里select into 是把找出的数放到变量里,不是建表用的

回答2:不可以

3,Oracle中insert into select和select into的区别是什么?

Oracle中insert into select和select into的区别:(select into 就相当于赋值语句,insert into是复制语句),在Oracle中,将一张表的数据复制到另外一个对象中。 通常会有这两种方法:insert into select 和 select into from。前者可以将select 出来的N行(0到任意数)结果集复制一个新表中,后者只能将"一行"结果复制到一个变量中。这样说吧,select into是PL/SQL language 的赋值语句。而前者是标准的SQL语句。 做一个简单测试,我们就可以很容易地看出两者的差别。 1、首先,我们创建两个表,一个作为源表,一个作为目标表; create table t_source( id number primary key, testname varchar2(20), createtime date, flag varchar2(10) ); create table t_target( id number primary key, testname varchar2(20), createtime date, flag varchar2(10) ); 2、接着,插入测试数据; insert into t_source values(1,'测试数据1....1',sysdate-2,'N'); insert into t_source values(2,'测试数据1....2',sysdate-2,'N'); insert into t_source values(3,'测试数据1....3',sysdate-2,'N'); commit; 测试insert into select 操作insert into test2 select * from t_source where id=1; commit; 测试select into 操作:因为select into是一个plsql语言中的复制语句,和:=实现的目标一样。 create or replace procedure sp_sync_test isaa varchar2(100);v_record t_source%rowtype; beginselect t1.testname into aa from t_source t1 where id = 1;dbms_output.put_line('普通变量 t1.testname= ' || aa); select t1.* into v_record from t_source t1 where id = 1;dbms_output.put_line('记录变量 t1.testname= ' || v_record.testname); end; 3、这里增加了原始类型的变量和记录类型的变量,便于大家理解。 甲骨文股份有限公司(Oracle)是全球大型数据库软件公司,总部位于美国加州红木城的红木岸。在2008年,甲骨文股份有限公司是继Microsoft及IBM后,全球收入第三多的软件公司。Oracle数据库产品为财富排行榜上的前1000家公司所采用,许多大型网站也选用了Oracle系统。甲骨文股份有限公司于1989年正式进入中国,在北京、上海、广州和成都均设立了分支机构。 2016年1月,甲骨文表示会收购网站数据追踪服务商AddThis。2016年2月,甲骨文收购了云计算创业公司Ravello Systems。2017年6月7日发布的2017年美国《财富》500强,甲骨文公司排名第81位。2017年6月,《2017年BrandZ最具价值全球品牌100强》公布,甲骨文公司排名第46位。 参考资料 csdn博客.csdn博客[引用时间2018-1-12]

4,oracle中select into 与fecth into 在给变量赋值时的区别在哪儿?

fetch是游标。。我们所说的游标一般指的是显式游标
个人看法是select...into选择一行。。。他属于隐式游标,不能人为控制
select ..into 语句结果必须有且只能有一行。 如果查询没有返回行,PL/SQL将抛出no_data_found异常。如果查询返回多行,则抛出 too_many_rows 异常。如果抛出异常,则停止执行,控制权转移到异常处理部分(没有 异常处理,则程序中断)。在引发异常时,将不使用属性%found,%notfound,%rowcount来查明DML语句是否 已影响了行数

如果要将某一个结果集逐一地读取一条记录的话用游标,fetch 是提取结果集中一行记录存储在变量中。每次提取之后,结果集指针 就向前移动一行。

5,Oracle中insert into select和select into的区别

Oracle中insert into select和select into的区别:(select into 就相当于赋值语句,insert into是复制语句),在Oracle中,将一张表的数据复制到另外一个对象中。 通常会有这两种方法:insert into select 和 select into from。前者可以将select 出来的N行(0到任意数)结果集复制一个新表中,后者只能将"一行"结果复制到一个变量中。这样说吧,select into是PL/SQL language 的赋值语句。而前者是标准的SQL语句。 做一个简单测试,我们就可以很容易地看出两者的差别。 1、首先,我们创建两个表,一个作为源表,一个作为目标表; create table t_source( id number primary key, testname varchar2(20), createtime date, flag varchar2(10) ); create table t_target( id number primary key, testname varchar2(20), createtime date, flag varchar2(10) ); 2、接着,插入测试数据; insert into t_source values(1,'测试数据1....1',sysdate-2,'N'); insert into t_source values(2,'测试数据1....2',sysdate-2,'N'); insert into t_source values(3,'测试数据1....3',sysdate-2,'N'); commit; 测试insert into select 操作insert into test2 select * from t_source where id=1; commit; 测试select into 操作:因为select into是一个plsql语言中的复制语句,和:=实现的目标一样。 create or replace procedure sp_sync_test isaa varchar2(100);v_record t_source%rowtype; beginselect t1.testname into aa from t_source t1 where id = 1;dbms_output.put_line('普通变量 t1.testname= ' || aa); select t1.* into v_record from t_source t1 where id = 1;dbms_output.put_line('记录变量 t1.testname= ' || v_record.testname); end; 3、这里增加了原始类型的变量和记录类型的变量,便于大家理解。 甲骨文股份有限公司(Oracle)是全球大型数据库软件公司,总部位于美国加州红木城的红木岸。在2008年,甲骨文股份有限公司是继Microsoft及IBM后,全球收入第三多的软件公司。Oracle数据库产品为财富排行榜上的前1000家公司所采用,许多大型网站也选用了Oracle系统。甲骨文股份有限公司于1989年正式进入中国,在北京、上海、广州和成都均设立了分支机构。 2016年1月,甲骨文表示会收购网站数据追踪服务商AddThis。2016年2月,甲骨文收购了云计算创业公司Ravello Systems。2017年6月7日发布的2017年美国《财富》500强,甲骨文公司排名第81位。2017年6月,《2017年BrandZ最具价值全球品牌100强》公布,甲骨文公司排名第46位。 参考资料 csdn博客.csdn博客[引用时间2018-1-12]

6,Oracle中insert into select和select into的区别

insert into select可以将select 出来的N行(0到任意数)结果集复制一个新表中,select into
from只能将"一行"结果复制到一个变量中。这样说吧,select into是PL/SQL language
的赋值语句。而前者是标准的SQL语句。


做一个测试看两者差别。

首先创建两个表,一个作为源表,一个作为目标表。


create table t_source(
id number primary key,
testname varchar2(20),
createtime date,
flag varchar2(10)
);

create table t_target(
id number primary key,
testname varchar2(20),
createtime date,
flag varchar2(10)
);



接着,插入测试数据


insert into t_source values(1,'测试数据1....1',sysdate-2,'N');
insert into t_source values(2,'测试数据1....2',sysdate-2,'N');
insert into t_source values(3,'测试数据1....3',sysdate-2,'N');
commit;


测试insert into select 操作


insert into test2 select * from t_source where id=1;
commit;


测试select into 操作
因为select into是一个plsql语言中的复制语句,和:=实现的目标一样。


create or replace procedure sp_sync_test is
aa varchar2(100);
v_record t_source%rowtype;
begin
select t1.testname into aa from t_source t1 where id = 1;
dbms_output.put_line('普通变量 t1.testname= ' || aa);

select t1.* into v_record from t_source t1 where id = 1;
dbms_output.put_line('记录变量 t1.testname= ' || v_record.testname);

end;



这里增加了原始类型的变量和记录类型的变量

7,SQL怎么创建一个临时表

创建临时表
方法一:
create table #临时表名(字段1 约束条件,
字段2 约束条件,
.....)
create table ##临时表名(字段1 约束条件,
字段2 约束条件,
.....)
方法二:
select * into #临时表名 from 你的表;
select * into ##临时表名 from 你的表;
注:以上的#代表局部临时表,##代表全局临时表

查询临时表
select * from #临时表名;
select * from ##临时表名;

删除临时表
drop table #临时表名;
drop table ##临时表名;