Out Varaible declaration inside Procedure

I am having a question taht is ,Inside Stored Procedure what is the difference in seting the OUT Parameter inside Procedure as shown below :
create or replace PROCEDURE clearing_details(p_file_id in varchar2,_country_code OUT VARCHAR2_)
IS
CURSOR PD1 IS
SELECT COUNTRY_CODE FROM LINK_STATUS WHERE country_code = 'japan';
BEGIN
OPEN PD1;
LOOP
FETCH PD1 INTO country_code;
DBMS_OUTPUT.PUT_LINE(country_code);
EXIT WHEN PD1%NOTFOUND;
END LOOP;
CLOSE PD1;
END ;
*2nd Approach :*
Here we use the OUT Variable inside the Declaration section
create or replace PROCEDURE clearing_details(p_file_id in varchar2)
IS
countrycode VARCHAR2(40);_
CURSOR PD1 IS
SELECT COUNTRY_CODE FROM LINK_STATUS WHERE country_code = 'pak';
BEGIN
OPEN PD1;
LOOP
FETCH PD1 INTO country_code;
DBMS_OUTPUT.PUT_LINE(country_code);
EXIT WHEN PD1%NOTFOUND;
END LOOP;
CLOSE PD1;
END ;

Hi,
An OUT parameter is passed back to the calling routine.
Use OUT parameters in procedure clearing_details if whoever calls clearing_details needs to do some additional work based on the results of clearing_details (that is, if the calling program needs to see how clearing_details left country_code).
If clearing_details itself is doing all the work, then there's no need for an OUT parameter.

Similar Messages

  • Dynamic Sql  no execute inside procedure

    Hi
    There are a new table, I give permission for select, update, inser and delete, when I executed query select work fine, but when This query is executed inside procedure with dynamic sql return error: ORA-01031 Insufficient Prvileges
    I try to test out procedure and work fine , see below
    declare
      CCURSOR SYS_REFCURSOR;
      RCURSOR TRITON.TTDSLS992901%ROWTYPE;
      V_SQL  VARCHAR2(2000);
    begin
       V_SQL :='SELECT * FROM TRITON.TTDSLS992'|| '901' || CHR(10);
       V_SQL := V_SQL || ' WHERE  T$CONO$O = 410705'|| CHR(10);
       V_SQL := V_SQL || ' AND    T$PONO$O = 10'|| CHR(10);
       V_SQL := V_SQL || ' AND    T$COND$O = 0'|| CHR(10);
       V_SQL := V_SQL ||'AND    T$ETPA$O = 1 '|| CHR(10);
       V_SQL := V_SQL || ' AND    ROWNUM   = 1'|| CHR(10);
       V_SQL := V_SQL || ' ORDER BY T$CONO$O, T$PONO$O, T$COND$O DESC';
    OPEN CCURSOR FOR V_SQL;
      FETCH CCURSOR INTO RCURSOR;
      IF CCURSOR%FOUND THEN
         NULL;
      ELSE
         NULL;  
      END IF;
      CLOSE CCURSOR;   
    end;the Code 901 is not constant, change when Company change
    Why return error permission inside procedure ?

    Hardcode the value to '901' & check TRITON.TTDSLS992901 has execute permission to schema where you want to call this
    TRITON.TTDSLS992'|| '901' ~Lokanath

  • Cannot get OUT parameter from stored procedure

    Hi,
    I am new to stored procedure programming. I wrote a simple java stored procedure as follows:
    package fvt;
    import java.sql.*;
    import java.io.*;
    public class FVTProcedures
    extends COM.ibm.db2.app.StoredProc {
    public void addRecord(int id, String name, int status)
    throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.Connection con = null;
    PrintWriter pw = null;
    try {
    status =3;
    pw = new PrintWriter(new FileWriter("c:/temp/fvtproc.txt"));
    pw.println("starting...");
    // get connection
    con =getConnection();
    pw.println("Got connection");
    stmt = con.createStatement();
    stmt.execute("INSERT INTO cmtest (id, name) values (" + id + ",'"+name+"')");
    pw.println("Inserted the record");
    if (!con.getAutoCommit()) {
    con.commit();
    pw.println("Committed the connection");
    catch (SQLException sqle) {
    pw.println(sqle.getMessage());
    catch (Exception e) {
    pw.println(e.getMessage());
    finally {
    status =2;
    pw.close();
    try {
    if (stmt != null) {
    stmt.close();
    catch (SQLException sqle) {}
    try {
    if (con != null) {
    con.close();
    catch (SQLException sqle) {}
    Then I use the following sql command to create this stored procedure, especially register status as OUT parameter.
    CREATE PROCEDURE addRecord (IN id INT, IN name VARCHAR(20), OUT status INTEGER)
    FENCED LANGUAGE JAVA EXTERNAL NAME 'fvt.FVTProcedures!addRecord' PARAMETER
    STYLE DB2GENERAL
    My java program calling this stored proc is as follows:
    import java.sql.*;
    import javax.sql.*;
    public class CallableStmtTest {
         COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource ds = null;
         public static void main(String args[]) {
              CallableStmtTest dt = new CallableStmtTest();
              try {
                   dt.test();
              } catch (Exception e) {
                   e.printStackTrace(System.out);
         public CallableStmtTest() {
              ds = new COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource();
              ds.setUser("username");
              ds.setPassword("password");
              ds.setDatabaseName("database");
    public void test() {
    java.sql.Connection conn = null;
    CallableStatement cs = null;
    String sql = "CALL ADDRECORD(?, ?, ?)" ;
    try {
    conn = ds.getPooledConnection().getConnection();
    conn.setAutoCommit(false);
    System.out.println("Got the connection");
    cs = conn.prepareCall( sql ) ; /* con is the connection */
    System.out.println("Callable statement is prepared");
    cs.registerOutParameter(3, java.sql.Types.INTEGER);
    cs.setInt(1, 1001 );
    cs.setString(2, "1001");
    cs.execute() ;
    System.out.println("Callable statement is executed, return status: "+cs.getInt(3));
    conn.commit();
    catch(SQLException sqle) {
    sqle.printStackTrace();
    finally {
    try {
    if (cs!=null) {cs.close();}
    catch (SQLException sqle1) {
    try {
    if (conn!=null) {conn.close();}
    catch (SQLException sqle1) {
    However, the out put is always
    Callable statement is executed, return status: 0
    while i expect to be
    Callable statement is executed, return status: 2
    Can anyone tell me what's wrong with that?
    thansk,
    JST

    public void addRecord(int id, String name, int status)
    throws SQLException {
    status =3;In regular java you are never going to see this value (3) outside of that method. Java doesn't work that way.
    So unless java inside the DB works really differently from regular java, you are going to have to pass something else.

  • Alter User Inside procedure

    Hi to all,
    I have a user named dbo and vijay.
    I have a procedure under dbo named as sp_alteruser
    CREATE OR REPLACE PROCEDURE DBO.SP_ALTERUSER
    P_USER_ID IN VARCHAR2,P_PASSWORD IN VARCHAR2,P_MSG OUT VARCHAR2)
    --Declaration of IN parameters
    IS
    E_PASSWORD EXCEPTION;
    E_INVALIDUSER EXCEPTION;
    PRAGMA EXCEPTION_INIT(E_PASSWORD,-00988);
    PRAGMA EXCEPTION_INIT(E_INVALIDUSER,-01918);
    BEGIN
    DECLARE
    V_COUNT NUMBER;
    V_STATEMENT1 VARCHAR2(200);
    BEGIN
    --To check whether the user has been already exists
    SELECT COUNT(*) INTO V_COUNT
    FROM ALL_USERS
    WHERE USERNAME = P_USER_ID;
    IF V_Count = 0 THEN
    --If the count is 0 means that the user does not exist
    DBMS_OUTPUT.PUT_LINE('User Does Not exist');
    END IF;
    IF V_COUNT>0 THEN
    --If the count is greater than 0 then the Alter statement is executed
    V_STATEMENT1:= 'ALTER USER ' ||P_USER_ID||' IDENTIFIED BY '
    ||P_PASSWORD;
         -- EXECUTE IMMEDIATE 'GRANT ALTER USER TO VIJAY';
    -- EXECUTE IMMEDIATE 'ALTER USER ' ||P_USER_ID||' IDENTIFIED BY ' ||P_PASSWORD;
    --EXECUTE IMMEDIATE v_STATEMENT1;
    P_MSG := 'Password Changed Sucessfully';
    END IF;
    END;
    EXCEPTION
    WHEN E_PASSWORD THEN
    P_MSG := 'Missing or Invalid Password';
    WHEN E_INVALIDUSER THEN
    P_MSG := 'User '||P_USER_id||' Does not exist';
    END;
    I have created a synonym with the same name as sp_alteruser and given the execute privilege to the user vijay...
    This procedure works fine when I run as DBO user, when I am trying from the vijay user it is throwing the error as insufficient privilege.
    I tried to give the alter user privilege explicitly but none gone right, when i gave dba privilege and checked with it works fine..
    Please help me in this regard.
    Thanks
    vijay

    Yes, I got it and apologies. Its not there so the error is correct. I am not sure that which priv is letting the dba role change another user, here is a list of privs for some default roles but none of them is there which depicts clearly the option to change another user.
    A very stupid answer, try giving the alter user with the admin option and see what happens. I don't ahve a db here otherwise I would had done it.
    HTH
    Aman....

  • Finding long running queries inside procedure

    Hi All,
    Without using trace file or not modifying the existing procedure, is there any way to find out the query which is taking longer time (say out of 20) inside oracle procedure?
    Thanks in Advance,
    Geetha

    Hi,
    if you are on your development or test database the best tool (after the sql trace :)) is DBMS_PROFILER. It's easy to use and shows you how long does it take to execute every line of procedure. It helps to find not only slow SQL but also bottlenecks in pl/sql code.
    Another option could be Active Session History that every 1s creates snapshot of active sessions. You have to open new session, run the procedure and use query like this:
    select *
    from v$sql s
        (select sql_id, max(sample_time) - min(sample_time) as duration
        from v$active_session_history
        where sid = sys_context('userenv', 'sid') --SID of the session that executed the procedure
        ) ash
    where s.sql_id = ash.sql_id
    order by duration desc;

  • Reason for not allowing static declarations inside an inner class

    Is the reason for not allowing static declarations inside an inner class is due to the fact that it can never be accessed at a class level as the outer class has to create an instance of the inner class and any attributes/methods of the inner class has to be accessed through that.
    Typically, an instance (non-static) variable can never be accessed in a statement or expression inside a static context but the class variable can be accessed inside a non-static context. Given this, shouldnt the static declarations be allowed inside an inner class?
    Correct me if my understanding is wrong.
    Thanks

    I still couldnt get it clearly. Why i cant i have a static value ( variable ) for all the instances of the inner class irrespective of its enclosing instances of it ( i.e outer class instances). Say in this example below,
    class Outer
    static int i = 0;
    public Inner inner = new Inner();
    class Inner // inner class ( non-static nested class )
    int j = 0;
    static final int k = 2; // compile time constants are allowed
    // ininner class
    public void m1()
    j++;
    System.out.println("j is " + j);
    i++
    System.out.println("i is " + i);
    public static void main(String[] arg)
    Outer outer1 = new Outer();
    outer1.inner.m1(); // j will be 1 & i will be 1
    Outer outer2 = new Outer();
    outer2.inner.m1() // j will be 1 again & i will be 2. But I would
    // want j to be 2. Why is this not allowed?
    Looks like something missing..

  • XML CLOB out from a stored procedure

    I'm using Oracle 8.1.7 and OO4O(Oracle Objects for OLE)
    8.1.7.0.1
    I'm generating an XML string in a CLOB using the XSU in a stored
    procedure.
    I'm then trying to pass the CLOB as an out parameter for that
    procedure to an
    ASP page using OO4O. I get the following error on the line
    where I call the ExecuteSql
    method of the OO4O Database object:
    Error Type:
    Oracle Automation (0x800A01B8)
    OIP-04796: Error in creating object instance
    If anyone can give me a a solution to this or a better way to
    do it I would much appreciate it. I've tried using a function
    as well.
    It does work if the CLOB is pulled from a database field, so I
    think
    the problem lies in the CLOB coming from the getXML method.
    Since I'm
    creating and XML datagram from relational tables, it doesn't
    make much
    sense to save the generated XML to a CLOB field and then load it
    right
    back to pass to the web page.
    Thanks in advance...
    Here's my code for the stored procedure:
    Procedure SP_INI_XML
    (result OUT CLOB)
    IS
    queryCtx SYS.DBMS_XMLQuery.ctxType;
    begin
    queryCtx := SYS.DBMS_XMLQuery.newContext(... SQL
    statement ...);
    SYS.DBMS_XMLQuery.setRowTag(queryCtx,'INI');
    SYS.DBMS_XMLQuery.setRowsetTag(queryCtx,'ROOT');
    SYS.DBMS_XMLQuery.setXSLT(queryCtx, 'http://site/file.xsl');
    result := SYS.DBMS_XMLQuery.getXML(queryCtx);
    SYS.DBMS_XMLQuery.closeContext(queryCtx);
    end;
    Here's my code from the ASP page:
    Set ses = Server.CreateObject("OracleInProcServer.XOraSession")
    Set con = ses.OpenDatabase(DBServer,ConStr,0)
    Const ORATYPE_CLOB = 112
    con.Parameters.Add "str",Null,2,ORATYPE_CLOB
    con.ExecuteSql("begin SP_INI_XML(:str);end;")

    Ah yes I see. Sorry I misunderstood what you were suggesting. I'm currently working on a test script that uses an approach similar to the one you mentioned, but I'm having trouble resolving foreign key relationships with test data.
    I've no access to the tables or anything so it's proving to be a time consuming task!!
    Is it required that all fields are given a value, even if they have a "DEFAULT" defined for them within the procedure. At the moment I'm using a rather cumbersome approach to this:
    i.e.
    With cmmAddRequest
        .ActiveConnection = strConnect
        .CommandType = adCmdText
        .CommandText = strSQL
        .Parameters(0).Direction = adParamInput
        .Parameters(1).Direction = adParamInput
        .Parameters(2).Direction = adParamInput
        .Parameters(3).Direction = adParamOutput
        .Parameters(4).Direction = adParamOutput
        .Parameters(5).Direction = adParamOutput
        .Parameters(0).Value = "COMP"
        .Parameters(1).Value = "FRML"
        .Parameters(2).Value = "1"
        .Execute
        WScript.Echo(.Parameters(5).Value)
    End With

  • I have an Ipod touch 2nd generation 8gb. Metal peice fell out from the inside where the home button is and I lost it. Put the screen plug in and put the screen on and it would turn on but it won't unlock or respond to anything I try to do. PLEASE HELP ME!

    I have an Ipod touch 2nd generation 8gb. Metal peice fell out from the inside where the home button is and I lost it. Put the screen plug in and put the screen on and it would turn on but it won't unlock or respond to anything I try to do. PLEASE HELP ME!!!!!!!!!!!!!!!!!!!

    Look her and it may give insite on what is missing. Otherwise:
    Apple will exchange your iPod for a refurbished one for $99. Likely not worth it for a your iPod. They do not fix yours.
    Apple - iPod Repair price              
    A third-party place like the following maybe less. Google for more.
    iPhone Repair, Service & Parts: iPod Touch, iPad, MacBook Pro Screens
    Repair it yourself if you are up to it
    iPod Touch Repair – iFixit

  • URGENT!!! a way to find out if Oracle stored procedures have OUT parameters

    I'm having problemes properly creating a string for the prepareCall().
    so that i can call up a stored procedure in oracle.
    the problem is that some stored procedures have OUT parameters that I have to register, and some stored procedures don't.
    how can i find out if a stored procedure has an OUT parameter or not?
    So that i can format a string with one less ? for statements that don't,
    and one more ? for statements that do have an OUT parameter.
    is there such a method as boolean OUTparameterExist();
    or i'll take any suggestions.

    any other solutions?That was the solution. You don't need to execute any sql statement to get Database Meta Data. You just need a connection, which you use to get the DatabaseMetaData instance
    DatabaseMetaData dbmd = connection.getMetaData();then invoke any of the (numerous) methods to get the info you require
    ResultSet rs = dbmd.getProcedureColumns("mydb","myschema","myproc",null);
    while(rs.next()) {
      String name = rs.getString("COLUMN_NAME");
      if (rs.getShort("COLUMN_TYPE")==DatabaseMetaData.procedureColumnOut) {
        // column is an OUT parameter
    }Dave

  • Problems getting a resultset out of a stored procedure

    We're having a problem getting a resultset out of a stored procedure with JDBC. The third parameter for the procedure is an out REF CURSOR. Connection to the database is fine, we just keep getting the following error when we do the GetCursor(3) statement:
    ORA-00942: table or view does not exist
    We know for definate that something is coming out of the database as we can call it from ODBC without any errors. If anyone's got any ideas as to what's going wrong please let me know!
    The cut-down code follows:
    public class JSMatt extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
    PrintWriter out = resp.getWriter();
    // Load the Oracle JDBC driver
    out.println("Registering driver...");
    Class.forName("oracle.jdbc.driver.OracleDriver");
    // Connect to the DB
    out.println("Connecting to database...");
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@computer:db",
    "username", "password");
    // Create a statement using a stored procedure
    out.println("Creating query...");
    OracleCallableStatement st = (OracleCallableStatement)conn.prepareCall ("BEGIN archive.spSrchLanguage (?, ?, ?); END;");
    st.registerOutParameter(3, OracleTypes.CURSOR);
    st.setInt(1, 0);
    st.setInt(2, 12);
    st.execute();
    ResultSet rs = ((OracleCallableStatement)st).getCursor(3);
    null

    Further study of my colleagues issue reveals that the problem only occurs where we are using a synonym for our package even though the user has permissions to run it (and indeed does when using ODBC or OLEDB).
    If we call a procedure in our package which does not return a ref cursor then the procedure is getting called fine (as can be evidenced by the database inserts etc within the procedures).
    Ideally we would like to use a synonym (I like to keep nice clean tidy schemas!) so if anyone knows how to get around it please let us know.
    Regards
    Jason.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Matthew Butt ([email protected]):
    We're having a problem getting a resultset out of a stored procedure with JDBC. The third parameter for the procedure is an out REF CURSOR. Connection to the database is fine, we just keep getting the following error when we do the GetCursor(3) statement:
    ORA-00942: table or view does not exist
    We know for definate that something is coming out of the database as we can call it from ODBC without any errors. If anyone's got any ideas as to what's going wrong please let me know!
    The cut-down code follows:
    public class JSMatt extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
    PrintWriter out = resp.getWriter();
    // Load the Oracle JDBC driver
    out.println("Registering driver...");
    Class.forName("oracle.jdbc.driver.OracleDriver");
    // Connect to the DB
    out.println("Connecting to database...");
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@computer:db",
    "username", "password");
    // Create a statement using a stored procedure
    out.println("Creating query...");
    OracleCallableStatement st = (OracleCallableStatement)conn.prepareCall ("BEGIN archive.spSrchLanguage (?, ?, ?); END;");
    st.registerOutParameter(3, OracleTypes.CURSOR);
    st.setInt(1, 0);
    st.setInt(2, 12);
    st.execute();
    ResultSet rs = ((OracleCallableStatement)st).getCursor(3);
    <HR></BLOCKQUOTE>
    null

  • Dbms_session.set_identifier inside procedure

    Hi
    How can I to use dbms_session.set_identifier inside procedure ?
    thank you

    Perhaps I'm just being dense, but what is the question, exactly?
    Do you know, in general, how to call procedure A from procedure B? Or are you asking how to do that?
    If you do know, in general, how to call one procedure from another, are you asking what parameters DBMS_SESSION.SET_IDENTIFIER takes? If so, it takes a VARCHAR2, but it seems like you'd know that from whatever documentation you consulted to learn that DBMS_SESSION.SET_IDENTIFIER exists?
    Or are you asking something else?
    Justin

  • CAN USE COPY COMMAND INSIDE PROCEDURE BODY

    Hi all
    can we use COPY command inside procedure body like this
    CREATE OR REPLACE procedure USER2.PRO1
    Begin
    execute immediate'copy from hr/hr@ERP to USER21/PASS@DB1 append user2.per_images using select * from hr.per_images';
    commit;
    end;
    YOU ADVICE PLEASE

    My advice is to check the manual.
    SQL*Plus COPY command
    http://download.oracle.com/docs/cd/B28359_01/server.111/b31189/ch12016.htm#i2675035
    SQL manual index
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/index.htm
    PL/SQL manual index
    http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/index.htm
    CTRL-F on the last two for COPY and it appears not.

  • How to copy out the song inside ipod nano

    how to copy out the song inside ipod nano

    Hi!, Go to the summary of your ipod and click to the square "Manually manage music and videos"

  • System.out.println statements inside my session beans

    I have some System.out.println statements inside my session beans to track some error conditions. I would like to know where this output will be printed. Is there any text file I should look for or start up any console to see the output.
    I am running iPlanet SP3 test drive edition iPlanet Web Server 4.1 on WIndows NT machine.

    Hi,
    These statements will be printed on the kjs logs file. To view them, go to control panel-> services-> select the iPlanet Application server and click "start up" tab. Check " allow this sevice to interact with the desk top" in the service window that has been popped up. Restart the iPlanet Application server.
    View the kjs window. All your System.out.println statements will be printed out there.
    If you have any further queries please get back to the forum.
    Thanks for visiting our web forum,
    Rakesh.

  • Get out values from stored procedure

    Hi folks,
    I have need of an aid. I have created this stored procedure:
    CREATE OR REPLACE PROCEDURE ProceduraDiProva (
    p_val1 IN NUMBER DEFAULT 1,
    p_val2 IN NUMBER DEFAULT 1,
    p_val3 OUT NUMBER,
    p_val4 OUT NUMBER)
    AS
    BEGIN
    p_val3 := p_val1 + p_val2;
    p_val4 := 999;
    END ProceduraDiProva;
    I call the procedure into shell script
    $ORACLE_HOME/bin/sqlplus -s user/pwd@oracleid > oracle.log << END
    spool ciccio.txt
    declare
    var a_out number;
    var b_out number;
    begin
    var a_out:=0;
    exec ProceduraDiProva(1, 2, a_out, b_out);
    end;
    spool off;
    exit
    END
    I would know as I make to insert 'a_out' and 'b_out' in a shell variables
    Tanks in advance

    I found an example with windows
    Create a file cmd with;
    FOR /F "usebackq delims=!" %%i IN (`sqlplus -s %usuario%/%pwd%@%ddbb% @1.sql`) DO set xresult=%%i
    echo %xresult%
    And the 1.sql:
    set timing off
    set feedback off
    set pages 0
    select sysdate from dual;
    exit
    ------------------------------------------------------------------------------------------

Maybe you are looking for

  • Bottom layer (image) protrudes from underneath top layer (Indesign shape) after export to PDF

    I have layered Indesign shapes (with 95% opacity) atop a black and white JPG (100% opacity). When I export the file as a PDF and open it in Acrobat, the background image bleeds under the shapes. The amount of bleed varies depending on the zoom level

  • How can i download the Adobe flash player 11?

    I have tried downloading the adobe flash player 11 because if i dont have this i cant access the things I like doing on my computer. So i clicked on it and followed the indtructions but then it told me to close programs listed, so i did. After i did

  • APPLE TV SUBTITLES!!

    I download a movie mp4 without internal subtitles, i download the subs separately, the movie is on my time capsule, when i try to play it, sometimes it says " ERROR LOADING THIS CONTENT PLEASE TRY AGAIN LATER ", it only plays when i copy the movie in

  • Exchange rate type settings

    Hello, In same client one company code use reference currency as local currency (XYZ) for exchange rate type u2018Mu2019. Exchange rates are maintained on daily base for the exchange rate type. New company code with different local currency would lik

  • How to make fields readonly in Interactive Form based on Roles

    Hello All, I want to make few fields readonly and also want to disable few fields from the Interactive form based on the role, logged in by user. Looking  for a code Snippet on this issue. Need help in this Regard. Thanks & regards, Debasish