Can a procedure return a value

Can a stored procedure return a value or will that generate an error, do you have to change it to a function

You would have to make it as a OUT (IN OUT) parameter if you wanted to return something to the caller from a procedure.
SQL> create or replace procedure test_proc is
  2  begin
  3    return(0) ;
  4  end ;
  5  /
Warning: Procedure created with compilation errors.
SQL> show errors
Errors for PROCEDURE TEST_PROC:
LINE/COL ERROR
3/3      PL/SQL: Statement ignored
3/3      PLS-00372: In a procedure, RETURN statement cannot contain an
         expression
SQL>                                               

Similar Messages

  • Can F4IF_INT_TABLE_VALUE_REQUEST FM return a value in a global variable?

    Hi everybody,
    I need to use F4IF_INT_TABLE_VALUE_REQUEST FM because I have to let users select an specific option before choosing another value. The point is that I need to save in a program global variable what the user selects, and decide something with it in the program.
    Is it possible that F4IF_INT_TABLE_VALUE_REQUEST FM returns the value in a sinple variable or it has to be paramter?
    I look in a lot of previous threads but I didn't find anything, and I don't know if it's possible.
    Thanks and kind regards,
    MMP.

    Hi,
    Sure you can. All you need to do is to store what the function returns in your global variable. It don't need to be returned back to screen field.
    DATA: BEGIN OF VALUES OCCURS 0,
             CARRID TYPE SPFLI-CARRID,
             CONNID TYPE SPFLI-CONNID,
           END OF VALUES.
    DATA: VALUES_TAB TYPE TABLE OF VALUES,
              G_VALUE TYPE SPFLI-CONNID.  "global variable to store what is returned
    "in PAI first populate your table
      SELECT  CARRID CONNID
        FROM  SPFLI
        INTO  CORRESPONDING FIELDS OF TABLE VALUES_TAB
        UP TO 10 ROWS.
    "then call the function but don't return the value to screen field
    "If you specify the import parameters DYNPPROG, DYNPNR, and DYNPROFIELD, the useru2019s selection is
    "returned to the corresponding field on the screen. If you specify the table parameter RETURN_TAB, the
    "selection is returned into the table instead.
    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
           EXPORTING
                RETFIELD         = 'CONNID'
                VALUE_ORG        = 'S'
           TABLES
                VALUE_TAB        = VALUES_TAB
                RETURN_TAB      = RETURN_TAB.
    "now simply read first row of return tab and store the value returned there in some global var
    READ RETURN_TAB INDEX 1.
    MOVE RETURN_TAB-FIELDVAL TO G_VALUE.
    Regards
    Marcin

  • Can a function return two values???

    Hi guys can a function return more than values?

    Or even better return an Object.
    ie
    public class Tester{
         public static Multi getM()
              Multi m=new Multi();
              m.x="testing";
              m.y="new value";
         public static void main(String [] args)
              Multi mt=getM();
              System.out.println(mt.x);
              System.out.println(mt.y);
         class Multi{
              public String x;
              public String y;
    }

  • Can the main return a value?

    is there a way for the main to return a value?
    possible something with the concept like public static void main -> public static int main?
    (it has been tested and doesnt work)
    i would like to have the main return an integer or boolean value.
    help plz?
    rwer

    System.exit(some_number);
    doesnt work, it doesnt even compileIt does if you use it correctly. Apparently you didn't, or literally coded 'some_number' instead of taking it as an example.
    and im pretty sure System.exit is a void functionSo? It ends up setting the process's exit code, so that the caller of the process may get that value.
    I just want to know if its possible to return a value
    from the main
    changing "void main" to "int main" and having a
    return 0; something that looks like
    public static void main(String[] args) throws
    Exception {
    return 0;
    will compile but will not run, im just looking for
    ways to do this, any help would be nice...As stated before, no. But since the JVM is the one who calls main() and isn't going to do anything with such a return code, what good would it do?

  • Execute SQL Task, OLE DB, Stored Procedure, Returns unexpected value upon second run

    when debugging SSIS, the "Execute SQL Task" runs a stored procedure and returns the expected value. When running the package a second time, the task returns an unexpected value. When running in VS2012 SQL editor, everything operates as expected.
    Please help me debug how to get the stored proc to return the same value every time the SSIS Package is run. thanks!
    Here is the sequence of events and what happens....
    Look for a Positor that matches the Application, Host, and User
    No matching PositorId is found, Creates new Positor row, returns that new PositorId
    Use PositorId to upload some data (Every thing works)
    re-run/debug the ssis pacakge
    Look for a Positor that matches the Application, Host, and User 
    <No clue what is happening>
    Returns -1 (SHOULD BE the same PositorId value returned in #2)
    "Execute SQL Task" Setup: No edits to Result Set nor Expressions
    "Execute SQL Task" Setup: GENERAL
    "Execute SQL Task" Setup: PARAMETER MAPPING
    SP called by "Execute SQL Task"
    CREATE PROCEDURE [posit].[Return_PositorId]
    AS
    BEGIN
    DECLARE @PositorId INT = [posit].[Get_PositorId]();
    IF (@PositorId IS NULL)
    BEGIN
    DECLARE @ProcedureDesc NVARCHAR(257) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID);
    DECLARE @PositorNote NVARCHAR(348) = N'Automatically created by: ' + @ProcedureDesc;
    EXECUTE @PositorId = [posit].[Insert_Positor] @PositorNote;
    END;
    RETURN @PositorId;
    END;
    Supporting SQL Objects:
    CREATE FUNCTION [posit].[Get_PositorId]
    RETURNS INT
    AS
    BEGIN
    DECLARE @PositorId INT = NULL;
    SELECT TOP 1
    @PositorId = [p].[PO_PositorId]
    FROM [posit].[PO_Positor] [p]
    WHERE [p].[PO_PositorApp] = APP_NAME()
    AND [p].[PO_PositorHost] = HOST_NAME()
    AND [p].[PO_PositorUID] = SUSER_ID();
    RETURN @PositorId;
    END;
    GO
    CREATE PROCEDURE [posit].[Insert_Positor]
    @PositorNote NVARCHAR(348) = NULL
    AS
    BEGIN
    DECLARE @ProcedureDesc NVARCHAR(257) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID);
    SET @PositorNote = COALESCE(@PositorNote, N'Automatically created by: ' + @ProcedureDesc);
    DECLARE @Id TABLE
    [Id] INT NOT NULL
    INSERT INTO [posit].[PO_Positor]([PO_PositorNote])
    OUTPUT [INSERTED].[PO_PositorId]
    INTO @Id([Id])
    VALUES(@PositorNote);
    RETURN (SELECT TOP 1 [Id] FROM @Id);
    END;
    GO
    CREATE TABLE [posit].[PO_Positor]
    [PO_PositorId] INT NOT NULL IDENTITY(0, 1),
    [PO_PositorApp] NVARCHAR(128) NOT NULL CONSTRAINT [DF__PO_Positor_PO_PositorApp] DEFAULT(APP_NAME()),
    CONSTRAINT [CL__PO_Positor_PO_PositorApp] CHECK([PO_PositorApp] <> ''),
    [PO_PositorName] NVARCHAR(256) NOT NULL CONSTRAINT [DF__PO_Positor_PO_PositorName] DEFAULT(SUSER_SNAME()),
    CONSTRAINT [CL__PO_Positor_PO_PositorName] CHECK([PO_PositorName] <> ''),
    [PO_PositorHost] NVARCHAR(128) NOT NULL CONSTRAINT [DF__PO_Positor_PO_PositorHost] DEFAULT(HOST_NAME()),
    CONSTRAINT [CL__PO_Positor_PO_PositorHost] CHECK([PO_PositorHost] <> ''),
    [PO_PositorSID] VARBINARY(85) NOT NULL CONSTRAINT [DF__PO_Positor_PO_PositorSID] DEFAULT(SUSER_SID()),
    [PO_PositorUID] INT NOT NULL CONSTRAINT [DF__PO_Positor_PO_PositorUID] DEFAULT(SUSER_ID()),
    [PO_PositorNote] VARCHAR(348) NULL CONSTRAINT [CL__PO_Positor_PO_PositorNote] CHECK([PO_PositorNote] <> ''),
    [PO_tsInserted] DATETIMEOFFSET(7) NOT NULL CONSTRAINT [DF__PO_Positor_PO_tsInserted] DEFAULT(SYSDATETIMEOFFSET()),
    [PO_RowGuid] UNIQUEIDENTIFIER NOT NULL CONSTRAINT [DF__PO_Positor_PO_RowGuid] DEFAULT(NEWSEQUENTIALID()) ROWGUIDCOL,
    CONSTRAINT [UX__PO_Positor_PO_RowGuid] UNIQUE NONCLUSTERED([PO_RowGuid]),
    CONSTRAINT [UK__Positor] UNIQUE CLUSTERED ([PO_PositorApp] ASC, [PO_PositorHost] ASC, [PO_PositorUID] ASC),
    CONSTRAINT [PK__Positor] PRIMARY KEY ([PO_PositorId] ASC)
    GO
    ssd

    The error is in item 7: Returns -1 (SHOULD BE the same PositorId value returned in #2); but no error message is returned or thrown from SSIS.
    The error message indicated referential integrity is not upheld when inserting records. This error message occurs AFTER the Execute SQL Task successfully completes; the E.SQL Task returns -1.  The executed SQL code will not allow values less than 0
    ([PO_PositorId] INT NOT NULL IDENTITY(0, 1),)
    [Platts Valid [41]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E2F.
    An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 11.0"  Hresult: 0x80040E2F  Description: "The statement has been terminated.".
    An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 11.0"  Hresult: 0x80040E2F  Description:
    "The INSERT statement conflicted with the FOREIGN KEY constraint "FK__PricingPlatts_Posit_PositorId". The conflict occurred in database "Pricing", table "posit.PO_Positor", column 'PO_PositorId'.".
    The aforementioned FOREIGN KEY constraint is due to the value being returned by the Execute SQL Task.; therefore, the error lies in the value returned by the Execute SQL Task.

  • Stored procedure returning some value

    Hi All Experts,
    I have written one stored procedure which is returning different
    integer values according to condition.I am calling this
    stored procedure through prepareCall() method then executeUpdate() method ,but it is always returning 1,not my desired value.
    Pl help by writing some sample code.
    Thanx in Advance.
    Pradipto

    ....haven't u study the sql api for java?
    "either the row count for INSERT, UPDATE or DELETE statements; or 0 for SQL statements that return nothing"
    return 1 means that u update 1 row count.
    So, if u want to return the data(int) from the database, u should use query to achieve it.

  • Can java method return  multiple values

    hey , I need big favor can i return two arrays in a single function

    Not directly no.
    But there are ways around it.
    You can create a "result object" which has attributes being the two arrays, and return that object (ie wrap the arrays in another object)
    You could put the arrays into a collection (eg ArrayList/Vector) and then return that object. You can then retrieve the two arrays as the first two items in that list.
    Either of those should work, even if they are hacks ;-)
    Cheers,
    evnafets

  • Can a method return a class ?

    hi,
    i have a simple question.
    can a method return class value ?
    in the below script i did'nt understand the commented line.
    package com.google.gwt.sample.stockwatcher.client;
    import com.google.gwt.user.client.rpc.RemoteService;
    import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
    @RemoteServiceRelativePath("login")
    public interface LoginService extends RemoteService {
      public LoginInfo login(String requestUri);  //What is this ? is this a sample of what i asked ?
    }

    The answer to your question is yes.
    The idea is that an object calls a function of another object (passing in objects to the function as arguments) in which that object returns an object (note the arguments or returned value of the function may alternately be primitive types). Each object typically encapsulates data and provides a rich set of functions to the calling object so that calling object doesn't have to deal with the raw data directly. Therefore, not only does the calling object get the data it wants, but also a rich set of functions that can manipulate that data.
    Example:
    Book book = new Book();
    int characterCount = book.getChapter(3).getParagraph(4).getSentence(12).getWord(8).getCharacterCount();
    In the above, each object (Book, Chapter,Paragraph,Sentence,Word) has a rich set of functions it provides to its caller.
    Example: the Sentence Object has a collection of word objects (raw data). Functions it provides to Paragraph object are:
    Word getWord(int index), Words getWords(), int getWordCount().
    If you haven't already done so, I suggest reading a book on Java from cover to cover to pick up such Object Oriented concepts.

  • MB52 doesn't show return quantyties values

    Dear experts
    After sales return, the qty shows under 'Returns'. But in MB51, corrosponding values are not shown under any column. can anybody guide on this issue, where i can see the return qty values? or in sap, return values doesn;t show in MB51?
    Thanks
    Venugopal

    Hi,
    This looks like a bug. A workaround is to set snapInterval=.1 as well as stepSize. Could you please log a bug on https://bugs.adobe.com/flex/?
    Thanks,
    -Kevin

  • Can a procedure in select return more of 1 value

    Is it possibile write a procedure called from a SELECT that return 2 value?
    For ex:
    SELECT proc_a (par1,par2, ret1,ret2) from xtable
    where ret1 and ret2 are value returned from proc_a
    Thanks

    Well it goes something like this. However you need to remember that joining in SQL may be considerably more efficient than calling PL/SQL functions, plus you should pay attention to how many times the function actually gets called in different scenarios (I report this via a call to DBMS_OUTPUT.PUT_LINE).
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    SQL> CREATE OR REPLACE TYPE ot_dept AS OBJECT (
      2     deptno NUMBER (2),
      3     dname VARCHAR2 (14),
      4     loc VARCHAR2 (13));
      5  /
    Type created.
    SQL> CREATE OR REPLACE FUNCTION f_dept (
      2     p_deptno IN dept.deptno%TYPE)
      3     RETURN ot_dept
      4  IS
      5     o_dept ot_dept;
      6  BEGIN
      7     DBMS_OUTPUT.PUT_LINE ('f_dept (' || p_deptno || ')');
      8
      9     SELECT ot_dept (d.deptno, d.dname, d.loc)
    10     INTO   o_dept
    11     FROM   dept d
    12     WHERE  d.deptno = p_deptno;
    13
    14     RETURN o_dept;
    15  END f_dept;
    16  /
    Function created.
    SQL> SET SERVEROUTPUT ON;
    SQL> SELECT e.empno, e.ename, e.job,
      2         e.d.deptno, e.d.dname, e.d.loc
      3  FROM  (SELECT e.empno, e.ename, e.job,
      4                f_dept (e.deptno) d
      5         FROM   emp e
      6         WHERE  job = 'CLERK') e;
         EMPNO ENAME      JOB         D.DEPTNO D.DNAME        D.LOC
          7369 SMITH      CLERK             20 RESEARCH       DALLAS
          7876 ADAMS      CLERK             20 RESEARCH       DALLAS
          7900 JAMES      CLERK             30 SALES          CHICAGO
          7934 MILLER     CLERK             10 ACCOUNTING     NEW YORK
    f_dept (20)
    f_dept (20)
    f_dept (20)
    f_dept (20)
    f_dept (20)
    f_dept (20)
    f_dept (30)
    f_dept (30)
    f_dept (30)
    f_dept (10)
    f_dept (10)
    f_dept (10)
    SQL> SELECT e.empno, e.ename, e.job,
      2         e.d.deptno, e.d.dname, e.d.loc
      3  FROM  (SELECT /*+ NO_MERGE */ e.empno, e.ename, e.job,
      4                f_dept (e.deptno) d
      5         FROM   emp e
      6         WHERE  job = 'CLERK') e;
         EMPNO ENAME      JOB         D.DEPTNO D.DNAME        D.LOC
          7369 SMITH      CLERK             20 RESEARCH       DALLAS
          7876 ADAMS      CLERK             20 RESEARCH       DALLAS
          7900 JAMES      CLERK             30 SALES          CHICAGO
          7934 MILLER     CLERK             10 ACCOUNTING     NEW YORK
    f_dept (20)
    f_dept (20)
    f_dept (20)
    f_dept (20)
    f_dept (30)
    f_dept (10)
    SQL> CREATE OR REPLACE TYPE ntt_dept AS TABLE OF ot_dept;
      2  /
    Type created.
    SQL> SELECT e.empno, e.ename, e.job,
      2         d.deptno, d.dname, d.loc
      3  FROM   emp e, TABLE (ntt_dept (f_dept (e.deptno))) d
      4  WHERE  e.job = 'CLERK';
         EMPNO ENAME      JOB           DEPTNO DNAME          LOC
          7369 SMITH      CLERK             20 RESEARCH       DALLAS
          7876 ADAMS      CLERK             20 RESEARCH       DALLAS
          7900 JAMES      CLERK             30 SALES          CHICAGO
          7934 MILLER     CLERK             10 ACCOUNTING     NEW YORK
    f_dept (20)
    f_dept (20)
    f_dept (30)
    f_dept (10)
    SQL>

  • Can we use return statement in procedure?

    Can we use return statement in procedure or we can use more than one return statement in procedure?

    HamidHelal wrote:
    NOReally? Did you at least test it? You can use RETURN in procedure or in anonymous PL/SQL block. The only restriction is you can't specify return value:
    SQL> begin
      2      dbms_output.put_line('Before return');
      3      return;
      4      dbms_output.put_line('After return');
      5  end;
      6  /
    Before return
    PL/SQL procedure successfully completed.
    SQL> create or replace
      2    procedure p1
      3      is
      4      begin
      5          dbms_output.put_line('Before return');
      6          return;
      7          dbms_output.put_line('After return');
      8  end;
      9  /
    Procedure created.
    SQL> exec p1;
    Before return
    PL/SQL procedure successfully completed.
    SQL> begin
      2      dbms_output.put_line('Before return');
      3      return 99;
      4          dbms_output.put_line('After return');
      5  end;
      6  /
        return 99;
    ERROR at line 3:
    ORA-06550: line 3, column 5:
    PLS-00372: In a procedure, RETURN statement cannot contain an expression
    ORA-06550: line 3, column 5:
    PL/SQL: Statement ignored
    SQL> create or replace
      2    procedure p1
      3      is
      4      begin
      5          dbms_output.put_line('Before return');
      6          return 99;
      7          dbms_output.put_line('After return');
      8  end;
      9  /
    Warning: Procedure created with compilation errors.
    SQL> show err
    Errors for PROCEDURE P1:
    LINE/COL ERROR
    5/9      PL/SQL: Statement ignored
    5/9      PLS-00372: In a procedure, RETURN statement cannot contain an
             expression
    SQL> SY.

  • SOAP TO JDBC scenario: calling stored procedure which will return the value

    Hi
    I have Soap To Jdbc scenario in which I am going to call the Stored Procedure at target side which will be executed and it is going to return the result set .
    Result contains following values.
    return code as ( 0 Or 1) and also specific exception message if its return code as 1.
    Could you suggest me the way by which I can handled this return code and send it back to the Sap PI system then the same thing is directed the to SMTP server for sending mail to consern person.
    Regards
    Kumar

    The OUT parameters of stored procedure will be returned as response. Where exactly are you facing the proble? Here is a complete walkthourgh
    /people/luis.melgar/blog/2008/05/13/synchronous-soap-to-jdbc--end-to-end-walkthrough
    In your case, you don't want response at sender. Instead you want to mail it. For this you may use BPM to design your scenario with following steps
    Receive (to receive data from sender)
    Send Sync (to stored procedure and get response)
    Send Async (to mail receiver)
    Regards,
    Prateek

  • Can oracle  function return more than one value

    Hi All
    please answer can oracle function return more than one value
    need one schenario
    regards

    Can any function, irrespective of the language, return multiple values?
    OF COURSE NOT!!
    So why do you think Oracle will now suddenly do it differently than all other languages? Never mind that it is impossible for a function (a unit/module of code) returning a memory address, to return multiple memory addresses. The machine code that does that, has not been yet been designed/implemented.
    I am continually amazed that this question is asked. It is about something so fundamental in almost every single 3rd and 4th generation language... something that is taught right at the start... the definition of what a procedure and what a function is.
    Sorry, but I simply cannot pull punches on this subject and smooth it over. There is something fundamentally wrong with your training as a programmer if you have to ask such a question about a function.
    And whatever programming skills you build on such a foundation, will be seriously lacking.
    I kindly suggest that you get back to the very basics of programming - and review and revisit until you fully understand it. There are no shortcuts in becomming a good programmer.
    Message was edited by:
    Billy Verreynne

  • Can be passed Formula Column value to Procedure/Function?

    Below cf_value is return after some calculation by using main query.
    Can be directly passed formula column value to procedure without assinged to placeorder?
    as below..
    f_convert(:cf_value,new_value);
    My Procedure is...
    PROCEDURE f_convert( val1 in number,val2 in out number) IS
    BEGIN
    val2 := val1 * 100;
    END;
    If anyone knows pls reply me....

    Actually, if there is any other calculations there (In Proceudre)
    Can I used is as below??
    PROCEDURE f_convert( val1 in number,val2 in out number) IS
    BEGIN
    val2 := val1 * 100;
    return (val2);
    END;
    ----A procedure cannot return a value, the return clause in my previous post was part of the function for formula column.
    Suppose you have a formula column say CF_2 then the function for it will be as:
    function cf_2formula return number
    is
    val1 number;
    val2 number;
    begin
    val2 := :cf_1 * 100; -- or val2 := val1 * 100 --parameters not allowed in formula column function
    -- All the other code that you need inclusive of calling function, procedure as in any PL/SQL block can be placed
    return (val2);
    end;So any other calculation can be used in the formula column function

  • Call plsql procedure from ADFBC which returns a value.

    Hi All,
    I want to call one of my SQL Procedures which returns 4 values after execution from my AMImpl file.
    The code snippet on how I am trying to call the procedure is below, but I am in need of how to fetch the return value of the procedure once its executed.
    public void callPlSql(String firstParm, String secondParm) {
    CallableStatement s = this.getDBTransaction().createCallableStatement("BEGIN my_pl_sql_procedure(?, ?); END;", 0);
    try {
    s.setString(1,firstParm);
    s.setString(2,secondParm);
    s.execute;
    } catch (SQLException e) {
    throw new JboException(e);
    any idea how to get hold of the return values from the executed procedure ?
    Thanks
    TK

    after you executed the procedure, you can get the output based on their type and index
    public void callPlSql(String firstParm, String secondParm) {
    CallableStatement s = this.getDBTransaction().createCallableStatement("BEGIN my_pl_sql_procedure(?, ?); END;", 0);
    try {
    s.setString(1,firstParm);
    s.setString(2,secondParm);
    s.execute;
    e.getDate(index of your output);
    e.getInt(index of your output);
    e.getString(index of your output);
    } catch (SQLException e) {
    throw new JboException(e);
    }you can also check this:
    http://download.oracle.com/docs/cd/E15523_01/web.1111/b31974/bcadvgen.htm#sm0458

Maybe you are looking for

  • Photoshop von 2. Monitor verschieben

    Hallo zusammen, ich bin relativ neu mit der CC Version. Bin von CS4 umgestiegen. Ich arbeite eigentlich an einem iMac 27" und habe gerade mein Photoshop vom iMac auf meinen 2. Monitor (DELL 2709W) verschoben. "Leider" hat der DELL nur eine Auflösung

  • Acrobat 7 Pro

    I am having activation problems with Acrobat 7 Professional.  After trying to activate by phone, I got a recording to download an activation-free version.  There is not one listed for the Pro version, just the standard version.  What do I need to do?

  • How to use SD_SHIPMENT_PROCESS to PACK deliveries into a HU?

    We are trying to duplicate the functionality behind the "Pack" button in the shipping document (vt03n) using the SD_SHIPMENT_PROCESS function module to associate deliveries to a handling unit.  Has anyone had experience with which structure need to b

  • CF MX 7 Standard Edition

    We're using Windows 2003 Server for both a SQL server 2000 database and a seperate ColdFusion MX 7 webserver. I created an odbc connection on the webserver but when I try to add the ODBC socket connection inside the ColdFusion Administrator page unde

  • HI,How can i set delta option for costumised Generic data source

    Hi Sir/Madam,       How can i set delta option for costumised Generic data source. Regards, Vishali.R Please search the forum before posting a thread Edited by: Pravender on Aug 15, 2011 1:26 PM