救急:查询正确,但无法把查询结果插入另一张表???

icbm icbm 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
-- 准备实验环境,创建t01、t02表,并在t01表中插入实验数据
create table t01(num number);
insert into t01 values(1);
insert into t01 values(3);
insert into t01 values(5);
insert into t01 values(7);
insert into t01 values(9);
insert into t01 values(2);
insert into t01 values(4);
insert into t01 values(6);
insert into t01 values(8);
insert into t01 values(10);
commit;

create table t02(num number);

-- 测试一,不使用PL/SQL,直接查询
select num
from
(
select num
from t01
order by num desc
) tmp01
where rownum<=5;



-- 测试二,使用PL/SQL匿名块,将查询结果插入t02表,子查询使用order by
begin
insert into t02(num)
select num
from
(
select num
from t01
order by num desc
) tmp01
where rownum<=5;
end;
/

-- 测试三,使用PL/SQL匿名块,将查询结果插入t02表,子查询“不”使用order by
begin
insert into t02(num)
select num
from
(
select num
from t01
) tmp01
where rownum<=5;
end;
/
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
icbm
Oracle 17,133 成员 55,258 内容