1

我正在尝试为数据库中所有表中列出的列创建动态更新查询。但是,查询失败,错误 代码:-942 消息:ORA-00942:表或视图不存在 ORA-06512:在“MANTAS.P_JRSDCN_TR”,第 14 行。

代码:-

CREATE or REPLACE PROCEDURE P_JRSDCN_TR
(
out_error_cd out number,        -- Returns 0 if no error; anything else is an error
out_error_msg out varchar2       -- Returns empty string if no error; otherwise the error and trace
)AUTHID CURRENT_USER
IS
    counter  number(20) :=0;   
CURSOR TAB_COL_CURSOR IS 
SELECT DISTINCT OWNER||'.'||TABLE_NAME as TABLE_NAME,COLUMN_NAME FROM ALL_TAB_COLS WHERE TABLE_NAME IN ('KDD_REVIEW') AND COLUMN_NAME='JRSDCN_CD';
 BEGIN  
     FOR TAB_COL_REC  IN TAB_COL_CURSOR
     LOOP

EXECUTE IMMEDIATE 'UPDATE TAB_COL_REC.TABLE_NAME SET TAB_COL_REC.COLUMN_NAME = P2||SUBSTR(TAB_COL_REC.COLUMN_NAME,3) WHERE SUBSTR(TAB_COL_REC.COLUMN_NAME,1,2)= PL';

counter := counter +SQL%rowcount ;
 If counter >= 50000 then
     counter := 0;
     --commit;
    end if;

-- Done!    
    out_error_cd := 0;
    out_error_msg := '';
    dbms_output.put_line('Turkey Jurisdiction Update completed sucessfully at ' || to_char(sysdate,'MM/dd/yyyy HH24:MI:SS'));
        END Loop;
exception when others then
        rollback;
        out_error_cd := SQLCODE;
        out_error_msg := substr(sqlerrm, 1, 200) || chr(10) || substr(DBMS_UTILITY.FORMAT_ERROR_BACKTRACE, 1, 3896);        
        dbms_output.put_line('  Code: ' || out_error_cd);
        dbms_output.put_line('  Message: ' || out_error_msg);
        dbms_output.put_line('Turkey Jurisdiction Update FAILED at ' || to_char(sysdate,'MM/dd/yyyy HH24:MI:SS'));
 end;
 /

感谢您对此过程的帮助。

4

3 回答 3

1

可能没有表叫TAB_COL_REC.TABLE_NAME

你可能想要这样的东西:

EXECUTE IMMEDIATE 'UPDATE ' || TAB_COL_REC.TABLE_NAME || ' SET ' || TAB_COL_REC.COLUMN_NAME || ' = P2||SUBSTR(' || TAB_COL_REC.COLUMN_NAME ||',3) WHERE SUBSTR(' || TAB_COL_REC.COLUMN_NAME || ',1,2)= PL';
于 2013-05-22T04:58:31.577 回答
0

https://forums.oracle.com/forums/thread.jspa?messageID=10896326

https://support.quest.com/SolutionDetail.aspx?id=SOL48289&pr=Code%20Tester%20for%20Oracle

http://www.orafaq.com/forum/t/176917/0/

http://www.coderanch.com/t/539059/ORM/databases/ORA-table-view-exist Oracle 错误代码 ORA-00942 的两个原因 表(或视图)确实不存在 数据库用户存在无权访问(或修改)表

于 2013-05-22T04:37:31.977 回答
0

http://vijvipin.wordpress.com/2009/02/18/plsql-finding-a-column-name-in-all-tables/ _

select a.table_name, column_name,DATA_TYPE,DATA_LENGTH from all_tab_columns
a,USER_ALL_TABLES u where a.TABLE_NAME=u.TABLE_NAME and column_name like 'empid%' order by DATA_LENGTH desc;

于 2013-05-22T05:18:54.603 回答