oracle动态sql问题
来源:百度知道 编辑:UC知道 时间:2024/06/21 14:48:14
create or replace procedure pro_drop
is
sql_str varchar(1000);
begin
for v_cat in (select table_name from cat where table_type='TABLE')loop
dbms_output.put_line(v_cat.table_name);
sql_str:='drop table '||v_cat.table_name||'';
dbms_output.put_line(sql_str);
execute immediate sql_str;
end loop;
end;
--执行
begin
pro_drop;
end;
--报错
ORA-00933: SQL 命令未正确结束
ORA-06512: 在 "PF.PRO_DROP", line 9
ORA-06512: 在 line 2
这是为什么?
sql_str:='drop table '||v_cat.table_name||''; --你这句明显有问题
sql_str:='drop table '||' '||v_cat.table_name; --改成这样就没问题了
--特别要强调一点,我就错过
sql_str:='drop table '||v_cat.table_name|| ';' ; --这样是不行滴
--感觉语句最后有个';'很对,其实这个字符串恰恰不需要';'
create or replace procedure pro_drop
is ----------------------------该成AS
sql_str varchar(1000);
begin
for v_cat in (select table_name from cat where table_type='TABLE')loop
dbms_output.put_line(v_cat.table_name);
sql_str:='drop table '||v_cat.table_name||'';
dbms_output.put_line(sql_str);
execute immediate sql_str;
end loop;
end;
调用存储过程使用
exec pro_drop
在试试!对oracle 不是很熟,但标准的SQL语法没你这样的
06512
Cause: This is usually the last of a message stack and indicates where a problem occurred in the PL/SQL code.
Action: Fix the problem causing t