如果我在Oracle SQL开发人员中运行它:
set serveroutput on
DECLARE
key_column varchar2(30) := 'Test';
BEGIN
dbms_output.put_line('key_col = ' || key_column );
SELECT cols.column_name INTO key_column
FROM all_constraints cons
INNER JOIN all_cons_columns cols ON cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
AND cons.constraint_type = 'P'
WHERE cons.owner = 'TAS'
AND cols.table_name = 'COMMENT_ALL_TXT';
DBMS_OUTPUT.PUT_LINE('1 key_column: ' || key_column);
END
;
输出结果为:
匿名阻止完成
key_col =测试
1 key_column:COM_ALL_TXT_KEY
当我将相同的代码放入过程时,这是输出:
ORA-01403:未找到数据
为什么程序代码在SQL工作表中运行代码时没有找到约束?
以下是程序代码:
create or replace PROCEDURE MMW1164.USP_BATCH_CLEANUP_NEW
IS
key_column VARCHAR2(100);
BEGIN
SELECT cols.column_name INTO key_column
FROM all_constraints cons
INNER JOIN all_cons_columns cols ON cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
AND cons.constraint_type = 'P'
WHERE cons.owner = 'TAS'
AND cols.table_name = 'COMMENT_ALL_TXT';
DBMS_OUTPUT.PUT_LINE('1 key_column: ' || key_column);
END
;