Is it possible to pass TABLE as the output parameter in stored procedure

Hey Experts,
  Is it possible to pass TABLE as the output parameter in stored procedure.
eg
create procedure spGetData
@tableName as TABLE(intValue INT NOT NUL)
as 

You can use OPENQUERY or OPENROWSET, as mentioned above, to make stored procedure results table like. There are
some limitations with these methods:
http://technet.microsoft.com/en-us/library/ms188427.aspx
In OPENQUERY this-sql-server-instance can be used instead of a linked server name. It requires setting data accces server option:
exec sp_serveroption @server = 'PRODSVR\SQL2012'
,@optname = 'DATA ACCESS'
,@optvalue = 'TRUE'
LINK: http://www.sqlusa.com/bestpractices/select-into/
Kalman Toth Database & OLAP Architect
SELECT Video Tutorials 4 Hours
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

Similar Messages

  • Passing the Dynamic Internal Table as the Output Parameter of the FM...

    Hi,
    How can we pass the internal table as the output from the Function Module TABLES parameter.
        SELECT * FROM TVRO BYPASSING BUFFER INTO TABLE <ltable>.
    Now I need to pass the dynamic internal table <ltable> as the output in the function module.
    Thanks!
    Puneet.

    I can't use TVRO as the table type. The Table name is as the Input. This program will download the contents of the table and create an app server file. It can be for any database table.
    so i want the output of this FM should be the data from that table. So what should be the TABLE type.
    like in  a program i will use:::
      FIELD-SYMBOLS: <ltable> TYPE ANY TABLE,
                     <l_line> TYPE ANY,
                     <l_field> TYPE ANY.
        SELECT * FROM (p_table) BYPASSING BUFFER INTO TABLE <ltable>.
    That is my requirement.

  • How to retrieve Table of Records output param from stored procedure ?

    Hi,
    I'm trying to retrieve data from a PL/SQL stored proc. It seems I can't modify this procedure (I'm not allowed to and I don't know PL/SQL :)).
    My only documentation is the PL/SQL code and its comments. And that's the first I have to deal with output of a defined complex PL/SQL type
    So the signature of the procedure is :
    FUNCTION FUN_AFF_EVELEG_IHM (
        pEntumTyp       IN          NUMBER,
        pEntnum         IN          VARCHAR2,
        pEveListSize      IN OUT      NUMBER,
        pEveList       IN OUT      pkg_funaff_eveleg.TableRecordEVL,
        pErrCode   IN OUT      VARCHAR2,
        pMessage        IN OUT      VARCHAR2)
      RETURN NUMBER;pkg_funaff_eveleg.TableRecordEVL type is defined as "TABLE of RecordEVL"
    pkg_funaff_eveleg.RecordEVL type is defined as "RECORD" (struct of 12 different fields : NUMBER or VARCHAR2)
    What is the correct syntax to call the stored procedure then ? I don't find how to manage the pEveList output param. Is it a Cursor ? An ARRAY ? And how to register it ?
    My code so far :
    public static void callFunaffEVL(Connection con, String rcs) {
        // CallableStatement procCstmt=null;
        OracleCallableStatement oraCstmt = null;
        try {
          // Identifiy the Stored procedure
          // package synonyme : pkg_aff_EVELEG_IHM
          // stored procedure name : FUN_AFF_EVELEG_IHM
          String command = new StringBuilder("{? = call pkg_aff_EVELEG_IHM.FUN_AFF_EVELEG_IHM(?,?,?,?,?,?");
          // 1 RETURN 
          // 2 pEntumTyp IN NUMBER
          // 3 pEntnum IN VARCHAR2
          // 4 pEveListSize IN OUT NUMBER,
          // 5 pEveList IN OUT pkg_funaff_eveleg.TableauRecordEVL,
          // 6 pErrCpde IN OUT VARCHAR2,
          // 7 pMessage IN OUT VARCHAR2)
          // Create a Callable Statement Object:
          oraCstmt = (OracleCallableStatement) con.prepareCall(command);
          // Assign IN and OUT parameters
          oraCstmt.registerOutParameter(1, OracleTypes.NUMBER); // RET
          oraCstmt.setInt(2, 0); // ENTNUMTYP
          oraCstmt.setString(3, rcs); // ENTNUM
          oraCstmt.registerOutParameter(4, OracleTypes.NUMBER); // pEveListSize
          oraCstmt.registerOutParameter(5, OracleTypes.ARRAY); // pEveList
          oraCstmt.registerOutParameter(6, OracleTypes.VARCHAR); // pErrCode
          oraCstmt.registerOutParameter(7, OracleTypes.VARCHAR); // pMessage
          // Execute the Procedure or Function Call:
          oraCstmt.execute();
          // Process the OUT Placeholders:
          int ret = oraCstmt.getInt(1);
          String errCode = oraCstmt.getString(6);
          String message = oraCstmt.getString(7);
          System.out.println("RCS : " + rcs);
          System.out.println("ret : " + ret);
          System.out.println("errCode : " + errCode );
          System.out.println("message : " + message);
        } catch (SQLException sqle) {
          sqle.printStackTrace();
        } finally {
          // Close the CallableStatement Object:
          try {
            oraCstmt.close();
          } catch (SQLException e) {
            e.printStackTrace();
    Return : java.sql.SQLException: Parameter type Conflict: sqlType=2003
    Any help ? I found several examples that might refer to this case, but everything I tried end by a SQL exception of one type or another...
    (and sorry for my poor english :))
    Cy

    As I said, "pkg_funaff_eveleg.TableRecordEVL" is TABLE of RecordEVL.
    i.e : I can find 2 defined types under the package pkg_funaff_eveleg :
    TYPE TableRecordEVL is TABLE of RecordEVL INDEX BY BINARY_INTEGER;
    TYPE RecordEVL is RECORD (
      EVLENTNUM_PK        EVENEMENTS_LEGAUX.EVLENTNUM_PK%TYPE,
      EVLENTNUMTYP_PK     EVENEMENTS_LEGAUX.EVLENTNUMTYP_PK%TYPE,
      EVLSEQ_PK           EVENEMENTS_LEGAUX.EVLSEQ_PK%TYPE,
      EVLTYPSRC           EVENEMENTS_LEGAUX.EVLTYPSRC%TYPE,
      EVLPK1              EVENEMENTS_LEGAUX.EVLPK1%TYPE,
      EVLPK2              EVENEMENTS_LEGAUX.EVLPK2%TYPE,
      EVLPK3              EVENEMENTS_LEGAUX.EVLPK3%TYPE,
      EVLPK4              EVENEMENTS_LEGAUX.EVLPK4%TYPE,
      EVLPK5              EVENEMENTS_LEGAUX.EVLPK5%TYPE,
      EVLPK6              EVENEMENTS_LEGAUX.EVLPK6%TYPE,
      EVLCODEVTSRC        EVENEMENTS_LEGAUX.EVLCODEVTSRC%TYPE,
      EVLLEGEVECOD        EVENEMENTS_LEGAUX.EVLLEGEVECOD%TYPE,
      EVLSEQREF_FK        EVENEMENTS_LEGAUX.EVLSEQREF_FK%TYPE,
      EVLCOMMENT          EVENEMENTS_LEGAUX.EVLCOMMENT%TYPE,
      EVLETATCOD          EVENEMENTS_LEGAUX.EVLETATCOD%TYPE,
      EVLHISDATPUB        EVENEMENTS_LEGAUX.EVLHISDATPUB%TYPE,
      EVLHISPUBPRE        EVENEMENTS_LEGAUX.EVLHISPUBPRE%TYPE,
      EVLHISDATEFF        EVENEMENTS_LEGAUX.EVLHISDATEFF%TYPE,
      EVLHISEFFPRE        EVENEMENTS_LEGAUX.EVLHISEFFPRE%TYPE,
      EVLHISPOIDATEFF     EVENEMENTS_LEGAUX.EVLHISPOIDATEFF%TYPE,
      EVLHISORICOD        EVENEMENTS_LEGAUX.EVLHISORICOD%TYPE,
      EVLHISSUPPORTCOD    EVENEMENTS_LEGAUX.EVLHISSUPPORTCOD%TYPE,
      EVLHISNUMSUPPORT    EVENEMENTS_LEGAUX.EVLHISNUMSUPPORT%TYPE,
      EVLHISNUMINF        EVENEMENTS_LEGAUX.EVLHISNUMINF%TYPE,
      ANNNUMBODPCL        CBODACCPROD.CODANN2.ANNNUMBOD%TYPE
    );If needed, I can translate each "EVENEMENTS_LEGAUX.EVLENTNUM_PK%TYPE", but they must be VARCHAR2 or NUMBER
    Do I answer your question ?

  • Pass multiple values with IN parameter in stored procedure

    CREATE TABLE VTEST_INSERT (
    MY_ID NUMBER,
    COLUMN1 VARCHAR2(50)
    --SELECT * FROM VTEST_INSERT;
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (1,'TEST1');
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (2,'TEST2');
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (3,'TEST3');
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (4,'TEST4');
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (5,'TEST5');
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (1,'TEST6');
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (2,'TEST7');
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (3,'TEST8');
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (4,'TEST9');
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (5,'TEST10');
    CREATE OR REPLACE
    PROCEDURE VTEST_INSERT_SP(vid IN VARCHAR2,vname IN VARCHAR2)
    AS
    BEGIN
    DELETE FROM VTEST_INSERT WHERE MY_ID IN (vid);
    INSERT INTO VTEST_INSERT (MY_ID,COLUMN1) VALUES (vid,vname);
    END;
    EXEC VTEST_INSERT_SP(1,'TEST999');
    This all works fine above. But I want to be able to pass in multiple vname values. so something like:
    EXEC VTEST_INSERT_SP(1,'TEST999','TEST888','TEST777');
    all help appreciated. thank you.
    This would do multiple inserts each with the same vid and the different vname values.

    Try something like this
    SET SQLBLANKLINES ON;
    ALTER SESSION SET PLSQL_WARNINGS='ENABLE:ALL';
    DROP TABLE vtest_insert;
    CREATE TABLE vtest_insert(vid NUMBER, vname VARCHAR2(20));
    INSERT ALL
       INTO vtest_insert(vid, vname) VALUES(1, 'aaaa')
       INTO vtest_insert(vid, vname) VALUES(1, 'bb')
       INTO vtest_insert(vid, vname) VALUES(1, 'cccccc')
       INTO vtest_insert(vid, vname) VALUES(2, 'ddd')
       INTO vtest_insert(vid, vname) VALUES(2, 'ee')
    SELECT * FROM "PUBLIC".dual;
    SELECT * FROM vtest_insert;
    CREATE OR REPLACE TYPE vnames_tab_ty IS TABLE OF VARCHAR2(20)
    SHOW ERRORS;
    CREATE OR REPLACE PROCEDURE vtest_insert_sp
       p_vid     IN  vtest_insert.vid%TYPE,
       p_vnames  IN  vnames_tab_ty
    AUTHID DEFINER
    IS
    BEGIN
       DELETE FROM vtest_insert WHERE vid = p_vid;
       FORALL idx IN p_vnames.FIRST .. p_vnames.LAST
           INSERT INTO vtest_insert(vid, vname) VALUES(p_vid, p_vnames(idx));
    END vtest_insert_sp;
    SHOW ERRORS;
    <<bk>>
    DECLARE
      vnames vnames_tab_ty;
      vid vtest_insert.vid%TYPE;
    BEGIN
      bk.vid := 1;
      bk.vnames := vnames_tab_ty('vn-01', 'vn-02', 'vn-03');
      vtest_insert_sp(p_vid=>bk.vid, p_vnames=>bk.vnames);
      COMMIT;
      bk.vid := 2;
      bk.vnames := vnames_tab_ty('vn-04', 'vn-05', 'vn-06', 'vn-07');
      vtest_insert_sp(p_vid=>bk.vid, p_vnames=>bk.vnames);
      COMMIT;
    END;
    SELECT * FROM vtest_insert;
    Which produces the following output
    Table created.
    5 rows created.
           VID VNAME
         1 aaaa
         1 bb
         1 cccccc
         2 ddd
         2 ee
    Type created.
    No errors.
    Procedure created.
    No errors.
    PL/SQL procedure successfully completed.
           VID VNAME
         1 vn-01
         1 vn-02
         1 vn-03
         2 vn-04
         2 vn-05
         2 vn-06
         2 vn-07
    7 rows selected.
    SQL>
    Regards,
    Dariyoosh

  • Is it possible to pass table type values as input parameter for con prg?

    Hi All,
    Could you please confirm that is it possible to pass table type value as input to concurrent program?
    If possible how to achive this?
    If not possible whether we have any ora doc which is confirming this.
    Any hel will be great.
    Thanks,

    Hi student;
    Please check (http://apps2fusion.com/at/45-as/241-enablingdisabling-concurrent-program-parameters)
    Hope it helps
    Regard
    Helios

  • Pass table name as a parameter to function

    Is there a way to pass table name as a parameter to functions? Then update the table in the function.
    Thanks a lot.
    Jiaxin

    Hi, Harm,
    Thank you very much for your suggestion and example. But to get my program work, i need to realise code like follows:
    CREATE OR REPLACE FUNCTION delstu_func(stuno char) RETURN NUMBER AS
    BEGIN
    EXECUTE IMMEDIATE 'DELETE FROM student s' ||
    'WHERE' || 's.student_number' || '=' || stuno;
    LOOP
    DBMS_OUTPUT.PUT_LINE('record deleted');
    END LOOP;
    END;
    SELECT delstu_func('s11') FROM STUDENT;
    The intention is to check if such a function can perform operations such as update, delete and insert on occurence of certain values. When executing the above statement, the system returns an error message:
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    ORA-06512: at "SCMJD1.DELSTU_FUNC", line 3
    Could you tell me where is wrong?
    Jiaxin

  • LabVIEW 6.1 If For Loop count terminal is zero then value going through the loop is not passed on to the output of the loop

    Hello, one of our customers just encountered an execution error in a vi running under LabVIEW 6.1, which doesn't exist under LabVIEW 5.1 or 6.01. I have a simple vi that has two encapsulated For Loops. Two string arrays go in, one goes out of the outer loop. Inside the outer loop the first array is indexed. The string which results from this indexing is compared with all other strings from the second string array in the inner loop. If it matches one of the strings of the second array, it is not outputted, otherwise this string goes through the inner For Loop to the output of the inner loop and from there to the output of the outer loop. The count
    terminal of the outer/inner loop is connected to the Array Size of the first/second string array. If the second array is empty, that means that the element in test from the first arry cannot match anything from the second array, so the element in test is send to the output of the inner loop and from there to the output of the outer loop. This works fine in LabVIEW 5.1 and 6.01, but NOT in LabVIEW 6.1. In LabVIEW 6.1 the inner loop is never executed if the count value is zero (which is correct), but the data line running through the loop is not executed either, which is different to what LabVIEW 5.1 and 6.01 do. There, the input string is sent to the output of the inner loop correctly even if the loop counter is zero. The solution is easy - I just have to connect the output of the outer loop to the data line BEFORE it enters the inner loop. But: I don't know if this is a LabVIEW 6.1 bug or if it is supposed to be a feature, but it brings some incompatibility in programming between the
    different LabVIEW versions.
    Best regards,
    Gabsi

    Hi,
    When a for-loop runs zero times, all outputs are 'undefined' (and should
    be).
    Besides, how would LV know what the output of a not executed routine should
    be?
    It might be handled differently in LV5 and LV6, which is unfortunate. In
    both cases, the result is undefined.
    It's not a bug. It's just something that should be avoided in any LV
    version.
    > The solution is easy - I just have to connect the
    > output of the outer loop to the data line BEFORE it enters the inner
    > loop. But: I don't know if this is a LabVIEW 6.1 bug or if it is
    In some cases this does the trick. But if the data is changed in the inner
    loop, this will effect the results if the N is not zero.
    Technically, I think the output in this construction is also 'undefined'.
    But LV handles this as expected / desired.
    Another solution is to use a shift register. If N is zero, the input is
    directly passed through to the output.
    Regards,
    Wiebe.
    "Gabs" wrote in message
    news:[email protected]...
    > LabVIEW 6.1 If For Loop count terminal is zero then value going
    > through the loop is not passed on to the output of the loop
    >
    > Hello, one of our customers just encountered an execution error in a
    > vi running under LabVIEW 6.1, which doesn't exist under LabVIEW 5.1 or
    > 6.01. I have a simple vi that has two encapsulated For Loops. Two
    > string arrays go in, one goes out of the outer loop. Inside the outer
    > loop the first array is indexed. The string which results from this
    > indexing is compared with all other strings from the second string
    > array in the inner loop. If it matches one of the strings of the
    > second array, it is not outputted, otherwise this string goes through
    > the inner For Loop to the output of the inner loop and from there to
    > the output of the outer loop. The count terminal of the outer/inner
    > loop is connected to the Array Size of the first/second string array.
    > If the second array is empty, that means that the element in test from
    > the first arry cannot match anything from the second array, so the
    > element in test is send to the output of the inner loop and from there
    > to the output of the outer loop. This works fine in LabVIEW 5.1 and
    > 6.01, but NOT in LabVIEW 6.1. In LabVIEW 6.1 the inner loop is never
    > executed if the count value is zero (which is correct), but the data
    > line running through the loop is not executed either, which is
    > different to what LabVIEW 5.1 and 6.01 do. There, the input string is
    > sent to the output of the inner loop correctly even if the loop
    > counter is zero. The solution is easy - I just have to connect the
    > output of the outer loop to the data line BEFORE it enters the inner
    > loop. But: I don't know if this is a LabVIEW 6.1 bug or if it is
    > supposed to be a feature, but it brings some incompatibility in
    > programming between the different LabVIEW versions.
    > Best regards,
    > Gabsi

  • Is it possible to pass a null Input Oracle parameter to a stored procedure

    I have a stored procedure that take 3 inputs and gives 1 output.I'm using Oracle parameter to add all 3 input parameters as follows :
    OracleParameter inobj = cmd.Parameters.Add("wid", OracleDbType.Int32,50);
    inobj.Direction = ParameterDirection.Input;
    inobj.Value = _employeeID;
    and added the output parameter as follows:
    OracleParameter outobj = _cmd.Parameters.Add("w_first", OracleDbType.Varchar2, 50);
    outobj.Direction = ParameterDirection.Output;
    On the UI end , the user has a choice to provide 1 input or all inputs or any 2 inputs based on his interest. Stored Proc looks as follows:
    SP( inp1 in parameter, inp2 in parameter, inp3 in parameter, output1 out parameter)
    If i just get 1 input or 2 inputs from the user, is it fine to query the data for output using same stored procedure or should i have individual stored procedures for each scenario(combination of different inputs)?
    Will i get any pl/sql error that says invalid number of arguements?

    This means if i have 1 input , i need to have a different method to pass 1 parameter value and other input parameters as null and if there are 2 inputs will need different method to handle. So 5 different methods all together?
    What if the stored procedure is as follows ,will its make things easier so that only one method is used for all scenarios?(optional parameters is set default value as null in the stored proc)
    Create or Replace
    Procedure GetFoo
    (cur_z OUT sys_refcursor,
    pub_date IN varchar2,
    fname IN varchar2 default null,
    lname IN varchar2 default null,
    phone IN varchar2 default null
    IS
    BEGIN
    ---get some data
    END;
    *actually i can test this but, all the database servers are down today. So, i need to have idea if this thing works before i confirm with someone. Thanks.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to verify the user information pass by the form with a stored procedure?

    Hi,
    I would like to know how to verify user information pass by the form with a stored procedure.
    I want make a portal which accepts to new user registration, but I want verify the new user's informations (like the name don't contain a number etc).
    Thanks for your help
    regards
    jla

    Hi Samson,
    You can use the UI API to do this. You can catch the form_ADD event and then validate the input from the users. You can even block the event from completing (and stop the document from being added) if your code finds some incorrect data using the bubbleEvent functionality.
    I don't have one specific example to show you, but if you look at some of the SDK samples (for example C:\Program Files\SAP\SAP Business One SDK\Samples\COM UI\VB.NET\02.CatchingEvents) to see how to work with events, you can then create your own validation to ensure the users data is valid.
    Regards,
    Niall

  • Passing Variable Number of Parameters to Cobol Stored Procedure

    Hi. I have a web front end that needs to access several different tables via Cobol stored procedures. It seems simple enough to call the stored procedures straight away (DAO Pattern perhaps?) but my boss is insistent on having an intermediate Cobol program that decides which table to access. I think he at a bigger picture than I can see.
    The problem lies in the number of parameters that need to be passed to the stored procedures; some need 3, others needs 5, a few need 4. The only two solutions that I can think of are to pass EVERYTHING (we're talking 50 parameters or so) to the intermediate stored procedure and then pulling only what is needed from that data set to access the desired table. Solution number two involves passing everything to a temp table and then pulling what is needed from it. The former solution seems a little cleaner but still involves passing a lot of parameters. If Cobol could handle some sort of dynamic memory allocation (Vector) there seems to be a possible solution there. Though, as far as I know, that isn't possible.
    Any ideas are much appreciated.
    Thanks in advance,
    Chris

    Hi Saurabh,
    The method in which stored procedures are called on form submit is something as follows.
    Let us take your scenario of a form which has multiple checkboxes and a submit button. On clicking the submit button, this form data is submitted using either get or post. The form's submit action invokes a procedure.
    The HTML form code will look something like this..
    htp.formOpen( curl => 'URL /myProcedure',
    cmethod => 'post' );
    htp.formCheckbox( cname => 'myCheckbox'
    cvalue => 'A');
    htp.formCheckbox( cname => 'myCheckbox'
    cvalue => 'B');
    htp.formCheckbox( cname => 'myCheckbox'
    cvalue => 'C');
    htp.formSubmit( cname => 'myButton',
    cvalue => 'OK');
    Now, whenever the submit button is clicked, all these form values are passed to our stored procedure 'myProcedure'.
    "myProcedure" looks something like this.
    procedure myProcedure
    myCheckbox IN sys.owa_util.vc_arr,
    myButton IN VARCHAR2
    is
    begin
    end myProcedure;
    The point to be noted here is that the name of the variable being passed in the procedure is the same as the name of the HTML element being created in the HTML form. So, there is a direct mapping between the elements in the HTML form and the procedure parameters.
    Another noteworthy point is that since you have multiple checkboxes in your HTML form, it is impractical to name all the checkboxes differently and then pass those many parameters to your procedure (Imagine a scenario where there are a hundred check-boxes in an HTML form!). So portal allows you to give the same name (cname) to all the checkboxes in your HTML form, and if multiple checkboxes are checked, it will return all the checkbox values in an array (Note the usage of "myCheckbox IN sys.owa_util.vc_arr" in myProcedure).
    You can check out this link for more information.
    Re: retrieving data from fields
    Thanks,
    Ashish.

  • Pass a null value to a JDBC stored procedure call?

    pass a null value to a JDBC stored procedure call? Is this even possible? My DBA gave me a procedure to call that sometimes requires a null value. I don't think this is even possible.

    do you mind tell me how to resolve your problem?i using the setnull method,but it doesn't work.

  • How do I merge data from table1 on server 1 to final table on server 2 with a stored procedure to execute every so many hours.

    How do I merge data from table1 on server 1 to final table on server 2 with a stored procedure to execute every so
    many hours.

    How big is the table on server B? Is that possible to bring the all data into a server A and merge the data locally?
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Pass a date parameter to Stored Procedure

    Hello friends,
    Can you help to pass a date parameter to Stored procedure from JSP. This is my code:
    In Oracle 9i I have this:
    PROCEDURE SP_EDORES(
    pfechaini IN hist_pol_reclama.hrc_fecha_contabilidad%Type, <-- This is a date field
    pfechafin IN hist_pol_reclama.hrc_fecha_contabilidad%Type, <-- This is a date field
    p_recordset OUT PKG_REP_CIERRE.cursor_type) AS
    In JSP have this:
    CallableStatement stmt = (CallableStatement)conn.prepareCall( "begin PKG_REP_CIERRE.SP_EDORES(?,?,?); end;" );
    stmt.registerOutParameter(3,oracle.jdbc.driver.OracleTypes.CURSOR);
    stmt.setDate(1,Date.valueOf("01-06-2005"));
    stmt.setDate(2,Date.valueOf("30-06-2005"));
    ResultSet rset = (ResultSet)stmt.getObject(3);
    while (rset.next()) {
    %>
    <TR>
    <TD ALIGN=CENTER> <%= rset.getString(1) %> </TD>
    <TD ALIGN=CENTER> <%= rset.getString(2) %> </TD>
    <TD ALIGN=CENTER> <%= rset.getString(3) %> </TD>
    <TD ALIGN=CENTER> <%= rset.getInt(4) %> </TD>
    </TR>
    <%
    The Stored Procedure returns de Result set, however I think does not recognized the date format because I need it with this format dd-mm-yyyy.
    Thanks in advance

    to use Date you will need the oracle package.
    u can try this other solution: use String, not Date
    CallableStatement stmt = (CallableStatement)conn.prepareCall( "begin PKG_REP_CIERRE.SP_EDORES(?,?,?); end;" );
    stmt.registerOutParameter(3,oracle.jdbc.driver.OracleTypes.CURSOR);
    stmt.setString(1,"01-06-2005");
    stmt.setString(2,"30-06-2005");
    ResultSet rset = (ResultSet)stmt.getObject(3);
    while (rset.next()) {
    %>
    if this don't work you can change your PL/SQL to get Strings and do the conversion with TO_DATE in the sql statement.

  • Passing variable number of arguments in a stored procedure

    Hi Team,
    i am facing a problem. I have a dynamic form which contains some checkboxes. The number of checkboxes are dynamically generated on querying the database. On the form submission i want to call a stored procedure that will update the values in the database. i want to know that is there any way to handle variable number of arguments in the stored procedure or can i get the variables through some session context and use it in my stored procedure.
    Any help is greatly appreciated.
    Thanks&Regards
    Saurabh Jain

    Hi Saurabh,
    The method in which stored procedures are called on form submit is something as follows.
    Let us take your scenario of a form which has multiple checkboxes and a submit button. On clicking the submit button, this form data is submitted using either get or post. The form's submit action invokes a procedure.
    The HTML form code will look something like this..
    htp.formOpen( curl => 'URL /myProcedure',
    cmethod => 'post' );
    htp.formCheckbox( cname => 'myCheckbox'
    cvalue => 'A');
    htp.formCheckbox( cname => 'myCheckbox'
    cvalue => 'B');
    htp.formCheckbox( cname => 'myCheckbox'
    cvalue => 'C');
    htp.formSubmit( cname => 'myButton',
    cvalue => 'OK');
    Now, whenever the submit button is clicked, all these form values are passed to our stored procedure 'myProcedure'.
    "myProcedure" looks something like this.
    procedure myProcedure
    myCheckbox IN sys.owa_util.vc_arr,
    myButton IN VARCHAR2
    is
    begin
    end myProcedure;
    The point to be noted here is that the name of the variable being passed in the procedure is the same as the name of the HTML element being created in the HTML form. So, there is a direct mapping between the elements in the HTML form and the procedure parameters.
    Another noteworthy point is that since you have multiple checkboxes in your HTML form, it is impractical to name all the checkboxes differently and then pass those many parameters to your procedure (Imagine a scenario where there are a hundred check-boxes in an HTML form!). So portal allows you to give the same name (cname) to all the checkboxes in your HTML form, and if multiple checkboxes are checked, it will return all the checkbox values in an array (Note the usage of "myCheckbox IN sys.owa_util.vc_arr" in myProcedure).
    You can check out this link for more information.
    Re: retrieving data from fields
    Thanks,
    Ashish.

  • Passing parameter to stored procedure from windows form getting error

    I've written a procedure which shows the data in a table according to the table flag selected from the windows form. My code is:
    --- stored procedure ------
    CREATE PROC [dbo].[PROC_SELECT_TABLES]
    @TBL_FLAG INT
    AS
    BEGIN
    SET NOCOUNT ON;
    IF (@TBL_FLAG = 1)
    SELECT * FROM MHT_APPUSER ;
    IF (@TBL_FLAG = 2)
    SELECT * FROM MHT_ISA11 ;
    IF (@TBL_FLAG = 3)
    SELECT * FROM MHT_ISA22 ;
    SET NOCOUNT OFF;
    END
    GO
    Now, the module for calling the above procedure
    namespace DAL;
    public class DisplayData
    SqlLayer layer = new SqlLayer();
    public int tblFlag { get; set; }
    public DataTable GetData(int tblFlag)
    SqlParameter[] p = new SqlParameter[1];
    p[0] = new SqlParameter("@tblFlag", this.tblFlag);
    return layer.ExecuteDataSet("PROC_SELECT_TABLES", p).Tables[0];
    Now the SQL LAYER, containing the ExecuteDataSet and database connection code:
    namespace DAL;
    public class SqlLayer
    // sql connection code
    public DataSet ExecuteDataSet(string commandText, SqlParameter[] sqlParameter)
    SqlCommand cmd = new SqlCommand(commandText, this.conn);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddRange(sqlParameter);
    SqlDataAdapter sda = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    sda.Fill(ds);
    return ds;
    Now the windows form layer:
    using DAL;
    namespace BookKeepingSystem
    public partial class DisplayDataForm : Form
    DisplayData view = new DisplayData();
    private void GetData()
    view.tblFlag = 3;
    DataTable dt = view.GetData(view.tblFlag);
    dgvDisplayData.DataSource = dt;
    public DisplayDataForm()
    InitializeComponent();
    private void DisplayData_Load(object sender, EventArgs e)
    GetData();
    private void btnExit_Click(object sender, EventArgs e)
    Application.Exit();
    When I run the code I got the error:
    "Unhandled exception has occurred in your application...
    Procedure or function 'PROC_SELECT_TABLES' expects parameter @TBL_FLAG, which was not supplied"
    I can not figure what is missing with my code. Please can any one point out please.
    Thank You!!!

    Try something like this for starting -- do just this procedure to see if it works first.
    private DataTable GetDataTable(SqlConnection conn1)
    SqlDataAdapter daS1 = new SqlDataAdapter();
    daS1.SelectCommand = new SqlCommand();
    daS1.SelectCommand.Connection = conn1;
    if (conn1.State == ConnectionState.Closed) conn1.Open();
    daS1.SelectCommand.CommandType = CommandType.StoredProcedure;
    daS1.SelectCommand.CommandText = "yourStoredProcedureName";
    daS1.SelectCommand.Parameters.Add("@ParamName", SqlDbType.Int, 4);
    DataSet DS1 = new DataSet();
    daS1.Fill(DS1, "tbl1");
    return DS1.Tables["tbl1"];
    Note:  in the CommandText part place the name of your stored procedure.  In the Parameter part put the name of your parameter exactly as it is in the actual stored procedure.  Also, (if you have not done this already) make sure your stored
    procedure runs OK -- first -- test out your stored procedure in Sql Server Management Studio.  If the procedure runs OK in SSMS, then try it from you app.  Just create a simple form with one button .  Place GetDataTable() code under
    the button and call it something like this:
    private void button1_Click(object sender, EventArgs e)
    int i = GetDataTbl().Rows.Count;
    Console.WriteLine("i is {0}", i);
    Rich P

Maybe you are looking for

  • Deleting duplicate rows based on three columns in Oracle 8i

    Hi all, The database we use is Oracle 8i. The query below raises the too_many_rows exception when I launch an application. So I want to delete the duplicated rows : select polarisation_1, polarisation_2 into v_pol1_tech, v_pol2_tech from v_cfh_lien_e

  • Error in Adobe AIR Instalation

    Hello everyone, i got the following error by installing Adobe Air can anyone plz help me [2013-08-19:13:29:43] Runtime Installer end with exit code 0 [2013-08-19:13:29:43] Elevated install completed [2013-08-19:13:29:47] Got an unexpected fatal error

  • Latest Value to Show in Query

    I'm trying to create a query where the latest value shows up on my query. For example, my data looks like the following: Week      Hours 05/2007   1360.0 06/2007   1360.0 07/2007   1440.0 08/2007   1440.0 09/2007   1400.0 If I have a variable on the

  • Liveupgrade on Mixed FS - Solaris 10 update 6 to Solaris 10 update 8.

    Hi Experts, I need help from you .My requirement is, I need to upgrade my exisiting solaris 10 u6 to solaris 10 u8 from a mixed filesystem enviornment. My current enviornment details are below. We are having UFS and ZFS filesystem in one of the solar

  • Distribution and collection

    Hi guys, I meet an issue that is very troublesome. I buid a distribution list to distribute an input schedule template to a few project companies. I use the function EVCVW to get each project company's entity dimension member. It is correct while dis