Calling a database stored function or stored proc that returns a valueOutput Parameter not Returned from Stored ProcFunction vs. Stored Procedure in SQL ServerDateTime parameter when calling stored function from java codeCalling a stored proc that returns a recordset from within a stored procC# SQL Server - Passing a list to a stored procedurecalling Oracle stored procedures in R - how to get the result set?Oracle query in a proc not returning resultsUsage of stored functions in entity frameworkUnable to retrieve out params from Oracle stored procedure in C#Call SQL stored proc with OUTPUT param from another stored proc

Why is the Digital 0 not 0V in computer systems?

In Germany, how can I maximize the impact of my charitable donations?

What is the CR of a Metallic Dragon that used Change Shape?

What was redacted in the Yellowhammer report? (Point 15)

How do EVA suits manage water excretion?

Is there a reliable way to hide/convey a message in vocal expressions (speech, song,...)

Stucturing information on this trade show banner

What is the purpose of this tool?

What hard drive connector is this?

"Literally" Vs "In the true sense of the word"

Why don't Wizards use wrist straps to protect against disarming charms?

Why does the speed of sound decrease at high altitudes although the air density decreases?

Write a function that returns an iterable object of all valid points 4-directionally adjacent to (x, y)

Diffraction of a wave passing through double slits

How to stabilise the bicycle seatpost and saddle when it is all the way up?

Can a warforged druid use composite plating?

Are scroll bars dead in 2019?

What officially disallows US presidents from driving?

How do email clients "send later" without storing a password?

Is a suit against a University Dorm for changing policies on a whim likely to succeed (USA)?

Why do sellers care about down payments?

Were Roman public roads build by private companies?

A medieval fantasy adventurer lights a torch in a 100% pure oxygen room. What happens?

What's the biggest organic molecule that could have a smell?



Calling a database stored function or stored proc that returns a value


Output Parameter not Returned from Stored ProcFunction vs. Stored Procedure in SQL ServerDateTime parameter when calling stored function from java codeCalling a stored proc that returns a recordset from within a stored procC# SQL Server - Passing a list to a stored procedurecalling Oracle stored procedures in R - how to get the result set?Oracle query in a proc not returning resultsUsage of stored functions in entity frameworkUnable to retrieve out params from Oracle stored procedure in C#Call SQL stored proc with OUTPUT param from another stored proc






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Using linq2db with an oracle 12 database, how can I call a stored function or a stored procedure that returns a value? From the info I could find, the solution seemed to be to use:



IEnumerable<T> QueryProc<T>(
this DataConnection connection,
string sql,
params DataParameter[] parameters);


But it doesn't work with functions and with a stored proc, I do not receive the output value from the proc.



create or replace PROCEDURE TESTPROC(inputParm VARCHAR2, outputParm OUT VARCHAR2)
IS
BEGIN
outputParm := 'TEST OUTPUT STRING';
END TESTPROC;


I call it with linq2db the following way:



DataParameter[] para = new DataParameter("inputParm", "some_string", DataType.VarChar), new DataParameter("outputParm", "", DataType.VarChar) ;

var res = myDataContext.QueryProc<string>("TESTPROC", para).FirstOrDefault();


What am I doing wrong?










share|improve this question
































    0















    Using linq2db with an oracle 12 database, how can I call a stored function or a stored procedure that returns a value? From the info I could find, the solution seemed to be to use:



    IEnumerable<T> QueryProc<T>(
    this DataConnection connection,
    string sql,
    params DataParameter[] parameters);


    But it doesn't work with functions and with a stored proc, I do not receive the output value from the proc.



    create or replace PROCEDURE TESTPROC(inputParm VARCHAR2, outputParm OUT VARCHAR2)
    IS
    BEGIN
    outputParm := 'TEST OUTPUT STRING';
    END TESTPROC;


    I call it with linq2db the following way:



    DataParameter[] para = new DataParameter("inputParm", "some_string", DataType.VarChar), new DataParameter("outputParm", "", DataType.VarChar) ;

    var res = myDataContext.QueryProc<string>("TESTPROC", para).FirstOrDefault();


    What am I doing wrong?










    share|improve this question




























      0












      0








      0








      Using linq2db with an oracle 12 database, how can I call a stored function or a stored procedure that returns a value? From the info I could find, the solution seemed to be to use:



      IEnumerable<T> QueryProc<T>(
      this DataConnection connection,
      string sql,
      params DataParameter[] parameters);


      But it doesn't work with functions and with a stored proc, I do not receive the output value from the proc.



      create or replace PROCEDURE TESTPROC(inputParm VARCHAR2, outputParm OUT VARCHAR2)
      IS
      BEGIN
      outputParm := 'TEST OUTPUT STRING';
      END TESTPROC;


      I call it with linq2db the following way:



      DataParameter[] para = new DataParameter("inputParm", "some_string", DataType.VarChar), new DataParameter("outputParm", "", DataType.VarChar) ;

      var res = myDataContext.QueryProc<string>("TESTPROC", para).FirstOrDefault();


      What am I doing wrong?










      share|improve this question
















      Using linq2db with an oracle 12 database, how can I call a stored function or a stored procedure that returns a value? From the info I could find, the solution seemed to be to use:



      IEnumerable<T> QueryProc<T>(
      this DataConnection connection,
      string sql,
      params DataParameter[] parameters);


      But it doesn't work with functions and with a stored proc, I do not receive the output value from the proc.



      create or replace PROCEDURE TESTPROC(inputParm VARCHAR2, outputParm OUT VARCHAR2)
      IS
      BEGIN
      outputParm := 'TEST OUTPUT STRING';
      END TESTPROC;


      I call it with linq2db the following way:



      DataParameter[] para = new DataParameter("inputParm", "some_string", DataType.VarChar), new DataParameter("outputParm", "", DataType.VarChar) ;

      var res = myDataContext.QueryProc<string>("TESTPROC", para).FirstOrDefault();


      What am I doing wrong?







      c# oracle stored-procedures stored-functions linq2db






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 1 at 8:44









      Uwe Keim

      28.2k33 gold badges142 silver badges228 bronze badges




      28.2k33 gold badges142 silver badges228 bronze badges










      asked Mar 28 at 10:30









      John VolkyaJohn Volkya

      5233 gold badges11 silver badges29 bronze badges




      5233 gold badges11 silver badges29 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          2
















          Update: updated answer to be correct



          IEnumerable<T> QueryProc<T>(...) return value is a data set, returned by procedure/function by select statement.



          If your procedure doesn't return table, you need to use non-generic version of ExecuteProc, which just returns number of affected records.



          To get output parameter value you need to access parameter in command:
          ((IDbDataParameter)dataConnection.Command.Parameters["parameter_name"]).Value



          below is an example of procedure call helper from linq2db tests, generatedd by T4 template:



          public static int OUTREFTEST(this DataConnection dataConnection, decimal? PID, out decimal? POUTPUTID, ref decimal? PINPUTOUTPUTID, string PSTR, out string POUTPUTSTR, ref string PINPUTOUTPUTSTR)

          var ret = dataConnection.ExecuteProc("TESTUSER.OUTREFTEST",
          new DataParameter("PID", PID, DataType.Decimal),
          new DataParameter("POUTPUTID", null, DataType.Decimal) Direction = ParameterDirection.Output, Size = 22 ,
          new DataParameter("PINPUTOUTPUTID", PINPUTOUTPUTID, DataType.Decimal) Direction = ParameterDirection.InputOutput, Size = 22 ,
          new DataParameter("PSTR", PSTR, DataType.NVarChar),
          new DataParameter("POUTPUTSTR", null, DataType.NVarChar) Direction = ParameterDirection.Output ,
          new DataParameter("PINPUTOUTPUTSTR", PINPUTOUTPUTSTR, DataType.NVarChar) Direction = ParameterDirection.InputOutput );

          POUTPUTID = Converter.ChangeTypeTo<decimal?>(((IDbDataParameter)dataConnection.Command.Parameters["POUTPUTID"]). Value);
          PINPUTOUTPUTID = Converter.ChangeTypeTo<decimal?>(((IDbDataParameter)dataConnection.Command.Parameters["PINPUTOUTPUTID"]). Value);
          POUTPUTSTR = Converter.ChangeTypeTo<string> (((IDbDataParameter)dataConnection.Command.Parameters["POUTPUTSTR"]). Value);
          PINPUTOUTPUTSTR = Converter.ChangeTypeTo<string> (((IDbDataParameter)dataConnection.Command.Parameters["PINPUTOUTPUTSTR"]).Value);

          return ret;






          share|improve this answer



























          • It doesn't work with a function, I get an error saying the proc is not found. If I use a proc with out parameter, the result is not set in the para[1].Value as you mention.

            – John Volkya
            Apr 1 at 12:37












          • my bad, updated answer

            – DLuk
            Apr 1 at 14:03











          • Thanks! It seems to be working like this.

            – John Volkya
            Apr 1 at 15:57










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );














          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55395359%2fcalling-a-database-stored-function-or-stored-proc-that-returns-a-value%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2
















          Update: updated answer to be correct



          IEnumerable<T> QueryProc<T>(...) return value is a data set, returned by procedure/function by select statement.



          If your procedure doesn't return table, you need to use non-generic version of ExecuteProc, which just returns number of affected records.



          To get output parameter value you need to access parameter in command:
          ((IDbDataParameter)dataConnection.Command.Parameters["parameter_name"]).Value



          below is an example of procedure call helper from linq2db tests, generatedd by T4 template:



          public static int OUTREFTEST(this DataConnection dataConnection, decimal? PID, out decimal? POUTPUTID, ref decimal? PINPUTOUTPUTID, string PSTR, out string POUTPUTSTR, ref string PINPUTOUTPUTSTR)

          var ret = dataConnection.ExecuteProc("TESTUSER.OUTREFTEST",
          new DataParameter("PID", PID, DataType.Decimal),
          new DataParameter("POUTPUTID", null, DataType.Decimal) Direction = ParameterDirection.Output, Size = 22 ,
          new DataParameter("PINPUTOUTPUTID", PINPUTOUTPUTID, DataType.Decimal) Direction = ParameterDirection.InputOutput, Size = 22 ,
          new DataParameter("PSTR", PSTR, DataType.NVarChar),
          new DataParameter("POUTPUTSTR", null, DataType.NVarChar) Direction = ParameterDirection.Output ,
          new DataParameter("PINPUTOUTPUTSTR", PINPUTOUTPUTSTR, DataType.NVarChar) Direction = ParameterDirection.InputOutput );

          POUTPUTID = Converter.ChangeTypeTo<decimal?>(((IDbDataParameter)dataConnection.Command.Parameters["POUTPUTID"]). Value);
          PINPUTOUTPUTID = Converter.ChangeTypeTo<decimal?>(((IDbDataParameter)dataConnection.Command.Parameters["PINPUTOUTPUTID"]). Value);
          POUTPUTSTR = Converter.ChangeTypeTo<string> (((IDbDataParameter)dataConnection.Command.Parameters["POUTPUTSTR"]). Value);
          PINPUTOUTPUTSTR = Converter.ChangeTypeTo<string> (((IDbDataParameter)dataConnection.Command.Parameters["PINPUTOUTPUTSTR"]).Value);

          return ret;






          share|improve this answer



























          • It doesn't work with a function, I get an error saying the proc is not found. If I use a proc with out parameter, the result is not set in the para[1].Value as you mention.

            – John Volkya
            Apr 1 at 12:37












          • my bad, updated answer

            – DLuk
            Apr 1 at 14:03











          • Thanks! It seems to be working like this.

            – John Volkya
            Apr 1 at 15:57















          2
















          Update: updated answer to be correct



          IEnumerable<T> QueryProc<T>(...) return value is a data set, returned by procedure/function by select statement.



          If your procedure doesn't return table, you need to use non-generic version of ExecuteProc, which just returns number of affected records.



          To get output parameter value you need to access parameter in command:
          ((IDbDataParameter)dataConnection.Command.Parameters["parameter_name"]).Value



          below is an example of procedure call helper from linq2db tests, generatedd by T4 template:



          public static int OUTREFTEST(this DataConnection dataConnection, decimal? PID, out decimal? POUTPUTID, ref decimal? PINPUTOUTPUTID, string PSTR, out string POUTPUTSTR, ref string PINPUTOUTPUTSTR)

          var ret = dataConnection.ExecuteProc("TESTUSER.OUTREFTEST",
          new DataParameter("PID", PID, DataType.Decimal),
          new DataParameter("POUTPUTID", null, DataType.Decimal) Direction = ParameterDirection.Output, Size = 22 ,
          new DataParameter("PINPUTOUTPUTID", PINPUTOUTPUTID, DataType.Decimal) Direction = ParameterDirection.InputOutput, Size = 22 ,
          new DataParameter("PSTR", PSTR, DataType.NVarChar),
          new DataParameter("POUTPUTSTR", null, DataType.NVarChar) Direction = ParameterDirection.Output ,
          new DataParameter("PINPUTOUTPUTSTR", PINPUTOUTPUTSTR, DataType.NVarChar) Direction = ParameterDirection.InputOutput );

          POUTPUTID = Converter.ChangeTypeTo<decimal?>(((IDbDataParameter)dataConnection.Command.Parameters["POUTPUTID"]). Value);
          PINPUTOUTPUTID = Converter.ChangeTypeTo<decimal?>(((IDbDataParameter)dataConnection.Command.Parameters["PINPUTOUTPUTID"]). Value);
          POUTPUTSTR = Converter.ChangeTypeTo<string> (((IDbDataParameter)dataConnection.Command.Parameters["POUTPUTSTR"]). Value);
          PINPUTOUTPUTSTR = Converter.ChangeTypeTo<string> (((IDbDataParameter)dataConnection.Command.Parameters["PINPUTOUTPUTSTR"]).Value);

          return ret;






          share|improve this answer



























          • It doesn't work with a function, I get an error saying the proc is not found. If I use a proc with out parameter, the result is not set in the para[1].Value as you mention.

            – John Volkya
            Apr 1 at 12:37












          • my bad, updated answer

            – DLuk
            Apr 1 at 14:03











          • Thanks! It seems to be working like this.

            – John Volkya
            Apr 1 at 15:57













          2














          2










          2









          Update: updated answer to be correct



          IEnumerable<T> QueryProc<T>(...) return value is a data set, returned by procedure/function by select statement.



          If your procedure doesn't return table, you need to use non-generic version of ExecuteProc, which just returns number of affected records.



          To get output parameter value you need to access parameter in command:
          ((IDbDataParameter)dataConnection.Command.Parameters["parameter_name"]).Value



          below is an example of procedure call helper from linq2db tests, generatedd by T4 template:



          public static int OUTREFTEST(this DataConnection dataConnection, decimal? PID, out decimal? POUTPUTID, ref decimal? PINPUTOUTPUTID, string PSTR, out string POUTPUTSTR, ref string PINPUTOUTPUTSTR)

          var ret = dataConnection.ExecuteProc("TESTUSER.OUTREFTEST",
          new DataParameter("PID", PID, DataType.Decimal),
          new DataParameter("POUTPUTID", null, DataType.Decimal) Direction = ParameterDirection.Output, Size = 22 ,
          new DataParameter("PINPUTOUTPUTID", PINPUTOUTPUTID, DataType.Decimal) Direction = ParameterDirection.InputOutput, Size = 22 ,
          new DataParameter("PSTR", PSTR, DataType.NVarChar),
          new DataParameter("POUTPUTSTR", null, DataType.NVarChar) Direction = ParameterDirection.Output ,
          new DataParameter("PINPUTOUTPUTSTR", PINPUTOUTPUTSTR, DataType.NVarChar) Direction = ParameterDirection.InputOutput );

          POUTPUTID = Converter.ChangeTypeTo<decimal?>(((IDbDataParameter)dataConnection.Command.Parameters["POUTPUTID"]). Value);
          PINPUTOUTPUTID = Converter.ChangeTypeTo<decimal?>(((IDbDataParameter)dataConnection.Command.Parameters["PINPUTOUTPUTID"]). Value);
          POUTPUTSTR = Converter.ChangeTypeTo<string> (((IDbDataParameter)dataConnection.Command.Parameters["POUTPUTSTR"]). Value);
          PINPUTOUTPUTSTR = Converter.ChangeTypeTo<string> (((IDbDataParameter)dataConnection.Command.Parameters["PINPUTOUTPUTSTR"]).Value);

          return ret;






          share|improve this answer















          Update: updated answer to be correct



          IEnumerable<T> QueryProc<T>(...) return value is a data set, returned by procedure/function by select statement.



          If your procedure doesn't return table, you need to use non-generic version of ExecuteProc, which just returns number of affected records.



          To get output parameter value you need to access parameter in command:
          ((IDbDataParameter)dataConnection.Command.Parameters["parameter_name"]).Value



          below is an example of procedure call helper from linq2db tests, generatedd by T4 template:



          public static int OUTREFTEST(this DataConnection dataConnection, decimal? PID, out decimal? POUTPUTID, ref decimal? PINPUTOUTPUTID, string PSTR, out string POUTPUTSTR, ref string PINPUTOUTPUTSTR)

          var ret = dataConnection.ExecuteProc("TESTUSER.OUTREFTEST",
          new DataParameter("PID", PID, DataType.Decimal),
          new DataParameter("POUTPUTID", null, DataType.Decimal) Direction = ParameterDirection.Output, Size = 22 ,
          new DataParameter("PINPUTOUTPUTID", PINPUTOUTPUTID, DataType.Decimal) Direction = ParameterDirection.InputOutput, Size = 22 ,
          new DataParameter("PSTR", PSTR, DataType.NVarChar),
          new DataParameter("POUTPUTSTR", null, DataType.NVarChar) Direction = ParameterDirection.Output ,
          new DataParameter("PINPUTOUTPUTSTR", PINPUTOUTPUTSTR, DataType.NVarChar) Direction = ParameterDirection.InputOutput );

          POUTPUTID = Converter.ChangeTypeTo<decimal?>(((IDbDataParameter)dataConnection.Command.Parameters["POUTPUTID"]). Value);
          PINPUTOUTPUTID = Converter.ChangeTypeTo<decimal?>(((IDbDataParameter)dataConnection.Command.Parameters["PINPUTOUTPUTID"]). Value);
          POUTPUTSTR = Converter.ChangeTypeTo<string> (((IDbDataParameter)dataConnection.Command.Parameters["POUTPUTSTR"]). Value);
          PINPUTOUTPUTSTR = Converter.ChangeTypeTo<string> (((IDbDataParameter)dataConnection.Command.Parameters["PINPUTOUTPUTSTR"]).Value);

          return ret;







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 1 at 14:03

























          answered Apr 1 at 8:39









          DLukDLuk

          6694 silver badges10 bronze badges




          6694 silver badges10 bronze badges















          • It doesn't work with a function, I get an error saying the proc is not found. If I use a proc with out parameter, the result is not set in the para[1].Value as you mention.

            – John Volkya
            Apr 1 at 12:37












          • my bad, updated answer

            – DLuk
            Apr 1 at 14:03











          • Thanks! It seems to be working like this.

            – John Volkya
            Apr 1 at 15:57

















          • It doesn't work with a function, I get an error saying the proc is not found. If I use a proc with out parameter, the result is not set in the para[1].Value as you mention.

            – John Volkya
            Apr 1 at 12:37












          • my bad, updated answer

            – DLuk
            Apr 1 at 14:03











          • Thanks! It seems to be working like this.

            – John Volkya
            Apr 1 at 15:57
















          It doesn't work with a function, I get an error saying the proc is not found. If I use a proc with out parameter, the result is not set in the para[1].Value as you mention.

          – John Volkya
          Apr 1 at 12:37






          It doesn't work with a function, I get an error saying the proc is not found. If I use a proc with out parameter, the result is not set in the para[1].Value as you mention.

          – John Volkya
          Apr 1 at 12:37














          my bad, updated answer

          – DLuk
          Apr 1 at 14:03





          my bad, updated answer

          – DLuk
          Apr 1 at 14:03













          Thanks! It seems to be working like this.

          – John Volkya
          Apr 1 at 15:57





          Thanks! It seems to be working like this.

          – John Volkya
          Apr 1 at 15:57








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















          draft saved

          draft discarded















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55395359%2fcalling-a-database-stored-function-or-stored-proc-that-returns-a-value%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현