请高手解决个oracle存储过程的问题,源码如下
CREATEORREPLACEPROCEDUREGET_INHERITED_APPLICATIONS(VAR_APP_IDnvarchar2,VAR_INHERITED_...
CREATE OR REPLACE PROCEDURE GET_INHERITED_APPLICATIONS(VAR_APP_ID nvarchar2,VAR_INHERITED_STATE INT)
AS
ROOT_LEVEL nvarchar2(32);
n int;
APP_TEMP APPLICATIONS%rowtype;
begin
n:=1;
SELECT RESOURCE_LEVEL into ROOT_LEVEL FROM APPLICATIONS WHERE ID = VAR_APP_ID;
SELECT * INTO APP_TEMP
FROM APPLICATIONS
WHERE (RESOURCE_LEVEL LIKE ROOT_LEVEL+'%'
AND bitand(INHERITED_STATE,VAR_INHERITED_STATE) = VAR_INHERITED_STATE)
OR ID = VAR_APP_ID
ORDER BY RESOURCE_LEVEL;
loop
exit when n = 0;
DELETE FROM APP_TEMP WHERE substr(RESOURCE_LEVEL,1,LENGTH(RESOURCE_LEVEL)-3) NOT IN (SELECT RESOURCE_LEVEL FROM APP_TEMP) AND RESOURCE_LEVEL <> ROOT_LEVEL;
n:=sql%rowcount;
end loop;
SELECT * FROM APP_TEMP
WHERE ID <> VAR_APP_ID;
end;
我想创建临时表,并对其做增删改查的操作,然后返回这个临时表,但是在DELETE那里总是报错说表或视图不存在,请高手指教啊! 展开
AS
ROOT_LEVEL nvarchar2(32);
n int;
APP_TEMP APPLICATIONS%rowtype;
begin
n:=1;
SELECT RESOURCE_LEVEL into ROOT_LEVEL FROM APPLICATIONS WHERE ID = VAR_APP_ID;
SELECT * INTO APP_TEMP
FROM APPLICATIONS
WHERE (RESOURCE_LEVEL LIKE ROOT_LEVEL+'%'
AND bitand(INHERITED_STATE,VAR_INHERITED_STATE) = VAR_INHERITED_STATE)
OR ID = VAR_APP_ID
ORDER BY RESOURCE_LEVEL;
loop
exit when n = 0;
DELETE FROM APP_TEMP WHERE substr(RESOURCE_LEVEL,1,LENGTH(RESOURCE_LEVEL)-3) NOT IN (SELECT RESOURCE_LEVEL FROM APP_TEMP) AND RESOURCE_LEVEL <> ROOT_LEVEL;
n:=sql%rowcount;
end loop;
SELECT * FROM APP_TEMP
WHERE ID <> VAR_APP_ID;
end;
我想创建临时表,并对其做增删改查的操作,然后返回这个临时表,但是在DELETE那里总是报错说表或视图不存在,请高手指教啊! 展开
展开全部
APP_TEMP这个只是个变量,又不是表.你做DELETE当然会错 ,
你应该先考虑用动态SQL建一张临时表.
比如:
execute immediate 'create table xxx as
SELECT *
FROM APPLICATIONS
WHERE (RESOURCE_LEVEL LIKE ROOT_LEVEL+''%''
AND bitand(INHERITED_STATE,VAR_INHERITED_STATE) = VAR_INHERITED_STATE)
OR ID = VAR_APP_ID
ORDER BY RESOURCE_LEVEL';
然后在对这个表进行DELETE操作
你应该先考虑用动态SQL建一张临时表.
比如:
execute immediate 'create table xxx as
SELECT *
FROM APPLICATIONS
WHERE (RESOURCE_LEVEL LIKE ROOT_LEVEL+''%''
AND bitand(INHERITED_STATE,VAR_INHERITED_STATE) = VAR_INHERITED_STATE)
OR ID = VAR_APP_ID
ORDER BY RESOURCE_LEVEL';
然后在对这个表进行DELETE操作
更多追问追答
追问
哦哦 我试试 那最后那句select怎么写呢?oracle里不能直接写查询语句,那我怎么得到查询结果呢?
追答
你直接在PL/SQL上面查这个表就行了社
存储过程里面是不行的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询