【发布时间】:2016-04-11 02:30:46
【问题描述】:
我使用execute immediate 创建了一个过程,当我在此过程中调试并跳转到execute immediate 时,它显示以下消息:
您的代码中发生了 Oracle 异常。如果代码包含异常处理程序,您可以继续单步执行该处理程序;否则,将显示错误消息并退出执行下一步。
然后我取出查询,execute immediate中的查询是:
update mstarea
set '||v_temp_position||' = :pid
where areacode = :pnewarea1
connect by prior areacode = areaparent
start with areacode in (:pnewarea1, :pnewarea2);
我尝试执行/编译该查询,但出现如下错误:
ORA-00933:SQL 命令未正确结束
update 是否支持 connect by prior?
这是我的程序,当到达execute immediate时,错误低于update mstarea。
CREATE OR REPLACE procedure PROC1(pid in varchar2, pposition in varchar2, pnewarea1 in varchar2, pnewarea2 in varchar2)
is
v_error_message varchar2(255);
v_temp_position varchar2(25 byte);
v_sql_statement varchar2(255);
n_count_role number;
cursor cuser is
select userid from master.mstuser where id = pid;
begin
for cdata in cuser
loop
begin
select count(role) into n_count_role from mstmapping where role = pposition;
if n_count_role > 0 then
begin
..........
if pnewarea1 = 'ALL' then
..........
else
..........
------------------- update mstarea -------------------
if pposition in ('A', 'B') then
select 'AB' into v_temp_position from dual;
else
select pposition into v_temp_position from dual;
end if;
v_sql_statement := 'update mstarea set '||v_temp_position||' = :pid where areacode = :pnewarea1 connect by prior areacode = areaparent start with areacode in (:pnewarea1, :pnewarea2)';
execute immediate v_sql_statement using pid, pnewarea1, pnewarea1, pnewarea2; -- advice from @Rene
------------------------------------------------------
..........
end;
end if;
end;
end if;
exception
when others then
..........
rollback;
end;
commit;
exit when cuser%notfound;
end loop;
end;
我应该怎么做才能解决这个问题?
【问题讨论】:
-
感谢@Jonny 编辑我的问题
-
connect by prior是否支持update? - 不,不是:docs.oracle.com/database/121/SQLRF/… -
@a_horse_with_no_name 感谢先生提供的信息!
标签: oracle stored-procedures sql-update execute-immediate