我试图使用以下参数调用此过程:
proc2_del_rows('EMP', 'JOB = CLERK')
但这会导致错误。为什么呢?
CREATE OR REPLACE PROCEDURE proc2_del_rows
(v_tname VARCHAR2,
v_condition VARCHAR2 DEFAULT NULL)
AS
sql_stmt VARCHAR2(500);
where_clause VARCHAR2(200) := 'WHERE'||' '||v_condition;
BEGIN
IF v_condition IS NULL THEN
where_clause := NULL;
END IF;
sql_stmt := 'DELETE FROM :1'||' '||where_clause;
EXECUTE IMMEDIATE sql_stmt USING v_tname;
COMMIT;
END;
答案 0 :(得分:1)
您正在调用条件设置为'JOB = CLERK'。这不起作用,因为CLERK需要引用它。要在引号分隔的字符串中嵌入引号,请将它们加倍:'JOB =''CLERK'''
proc2_del_rows('EMP', 'JOB = ''CLERK''')
下面第一条评论中的错误是由于查询中表格的语法不正确。尝试:
sql_stmt := 'DELETE FROM '|| v_tname ||' '||where_clause;
EXECUTE IMMEDIATE sql_stmt;