2

我必须从 Oracle 函数中提取一个返回值,好的

这是一个函数:

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;

但是没有,所以我该怎么做

谢谢前面!!

4

1 回答 1

3

解决这个问题!!它必须是这样的:

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();
于 2012-05-28T08:47:13.023 回答