Stored procedure API: does "TEXT" equal "CURSOR"?

I'm trying to call an Oracle stored procedure from Java. The API for the stored procedure has a couple of OUT parameters that are labeled type "TEXT," and it appears that each of these parameters has many subordinate parameters that are of simple types (varchar2, integer, etc.). Two questions:
1. Do I need to do a registerOutParameter only for the two "TEXT" parameters, or do I need to have a separate registerOutParameter for each subordinate parameter?
2. In the registerOutParameter statements, should I use OracleTypes.CURSOR? Will java.sql.Types.CURSOR work just as well?
Thanks:)
Doug

Having just upgraded from forms 9i to 10g we are having exactly the same problem as begenwald.
Did you ever find a solution?
I can confirm that the code is definately connecting to the correct database and executing a package that DOES exist, so this is not a tnsnames issue or anything to do with the wrong database being used.
If the strored package procedure being called from the form takes a record structure as a parameter then the "ORA-04067: not execute, stored procedure "PUBLIC." does not exist" error is raised, however, if I change the parameter to a simple scalar parameter e.g. a varchar2 then the error does not occur.
This appears to be due to a bug in forms10g on unix.
Any pointers would be appreciated as this is driving me mad, not to mention wasting a lot of my time.

Similar Messages

  • Copy values from stored procedure to a text pad

    Any Suggestions
    We have a table 'A' and wrote a select query to get the values from that table 'A'. I place this select query in Stored procedure and when I run that procedure every month the output should be sent t a text pad. Any suggestions how to write it
    thanks
    Is there any other method if we dont have the privelage to create directory?
    Edited by: user646635 on Oct 2, 2008 7:16 AM

    user646635 wrote:
    want to store the output in a text file?
    we are using oracle 9iHere's a basic example for you...
    AS SYS:
    create or replace directory TEST_DIR as 'c:\test_dir'; -- This creates an oracle directory object.  The actual operating system directory must be created manually
    grant read,write on directory test_dir to my_user;  -- Grant permission to use that directory object to the required user(s)AS my_user:
    declare
      cursor cur_emp is
        select ename, deptno
        from emp;
      v_fh UTL_FILE.FILE_TYPE;  -- This is a file handle
    begin
      v_fh := UTL_FILE.FOPEN('TEST_DIR', 'file.txt', 'w', 32767);  -- Open the file for writing and obtain a handle to it
      FOR i IN cur_emp -- process the query in a loop
      LOOP
        UTL_FILE.FPUT_LINE(v_fh, i.ename||','||to_char(i.deptno,'fm099')); -- write out lines of text to the file
      END LOOP;
      UTL_FILE.FCLOSE(v_fh); -- Close the file (also flushes any unwritten buffered data).
    end;

  • Stored Procedure: Extract data into second cursor

    This is ready-to-run script with a commented out INCOMPLETE section of code where i need to select from a cursor.
    --==  PDF Dcument Table of contents ==---
    --==  PDF Report contains Period to date on condiments and bun sales for a region
    --==  For each week for a 4-week period with week 6 representing PTD and week 7 representing
    --==  YTD. Data should be gathered in rowsets and pivoted on client
    --== 
    --== Basic Functionallity:
    --=== Write a stored procedure that performs the following:
    --==  1) Select the report data into cursor 1  in the order with a resultset order
    --==     in the way it will be printed to report.
    --==  2) Create list of inique stores in separate cursor
    --==  Approach: 
    --== Create the Type object of fields needed to build table of contents for each row of the table. Add a sort field
    --== to enable restore the original order of data after any sorting done on client 
    --== Create table table of the row objects
    --== Declare 2 cursors:
    --   a) ) First cursor holds the data for the PDF Report  to be pivoted by the client
    --   b) ) Second should contain a table of contents (unique storenbr) in the 
    --== same order as the stores in the first cursor.
    --== Oracle version 10g v2 on  W2K3
    begin  execute immediate 'drop type TYP_TBL_CWSR_TOC'; exception when others then null; end;
    begin  execute immediate 'drop type TYP_CWSR_TOC';  exception when others then null;  end;
    begin execute immediate 'drop procedure Create_Rpt_and_TOC'; exception when others then null; end;
    create or replace TYPE TYP_CWSR_TOC AS OBJECT
           (   sortcol         number             --== probably not needed, just in case
            ,  storenbr        varchar2(100)
            ,  storename       varchar2(200) 
    create or replace TYPE TYP_TBL_CWSR_TOC AS TABLE OF TYP_CWSR_TOC;
    create or replace procedure create_rpt_and_toc
         pc_report_data               OUT sys_refcursor
    ,    pc_TOC   OUT sys_refcursor     
    AS
    v_tblTOC        TYP_TBL_CWSR_TOC;
    v_rec           TYP_CWSR_TOC := TYP_CWSR_TOC(NULL,NULL, NULL);
    BEGIN
    OPEN pc_report_data FOR
    with  sample_data as
    (    select 22 storeid , 1 week_nbr, 15942 net_sales, 372 buns, 176 condiments  from dual union all
          select 22 storeid , 6 week_nbr, 15942 net_sales, 372 buns, 176 condiments  from dual union all
          select 22 storeid , 7 week_nbr, 15942 net_sales, 372 buns, 176 condiments  from dual union all
          select 23 storeid , 1 week_nbr, 25302 net_sales, 481 buns, 221 condiments  from dual union all
          select 23 storeid , 6 week_nbr, 25302 net_sales, 481 buns, 221 condiments  from dual union all
          select 23 storeid , 7 week_nbr, 25302 net_sales, 481 buns, 221 condiments  from dual union all
          select 24 storeid , 1 week_nbr, 29347 net_sales, 598 buns, 238 condiments  from dual union all
          select 24 storeid , 6 week_nbr, 29347 net_sales, 598 buns, 238 condiments  from dual union all
          select 24 storeid , 7 week_nbr, 29347 net_sales, 598 buns, 238 condiments  from dual union all
          select 25 storeid , 1 week_nbr, 17637 net_sales, 360 buns, 165 condiments  from dual union all
          select 25 storeid , 6 week_nbr, 17637 net_sales, 360 buns, 165 condiments  from dual union all
          select 25 storeid , 7 week_nbr, 17637 net_sales, 360 buns, 165 condiments  from dual union all
          select 27 storeid , 1 week_nbr, 22010 net_sales, 405 buns, 172 condiments  from dual union all
          select 27 storeid , 6 week_nbr, 22010 net_sales, 405 buns, 172 condiments  from dual union all
          select 27 storeid , 7 week_nbr, 22010 net_sales, 405 buns, 172 condiments  from dual union all
          select 31 storeid , 1 week_nbr, 16836 net_sales, 345 buns, 168 condiments  from dual union all
          select 31 storeid , 6 week_nbr, 16836 net_sales, 345 buns, 168 condiments  from dual union all
          select 31 storeid , 7 week_nbr, 16836 net_sales, 345 buns, 168 condiments  from dual union all
          select 38 storeid , 1 week_nbr, 28244 net_sales, 524 buns, 247 condiments  from dual union all
          select 38 storeid , 6 week_nbr, 28244 net_sales, 524 buns, 247 condiments  from dual union all
          select 38 storeid , 7 week_nbr, 28244 net_sales, 524 buns, 247 condiments  from dual union all
          select 39 storeid , 1 week_nbr, 21011 net_sales, 407 buns, 238 condiments  from dual union all
          select 39 storeid , 6 week_nbr, 21011 net_sales, 407 buns, 238 condiments  from dual union all
          select 39 storeid , 7 week_nbr, 21011 net_sales, 407 buns, 238 condiments  from dual union all
          select 41 storeid , 1 week_nbr, 18026 net_sales, 430 buns, 179 condiments  from dual union all
          select 41 storeid , 6 week_nbr, 18026 net_sales, 430 buns, 179 condiments  from dual union all
          select 41 storeid , 7 week_nbr, 18026 net_sales, 430 buns, 179 condiments  from dual union all
          select 42 storeid , 1 week_nbr, 24821 net_sales, 466 buns, 212 condiments  from dual union all
          select 42 storeid , 6 week_nbr, 24821 net_sales, 466 buns, 212 condiments  from dual union all
          select 42 storeid , 7 week_nbr, 24821 net_sales, 466 buns, 212 condiments  from dual union all
          select 65 storeid , 1 week_nbr, 13356 net_sales, 281 buns, 136 condiments  from dual union all
          select 65 storeid , 6 week_nbr, 13356 net_sales, 281 buns, 136 condiments  from dual union all
          select 65 storeid , 7 week_nbr, 13356 net_sales, 281 buns, 136 condiments  from dual union all
          select 66 storeid , 1 week_nbr, 15421 net_sales, 337 buns, 155 condiments  from dual union all
          select 66 storeid , 6 week_nbr, 15421 net_sales, 337 buns, 155 condiments  from dual union all
          select 66 storeid , 7 week_nbr, 15421 net_sales, 337 buns, 155 condiments  from dual union all
          select 67 storeid , 1 week_nbr, 28064 net_sales, 625 buns, 283 condiments  from dual union all
          select 67 storeid , 6 week_nbr, 28064 net_sales, 625 buns, 283 condiments  from dual union all
          select 67 storeid , 7 week_nbr, 28064 net_sales, 625 buns, 283 condiments  from dual union all
          select 68 storeid , 1 week_nbr, 22875 net_sales, 493 buns, 238 condiments  from dual union all
          select 68 storeid , 6 week_nbr, 22875 net_sales, 493 buns, 238 condiments  from dual union all
          select 68 storeid , 7 week_nbr, 22875 net_sales, 493 buns, 238 condiments  from dual union all
          select 70 storeid , 1 week_nbr, 26434 net_sales, 562 buns, 248 condiments  from dual union all
          select 70 storeid , 6 week_nbr, 26434 net_sales, 562 buns, 248 condiments  from dual union all
          select 70 storeid , 7 week_nbr, 26434 net_sales, 562 buns, 248 condiments  from dual union all
          select 71 storeid , 1 week_nbr, 14259 net_sales, 297 buns, 133 condiments  from dual union all
          select 71 storeid , 6 week_nbr, 14259 net_sales, 297 buns, 133 condiments  from dual union all
          select 71 storeid , 7 week_nbr, 14259 net_sales, 297 buns, 133 condiments  from dual union all
          select 82 storeid , 1 week_nbr, 24446 net_sales, 469 buns, 210 condiments  from dual union all
          select 82 storeid , 6 week_nbr, 24446 net_sales, 469 buns, 210 condiments  from dual union all
          select 82 storeid , 7 week_nbr, 24446 net_sales, 469 buns, 210 condiments  from dual union all
          select 83 storeid , 1 week_nbr, 13959 net_sales, 280 buns, 104 condiments  from dual union all
          select 83 storeid , 6 week_nbr, 13959 net_sales, 280 buns, 104 condiments  from dual union all
          select 83 storeid , 7 week_nbr, 13959 net_sales, 280 buns, 104 condiments  from dual union all
          select 181 storeid , 1 week_nbr, 13140 net_sales, 273 buns, 136 condiments  from dual union all
          select 181 storeid , 6 week_nbr, 13140 net_sales, 273 buns, 136 condiments  from dual union all
          select 181 storeid , 7 week_nbr, 13140 net_sales, 273 buns, 136 condiments  from dual union all
          select 221 storeid , 1 week_nbr, 27347 net_sales, 546 buns, 289 condiments  from dual union all
          select 221 storeid , 6 week_nbr, 27347 net_sales, 546 buns, 289 condiments  from dual union all
          select 221 storeid , 7 week_nbr, 27347 net_sales, 546 buns, 289 condiments  from dual union all
          select 222 storeid , 1 week_nbr, 16456 net_sales, 379 buns, 148 condiments  from dual union all
          select 222 storeid , 6 week_nbr, 16456 net_sales, 379 buns, 148 condiments  from dual union all
          select 222 storeid , 7 week_nbr, 16456 net_sales, 379 buns, 148 condiments  from dual union all
          select 223 storeid , 1 week_nbr, 20611 net_sales, 439 buns, 165 condiments  from dual union all
          select 223 storeid , 6 week_nbr, 20611 net_sales, 439 buns, 165 condiments  from dual union all
          select 223 storeid , 7 week_nbr, 20611 net_sales, 439 buns, 165 condiments  from dual union all
          select 224 storeid , 1 week_nbr, 21537 net_sales, 420 buns, 173 condiments  from dual union all
          select 224 storeid , 6 week_nbr, 21537 net_sales, 420 buns, 173 condiments  from dual union all
          select 224 storeid , 7 week_nbr, 21537 net_sales, 420 buns, 173 condiments  from dual union all
          select 260 storeid , 1 week_nbr, 19329 net_sales, 380 buns, 196 condiments  from dual union all
          select 260 storeid , 6 week_nbr, 19329 net_sales, 380 buns, 196 condiments  from dual union all
          select 260 storeid , 7 week_nbr, 19329 net_sales, 380 buns, 196 condiments  from dual union all
          select 280 storeid , 1 week_nbr, 20692 net_sales, 512 buns, 202 condiments  from dual union all
          select 280 storeid , 6 week_nbr, 20692 net_sales, 512 buns, 202 condiments  from dual union all
          select 280 storeid , 7 week_nbr, 20692 net_sales, 512 buns, 202 condiments  from dual union all
          select 294 storeid , 1 week_nbr, 26522 net_sales, 481 buns, 252 condiments  from dual union all
          select 294 storeid , 6 week_nbr, 26522 net_sales, 481 buns, 252 condiments  from dual union all
          select 294 storeid , 7 week_nbr, 26522 net_sales, 481 buns, 252 condiments  from dual union all
          select 362 storeid , 1 week_nbr, 20611 net_sales, 317 buns, 221 condiments  from dual union all
          select 362 storeid , 6 week_nbr, 20611 net_sales, 317 buns, 221 condiments  from dual union all
          select 362 storeid , 7 week_nbr, 20611 net_sales, 317 buns, 221 condiments  from dual union all
          select 501 storeid , 1 week_nbr, 28337 net_sales, 518 buns, 273 condiments  from dual union all
          select 501 storeid , 6 week_nbr, 28337 net_sales, 518 buns, 273 condiments  from dual union all
          select 501 storeid , 7 week_nbr, 28337 net_sales, 518 buns, 273 condiments  from dual union all
          select 521 storeid , 1 week_nbr, 26118 net_sales, 438 buns, 257 condiments  from dual union all
          select 521 storeid , 6 week_nbr, 26118 net_sales, 438 buns, 257 condiments  from dual union all
          select 521 storeid , 7 week_nbr, 26118 net_sales, 438 buns, 257 condiments  from dual union all
          select 524 storeid , 1 week_nbr, 31929 net_sales, 582 buns, 247 condiments  from dual union all
          select 524 storeid , 6 week_nbr, 31929 net_sales, 582 buns, 247 condiments  from dual union all
          select 524 storeid , 7 week_nbr, 31929 net_sales, 582 buns, 247 condiments  from dual
    , store_data as
          select 27   storeid,  'County Gate' storename ,    '5601' storenbr ,     'R1-Roosevelt' regionname ,   'D11-Wilcox' districtname , 'VMS' companyname  from dual union all                                                                
          select 67   storeid,  'N. Jackson' storename ,    '0177' storenbr ,     'R1-Roosevelt' regionname ,   'D14-Sandus' districtname , 'VMS' companyname  from dual union all                                                                  
          select 68   storeid,  'Dyersburg' storename ,    '0277' storenbr ,     'R1-Roosevelt' regionname ,   'D14-Sandus' districtname , 'VMS' companyname  from dual union all                                                                  
          select 280   storeid,  'Poplar Ave.' storename ,    '3080' storenbr ,     'R1-Roosevelt' regionname ,   'D12-Smart' districtname , 'VMS' companyname  from dual union all                                                                   
          select 294   storeid,  'Goodman Rd' storename ,    '5702' storenbr ,     'R1-Roosevelt' regionname ,   'D12-Smart' districtname , 'VMS' companyname  from dual union all                                                                     
          select 25   storeid,  'Germantown' storename ,    '5094' storenbr ,     'R1-Roosevelt' regionname ,   'D11-Wilcox' districtname , 'VMS' companyname  from dual union all                                                              
          select 181   storeid,  'Mendehall' storename ,    '4090' storenbr ,     'R1-Roosevelt' regionname ,   'D12-Smart' districtname , 'VMS' companyname  from dual union all                                                                    
          select 31   storeid,  'Winchester' storename ,    '2684' storenbr ,     'R1-Roosevelt' regionname ,   'D11-Wilcox' districtname , 'VMS' companyname  from dual union all                                                                    
          select 41   storeid,  'Washington' storename ,    '4190' storenbr ,     'R1-Roosevelt' regionname ,   'D13-Bowser' districtname , 'VMS' companyname  from dual union all                                                                   
          select 42   storeid,  'Cordova' storename ,    '4393' storenbr ,     'R1-Roosevelt' regionname ,   'D13-Bowser' districtname , 'VMS' companyname  from dual union all                                                                       
          select 70   storeid,  'S. Jackson' storename ,    '0679' storenbr ,     'R1-Roosevelt' regionname ,   'D14-Sandus' districtname , 'VMS' companyname  from dual union all                                                                                                                                                                      
          select 221   storeid,  'Jackson' storename ,    '5500' storenbr ,     'R1-Roosevelt' regionname ,   'D14-Sandus' districtname , 'VMS' companyname  from dual union all                                                                      
          select 223   storeid,  'Highway 51' storename ,    '3485' storenbr ,     'R1-Roosevelt' regionname ,   'D14-Sandus' districtname , 'VMS' companyname  from dual union all                                                        
          select 66   storeid,  'New Summer' storename ,    '2980' storenbr ,     'R1-Roosevelt' regionname ,   'D15-Rickard' districtname , 'VMS' companyname  from dual union all                                                                    
          select 82   storeid,  'Navy Road' storename ,    '1476' storenbr ,     'R1-Roosevelt' regionname ,   'D15-Rickard' districtname , 'VMS' companyname  from dual union all                                                                   
          select 224   storeid,  'New Covington' storename ,    '5397' storenbr ,     'R1-Roosevelt' regionname ,   'D15-Rickard' districtname , 'VMS' companyname  from dual union all                                                              
          select 501   storeid,  'Kirby Quince' storename ,    '6504' storenbr ,     'R1-Roosevelt' regionname ,   'D11-Wilcox' districtname , 'VMS' companyname  from dual union all                                                               
          select 22   storeid,  'Wchstr/Good' storename ,    '2385' storenbr ,     'R1-Roosevelt' regionname ,   'D11-Wilcox' districtname , 'VMS' companyname  from dual union all                                                                  
          select 23   storeid,  'Union Ave' storename ,    '1275' storenbr ,     'R1-Roosevelt' regionname ,   'D13-Bowser' districtname , 'VMS' companyname  from dual union all                                                                 
          select 24   storeid,  'West Poplar' storename ,    '4290' storenbr ,     'R1-Roosevelt' regionname ,   'D11-Wilcox' districtname , 'VMS' companyname  from dual union all                                                                   
          select 222   storeid,  'Thomas St.' storename ,    '1977' storenbr ,     'R1-Roosevelt' regionname ,   'D15-Rickard' districtname , 'VMS' companyname  from dual union all                                                                
          select 362   storeid,  'Wolfchase' storename ,    '5802' storenbr ,     'R1-Roosevelt' regionname ,   'D13-Bowser' districtname , 'VMS' companyname  from dual union all                                                                 
          select 524   storeid,  'Houston Levee' storename ,    '6705' storenbr ,     'R1-Roosevelt' regionname ,   'D15-Rickard' districtname , 'VMS' companyname  from dual union all                                                             
          select 521   storeid,  'G-Town/I-40' storename ,    '6604' storenbr ,     'R1-Roosevelt' regionname ,   'D15-Rickard' districtname , 'VMS' companyname  from dual union all                                                               
          select 38   storeid,  'Horn Lake' storename ,    '4994' storenbr ,     'R1-Roosevelt' regionname ,   'D12-Smart' districtname , 'VMS' companyname  from dual union all                                                                    
          select 39   storeid,  'Macon/Syc' storename ,    '2885' storenbr ,     'R1-Roosevelt' regionname ,   'D13-Bowser' districtname , 'VMS' companyname  from dual union all                                                                    
          select 65   storeid,  'Poplar/Fenwick' storename ,    '2581' storenbr ,     'R1-Roosevelt' regionname ,   'D13-Bowser' districtname , 'VMS' companyname  from dual union all                                                                
          select 71   storeid,  'Humboldt' storename ,    '0785' storenbr ,     'R1-Roosevelt' regionname ,   'D14-Sandus' districtname , 'VMS' companyname  from dual union all                                                                      
          select 83   storeid,  'Mt. Moriah' storename ,    '1174' storenbr ,     'R1-Roosevelt' regionname ,   'D15-Rickard' districtname , 'VMS' companyname  from dual union all                                                                
          select 260   storeid,  'Getwell' storename ,    '1576' storenbr ,     'R1-Roosevelt' regionname ,   'D12-Smart' districtname , 'VMS' companyname  from dual
    select decode(gc,0,companyname, 'VanderbiltFoods') as companyname
    ,       decode(gr,0,regionname,decode(gc,0,companyname, 'VanderbiltFoods')) as regionname
    ,       decode(gd,0,districtname,decode(gr,0,regionname,decode(gc,0,companyname, 'VanderbiltFoods'))) as districtname
    ,       decode(gs,0,storenbr,decode(gd,0,districtname,decode(gr,0,regionname,decode(gc,0,companyname, 'VanderbiltFoods')))) as storenbr
    ,       decode(gs,0,storename,decode(gd,0,districtname,decode(gr,0,regionname,decode(gc,0,companyname, 'VanderbiltFoods')))) as storename
    ,       net_sales
    ,       buns
    ,       condiments
    from    (   select    companyname
                ,         grouping(companyname)     gc
                ,         regionname
                ,         grouping(regionname)      gr
                ,         districtname
                ,         grouping(districtname)    gd
                ,         storenbr
                ,         grouping(storenbr)        gs
                ,         max(storename) storename
                ,         sum(net_sales)            net_sales
                ,         sum(buns)                 buns
                ,         sum(condiments)           condiments
                from store_data  stdata
                inner join sample_data   sampdata on sampdata.storeid  = stdata.storeid
                group by   rollup(companyname, regionname, districtname, storenbr), week_nbr
                order by   companyname nulls first,gc desc, regionname nulls first, gr desc, districtname nulls first, gd desc,storenbr nulls first, gs desc
    /*  --==  INCOMPLETE CODE --
        --== GET TABLE OF CONTENTS In same order as first cursor
        open pc_report_data for
        select   rownum as sortcol
        ,        storenbr
        ,        storename)
        BULK COLLECT INTO pc_TOC
    END create_rpt_and_toc;I don't know sQL developer well enough to view cursor results from stored procedure
    but here is test code from debugger window
    DECLARE
      PC_REPORT_DATA sys_refcursor;
      PC_TOC sys_refcursor;
    BEGIN
      CREATE_RPT_AND_TOC(
        PC_REPORT_DATA => PC_REPORT_DATA,
        PC_TOC => PC_TOC
      -- Modify the code to output the variable
      -- DBMS_OUTPUT.PUT_LINE('PC_REPORT_DATA = ' || PC_REPORT_DATA);
      -- Modify the code to output the variable
      -- DBMS_OUTPUT.PUT_LINE('PC_TOC = ' || PC_TOC);
    END;

    I am currently doing this in the presentation layer but is a lot cleaner and easier to maintain if handled in DB
    I'd googled that suggested this was possible. I had decided on the FETCH. But I've been to avoid FETCH and LOOP
    wherever possible.
    One eample I found: I always try so much stuff, I forget where i got the idea) was:
    -- pseudoscript
    FETCH outer cursor.
        Select outer cursor
        open second cursor for select into and CLOSE Cursor. 
    LOOPI also found this.
    create or replace procedure testproc(c_test out sys_refcursor) is
        begin
          open c_test for select first_name, last_name, email from employees where rownum < 10;
       end;Here though, its a simple select from a table vs. a cursor.
    I thouht it was woth asking the question.

  • Toplink support for stored procedure with 2 OUT  REF CURSOR ?

    Can Toplink StoredProcedureCall be used with Oracle PLSql procedure with 2 OUT parameters. Parameter type is Ref Cursor (Oracle PLSQL resulset)
    Regards

    In a TopLink StoredProcedureCall using an OUT CURSOR the cursor is assumed to map to the result set for the TopLink query.
    For example if you had a stored procedure READ_ALL_EMP that returned a out cursor of EMP rows, you could use that procedure in a TopLink mapped Employee class mapped to the EMP table and use the stored procedure in a ReadAllQuery for the Employee class.
    If the procedure does not return data that maps to objects, you can use a DataReadQuery to access the data. The out cursor would be returned as a Vector of DatabaseRows that contain the data from the cursor rows.
    If the procedures data is complex and does not map to objects, it may be better to access the procedure directly through JDBC.

  • Is BC4J a viabl option for database with stored procedure (ref cursor) API?

    I'm about to begin a Web application development project. As foundation, we have a (Oracle) database of certain complexity that have a data access API developed with PL/SQL packages.
    This API is designed to get data through stored procedures/functions that return REF CURSOR.
    Personally I have been investigating about Oracle ADF/JSF, and a number of others J2EE technologies, and at this moment I am doubting if ADF BC are a viable option to my development team.
    I think this because I have noticed that one of the great drawback in ADF BC is the lack of simplicity to get data through stored procedures/functions that returns REF CURSORS.
    I have been looking for documentation and the only thing that I have found are two examples:
    1.- One that really do not work (fails in get data from ref cursor): ADF BC StoredProcedure Sample application.
    2.- And other published by Steve Muench in
    http://radio.weblogs.com/0118231/stories/2003/03/03/gettingAViewObjectsResultRowsFromARefCursor.html. This sample works fine.
    But, the problem with the approach of this last article is the amount (and complexity) of the code necessary to make so basic and recurrent operation as is "obtain data through a stored procedure (ref cursor)".
    Below it is the code that I have constructed to call a function that returns a ref cursor (based on steve's article).
    If this is the only way to make this (historically so basic and simple) task, then it is obvious that BC is not a viable technology to my (or I am in a mistake?), since we have about 50 stored procedures/functions to access the underlying data; that stored procedures/functions are key to development of the new application (and, still more, currently are used to anothers apps ).
    By all this, I would like consult to Oracle's people:
    1.- I really must reject BC as technology to implement this project ?
    2.- It is possible to access stored procedures in a simpler way using BC?
    3.- If the answer to 2 is NOT: in near future, the BC team has plans to give more support to the simple access to stored procedures?
    4.- If the answer to 3 is NOT: what another technology you recommend to construct my data access/business tier and still be able to using the others characteristics of ADF?
    Thank you very much for your guidelines.
    Regards, RL.
    ** And the code!!!
    ** ###   I am forced to do this for each call to a procedure???? ###
    package myrefcursor.model;
    import java.math.BigDecimal;
    import java.sql.CallableStatement;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    import java.sql.SQLException;
    import java.sql.Types;
    import oracle.jbo.JboException;
    import oracle.jbo.domain.NullValue;
    import oracle.jbo.domain.Number;
    import oracle.jbo.server.DBTransaction;
    import oracle.jbo.server.ViewObjectImpl;
    import oracle.jbo.server.ViewRowImpl;
    import oracle.jbo.server.ViewRowSetImpl;
    import oracle.jdbc.driver.OracleCallableStatement;
    import oracle.jdbc.driver.OracleTypes;
    public class TraePolizasViewImpl extends ViewObjectImpl {
        private static final String SQL = "begin ? := PKG_PRUEBA.trae_polizas(?);end;";
        private static final String COUNTSQL = "begin ? := PKG_PRUEBA.count_trae_polizas(?);end;";
        public TraePolizasViewImpl() {
        protected void executeQueryForCollection(Object qc,Object[] params,int numUserParams) {
            BigDecimal rut_contratante = null;
            Object[] theUserParam = null;
            System.out.println(params);
            System.out.println(params[0]);
            if (params != null)
                theUserParam = (Object[]) params[0];
            //if (theUserParam != null && theUserParam.length > 0 )
            if (! (theUserParam[1]   instanceof NullValue) )
                rut_contratante = (BigDecimal)theUserParam[1];
            storeNewResultSet(qc ,retrieveRefCursor(qc, rut_contratante));
            super.executeQueryForCollection(qc, params, numUserParams);
        protected void create() {
          getViewDef().setQuery(null);
          getViewDef().setSelectClause(null);
          setQuery(null);
        protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet rs) {
          rs = getResultSet(qc);
          ViewRowImpl r = createNewRowForCollection(qc);
          try {
            populateAttributeForRow(r,0, nullOrNewNumber(rs.getBigDecimal(1)));
            populateAttributeForRow(r,1, rs.getString(2));
          catch (SQLException s) {
           throw new JboException(s);
          return r;
        protected boolean hasNextForCollection(Object qc) {
          ResultSet rs = getResultSet(qc);
          boolean nextOne = false;
          try {
            nextOne = rs.next();
            if (!nextOne) {
              setFetchCompleteForCollection(qc, true);
              rs.close();
          catch (SQLException s) {
           throw new JboException(s);
          return nextOne;
        protected void releaseUserDataForCollection(Object qc, Object rs) {
           ResultSet userDataRS = getResultSet(qc);
           if (userDataRS != null) {
            try {    userDataRS.close();    }
            catch (SQLException s) { ; }  
          super.releaseUserDataForCollection(qc, rs);
        public long getQueryHitCount(ViewRowSetImpl viewRowSet) {
          return viewRowSet.getRowCount();
        private ResultSet retrieveRefCursor(Object qc, BigDecimal rut_contratante) {
          CallableStatement st = null;
          try {
            st = getDBTransaction().createCallableStatement(SQL, DBTransaction.DEFAULT);
            st.registerOutParameter(1,OracleTypes.CURSOR);
            if (rut_contratante == null)
                st.setNull(2, Types.NUMERIC);
            else
                st.setBigDecimal(2, rut_contratante);
            st.execute();
            ResultSet rs = ((OracleCallableStatement)st).getCursor(1);
            rs.setFetchSize(getFetchSize());
            return rs ;
          catch (SQLException s) {
            throw new JboException(s);
          finally {try {st.close();} catch (SQLException s) {;}}
        private void storeNewResultSet(Object qc, ResultSet rs) {
          ResultSet existingRs = getResultSet(qc);
          if (existingRs != null) {
            try {existingRs.close();} catch (SQLException s) {;}  
          setUserDataForCollection(qc,rs);
          hasNextForCollection(qc); // Prime the pump with the first row.
        private ResultSet getResultSet(Object qc) {
            return (ResultSet)getUserDataForCollection(qc);
        private static Number nullOrNewNumber(BigDecimal b) {
             try {
               return b != null ? new Number(b) : null;
             catch (SQLException s) { ; }
             return null;
        public BigDecimal getprutcontratante() {
            return (BigDecimal)getNamedWhereClauseParam("prutcontratante");
        public void setprutcontratante(BigDecimal value) {
            setNamedWhereClauseParam("prutcontratante", value);
    }

    no?

  • Problem calling a ref cursor that is in a stored procedure

    I have a stored procedure that returns a ref cursor as follows and I want to call it from another procedure in the same package. It compiles, but when I run it, it gets errors.
    procedure procGetRefCursor(p_string in varchar2, p_int in integer, p_return out sys_refcursor) AS
    l_subrefcursor l_refcursor;
    begin
    open l_subrefcursor for
    SELECT myval
    FROM mytab a
    WHERE myval1 = p_string;
    end procGetRefCursor;
    The following code compiles, but when I run it it errors out on the fetch.
    ERROR at line 1:
    ORA-01001: invalid cursor
    I also tried opening the cursor first and that does not compile. I also tried
    fetch p_return.myval in l_myval
    that does not compile
    procedure callGetRefCursor(p_string in varchar2,p_int in integer) is
    p_return sys_refcursor;
    l_myval varchar2(100);
    begin
    procGetRefCursor(p_string, p_int, p_return);
    loop
    fetch p_return into l_myval;
    dbms_output.put_line('myval '||l_myval);
    exit when p_return%notfound;
    end loop;
    end;

    Where is l_refcursor defined?
    And why?
    Aren't you using SYS_REFCURSOR?

  • Stored procedure with multiple Reference Cursors

    In Sybase and SQLServer, result sets are returned to the application implicitly. Oracle emulates this by passing back weak reference cursors to the application through an IN OUT parameter.The number of reference cursors must match the number of results sets. For example, if 2 select statements are present in the stored procedure code, then 2 reference cursors are passed back.The Oracle Migration Workbench creates the correct number of reference cursors but assigns each select statement results to the first cursor created. Therefore only the last set of results are returned to the client.
    Before (SQLServer)
    CREATE PROCEDURE get_sch_associated_appointment_info (@piAcc_itn int) AS SELECT s.acc_itn, r.internal_key, r.mnemonic, r.descp, sh.start_dtime, sh.end_dtime FROM schdtl s, schdtlhdr sh, resource r WHERE s.acc_itn = @piAcc_itn and sh.acc_itn = @piAcc_itn and sh.resource_itn = r.internal_key SELECT sdcr.acc_itn, sdcr.rsch_dtime, sdcr.rsch_by_init, sdcr.rsch_code, sdcr.rsch_reason, sdcr.cncl_dtime, sdcr.cncl_by_init, sdcr.cncl_code, sdcr.cncl_reason, sdcr.prev_start_dtime, sdcr.prev_by_init FROM schdtl_canrsch sdcr WHERE sdcr.acc_itn = @piAcc_itn SELECT sdi.acc_itn, i.sched_notes, i.post_sched_notes, d.pre_sch_notes, d.post_sch_notes, i.detail_key, i.output_notes FROM schdtl_info sdi, extitem i, dept d WHERE sdi.acc_itn = @piAcc_itn and sdi.actual_dept = i.dept and sdi.actual_proc_no = i.proc_no and sdi.actual_dept = d.dept
    After (Migration Workbench) – Optional Section
    CREATE OR REPLACE PROCEDURE get_sch_associated_appointment_info (piAcc_itn int, RC1 IN OUT Omwb_emulation.globalPkg.RCT1) AS OPEN RC1 SELECT s.acc_itn, r.internal_key, r.mnemonic, r.descp, sh.start_dtime, sh.end_dtime FROM schdtl s, schdtlhdr sh, resource r WHERE s.acc_itn = piAcc_itn and sh.acc_itn = piAcc_itn and sh.resource_itn = r.internal_key; OPEN RC1 SELECT sdcr.acc_itn, sdcr.rsch_dtime, sdcr.rsch_by_init, sdcr.rsch_code, sdcr.rsch_reason, sdcr.cncl_dtime, sdcr.cncl_by_init, sdcr.cncl_code, sdcr.cncl_reason, sdcr.prev_start_dtime, sdcr.prev_by_init FROM schdtl_canrsch sdcr WHERE sdcr.acc_itn = piAcc_itn; OPEN RC1 SELECT sdi.acc_itn, i.sched_notes, i.post_sched_notes, d.pre_sch_notes, d.post_sch_notes, i.detail_key, i.output_notes FROM schdtl_info sdi, extitem i, dept d WHERE sdi.acc_itn = piAcc_itn and sdi.actual_dept = i.dept and sdi.actual_proc_no = i.proc_no and sdi.actual_dept = d.dept;
    After (Manual Change)
    CREATE OR REPLACE PROCEDURE get_sch_associated_appointment_info (piAcc_itn int, RC1 IN OUT Omwb_emulation.globalPkg.RCT1, RC2 IN OUT Omwb_emulation.globalPkg.RCT1, RC3 IN OUT Omwb_emulation.globalPkg.RCT1) AS OPEN RC1 SELECT s.acc_itn, r.internal_key, r.mnemonic, r.descp, sh.start_dtime, sh.end_dtime FROM schdtl s, schdtlhdr sh, resource r WHERE s.acc_itn = piAcc_itn and sh.acc_itn = piAcc_itn and sh.resource_itn = r.internal_key; OPEN RC2 SELECT sdcr.acc_itn, sdcr.rsch_dtime, sdcr.rsch_by_init, sdcr.rsch_code, sdcr.rsch_reason, sdcr.cncl_dtime, sdcr.cncl_by_init, sdcr.cncl_code, sdcr.cncl_reason, sdcr.prev_start_dtime, sdcr.prev_by_init FROM schdtl_canrsch sdcr WHERE sdcr.acc_itn = piAcc_itn; OPEN RC3 SELECT sdi.acc_itn, i.sched_notes, i.post_sched_notes, d.pre_sch_notes, d.post_sch_notes, i.detail_key, i.output_notes FROM schdtl_info sdi, extitem i, dept d WHERE sdi.acc_itn = piAcc_itn and sdi.actual_dept = i.dept and sdi.actual_proc_no = i.proc_no and sdi.actual_dept = d.dept;

    I believe you are using .NET(?). If that is the case, please post this query to the .NET Development - Crystal Reports  forum:
    SAP Crystal Reports, version for Visual Studio
    That forum is monitored by qualified technicians and you will get a faster response there.
    Thank you for your understanding,
    Ludek

  • STORED PROCEDURE/REF CURSOR: How to output entire buffer

    I wrote a Stored Procedure wherein I use a Cursor to extract multiple
    rows and columns. I then write them into the buffer
    (dmbs_output.put_line). But when I try to capture the entire result
    into an OUT variable, I only get the last buffered line.
    So how do I output the entire buffer- all rows and columns? In other words (maybe), how do I use dbms_output.get_lines() to assign value to an OUT variable?
    Alternatively, using REF CURSOR as OUT variable, I added the following to "CREATE OR REPLACE PROCEDURE ... ()":
    cursor_out_test OUT cursor_test
    But when I tried:
    DEFINE CURSOR TYPE cursor_test IS REF CURSOR RETURN table%ROWTYPE;
    ...or...
    DECLARE TYPE cursor_test IS REF CURSOR RETURN table%ROWTYPE;
    I still got syntax errors.
    In one line, what I am trying to do is break the result array at the database level rather than at the application level.
    Cheers, Bill
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#LNPLS00605

    I did the following:
    OPEN CURSOR x
         LOOP
              FETCH CURSOR x INTO col1, col2
              (EXIT WHEN...)
              variable_line := col1 || col2
         END LOOP
    CLOSE CURSOR
    But after closing this cursor, variable_line contains only the last buffered line. I want all the looped lines (without using associative arrays, nested tables etc). So I guess I am just looking for some way to append data lines- adding chr(10) doesn't work either.
    Cheers, Bill

  • Updateable recordset from a stored procedure

    I would like to retrieve an updateable recordset from a stored procedure using the oracle 9.2.0.2.0
    oledb provider
    I am using the sample code/tables provided from Oracle.
    Does anyone have an example or has actually created an updatedable recordset from a stored procedure ?

    Assuming your stored procedure is returning a REF CURSOR, it cannot be done. Oracle's REF CURSORS are read only constructs.
    Justin

  • Prevent Duplicates from Inserting from File in Stored Procedure

    CREATE TABLE dbo.Logins
    [ID] numeric(10, 0) NOT NULL Primary Key,
    [Dr_FName] varchar(50) NOT NULL,
    [Dr_LName] varchar(50) NOT NULL,
    [Login] varchar(50) NOT NULL
    GO
    CREATE TABLE [dbo].[CRIS_USER] (
    [id] numeric(10, 0) NOT NULL Primary Key,
    [login_id] varchar(20) NOT NULL
    GO
    CREATE TABLE [dbo].[CRIS_SYSTEM_USER] (
    [id] numeric(10, 0) NOT NULL Primary Key,
    [cris_user_id] numeric(10, 0) NOT NULL,
    INSERT INTO Logins
    (ID, Dr_FName, Dr_LName,Login)
    VALUES(1,'Lisa','Mars','lmars')
    INSERT INTO Logins
    (ID, Dr_FName, Dr_LName,Login)
    VALUES(2,'Becky','Saturn','bsaturn')
    INSERT INTO Logins
    (ID, Dr_FName, Dr_LName,Login)
    VALUES(3,'Mary','Venus','mvenus')
    INSERT INTO CRIS_USER
    (ID,login_id)
    VALUES(10, 'lmars')
    INSERT INTO CRIS_USER
    (ID,login_id)
    VALUES(20, 'bsaturn')
    INSERT INTO CRIS_USER
    (ID,login_id)
    VALUES(30, 'mvenus')
    INSERT INTO CRIS_SYSTEM_USER
    (ID,cris_user_id)
    VALUES(110, 10)
    INSERT INTO CRIS_SYSTEM_USER
    (ID,cris_user_id)
    VALUES(120,20)
    INSERT INTO CRIS_SYSTEM_USER
    (ID,cris_user_id)
    VALUES(130, 30)
    I'm aware that "ID" is a bad column name and that it should not be numeric. The ID columns are incremented by a program. They are not auto incremented. I didn't design it.
    I have a stored procedure that does a bulk insert from a tab delimited file into the three tables:
    CREATE PROCEDURE [dbo].[InsertUserText]
    WITH EXEC AS CALLER
    AS
    IF OBJECT_ID('TEMPDB..#LoginTemp') IS NULL
    BEGIN
    CREATE TABLE #LoginTemp(Login varchar(50),Dr_FName varchar(50),Dr_LName varchar(50))
    BULK INSERT #LoginTemp
    FROM 'C:\loginstest\InsertUserText.txt'
    WITH (ROWTERMINATOR ='\n'
    -- New Line Feed (\n) automatically adds Carrige Return (\r)
    ,FIELDTERMINATOR = '\t'
    --delimiter
    ,FIRSTROW=4)
    PRINT 'File data copied to Temp table'
    END
    DECLARE @maxid NUMERIC(10,0)
    DECLARE @maxid2 NUMERIC(10,0)
    DECLARE @maxid3 NUMERIC(10,0)
    BEGIN TRANSACTION
    SELECT @maxid = coalesce(MAX(ID), 0)
    FROM dbo.LOGINS WITH (UPDLOCK)
    INSERT INTO dbo.LOGINS(ID,Dr_FName,Dr_LName,Login)
    SELECT row_number() OVER(ORDER BY (SELECT NULL)) + @maxid,
    Dr_FName,Dr_LName,Login
    FROM #LoginTemp
    WHERE #LoginTemp.Dr_FName is not Null;
    SELECT @maxid3 = coalesce(MAX(id), 0)
    FROM dbo.CRIS_USER WITH (UPDLOCK)
    INSERT INTO dbo.CRIS_USER(id,login_id)
    SELECT row_number() OVER(ORDER BY (SELECT NULL)) + @maxid3,
    Login
    FROM #LoginTemp
    WHERE #LoginTemp.Dr_FName is not Null;
    SELECT @maxid2 = coalesce(MAX(id), 0)
    FROM dbo.CRIS_SYSTEM_USER WITH (UPDLOCK)
    INSERT INTO dbo.CRIS_SYSTEM_USER(id,cris_user_id)
    SELECT row_number() OVER(ORDER BY (SELECT NULL)) + @maxid2,
    + row_number() OVER(ORDER BY (SELECT NULL)) + @maxid3
    FROM #LoginTemp
    WHERE #LoginTemp.Dr_FName is not Null;
    PRINT 'Copied from Temp table to CRIS_USER'
    COMMIT TRANSACTION
    GO
    What suggestions do you have to prevent a duplicate Logins.Login? None of the inserts for all three tables should occur if a login already exists in the Logins table. There should be a message to indicate which Login failed. I haven't yet decided if I want
    all of the logins in the text file to fail if there is a duplicate, or just the one with the duplicate. I'm open to suggestions on that. So far, the duplicates only occur when someone forgets to update the tabbed delimited file and accidently runs the procedure
    on an old one. I'm sure I can come up with an if statement that will accomplish this. I could maybe use WHERE EXISTS or WHERE NOT EXISTS. But I know I can get a good solution here.
    I'm also aware that duplicates could be prevented in the table design. Again, I didn't design it.
    I have a tab delimited file created but don't see a way to attach it.
    Thanks for any help.

    Thanks to all three that replied. I meant to mark the question as answered sooner. I've tried all the suggestions on a test system. All will work with maybe some slight variations. Below was my temporary quick fix. I'm working on switching to a permanent
    solution based on the replies.
    This is not the real solution and is not the answer to my question. It's just temporary.
    IF OBJECT_ID('TEMPDB..#LoginTemp') IS NULL
    BEGIN
    CREATE TABLE #LoginTemp(Login varchar(50),Dr_FName varchar(50),Dr_LName varchar(50))
    BULK INSERT #LoginTemp
    FROM 'C:\loginstest\InsertUserText.txt'
    WITH (ROWTERMINATOR ='\n'
    Return (\r)
    ,FIELDTERMINATOR = '\t'
    ,FIRSTROW=4)
    PRINT 'File data copied to Temp table'
    END
    DECLARE @maxid NUMERIC(10,0)
    DECLARE @maxid2 NUMERIC(10,0)
    DECLARE @maxid3 NUMERIC(10,0)
    IF EXISTS(SELECT 'True' FROM Logins L INNER JOIN #LoginTemp LT on L.Login = LT.Login
    BEGIN
    SELECT 'Duplicate row!'
    END
    ELSE
    BEGIN
    BEGIN TRANSACTION
    SELECT @maxid = coalesce(MAX(ID), 0)
    FROM dbo.LOGINS WITH (UPDLOCK)
    INSERT INTO dbo.LOGINS(ID,Dr_FName,Dr_LName,Login)
    SELECT row_number() OVER(ORDER BY (SELECT NULL)) + @maxid,
    Dr_FName,Dr_LName,Login
    FROM #LoginTemp
    WHERE #LoginTemp.Dr_FName is not Null;
    SELECT @maxid3 = coalesce(MAX(id), 0)
    FROM dbo.CRIS_USER WITH (UPDLOCK)
    INSERT INTO dbo.CRIS_USER(id,login_id)
    SELECT row_number() OVER(ORDER BY (SELECT NULL)) + @maxid3,
    Login
    FROM #LoginTemp
    WHERE #LoginTemp.Dr_FName is not Null;
    SELECT @maxid2 = coalesce(MAX(id), 0)
    FROM dbo.CRIS_SYSTEM_USER WITH (UPDLOCK)
    INSERT INTO dbo.CRIS_SYSTEM_USER(id,cris_user_id)
    SELECT row_number() OVER(ORDER BY (SELECT NULL)) + @maxid2,
    + row_number() OVER(ORDER BY (SELECT NULL)) + @maxid3
    FROM #LoginTemp
    WHERE #LoginTemp.Dr_FName is not Null;
    COMMIT TRANSACTION
    END
    GO

  • How to determine number of records in recordset returned by stored procedure?

    In TestStand 3.0 I am calling an SQL stored procedure where the stored
    procedure returns a recordset. Everything appears to work (I can
    iterate through the recordset and see that the data is valid).
    However, I can not figure out how to easilly determine how many
    records are actually in the recordset. Unlike the 'Open SQL
    Statement' step, in the 'Data Operation' step that actually invokes
    the stored procedure, there is no 'Number of Records Selected' option
    to specify a TestStand variable to accept this value. I know I could
    iterate through the returned recordset incrementing a counter until a
    Fetch fails, but for larger recordsets, traversing the table multiple
    times would be quite time consuming
    . I am hoping to avoid this if
    possible. Is there an easier way to get the number of records in a
    recordset returned from a stored procedure call?
    Bob

    Bob -
    The cursor type of the ADO Recordset object affects whether the number of records can be determined. The Recordset.RecordCount property will return -1 for a forward-only cursor; the actual count for a static or keyset cursor; and either -1 or the actual count for a dynamic cursor, depending on the data source.
    Because ADO does not let me set the cursor type for command objects which is what a stored procedure requires, it is up to the data source to determine the type of cursor and the support for record count.
    Scott Richardson (NI)
    Scott Richardson
    National Instruments

  • Calling stored procedure

    Hello Techies
    I want to call a stored procedure which does not return anything but it executes the query inside itself.
    How should I take the output from it �I want 3 values from that procedure.
    The stored procedure is:::::::
    CREATE Procedure NewPFAttendance_Register
         @fromdate varchar(25),
         @todate varchar(25),
    @Ecode nvarchar(200)
    As
    SET NOCOUNT ON
    Declare @l varchar(10)
    Declare @todate1 datetime
    Declare @fromdate1 datetime
    set @todate1=convert(varchar(25),@todate)
    set @fromdate1=convert(varchar(25),@fromdate)
    Create table #tempdate (tdate datetime,ecode nvarchar(20))
    Create table #Tcode (empcode nvarchar(30))
    Create table #Details(empcode nvarchar(30),wdays int,pdays int,adays int,ldays int)
    Create table #tempmon(mon nvarchar(20),yr int)
    Create table #final(ecode nvarchar(20),mon nvarchar(20),yr int,nodays int,mindate datetime,maxdate datetime,wdays int,pdays int)
    Create table #finalP(ecode nvarchar(20),pdays int)
    if datediff(d,@todate1,@fromdate1)>0
    raiserror ('Todate should be greater then from date',18,1)
    while datediff(d,@todate1,@fromdate1)<=0
    begin
    insert into #tempdate values (@fromdate1,@Ecode)
    set @fromdate1=dateadd (d,1,@fromdate1)
    end
    Declare @Totalmon int, @MName nvarchar(20)
    Set @Totalmon=DateDiff(month,@fromdate,@todate)
    Declare @i int
    Set @i=0
    while (@Totalmon>=0)
    begin
    insert into #tempmon(mon,yr) values (DATENAME(month,@fromdate1),DATENAME(year,@fromdate1))
    Set @Totalmon=@Totalmon-1
    Set @fromdate1=dateadd (mm,-1,@fromdate1)
    end
    -- Added By Prashant on 11 Oct 2005
    insert into #Tcode values (@ECODE)
    --End
    Select a.empcode,a.name,tdate,
    Case when (select timein from tblattendance c where c.empcode=a.empcode
         and c.tsdate=b.tdate )is null
    then
    Case when (select purpose from tblholiday a where a.tsdate=b.tdate )is null
    then
         Case when (select leave from tblleave l where l.empcode=a.empcode and
              l.tsdate=b.tdate )is null then 'A'
    else
              (select leave from tblleave l where l.empcode=a.empcode and
              l.tsdate=b.tdate )--is null then 'A'--'L'
              end
    else
    'H'
    end
         else
    'P'
    end
    as intime,a.designation,a.DOJ
    into #umang
    from tblcode a,#tempdate b order by a.empcode
    --,#TCode d where d.empcode=a.empcode and b.tdate>=d.tcdate order by a.empcode
    alter table #umang alter COLUMN intime varchar(25)
    update #umang set intime='Sat' where datepart (dw,tdate)=7
    update #umang set intime='Sun' where datepart (dw,tdate)=1
    Declare @Predate datetime
    Declare Present1 Cursor for
    Select tdate from #Tempdate
    Open Present1
    fetch next from Present1 into @Predate
    Declare @Cnt int
    Set @Cnt=0
    while @@fetch_status=0
    begin
    --Print @Predate
    if (datepart(dw,@Predate)=7 or datepart(dw,@Predate)=1)
    begin
    Set @Cnt=@Cnt+1
    end
    fetch next from Present1 into @Predate
    end
    CLOSE Present1
    Deallocate Present1
    Declare @Workday int ,@TotalDays Int
    set @Workday=dbo.fWorkingDaysBetween(@fromdate,@todate)
    Set @TotalDays=DateDiff(day,@fromdate,@todate)
    --Print @TotalDays
    Declare @Pre nvarchar(25)
    Declare Present Cursor for
    Select empcode from #TCode
    Open Present
    fetch next from Present into @Pre
    Declare @Pdays int
    Declare @Ldays int
    Declare @Adays int
    Declare @Adays1 int
    Declare @Adays2 int
    Declare @Adays3 int
    while @@fetch_status=0
    begin
    Set @Pdays=(select count(timein) from tblattendance a,#TCODE b where tsdate between @fromdate and @todate and a.empcode=b.empcode and a.empcode=@Pre and datepart(dw,tsdate)<>7 and datepart(dw,tsdate)<> 1)
    Set @Ldays=(select count(*) from tblleave a,#TCODE b where tsdate between @fromdate and @todate and a.empcode=b.empcode and a.empcode=@Pre )
    Set @Adays=@Workday-(@Pdays+@Ldays)
    DECLARE @final int
    Set @final=(@TotalDays-@Adays)
    insert into #Details values(@Pre,@WorkDay,@Pdays,@Adays,@Ldays)
    fetch next from Present into @Pre
    end
    CLOSE Present
    Deallocate Present
    insert into #final (ecode,mon,yr,nodays ,mindate ,maxdate ,wdays)
    select ecode,DateName(month,max(tdate)),Datename(year,max(tdate)), count (tdate), min(tdate),max(tdate),dbo.fWorkingDaysBetween(min(tdate),max(tdate)) as working from #tempdate group by month(tdate),year(tdate),ecode
    select * from #final
    Declare @Dt1 datetime,@Dt2 datetime
    Declare DtCal Cursor for
    Select mindate,maxdate from #final
    Open DtCal
    fetch next from DtCal into @Dt1,@Dt2
    while @@fetch_status=0
    begin
    Declare @Dtfin1 varchar(25)
    Declare @Dtfin2 varchar(25)
    set @Dtfin1=convert(varchar(25),@Dt1,101)
    set @Dtfin2=convert(varchar(25),@Dt2,101)
    --Print @Dt1
    --Print @Dt2
    --Print @Dtfin1
    --Print @Dtfin2
    Declare @Pldays int ,@Abdays int ,@Monnm nvarchar(20),@Yrnm int
    Set @Pldays=(select count(timein) from tblattendance where tsdate between @Dtfin1 and @Dtfin2 and empcode=@Ecode and datepart(dw,tsdate)<>7 and datepart(dw,tsdate)<> 1 )
    Set @Monnm=(select Datename(month,@Dt1))
    Set @Yrnm=(select Datename(year,@Dt1))
    update #final set Pdays=@Pldays where mon=@Monnm and yr=@Yrnm
    --update #final set pdays='0' where  mon='January' and yr='2005'
    --insert into #finalP(ecode,pdays) values (@Ecode,@Pldays)
    Print @Monnm
    Print @Pldays
    fetch next from DtCal into @Dt1,@Dt2
    end
    CLOSE DtCal
    Deallocate DtCal
    select * from #final
    --select * from #final a, #finalP b where a.ecode= b.ecode and a.
    --EXEC NewPFAttendance_Register '01/01/2005','03/02/2005','2854'
    GO
    My java code is :::::::
    "In my code ,in line
    sDate = cstmt.getString("mon");
    "mon" is the column name"
    public String callStoredProcedureResultset(String startDate,String >endDate,String empId){             
         CallableStatement cstmt = null;
         String sDate = null;
         try{                 
              cstmt =conn.prepareCall("{call >NewPFAttendance_Register(?,?,?)}");     
              cstmt.setString(1,startDate);
    cstmt.setString(2,endDate);
    cstmt.setString(3,empId);
    ResultSet rs = cstmt.executeQuery();
    while(rs.next()){
    sDate = cstmt.getString("mon");
              System.out.println("Start Date in >callStoredProcedureResultset::::::"+sDate);
    cstmt.close();
    } }catch (Exception e){
    e.printStackTrace();}
         return sDate;
    }//End of callStoredProcedureResultset

    I want to call a stored procedure which does not
    return anything but it executes the query inside
    itself.
    How should I take the output from it �I want 3 values
    from that procedure.declare the variables as OUT and register them as output parameters.
    The stored procedure is:::::::instead of writing all that, it is better to post something which would be readable.

  • Multithreading and stored procedures

    Hi,
    Does anyone know of any problems with calling a stored procedure that returns a reference cursor in a multithreading application? In other words, if I have multiple threads calling the same stored procedure is the reference cursor guarenteed to be unique to each thread/thread safe?
    Thanks in advance,
    Glenn

    That should work fine and each call will get a separate ref cursor as long as the app is written properly and is managing it's threads anbd handles properly. Are you seeing some behaviour that suggests this is not the case?
    Chris

  • Using VARRAYs as parameters to a Stored Procedure

    I'm trying to pass a VARRAY as an IN/OUT parameter into a simple stored procedure by doing the following ..
    call.addNamedInOutputArgument(.., .., .., oracle.sql.ARRAY.class);
    I'm using a DataReadQuery. I set the call in the query, bind all parameters and add the IN/OUT argument to the query (i.e. query.addArgument(<name>)). Then I create an oracle.sql.ArrayDescriptor to describe the ARRAY.
    ArrayDescriptor ad = ArrayDescriptor.createDescriptor(<name of VARRAY>, <connection>);
    The VARRAY is of size 1 whose type is INTEGER. I create an ARRAY of Integer objects.
    Integer fields[1] = new Integer[1];
    fields[0] = new Integer(2);
    ARRAY a = new ARRAY(ad, <connection>, fields);
    I create a Vector of parameters and add the ARRAY to it. Then I execute the query ..
    Object result = session.executeQuery(<query>, <Vector>);
    When I execute the query I keep getting an ORA-06550: wrong number or types of arguments in call to <stored procedure>. Any help would be appreciated. Thanks. -Michael-

    The workaround above using JDBC directly to call store procedures using VARRAY types is still probably your best solution.
    In TopLink 10.1.3 there is a new API on StoredProcedureCall that allows passing the JDBC type code which should allow binding of VARRAY output parameters.
    addNamedInOutputArgument(String procedureParameterName, String inArgumentFieldName, String outArgumentFieldName, int type, String typeName) {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Passing DATE parameters to Oracle Stored Procedures using ADO

    Does anyone know how can I pass a date parameter to an Oracle
    Stored Procedure? The IN parameter of the procedure is of type
    DATE and the ADO parameter is of type DBDate (I've tried Date
    and DBTimeStamp,too). The execution freezes at "Cmd.Execute".
    Can anyone suggest a solution?
    Thanx for any tips

    As far as I know the documentation on CR & stored procedures says that the REF CURSOR has to be a strongly bound one.
    Could you go into a little more detail? Do you mean I should put a multi-valued parameter into a REF CURSOR? Can you post some code snippets here?

Maybe you are looking for