如何使用来自 DBTransactionImpl 的类型化输入参数执行 PL/SQL 过程

How to Execute PL/SQL Procedure with Typed Input Param from DBTransactionImpl

甲骨文 ADF/JDeveloper 11.1.1.7。 Oracle 数据库。

我正在尝试调用如下所示的存储过程:

create or replace 
PROCEDURE SP_ADD_AUDIT_COMMENT_BY_RECID (ct_comments IN TYPE_AUDIT_COMMENT)
    AS
            MISSING_REQUIRED_INPUT EXCEPTION;
        BEGIN  
            IF 
                (ct_comments.CUSTOM_APP_RECORD_ID  IS NULL) OR
                (ct_comments.CUSTOM_SOURCE  IS NULL) OR
                (ct_comments.UPDATEDBYDISPLAYNAME IS NULL) OR
                (ct_comments.COMMENTDATE IS NULL) OR
                (ct_comments.WFCOMMENT IS NULL)
            THEN
                RAISE MISSING_REQUIRED_INPUT;
            ELSE
                INSERT All
                    INTO AUDIT_RECORD_INSTANCE (CUSTOM_APP_RECORD_ID, CUSTOM_SOURCE, INSTANCEID, COMPOSITEINSTANCEID) VALUES (ct_comments.CUSTOM_APP_RECORD_ID, ct_comments.CUSTOM_SOURCE, ct_comments.INSTANCEID, ct_comments.COMPOSITEINSTANCEID)
                    INTO AUDIT_WFCOMMENTS (CUSTOM_APP_RECORD_ID, CUSTOM_SOURCE, TASKID, UPDATEDBY, UPDATEDBYDISPLAYNAME, COMMENTDATE, WFCOMMENT, SCOPE ) VALUES (ct_comments.CUSTOM_APP_RECORD_ID, ct_comments.CUSTOM_SOURCE, ct_comments.TASKID, ct_comments.UPDATEDBY, ct_comments.UPDATEDBYDISPLAYNAME, ct_comments.COMMENTDATE, ct_comments.WFCOMMENT, ct_comments.SCOPE)
                SELECT * FROM dual;            
            END IF;
            EXCEPTION
                WHEN MISSING_REQUIRED_INPUT THEN
                --DBMS_OUTPUT.PUT_LINE ('One or more required input values are missing.');
                raise_application_error (-20001,'One or more required input values are missing.');
        END;

这在 SQL 工作表中工作正常,使用:

DECLARE pComment TYPE_AUDIT_COMMENT;
    BEGIN
                    pComment := TYPE_AUDIT_COMMENT('123','SOURCE','1','2','3','jSmith','Joe Smith',
                    to_timestamp('06-APR-15 02.25.58.187000000 PM','DD-MON-RR HH.MI.SS.FF AM'),'TEST COMMENT SP','SCOPE');
                    SCHEMANAME.SP_ADD_AUDIT_COMMENT_BY_RECID(pComment);

           END;

在 AppModule 中,一个方法获取参数并尝试按如下方式执行过程:

public void insertNewGenericComment(Comments comments){
         String input =
            "pComment := TYPE_AUDIT_COMMENT('" + comments.getAssessmentId() + "', '"
            + comments.getCustomSource() + "', '"
            + comments.getInstanceid() + "', '"
            + comments.getTaskId() + "', '"
            + comments.getCompositeInstanceId() + "', '"
            + comments.getUpdatedBy() + "', '"
            + comments.getUpdatedbyDisplayName() + "', to_timestamp('"
            + comments.getCommentDate() + "','DD-MON-RR HH.MI.SS.FF AM'), '"
            + comments.getComment() + "', '"
            + comments.getScope() + "'); SCHEMANAME.SP_ADD_AUDIT_COMMENT_BY_RECID(pComment);";

        DBTransactionImpl dbti = (DBTransactionImpl)getDBTransaction();
        dbti.executeCommand("DECLARE pComment TYPE_AUDIT_COMMENT; begin " + input + " end;");

我尝试了很多变体,但为什么我不能像在工作表中那样执行 sql?

上面的 JBO 错误是:

There was an error adding a new comment: oracle.jbo.SQLStmtException: JBO-27121: SQL error during statement execution. Statement: DECLARE pComment TYPE_AUDIT_COMMENT; begin pComment := TYPE_AUDIT_COMMENT('210', 'AssignCustomTaskflow', 'NA', 'NA', 'NA', 'anonymous', 'anonymous', to_timestamp('16-Jun-15 02.58.20.000000502 PM','DD-MON-RR HH.MI.SS.FF AM'), ' test', 'NA'); SCHEMANAME.SP_ADD_AUDIT_COMMENT_BY_RECID(pComment); end;

错误消息中的语句粘贴到 SQL 工作表中也可以正常执行。没有办法从 ADF 传递逐字过程调用吗?

下面是一个示例,向您展示如何使用自定义类型调用数据库过程。

Callable Statements with custom database type adf