这是我一开始写的存储过程:
create or replace procedure proc_test()
is
--变量区域
--sql脚本
v_sql varchar2(2000) := '';
--记录学生数量
v_num number;
begin
--执行区域
-- execute immediate用法1:立刻执行sql语句
v_sql := 'create or replace view myview as select id,name from student';
execute immediate v_sql;
dbms_output.put_line('创建视图成功');
-- execute immediate用法2:立刻执行sql语句,并赋值给某个变量
v_sql := 'select count(1) from student';
execute immediate v_sql into v_num;
dbms_output.put_line('student表中一共有'||v_num||'条记录');
-- execute immediate用法3:带参数的sql
v_sql:='select * from student t where t.name=:1 and t.age=:2';
execute immediate v_sql using 'yyy01',11;
dbms_output.put_line('执行完了查询结果');
end proc_test;
执行的时候报错:编译后错误提示为pls-00103
百度不思其解,最后经过自己的摸索,既然没有参数,就不要加括号了。最终去掉括号就执行成功了。
create or replace procedure proc_test
is
--变量区域
--sql脚本
v_sql varchar2(2000) := '';
--记录学生数量
v_num number;
begin
--执行区域
-- execute immediate用法1:立刻执行sql语句
v_sql := 'create or replace view myview as select id,name from student';
execute immediate v_sql;
dbms_output.put_line('创建视图成功');
-- execute immediate用法2:立刻执行sql语句,并赋值给某个变量
v_sql := 'select count(1) from student';
execute immediate v_sql into v_num;
dbms_output.put_line('student表中一共有'||v_num||'条记录');
-- execute immediate用法3:带参数的sql
v_sql:='select * from student t where t.name=:1 and t.age=:2';
execute immediate v_sql using 'yyy01',11;
dbms_output.put_line('执行完了查询结果');
end proc_test;