从 ORACLE 函数中提取返回值

本文关键字:提取 返回值 函数 ORACLE | 更新日期: 2023-09-27 18:35:27

我必须从 Oracle 函数中提取一个 retrun 值,好的,这里去

这是一个函数:

FUNCTION set_idoc
    (Pidoctyp       in varchar2,    -- tip idoc-a
     Pdirect        in varchar2,    -- smjer idoc-a
     Psgln01        in varchar2,    -- identifikator pošiljatelja
     Prgln01        in varchar2,    -- identifikator primatelja
     Pdtdc01        in varchar2,    -- datum i vrijeme kreiranja poruke
     Pbodi01        in varchar2)    -- identifikator
return number is
Lidoc_num       NUMBER;
Lind_obr        AGR3PL_IDOC.ind_obr%TYPE;
BEGIN
    SELECT SEQ_IDOC.nextval, DECODE(Pdirect, '1', 'U', 'P')
      INTO Lidoc_num, Lind_obr
      FROM DUAL;
    INSERT INTO AGR3PL_IDOC (idoc_num, direct, idoctyp, sgln01, rgln01, dtdc01, bodi01, ind_obr)
    VALUES (Lidoc_num, Pdirect, Pidoctyp, Psgln01, Prgln01, Pdtdc01, Pbodi01, Lind_obr);
    return Lidoc_num;
EXCEPTION
    when others then raise;
END; 

所以我想要提取一个Lidoc_num值

我试过这样:

System.Data.OracleClient.OracleParameter Lidoc_num = new  System.Data.OracleClient.OracleParameter();
Lidoc_num.Direction = ParameterDirection.ReturnValue;
  Lidoc_num.Size = 16;
                        com1.Parameters.Add(Lidoc_num);
                        //Predaj parametre funkciji i vrati broj dokumneta iz baze
                        com1.CommandText = "TRB01.set_idoc('DOC','1','"
                                                           + sender + "','"
                                                           + reciver + "','"
                                                           + cre_date + "','"
                                                           + bod_ID + "')";
                        com1.ExecuteNonQuery();
                        Lidoc_num = com1.Parameters[0].Value;

但是什么都没有,所以我怎么能做到这一点

谢谢前面!!

从 ORACLE 函数中提取返回值

解决它!!它必须是这样的:

System.Data.OracleClient.OracleParameter prm = new System.Data.OracleClient.OracleParameter();
                prm.Direction = ParameterDirection.ReturnValue;
                prm.DbType = DbType.AnsiString;
                prm.Size = 16;
                com1.Parameters.Add(prm);

                com1.CommandText = "TRB01.set_idoc('DOC','1','"
                                                   + sender + "','"
                                                   + reciver + "','"
                                                   + cre_date + "','"
                                                   + bod_ID + "')";
                com1.ExecuteNonQuery();
                Lidoc_num = com1.Parameters[0].Value.ToString();