How to return a value from stored procedure.

Hello

I have an insert in which insert a username through generated sequence number.

I need this generated sequence number stored procedure return.

Kindly help me to achieve this goal.

It might be useful if there is a code sample for the same thing.

Thank you
Ahmed Shareefuddin

Something like this:

create or replace procedure xproc (num out number) is
begin
 insert into mytab values (myseq.nextval);
 select myseq.currval into num from dual;
end;
/

Max
http://oracleitalia.WordPress.com

Tags: Database

Similar Questions

  • ORA-06565: cannot run the ROLE VALUE from stored procedures

    Hello!

    I'm trying to call a procedure from a function. Among the statements in the procedure stored is of dbms_session.set_role ('HAVE');

    I get the error "Cannot run a DEFINED ROLE less stored proceduers". I joined the call in an anonymous block above, but the error still exists.

    Any idea will really help me.

    Thank you

    >
    I'm trying to call a procedure from a function. Among the statements in the procedure stored is of dbms_session.set_role ('HAVE');

    I get the error "Cannot run a DEFINED ROLE less stored proceduers". I joined the call in an anonymous block above, but the error still exists.

    Any idea will really help me.
    >
    This will work only if the procedure is defined for the APPELLANT's rights.

    Roles are disabled in named PL/SQL blocks unless you use of the APPELLANT's rights by setting the code with AUTHID CURRENT_USER.

    The Oracle documentation provides a very clear explanation - based restriction is for the NAMED PL/SQL blocks rights DEFINER of this use (the default):
    >
    Roles used in the appointed with rights to define blocks

    All roles are disabled in any PL/SQL block named (stored procedure, function, or trigger) that runs with the rights of the author. Roles are not used to privilege control, and you cannot define roles within the procedure of a DEFINER rights.
    >
    The database Security Guide has the information in the section "operation of the roles in PL/SQL blocks (which, of course, wouldln was necessary if they didn't work.).
    http://docs.Oracle.com/CD/B28359_01/network.111/B28531/authorization.htm#i1007304
    >
    The use of roles in a PL/SQL block depends on if it is an anonymous block, or a block named (stored procedure, function, or trigger), and if it runs with the rights of the author or the rights of the applicant.

    Roles used in the appointed with rights to define blocks
    All roles are disabled in any PL/SQL block named (stored procedure, function, or trigger) that runs with the rights of the author. Roles are not used to privilege control, and you cannot define roles within the procedure of a DEFINER rights.

    The SESSION_ROLES view shows all roles that are currently enabled. If a named PL/SQL block that runs with DEFINER SESSION_ROLES rights issues, the query returns no rows.

    See also:

    Oracle database reference

    Roles used in blocks named with the rights of the plaintiff and anonymous PL/SQL
    Named PL/SQL blocks that run with the rights of the applicant and the anonymous PL/SQL blocks are executed at the end of the privileges granted through active roles. Current roles are used for verification within rights Summoner of privilege the PL/SQL block. You can use dynamic SQL statements to define a role in the session.

  • Return a value from a procedure at the apex

    Hello

    I am running a procedure that has a flag of return if the procedure correctly a command I send to him, I do something like that to call the procedure in the process of the apex


    Declare
    x NUMBER;
    BEGIN
    APEX_SCHEMA. EXECUTE_CREATE_ITEM ("asd", x);


    DBMS_OUTPUT. PUT_LINE ('OUTPUT :'|| x);

    END;


    can I return to the apex of the variable x to display it in the message of success or error of the process?

    Tanks

    You can use
    apex_application.g_print_success_message: = x;
    or
    apex_application.g_notification: = x;
    in your process of PL/SQL

  • Return multiple values from a table

    Hi there I'm working on a bit of sql that returns values when they exist in a table.
    The code I have returns the correct value when there is an entry in the tbl_studentmodules table, as soon as there is more than one entry in this table it does display no line at all: (.)

    Can someone tell how to return multiple values?

                 select modulename from tbl_modulefeedback
    where 1 = (select count(*) from tbl_studentmodules
           where upper(:APP_USER) = upper(student_id))
    and 1 = (select count(*) from tbl_modulefeedback, tbl_studentmodules
          where tbl_modulefeedback.modulecode = tbl_studentmodules.modulecode)
    Thanks in advance!

    Ashleigh

    Try this:

    select modulename
    from tbl_modulefeedback
    where 1 <= (select count(*) from tbl_studentmodules
           where upper(:APP_USER) = upper(student_id))
    and 1 <= (select count(*) from tbl_modulefeedback, tbl_studentmodules
          where tbl_modulefeedback.modulecode = tbl_studentmodules.modulecode)
    

    When you ask questions, please enter CREATE TABLE and INSERT some commands to make it easier to help you.

  • How to create temporary tables in stored procedures.

    Hello

    I am new to oracle, I have a requirement where I need to run a query in a loop for different values of where condition. Here, I need to record the results of the query on each iteration. After the end of the loop, I need to send the results to the front end. I did a lot of research for the concept of the temporary table in oracle, but I found myself unresolved except headaches. Everyone is showing how to create temporary tables in general but not in stored procedure.

    Bad, I need the concept of temporary tables, or is there an alternative way to store temporary results. My procedure looks like this.

    create or replace
    procedure uspMatchCode (parWord varchar2, p_recorderSet to types.cursor_type)
    as
    smallint parCnt;
    Start
    parcnt: = 0;
    Select count (1) in parCnt of...;
    If parcnt > 0 then
    Open for P_recorderSet
    Select field1, field2, field3,... of table1, table2, table2 where < < condition > >
    on the other
    -Here, I want to create a temporary table and store the result for the loop shape into the temporary table.
    CREATE TEMPORARY TABLE global my_temp_table (NUMBER of Column1, Column2) ON COMMIT DELETE ROWS.
    FOR parCnt in 0.3
    loop
    INSERT into my_temp_table select Field1, Field2, field3,... from table1, table2, table2 where < < condition > >
    end loop;
    Open for P_recorderSet
    Select * from < < temporary table > >
    end if;
    end;

    Any help would be great to check me on the problem.

    Thank you
    Kiran.

    This is a change to the query Kiss has posted:

    with data_text like)
    Select regexp_substr (' sales financing marketing ',' [^] +', 1, level ") val
    of tconnect by level<= length('sales="" finance="" marketing')-="" length(replace('sales="" finance="" marketing','="">
    )
    Select * from t, data_text, where t.colname like '% "| data_text. Val |' %'

    This will help you. Please change the column names and the name of the table as a result

  • How to compare a value from array in an if statement

    When I compare cdlCorrect [index] 0, it displays true, but when I draw it, it 2.

    The if statement seems to be comparing the index itself to 0. How can I compare the value. In fact, as I continue to call this function (by clicking on the button), it always compares to 0, but the trace will return as 2, then 1, then 2, then 0, then 0. I think I'm getting the index, but then they must compare to 0, then 1, then 2, etc. I do not understand why it always compares to zero.

    function chkAnswer(mevt:MouseEvent):void {}

    cdlDone [index] = 1;

    var rectSize:uint = 300;

    var correctRect:Shape = new Shape();

    correctRect.graphics.beginFill (0x00FF00, 0.5);

    if (cdlCorrect [index] == 0) {}

    correctRect.graphics.drawRect (45, 40, rectSize, 30);      Address: 45:x 120:y rectSize:width 50:height

    trace ("this is 0");

    }

    If (cdlCorrect [index] == 1) {}

    correctRect.graphics.drawRect (45, 80, rectSize, 30);      Address: 45:x 120:y rectSize:width 50:height

    trace ("it is 1");

    }

    If (cdlCorrect [index] == 2) {}

    correctRect.graphics.drawRect (45, 80, rectSize, 30);      Address: 45:x 120:y rectSize:width 50:height

    trace ("this is 2");

    }  

    trace (cdlCorrect [index]);        2  

    trace (cdlCorrect);                  2,1,2,0,0

    }

    If you read the values from an xml file then you need to convert them into numbers, or you need to test them as strings.

    try changing

    If (cdlCorrect [index] == "0") {}

    and similarly for the other institutions

  • How to return the value 0 for no data using the County?

    Hi all
    I used this query to count the number of records for each month of the year:

    SELECT DISTINCT COUNT (I.information_sid) COUNT, TO_DATE (TO_CHAR (INSERT_DATE, 'MM'), 'MM') MONTH

    INFORMATION I

    TO_DATE GROUP (TO_CHAR (INSERT_DATE, 'MM'), 'MM')

    ORDER BY TO_DATE (TO_CHAR (INSERT_DATE, 'MM'), 'MM')

    But this code returns no value for months without data
    I want to return the value '0' for any month of data. How, please?

    Note: I use reports 6i.

    Maybe this?

    SELECT SUM(CNT_REC) CNT_REC, MONTH
    FROM
    (
    SELECT COUNT(I.information_sid) CNT_REC, TO_DATE(TO_CHAR(INSERT_DATE,'MM'),'MM') MONTH
    FROM INFORMATIONS I
    GROUP BY TO_DATE(TO_CHAR(INSERT_DATE,'MM'),'MM')
    UNION ALL
    SELECT 0, LPAD(ROWNUM,2,0)
    FROM ALL_OBJECTS
    WHERE ROWNUM <= 12
    )
    GROUP BY MONTH
    ORDER BY MONTH
    

    No need to SEPARATE during the use of GROUP BY.

    -Clément

  • Return multiple values from a function in a SELECT statement

    I hope I've provided enough information here. If not, let me know what I'm missing.

    I create a view that will combine the information from several tables. Most are pretty simple, but there are a couple of columns in the view that I need to get by running a function within a package. Even if this is quite simple (I have a function named action_date in a package called rp, for example, that I can use to return the date that I need through SOME rp.action_date (sequence_number).

    Here is the question: I really need to return several bits of information of the same record (not only action_date, but also action_office, action_value, etc.)-a join of the tables will work not here, as I will explain below. I can, of course, perform a function separate for each statement, but this is obviously inefficient. Within the select statement of the view, however, I don't know how each of the values that I need to get back.

    For example, right now, I have:

    Table 1:
    sequence_number NUMBER (10),
    name varchar (30),
    ...

    Table2:
    Table1_seq NUMBER (10),
    action_seq NUMBER (10),
    action_date DATE,
    action_office VARCHAR (3),
    action_value VARCHAR (60),
    ...

    I can't just simply join Table1 and Table2 because I have to perform processing in order to determine the rows returned matching, I really need to select. If the package opens a cursor and treats each line until it finds the one I need.

    The following works but is ineffective since all calls to the package returns the columns of the same record. I don't know how to put all the values that I need in the SELECT statement.
    CREATE VIEW all_this_stuff AS
    SELECT sequence_number, name,
    RP.action_date (sequence_number) action_date,
    RP.action_office (sequence_number) action_office,
    RP.action_value (sequence_number) action_value
    FROM table1

    Is there a way to return multiple values in my SELECT statement or I'm going about this all wrong?

    Any suggestions?

    Thank you very much!

    Hello

    What you want is a Query of Top - N , what you can do using the ROW_NUMBER analytic function in a subquery, like this:

    WITH     got_rnum     AS
    (
         SELECT     action_seq, action_dt, action_office, action_type, action_value
         ,     ROW_NUMBER () OVER ( ORDER BY  action_date
                                   ,            action_seq
                             ,            action_serial
                           ) AS rnum
         FROM     table2
         WHERE     action_code     = 'AB'
         AND     action_office     LIKE 'E'     -- Is this right?
    )
    SELECT     action_seq, action_dt, action_office, action_type, action_value
    FROM     got_rnum
    WHERE     rnum     = 1
    ;
    

    As written, this returns a single line (at most).
    I suspect you'll actually get a rank for each group , where a group is defined by a value in a table in which you join.
    In this case, add a PARTITION BY clause to the ROW_NUMBER function.
    If post you a small example of data (CREATE TABLE and INSERT statements), I could show you exactly how.
    As I don't have your tables, I'll show you the use of the tables in the scott schema.
    This is a view containing data in the scott.dept table and also to scott.emp, but only for the highest employee in each Department (in other words, the employee whose oldest hire date). If there be a tie for the first hire date, while the candidate with the lowest empno is selected.

    CREATE OR REPLACE VIEW     senior_emp
    AS
    WITH     got_rnum     AS
    (
         SELECT     d.deptno
         ,     d.dname
         ,     e.empno
         ,     e.ename
         ,     e.hiredate
         ,     ROW_NUMBER () OVER ( PARTITION BY  d.deptno
                                   ORDER BY          e.hiredate
                             ,                e.empno
                           ) AS rnum
         FROM     scott.dept     d
         JOIN     scott.emp     e     ON     d.deptno     = e.deptno
    )
    SELECT     deptno
    ,     dname
    ,     empno
    ,     ename
    ,     hiredate
    FROM     got_rnum
    WHERE     rnum     = 1
    ;
    
    SELECT     *
    FROM     senior_emp
    ;
    

    Output:

    .    DEPTNO DNAME               EMPNO ENAME      HIREDATE
    ---------- -------------- ---------- ---------- ---------
            10 ACCOUNTING           7782 CLARK      09-JUN-81
            20 RESEARCH             7369 SMITH      17-DEC-80
            30 SALES                7499 ALLEN      20-FEB-81
    

    Moreover, one of the conditions to the query you posted has been

    action_office     LIKE 'E'
    

    which equals

    action_office     = 'E'
    

    (AS is always equivalent to = if the string that follows AS does not contain the winning cards.)
    Did you mean say that or did you mean something like this:

    action_office     LIKE 'E%'
    

    Instead?

  • How to return two values of a function?

    Hi all
    I have a function which returns a varchar2 value. This value is used in the SQL of a ref cursor

    Now I want this function returns two values. I tried to use varray, but could not accomplish the task.

    Can you tell me how can I find the two values from a function? and how this function can be called in a SQL query?

    Thank you very much

    The query should look like:

    SELECT v.col.name AS name
         , v.col.flag AS flag
    FROM   ( SELECT kk_test_kk(t.somecolumn,t.someothercolumn,42) AS col
             FROM   sometable t ) v;
    

    Note that you need to prefix with the name of view inline ('v' in the example) and the expression of the function ('col' in the example).

  • How can I automatically run a stored procedure when a report is called?

    I've created a classic report on a table (without screen). When I go to this report, I would like to the stored procedure that deletes and inserts information about the table that is based on the report has been started automatically. Where and how can I do to put the call to the stored procedure that the report displays the data once the report is called?

    Thank you!

    Mark1970 wrote:

    I've created a classic report on a table (without screen). When I go to this report, I would like to the stored procedure that deletes and inserts information about the table that is based on the report has been started automatically. Where and how can I do to put the call to the stored procedure that the report displays the data once the report is called?

    Create a page of PL/SQL process by calling the procedure with a Point process On Load - front of regions.

    The report is based on a global temporary table?

  • How to edit or change a stored procedure?

    I created a stored procedure with the name getRecords 1 months ago


    I want to change this getRecords of stored procedure

    Please tell me how to change the stored procedure

    So what you would do is

    Starting sqldeveloper, connecting as the owner of the procedure.
    In the tree list, expand the entry procedures.
    You will see all the procedures in this scheme.
    Double-click the procedure that you want to modify, and a window opens with the source code.

    -----------
    Sybrand Bakker
    Senior Oracle DBA

  • Transfer a value from a procedure at the apex

    Hello

    I have a login procedure where I check the status of the user.
    at the moment only through dbms_output.put_line status.

    Now I want to transfer this status to apex - how can I do this?
    If I have for example an element of application for the State, how can I assign the status at this point?

    Thank you
    Lena

    Published by: Lena F March 7, 2011 06:15

    If you want to set the element from the procedure directly, you can use the APEX_UTIL. SET_SESSION_STATE function (a session valid apex)

    You could call it after authentication or Application process that runs when a new session is created

  • How to execute a pl/sql stored procedure as a concurrent program

    Hi all


    I created a PURGE_DEAL_REQUESTS package. It contains a QPR_DELETE_CANCELLED_REQUESTS procedure. I want to execute this stored procedure as simultaneous program in suite ebs...

    Can someone tell me how to perform this procedure as a simultaneous program (in the suite of BSE)...?


    Thank you
    Swathi.

    Switch to the responsibility at the request of the group to which you assigned the request of Conurrent.
    Navigate to view > query > submit a new request to the toolbar.

    Kind regards
    Ousseni

  • How to read a value from a cell in a row

    Hello;

    I need the name of a function that is able to read a value from a cell in a row. the line contains multiple values.

    If you can post for me, I grow


  • Y at - it a syntax better/more runs to get data to and from stored procedures?

    To test the stored procedure call, I created a simple package

    create or replace package TEST_PROCEDURES as
    
    procedure Test1 (
       arg1 in number,
       arg2 in number,
    
       res1 out number,
       res2 out number);
    
    end;
    
    

    and a page with fields number four (P1_INPUT_2, P1_OUTPUT_1, P1_INPUT_1, P1_OUTPUT_2) and a button excuting the code following PL/SQL:

    declare
      arg1 integer;
      arg2 integer;
      res1 integer;
      res2 integer;
    begin
      arg1 := :P1_INPUT_1;
      arg2 := :P1_INPUT_2;
    
      TEST_PROCEDURES.Test1(arg1, arg2,
                            res1, res2);
                        
      APEX_UTIL.SET_SESSION_STATE('P1_OUTPUT_1', res1);
      APEX_UTIL.SET_SESSION_STATE('P1_OUTPUT_2', res2);
    end;
    
    

    It works, but it looks like a lot of unnecessary code to me. Any suggestions?

    TryingAPEX wrote:

    To test the stored procedure call, I created a simple package

    create or replace package TEST_PROCEDURES as

    procedure (Test1

    in number arg1,

    arg2 in number,

    RES1 number,

    Res2 number);

    end;

    and a page with fields number four (P1_INPUT_2, P1_OUTPUT_1, P1_INPUT_1, P1_OUTPUT_2) and a button excuting the code following PL/SQL:

    declare

    whole arg1;

    Whole arg2;

    integer res1.

    whole Res2;

    Start

    arg1: =: P1_INPUT_1;

    Arg2: =: P1_INPUT_2;

    TEST_PROCEDURES. Test1 (arg1, arg2,

    RES1, res2);

    APEX_UTIL. SET_SESSION_STATE ('P1_OUTPUT_1', res1);

    APEX_UTIL. SET_SESSION_STATE ('P1_OUTPUT_2', res2);

    end;

    It works, but it looks like a lot of unnecessary code to me. Any suggestions?

    Why would you do that? APEX may be referenced in the same way as all the other bind variables (although it is worth noting that their type is always VARCHAR2, so in this case, it will rely on the implicit conversion):

    begin
      test_procedures.test1(:p1_input_1, :p1_input_2, :p1_output_1, :p1_output_2);
    end;
    

    For the previous discussion on this topic, see set manually with PL/SQL session state .

    Always advanced postal code using the functionality of the syntax highlighted in the editor.

Maybe you are looking for

  • App note make random text in links

    Random text (spontaneously) turned into links (see screenshot) in the Notes application. More info Sometimes I remove links (individually), but the other links will reappear later. Some good links (for example, turning a url into a link, turning a da

  • Problem with my Qosmio G40 - 10F BIOS

    Hello I m desperate I need access to my computer before Wednesday or I could lose my job. I installed an SSD that went well. I adjusted the BIOS settings and now my computer will not boot. He goes to logo Qosmio and logos of hard drives USB etc and c

  • Is iCloud duplication pictures library after I moved it?

    Why iCloud download my entire library once I moved to its location? I just moved my library of Photos on an SD card that is I installed on my Mac after following these instructions--> How can I move my library of photos on an external drive? I agree

  • Having problems all the time trying to use MSN, just get a series of announcements

    These ads I seem unable to get rid of, usually are advertising job, or offer free cameras etc. I usually finish which for Skype where I don't have the same problem

  • Impossible to update KB2656353 & 2656370 KB

    Whenever I connect I asked windows update Despite many efforts, I am unable to update KB2656353 and 2656370 KB Advised failed every time Similar experiences / solutions?