oracle 中 select into 的使用

ddwren 2011-08-22 03:47:10
eg

select * into new_table from table;

一直报 缺少关键字 求高手帮忙 oracle 中 select into 是如何使用的?
...全文
16281 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhoudianzhang 2011-11-14
  • 打赏
  • 举报
回复
期待高手能解决哦!我也是遇到这样的问题,难道into不是赋值到一个新的表中吗(在oracle中)
yjytiantang 2011-08-31
  • 打赏
  • 举报
回复
创建一个表:
create table new_table as
select * from table;
查询字段赋值:
select 某一字段 into str from table;
yixilan 2011-08-31
  • 打赏
  • 举报
回复
[Quote=引用楼主 ddwren 的回复:]
select * into new_table from table;
一直报 缺少关键字 求高手帮忙 oracle 中 select into 是如何使用的?
[/Quote]
两种用法:
1.指定具体字段
vs_col1 table1.col1%TYPE;
vs_col2 table1.col2%TYPE;
select col1, col2 into vs_col1, vs_col2 from table1 where rownum = 1;
dbms_output.put_line(vs_col1);
dbms_output.put_line(vs_col2);
2.全表字段
table_type table1%ROWTYPE;
select * into table_type from table1 where rownum = 1;
dbms_output.put_line(table_type.col1);
dbms_output.put_line(table_type.col2);
*注意:用这种select .. into 的时候,要保证每次只有一条记录被选出
huangdh12 2011-08-30
  • 打赏
  • 举报
回复
create table1 as select * from table2;
不要悲剧人生 2011-08-30
  • 打赏
  • 举报
回复
看不你想干啥,如果是将查询结果集来生成一张表并插入数据。可以这样写
create table new_table_name as select * from table_name;
cutebear2008 2011-08-30
  • 打赏
  • 举报
回复
在sql server里面该语句会创建一个新表! 在oracle里面select...into...是pl/sql的变量赋值语句!
yuyeyi 2011-08-30
  • 打赏
  • 举报
回复

tab table%ROWTYPE
SELECT * INTO TAB FROM TABLE


nvhaixx 2011-08-30
  • 打赏
  • 举报
回复
create table new_table as select * from table;
insert into new_table values select * from table;
晨与飞扬 2011-08-30
  • 打赏
  • 举报
回复
在运行时,会有多种数据类型,不知道楼主是什么意思,如果把单行into到一个变量对象中,那就将这个变量用%rowtype,定义一下。如果要into到一个表的变量对象,,就定义一个表的对象变量。当然也可into到变量中,像varchar2. number啦。至于写法吧,请楼主去查一下帮助文档,我这里记不得的了。
wuhuipengwhp 2011-08-24
  • 打赏
  • 举报
回复
declare
v_ename varchar2(50);
begin
select ename into v_ename from emp where empno=&no;
dbms_output.put_line('你的用户名是:'||v_name);
end;
njlywy 2011-08-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 opps_zhou 的回复:]
SQL code

create new_table as select * from table;



你的写法是 sql server 的
[/Quote]
+1
hanzs 2011-08-22
  • 打赏
  • 举报
回复

--只查询一条记录
declare
emp_rows emp%rowtype; -- 定义表的行类型
begin
select * into emp_rows from emp where empno = 7788; -- 必须保证记录数只有一条
dbms_output.put_line(emp_rows.empno || ',' || to_char(emp_rows.ename));
end;

--多条记录
declare
emp_rows emp%rowtype; -- 定义表的行类型
cursor cur is select * from emp;
begin
open cur;
loop
fetch cur into emp_rows;
exit when cur%notfound;
dbms_output.put_line(emp_rows.empno || ',' || to_char(emp_rows.ename));
end loop;
close cur;
end;
opps_zhou 2011-08-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 ddwren 的回复:]
引用 2 楼 hanzs 的回复:

SQL code

select * into new_table from table;
new_table应该是表对象,定义了吗?


求教大侠 如何定义表对象 我平时也就建表 查数据 不是太清楚
[/Quote]



declare
emp_rows emp%rowtype; -- 定义表的行类型
begin
select * into emp_rows from emp where empno = 7788; -- 必须保证记录数只有一条
dbms_output.put_line(emp_rows.empno || ',' || to_char(emp_rows.ename));
end;


opps_zhou 2011-08-22
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 ddwren 的回复:]
引用 3 楼 ddwren 的回复:

引用 1 楼 opps_zhou 的回复:

SQL code

create new_table as select * from table;



你的写法是 sql server 的


求教大侠 有关于oracle sql 的详细文档吗 类似于w3cshool中sql 部分的


我写大侠给我的sql 直接报无效的O……
[/Quote]



SQL> create table new_emp as select * from emp;

Table created

SQL>


上面的命令少了一个 table 关键字
opps_zhou 2011-08-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ddwren 的回复:]
引用 1 楼 opps_zhou 的回复:

SQL code

create new_table as select * from table;



你的写法是 sql server 的


求教大侠 有关于oracle sql 的详细文档吗 类似于w3cshool中sql 部分的
[/Quote]

oracle官方网站里提供了帮助文档下载,或者在线搜索的,不过是全英文
ddwren 2011-08-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ddwren 的回复:]

引用 1 楼 opps_zhou 的回复:

SQL code

create new_table as select * from table;



你的写法是 sql server 的


求教大侠 有关于oracle sql 的详细文档吗 类似于w3cshool中sql 部分的
[/Quote]

我写大侠给我的sql 直接报无效的ORACLE 命令
Rotel-刘志东 2011-08-22
  • 打赏
  • 举报
回复
---在sql server可以这样写
select * into new_table from table;
----在oracle中只能定义变量new_table
select * into new_table from table
ddwren 2011-08-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hanzs 的回复:]

SQL code

select * into new_table from table;
new_table应该是表对象,定义了吗?
[/Quote]

求教大侠 如何定义表对象 我平时也就建表 查数据 不是太清楚
Phoenix_99 2011-08-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 opps_zhou 的回复:]
SQL code


create new_table as select * from table;



你的写法是 sql server 的
[/Quote]

同上
ddwren 2011-08-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 opps_zhou 的回复:]

SQL code

create new_table as select * from table;



你的写法是 sql server 的
[/Quote]

求教大侠 有关于oracle sql 的详细文档吗 类似于w3cshool中sql 部分的
加载更多回复(2)

17,090

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧