PLS-00103错误,代码中有什么问题

时间:2015-04-29 12:57:37

标签: plsql

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;
/

2 个答案:

答案 0 :(得分:1)

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 '||v_tname||' '||where_clause;

        EXECUTE IMMEDIATE sql_stmt;

END;
/

答案 1 :(得分:0)

要在字符串文字中包含单引号字符,您需要将单引号加倍,例如proc2_del_rows('EMP', 'JOB=''CLERK''')

Documentation here

分享并享受。