我对record和嵌套表的测试—之五

本文深入探讨了SQL语句中的数据赋值机制,包括记录与集合的赋值,以及如何避免常见错误。重点讲解了如何通过SQL进行数据集间的赋值操作,并分析了相关语法限制。

declare
  
   rec_1 test_2%rowtype;
   rec_2 test_2%rowtype;

   type t_tbl is table of test_2%rowtype;
   v_tbl_1 t_tbl;
   v_tbl_2 t_tbl;
  
begin
   rec_1:=rec_2; ---记录可以互相赋值
   v_tbl_1:=v_tbl_2; ---集合可以互相赋值
   ---select * into rec_1 from test_2 ;----error 实际返回的行数超出了请求行数
   select * into rec_1 from test_2 where rownum=1;
   select * bulk collect into v_tbl_1 from test_2; ---可以用bulk collect into赋值
   rec_1.col_1:=3; ---记录可以用.引用
   ---v_tbl_1.col_1:=3;---error 必须声明col_1组件
end;

 

create or replace procedure proc_test is
   type t_target_id is table of varchar2(50);
   v_target_id t_target_id:=t_target_id();

begin
select target_id bulk collect into v_target_id from tm_table_sources;
insert into test_table(target_id)
select * from table(v_target_id);----error sql语句中不能使用本地收集变量
commit;
end proc_test;
把type t_target_id is table of varchar2(50);====》create type t_target_id is table of varchar2(50);
就好了,因为sql语句中的类型必须要是schema级别的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值