使用IN和OUT参数创建存储过程

时间:2018-04-09 14:59:12

标签: sql oracle plsql

这是我第一次创建一个包含IN和OUT参数的存储过程,而且我很丢失。我想要做的是将3个参数(ID_TX,FORM_NAME和DATA_DATE)中的API传递到我的存储过程中,让我的存储过程执行一个简单的插入,然后传递一个值(SUBMISSION_ID)。但是,当我尝试编译代码时,我不断收到错误。错误如下:

 Error(8,1): PLS-00103: Encountered the symbol "INSERT" when expecting one of the following:     begin function pragma procedure subtype type <an identifier>    <a double-quoted delimited-identifier> current cursor delete    exists prior The symbol "begin" was substituted for "INSERT" to continue. 

Error(10,1): PLS-00103: Encountered the symbol "RETURNING" when expecting one of the following:     . ( ) , * % & = - + < / > at in is mod remainder not rem =>    <an exponent (**)> <> or != or ~= >= <= <> and or like like2    like4 likec between || multiset member submultiset 

Error(11,1): PLS-00103: Encountered the symbol "END" 

我缺少一些语法基础/知识吗?提前谢谢!

create or replace procedure API_SUBMISSION(rID_TX IN VARCHAR, rFORM_NAME IN VARCHAR, rDATA_DATE IN VARCHAR, v_submission_id OUT NUMBER)
IS BEGIN
DECLARE
v_submission_id number;
insert into submission (SUBMISSION_ID, RESPONDENT_ID, SUBMISSION_DT, SUBMISSION_TYPE_ID, SUBMISSION_NAME_TX, SUBMISSION_SEQ_NB, CREATE_DT, CREATE_USER_ID, MODIFY_DT, MODIFY_USER_ID, EFFECTIVE_DT, INACTIVE_DT)
            VALUES (null, get__respondent_id(rID_TX, rFORM_NAME, trunc(sysdate), sysdate, rDATA_DATE || 'TEST ' || rFORM_NAME, 1, sysdate, 1, null, null, null, null)
returning submission_id into v_submission_id;
END API_SUBMISSION;

1 个答案:

答案 0 :(得分:2)

您的手术有几个问题:

  1. 您已声明一个out参数来保存返回的submission_id,因此无需重新声明它。
  2. 您不需要在过程/函数中使用declare关键字,除非a)它是匿名块或b)您正在嵌套PL / SQL块。你没有做过;您可以简单地利用IS/ASBEGIN关键字之间的隐式声明部分。在这种情况下不是你需要的。
  3. 您在调用get__respondent_id时错过了一个结束括号 - 我认为它有两个参数?
  4. 这意味着您可以将您的程序重写为:

    CREATE OR REPLACE PROCEDURE api_submission(rid_tx          IN VARCHAR2,
                                 rform_name      IN VARCHAR2,
                                 rdata_date      IN VARCHAR2,
                                 v_submission_id OUT NUMBER) IS
    BEGIN
      INSERT INTO submission
        (submission_id,
         respondent_id,
         submission_dt,
         submission_type_id,
         submission_name_tx,
         submission_seq_nb,
         create_dt,
         create_user_id,
         modify_dt,
         modify_user_id,
         effective_dt,
         inactive_dt)
      VALUES
        (NULL,
         get__respondent_id(reia_id_tx, rform_name),
         trunc(SYSDATE),
         SYSDATE,
         rdata_date || 'TEST ' || rform_name,
         1,
         SYSDATE,
         1,
         NULL,
         NULL,
         NULL,
         NULL)
      RETURNING submission_id INTO v_submission_id;
    
    END api_submission;
    /