我正在尝试使用存储过程更新表,但它发出错误,请解释原因。这是代码。
CREATE OR REPLACE Procedure UpdateItem
( ITEM_TYPE_NAME IN varchar2 )
IS
V_TABLE_NAME VARCHAR2(100);
V_R_TABLE_NAME VARCHAR2(100);
V_SQL_STMT VARCHAR2(1000);
cursor c1 is
select C.RTARGETITEMID ||'#'||C.VERSIONID||'#'||trim(p.CREATEUSERID)||'#bsacm#CBR.CLLCT001# #/icmrm/ICMResourceManager#727665642020202020202020#2509.000000#9080#1#ICMNLSDB# #201#1#' as ITEM_REF, C.ITEMID as ITEM_ID
from V_TABLE_NAME C, V_R_TABLE_NAME R
where C.TIEFLAG = 0 and C.ITEMID=R.ITEMID;
BEGIN
select TABLE_NAME into V_TABLE_NAME
from user_indexes
where INDEX_NAME = (SELECT distinct c.INDEXNAME
FROM ICMSTNLSKEYWORDS k, ICMSTCOMPDEFS d, ICMSTTEXTINDEXES c
WHERE k.KEYWORDCLASS = 2 AND k.KEYWORDCODE = d.ITEMTYPEID AND d.COMPONENTTYPEID = c.COMPONENTTYPEID AND k.KEYWORDNAME = ITEM_TYPE_NAME);
select TABLE_NAME into V_R_TABLE_NAME
from user_constraints
where CONSTRAINT_NAME in (select distinct R_CONSTRAINT_NAME
from user_constraints
where TABLE_NAME in (select TABLE_NAME
from user_indexes
where INDEX_NAME = (SELECT distinct c.INDEXNAME
FROM ICMSTNLSKEYWORDS k, ICMSTCOMPDEFS d, ICMSTTEXTINDEXES c
WHERE k.KEYWORDCLASS = 2 AND k.KEYWORDCODE = d.ITEMTYPEID AND d.COMPONENTTYPEID = c.COMPONENTTYPEID AND k.KEYWORDNAME=ITEM_TYPE_NAME)));
open c1;
fetch c1 into V_SQL_STMT;
EXECUTE IMMEDIATE 'UPDATE V_TABLE_NAME set TIEFLAG = ''1'',TIEREF = c1.ITEM_REF WHERE ITEMID = ITEM.ITEM_ID';
commit;
close c1;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
END;
这就是错误:
错误(9,5):PL / SQL:SQL语句 忽略错误(10,28):PL / SQL: ORA-00942:表或视图没有 存在
答案 0 :(得分:0)
由于V_TABLE_NAME是变量,您需要在字符串中连接变量。您的方式假定您的系统中有一个名为* V_TABLE_NAME *的表。
据我所知,你需要更改一行:
EXECUTE IMMEDIATE 'UPDATE V_TABLE_NAME set TIEFLAG = ''1'',TIEREF = c1.ITEM_REF WHERE ITEMID = ITEM.ITEM_ID';
到
EXECUTE IMMEDIATE 'UPDATE '||V_TABLE_NAME||' set TIEFLAG = ''1'',TIEREF = c1.ITEM_REF WHERE ITEMID = ITEM.ITEM_ID';