Procedure which returns value

Well! Simply I want, to write procedure which will insert or updates (is dependent from ID if ID <=0 then there is an insert otherwise updating) the information of the Student, and returns it's ID....... how I can write procedure like this???
is this procedure correct ???
create or replace procedure sp_InsertUpdate_T_STUDENT
nResID out NUMBER,
nID in NUMBER,
vchNAME in VARCHAR2,
vchSURNAME in VARCHAR2,
nAGE in NUMBER,
nCNAUTHORID in NUMBER
as
begin
if nID<=0 then
insert into T_STUDENT (NAME,SURNAME,AGE,CNAUTHORID) values (vchNAME,vchSURNAME,nAGE,nCNAUTHORID );
else
update T_STUDENT set NAME=vchNAME,SURNAME=vchSURNAME,AGE=nAGE,CNAUTHORID=nCNAUTHORID
where ID=nID;
end if;
select ID into nResID from T_STUDENT where NAME=vchNAME and
SURNAME=vchSURNAME and AGE=nAGE and CNAUTHORID=nCNAUTHORID;
end;

is this procedure correct ???Does it work?
You might change the insert logic so that it uses a RETURNING clause to set nResID as part of the insert, instead of doing it later.

Similar Messages

  • Calling a stored procedure which returns a value

    Hi Friends,
    I want to call a stored procedure which returns a value.
    Eg
    create or replace procedure xyz(a1 in varchar2, a2 in varchar2, z1 out number)
    thanks

    Hi,
    use this.
    declare
    retval number;
    begin
    abc('aaa','bbb',retval);
    dbms_output.put_line('retval is ' ||retval);
    end;
    --Basava.S                                                                                                                                                                                                                                                                                               

  • To_date function in procedure which returns a cursor type

    Hi All
    When i execute the following query ,it runs fine and i get required result also
    select *from a where adate>to_date('31-dec-2001')
    But When i use the same query in a procedure which returns a cursor i get a error
    "non numeric character was found where a numeric value was expected".
    Then i changed the query to
    select *from a where adate>to_date('31-dec-2001','dd-mon-yyyy') and it worked fine.
    As i know default date format is 'dd-mon-yyyy' and no need to give the date format
    explicitly in to_date function if the date(string) is in default format.
    Can any body tell me the reason behind it?
    Thanks
    Satya

    Given a comparison between a date and a string Oracle will convert the string to a date. This means that if you have an index on a string column and compare it to a date the index will not be available, but if you have an index ona date column and compare it to a string column the index will be available.
    create table t (string varchar2(30), d  date);
    insert into t values (to_char(sysdate), sysdate);
    commit;
    create index t_n1 on t(string);
    create index t_n2 on t(d);
    SQL> set autotrace traceonly
    SQL> select /*+ index t_n1 */
      2         *
      3    from t
      4   where string = sysdate;
    no rows selected
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE
       1    0   TABLE ACCESS (FULL) OF 'T'
    SQL> select /*+ index t_n2 */
      2         *
      3    from t
      4   where d = to_char(sysdate);
    no rows selected
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE
       1    0   TABLE ACCESS (BY INDEX ROWID) OF 'T'
       2    1     INDEX (RANGE SCAN) OF 'T_N2' (NON-UNIQUE)
    SQL>

  • How to test a procedure which returns a recordset from pl/sql

    hello,
    Is it possible to test a procedure which returns a recordset from pl/sql?
    Everything I try results in errors like PLS-00382: expression is of wrong type, when I try to open the result cursor
    or PLS-00221: tc is not a procedure or is undefined.
    I created the following procedure:
    CREATE OR REPLACE PACKAGE test AS
    TYPE cursorType is REF CURSOR;
    PROCEDURE test_cursor( tc IN OUT cursorType,
    v_err OUT varchar2,
    v_msg OUT varchar2);
    END;
    CREATE OR REPLACE
    PACKAGE BODY test AS
    PROCEDURE test_cursor
    (tc IN OUT cursorType,
    v_err OUT varchar2,
    v_msg OUT varchar2)
    AS
    BEGIN
    open tc for
    SELECT '1' "number" FROM dual
    union
    select '2' "number" from dual;
    v_msg := 'no errors';
    v_err := 0;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    v_msg := 'no data found';
    v_err := SQLCODE;
    WHEN OTHERS
    THEN
    v_msg := SQLERRM;
    v_err := SQLCODE;
    END;
    END;
    I try to get the output from pl/sql with something like this:
    DECLARE
    TC PROVGRON.TEST.cursorType;
    V_ERR VARCHAR2(200);
    V_MSG VARCHAR2(200);
    BEGIN
    V_ERR := NULL;
    V_MSG := NULL;
    PROVGRON.TEST.TEST_CURSOR ( TC, V_ERR, V_MSG );
    DBMS_OUTPUT.Put_Line('V_ERR = ' || V_ERR);
    DBMS_OUTPUT.Put_Line('V_MSG = ' || V_MSG);
    -- in tc I was hoping to hava a cursor??
    FOR i IN tc
    LOOP
    DBMS_OUTPUT.PUT_LINE (i.number);
    END LOOP;
    END;
    Without the for loop (or open tc) the pl/sql will output:
    V_ERR = 0
    V_MSG = no errors
    PL/SQL procedure successfully completed.
    With anything I try with the cursor I get errors?
    What am I doing wrong?

    http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch5.htm#sthref1122

  • Test a procedure which returns a sys_refcursor

    Hi all,
    Oracle 9i
    Got a simple stand alone procedure which has an input param and an output param, the second of which
    is a ref cursor.
    Can anyone tell me how I can go about testing this from within Pl/SQL (Command line)?
    CREATE OR REPLACE PROCEDURE "LOGMNR"."LM"
    (p_filename in varchar2, p_recordset OUT SYS_REFCURSOR)
    as
    begin
    begin
    dbms_output.put_line('Hello World');
    OPEN p_recordset FOR
    SELECT *
    FROM test_table;
    end;
    end LM;
    Also, and I know this is a huge long-shot. I'm going to be calling this procedure from VB6 (yes I know!), via ADODB, but I'm not
    sure what type to add for the second parameter. Anyone called an Oracle procedure with ADODB which returns a refcursor/result set?
    cmd.Parameters.Append cmd.CreateParameter("p_filename", adVarChar, adParamInput, 255, "c:\test.dat")
    cmd.Parameters.Append cmd.CreateParameter("p_recordset", *???*, adParamOutput, 6000, "")
    Regards
    Dave

    Why don't you just use sqlplus as already suggested
    Re: Test a procedure which returns a sys_refcursor
    SQL> var c refcursor
    SQL> begin
      2      open :c for
      3          select * from
      4              (
      5              select * from all_tab_comments
      6              where owner = 'SYS'
      7              order by (length(comments)) desc nulls last
      8              )
      9          where rownum <= 3;
    10  end;
    11  /
    PL/SQL procedure successfully completed.
    SQL> print c
    OWNER                          TABLE_NAME                     TABLE_TYPE  COMMENTS
    SYS                            USER_AUDIT_OBJECT              VIEW        Audit trail records for statements concerning objects, specificall
    y: table, cluster, view, index, sequence,  [public] database link, [public] synonym, procedure, trigger, rollback segment, tablespace, role,
    user
    SYS                            ALL_JAVA_DERIVATIONS           VIEW        this view maps java source objects and their derived java class ob
    jects and java resource objects  for the java class accessible to user
    SYS                            USER_JAVA_DERIVATIONS          VIEW        this view maps java source objects and their derived java class ob
    jects and java resource objects  for the java class owned by user
    SQL>* Interesting how two out of three of the wordiest comments relate to java.

  • How in ColdFusion with in variables get a Oracle stored procedure to return values?

    How in ColdFusion with in variables get a Oracle stored procedure to return values?
    We have tried several things, we can get  a stored procedure to return a result set if we are not passing in variables but we cannot get them when we are passing in variables.
    We know how to do it calling  MS SQL.
    Thanks for any help,
    Nathan Sr
    P.S. we have heard this may not be possible with the current Oracle Driver is there a different Oracle driver?

    I can only barely understand what you're asking here (not from a technical perspective, but from understanding your written English), but I suspect you're wanting to know how to pass back values other than recordsets from Oracle?
    You should be able to pass them back via a type=out proc param, shouldn't you?
    If you could reword your post so it's a bit more coherent, and possibly post some code, that might help.
    Adam

  • Calling Stored Procedure which returns single or multiple 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 also tell me,if my stored procedure returns more than one value
    then how will i get those values in my java program?
    Pl help by writing some sample code.
    Thanx in Advance.
    Pradipto

    1) Create CallableStatement
    2) For each of returning value you have to call RegisterOutParameter()
    3) For others user setXXX() method depending on type of parameter
    4) call
    5) use vars registered through RegisterOutParameter() - all your values should be there
    Pavel

  • Procedure which return multiple values

    Hi
    I want to create 1 procedure which will return multiple id's and sub id's for 1 emp id.
    like
    Emp ID Id Sub Id
    100 1 1
    100 1 3
    Now I want to create a procedure where i will pass 100 and it will return as out parameter 1,1 and 1,3.
    Pls help.
    Thanks
    Regards
    Anant

    Or if you prefer a function to a procedure, you can use a pipelined function...
    CREATE OR REPLACE TYPE myrec AS OBJECT
    ( col1   VARCHAR2(10),
      col2   VARCHAR2(10)
    CREATE OR REPLACE TYPE myrectable AS TABLE OF myrec
    CREATE OR REPLACE FUNCTION pipedata(p_str IN VARCHAR2) RETURN myrectable PIPELINED IS
      v_str VARCHAR2(4000) := REPLACE(REPLACE(p_str, '('),')');
      v_obj myrec := myrec(NULL,NULL);
    BEGIN
      LOOP
        EXIT WHEN v_str IS NULL;
        v_obj.col1 := SUBSTR(v_str,1,INSTR(v_str,',')-1);
        v_str := SUBSTR(v_str,INSTR(v_str,',')+1);
        IF INSTR(v_str,',')>0 THEN
          v_obj.col2 := SUBSTR(v_str,1,INSTR(v_str,',')-1);
          v_str := SUBSTR(v_str,INSTR(v_str,',')+1);
        ELSE
          v_obj.col2 := v_str;
          v_str := NULL;
        END IF;
        PIPE ROW (v_obj);
      END LOOP;
      RETURN;
    END;
    SQL> select *
      2  from table(pipedata('(1,2),(3,4),(5,6)'));
    COL1       COL2
    1          2
    3          4
    5          6

  • How to use stored procedure which returns result set in OBIEE

    Hi,
    I hav one stored procedure (one parameter) which returns a result set. Can we use this stored procedure in OBIEE? If so, how we hav to use.
    I know we hav the Evaluate function but not sure whether I can use for my SP which returns result set. Is there any other way where I can use my SP?
    Pls help me in solving this.
    Thanks

    Hi Radha,
    If you want to cache the results in the Oracle BI Server, you should check that option. When you run a query the Oracle BI Server will get its results from the cache, based on the persistence time you define. If the cache is expired, the Oracle BI Server will go to the database to get the results.
    If you want to use caching, you should enable caching in the nqsconfig.ini file.
    Cheers,
    Daan Bakboord

  • Stored procedure which returns date error

    if have a function getGmtDate in the package pa which uses a date as parameter and returns a date
    conn.Connect()
    strSQL = "pa.getGmtDate"
    P_RETURN As New OracleParameter(":pRETURN", OracleDbType.Date, ParameterDirection.ReturnValue)
    Dim P_DATE As New OracleParameter(":pDATE", OracleDbType.Date, 0, ParameterDirection.Input)
    P_DATE.Value = Now 'current date
    Dim cmd As New OracleCommand(strSQL, conn.getConnection)
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Parameters.Add(P_RETURN)
    cmd.Parameters.Add(P_DATE)
    cmd.ExecuteNonQuery()
    dim returnValue as Date = P_RETURN.Value
    and the date is retrieved correct from the db, but when I want to bind the resultdate to a variable then it throws an exception:
    Cast from type 'OracleDate' to type 'Date' is not valid
    can anyone help me?

    1) Create CallableStatement
    2) For each of returning value you have to call RegisterOutParameter()
    3) For others user setXXX() method depending on type of parameter
    4) call
    5) use vars registered through RegisterOutParameter() - all your values should be there
    Pavel

  • Design a procedure which returns a result set of a select Query

    Hi...
    Can some one help me out with a brief design or work around for creating a stored procedure which runs a select Query and Returns a result set...
    If not a stored procedure, at least a function which makes the job simple....
    Awaiting help in this regard ........

    Hi...
    I am sorry for providing insufficient Info...
    Actually I am using Oracle 10G DB...
    I have a select Query..
    Since I am a part of team which is building a Complete Data Driven site, Even an SQL Query and a PL/SQL function body was stored in the Table itself to bring in some kind of Dynamism in the site.... But the master table was loaded with a lot of data and hence Now we decided to Store everythin in a generic package..
    I used REF CURSORS to store a result set of a simple SELECT Query.... and declaring it as an out parameter in my Procedure body so that the JAVA team can directly access the Procedure from the JAVA layer....
    Now I want to know can I do anything more efficient to carry out the above operation....

  • Oralce Store Procedure not returning values in out parameters

    I am goig to execute an oracle store procedure using C# through through ODP.NET. The store procedure executes succsfully but it does not return any value in the out parameter.
    When I execute the same store procedure with the same input parameteres from within SQL*Plus. It does return values.
    This is to be clearify here that in the oracle store procedure the data type for the out parameter is number and in the c# the variavle that will hold its value is Integer. I also tried using Long on the C# side but it is still not working. After the successfull execution of the store procedure the C# variable contains nulll value.

    I am goig to execute an oracle store procedure using C# through through ODP.NET. The store procedure executes succsfully but it does not return any value in the out parameter.
    When I execute the same store procedure with the same input parameteres from within SQL*Plus. It does return values.
    This is to be clearify here that in the oracle store procedure the data type for the out parameter is number and in the c# the variavle that will hold its value is Integer. I also tried using Long on the C# side but it is still not working. After the successfull execution of the store procedure the C# variable contains nulll value.

  • How to call a procedure which returns out parameter in form personalization

    Dear All,
    I have one procedure which is having 2 parameter in and one parameter out .
    The question is how to get the parameter out in from personalization in a local or global variable?
    Thanks

    Yes.
    You can use the "forms_ddl" builtin
    See the following examples. Make sure you include the single quotes as well as the = sign in the begining.
    See http://phenix.blog.163.com/blog/static/8397219320096213953151/
    http://oracle.anilpassi.com/forms-personalizations.html
    Sandeep Gandhi

  • How to execute an Oracle stored procedure which returns many records?

    I have two synchronous scenarios XI<->PI<->JDBC, where JDBC is receiver adapter.
    Each scenario runs a different stored procedure in Oracle database.
    The first stored procedure returns only one record, the second stored procedure returns many records, which come from a cursor.
    In the first scenario I executed the stored procedure following the directions of Help SAP page and works perfectly.
    Link: [http://help.sap.com/saphelp_nw70/helpdata/en/2e/96fd3f2d14e869e10000000a155106/content.htm]
    <root>
      <StatementName5>
        <storedProcedureName action=u201DEXECUTEu201D>
          <table>realStoredProcedureName</table>
          <param1 [isInput=u201Dtrueu201D] [isOutput=true] type=SQLDatatype>val1</param1>
        </storedProcedureName>
      </StatementName5>
    <root>
    I have sought in the forums of SDN and cannot find the way to run the second stored procedure, and receive the information it returns.
    Thank you for your help.
    Rafael Rojas.

    Think It doesnt matter either cursor or result set. Try to get the response back from JDBC and see what are the fields it exactly populating.
    In Procedure you can able to find the columns selecting in Cursors. Give those columns in the DT.
    File - JDBC (Execute-- Procedure)
    To get the response
    JDBC_respose -  File
    Correct me if im wrong.
    Regards
    Ramg

  • XI calling an Oracle Stored Procedure which returns an Object to XI

    I am currently trying to call an Oracle Packaged/Procedure from XI which accepts a couple of parameters as I/O and returns an Object as one of the parameters.
    I have created the Object within the Oracle Database CREATE OR REPLACE TYPE xy_jdbc AS OBJECT
    column_name type ...etc
    CREATE OR REPLACE TYPE xy_tab_jdbc AS TABLE OF xy_jdbc;
    One of the parameters for the stored procedure is set up as this type xy_tab_jdbc this will be populated based upon one of the parameters passed into the  Package/Procedure.
    Is this possible? If it is, how do I map the returned object within XI?

    Dear Hilary,
    the JDBC adapter does not support vendor-specific or non-scalar data types.
    Workaround: Change the stored proc's signature not to use an object, but the object's fields instead.
    Regards,
    Thilo

Maybe you are looking for

  • Error while generating the Business Object in Mobile Sales

    Hi, I made changes to the Business Object BOCAPGEN. Now I am trying to generate the business object but it is giving out the error saying Error intializing RT Generator !.RT Generator Failed for ".Error arsrep.dat is in use so Generation cannot be do

  • CSV downloaded file cuts on the way

    Hi I'am Junji from Tokyo. I use 10.2.0.2.0 Oracle Database 10g Release and Oracle Application Server 10g Release2. A DB server and the Web server become another server, but PL/SQL on a DB server kicked with mod_plsql by a Web screen starts, and take

  • Component Server greyed out

    When trying to remove a site server, the component server role doesnt seem to have uninstalled correctly and now the option to remove the role is greyed out.  Also, if I try to just delete the server, I get a prompt saying that it can't be removed un

  • Putting Flash Video Online

    Have a limited time to get up a site...really having trouble with Flash Video...I think I know where I am stuck...I seem to have no trouble encoding and publishing videos, I think where I am going wrong is when I use the component inspecter to add a

  • Green screen with 720p H264 footage

    I can't find media encoder in the "Feature Request/Bug Report Form" dropdown menu so I post it here. I get a green screen when trying to convert a H264 720p .mov file with AAC 48k audio that was sent to me. Awesome. It plays fine in Quicktime and VLC