日期:2014-05-16  浏览次数:20462 次

using(动态语句)
--创建测试表
create table t01(id integer,name varchar2(10));

--创建测试数据
insert into t01(id,name) values (1,'a');
insert into t01(id,name) values (2,'b');
insert into t01(id,name) values (3,'c');

--提交
commit;

--查询表的数据
select * from t01;

--使用动态语句为变量赋值
declare id t01.id%type := '1';
name t01.name%type;
begin
  execute immediate 'select name from t01 t where id=:1' into name using id;
  dbms_output.put_line(name);
end;

--使用动态语句插入数据
declare id t01.id%type := 4;name t01.name%type := 'd';
begin
  execute immediate 'insert into t01(id,name) values(:1,:2)' using id,name;
  commit;
end;

--使用动态语句更新数据
declare id t01.id%type := 3;name t01.name%type := 'd';
begin
  execute immediate 'update t01 set name=:1 where id=:2' using name,id;
  commit;
end;

--使用动态语句删除数据
declare id t01.id%type := 4;
begin
  execute immediate 'delete from t01 where id=:1' using id;
  commit;
end;