Sql greater than 32k in sys_refcursor

hi
We have to write function/procedure to form reports in java there we just bind the record sets into grid. We have to return the record set as SYS_REFCURSOR.
Most of the sqls are involved in pivoting and so query length is beat 32k.
Is there any way to pass the large sql to ref cursor?
    CREATE OR REPLACE FUNCTION TESTFUN (pREFCUR OUT SYS_REFCURSOR) RETURN NUMBER
    IS
        vSQLSTR VARCHAR2(32000);
        nRETURN NUMBER;
    BEGIN
        vSQLSTR := ' SQL > 32K ';
        OPEN pREFCUR FOR vSQLSTR;
            RETURN 1;
        EXCEPTION
            WHEN OTHERS THEN
                COMMONEXCEPTIONHANDLER(SQLCODE, SQLERRM); -- log errors which is having RAISE_APPLICATION_ERROR
                RETURN -1;
    END;version
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE    10.2.0.1.0      Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - ProductionAdded Version details
Edited by: knksoft on Jun 7, 2013 6:44 AM

>
using DBMS_SQL i can parse and execute sqls. But i have to return my output by refcursor. If it is PLSql limit, is there any work around available?
>
The only option I can think of for your Oracle version is:
1. create a pipelined function that uses DBMS_SQL to create rows for the result set. Here is a sample PIPELINED function; yours would gather the rows using DBMS_SQL.
CREATE OR REPLACE function get_emp_data
  return emp_table_type
  PIPELINED
  as
   TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
    emp_cv EmpCurTyp;
    l_rec  emp%rowtype;
  begin
    open emp_cv for select * from emp;
    loop
      fetch emp_cv into l_rec;
      exit when (emp_cv%notfound);
      pipe row( emp_scalar_type( l_rec.empno, LOWER(l_rec.ename),
          l_rec.job, l_rec.mgr, l_rec.hiredate, l_rec.sal, l_rec.comm, l_rec.deptno ) );
    end loop;
    return;
  end;
/ 2. create a simple procedure that opens and returns a REF CURSOR on a call to that pipelined procedure
OPEN myCursor FOR SELECT * FROM TABLE(get_emp_data);That 'myCursor' would be the REF CURSOR that gets returned to the client.

Similar Messages

  • Output from Concurrent program in XML format for bytes greater than 32K

    Hi,
    I created a custom concurrent program where i send the generated XML data as an output to the program.
    I have an XML template attached to the program, so the template picks up the xml output and converts it to a PDF.
    so ultimately when i run the concurrent program, the output is a PDF file. This way it is easy for the user to just run a program and get a PDF file.
    Now the generated XML data is from an oracle seeded program and it is a BLOB.
    I am converting it to a CLOB so that i can write it to the output. if the CLOB doesnt exceed 32K bytes, i have no issues writing it to the output.
    But since we cannot write more than 32K bytes, i an using a substr to write chunks of the CLOB for every 30,000 bytes.
    since it is chunking at every 30,000 bytes the next 30,000 bytes are coming in the next line and XML publisher is throwing an error with invalid character.
    Any idea how i can overcome this?
    Either i write the whole 33000+ bytes in one line to the fnd output or try to remove the line breaks from the xml data.
    Thanks in advance for anyone reading this!

    >
    > since it is chunking at every 30,000 bytes the next 30,000 bytes are coming in the next line and XML publisher is throwing an error with invalid character.
    Any idea how i can overcome this?So I suppose you're using FND_FILE.PUT_LINE ?
    Why not use FND_FILE.PUT instead, so that no new line is generated after each chunk ?
    http://docs.oracle.com/cd/E18727_01/doc.121/e12897/T302934T458258.htm#I_fndfile

  • Passing variable of size greater than 32767 from Pro*C to PL/SQL procedure

    Hi,
    I am trying to pass a variable os size greater than 32767 from Pro*C to an SQL procedure.I tried assigning the host variable directly to a CLOB in the SQL section but nothing happens.In the below code the size of l_var1 is 33000.PROC_DATA is a procedure that takes CLOB as input and gives the other three(Data,Err_Code,Err_Msg) as output.These variables are declared globally.
    Process_Data(char* l_var1)
    EXEC SQL EXECUTE
    DECLARE
    l_clob clob;
    BEGIN
    l_clob := :l_var1
    PROC_DATA(l_clob,:Data,:Err_Code,:Err_Msg) ;
    COMMIT;
    END;
    END-EXEC;
    I also tried using DBMS_LOB.This was the code that i used.
    Process_Data(char* l_var1)
    EXEC SQL EXECUTE
    DECLARE
    l_clob clob;
    BEGIN
    DBMS_LOB.CREATETEMPORARY(l_clob,TRUE);
    DBMS_LOB.OPEN(l_clob,dbms_lob.lob_readwrite);
    DBMS_LOB.WRITE (l_clob, LENGTH (:l_var1), 1,:l_var1);
    PROC_DATA(l_clob,:Data,:Err_Code,:Err_Msg) ;
    COMMIT;
    END;
    END-EXEC;
    Here since DBMS_LOB packages allow a maximum of 32767,the value of l_var1 is not being assigned to l_clob.
    I am able to do the above process provided i split l_var1 into two variables and then append to l_clob using WRITEAPPEND.i.e l_var1 is 32000 in length and l_var2 contains the rest.
    Process_Data(char* l_var1,char* l_var2)
    EXEC SQL EXECUTE
    DECLARE
    l_clob clob;
    BEGIN
    dbms_lob.createtemporary(l_clob,TRUE);
    dbms_lob.OPEN(l_clob,dbms_lob.lob_readwrite);
    DBMS_LOB.WRITE (l_clob, LENGTH (:l_var1), 1,:l_var1);
    DBMS_LOB.WRITEAPPEND (l_clob, LENGTH(:l_var2), :l_var2);
    PROC_DATA(l_clob,:Data,:Err_Code,:Err_Msg) ;
    COMMIT;
    END;
    END-EXEC;
    But the above code requires dynamic memory allocation in Pro*C which i would like to avoid.Could you let me know if there is any other way to perform the above?

    Hi,
    The Long Datatype has been deprecated use Clob or Blob. This will solve lot of problems inherent with the datatype.
    Regards,
    Ganesh R

  • GREATER THAN symbol appearing as &gt ; in SQL*Plus

    Version:11.2.0.3
    OS : RHEL 5.4
    We are a Software vedor firm.We have sent our SQL files to our client to execute. But the codes for various procedures and functions were failing
    because, in their SQL*Plus session (in Putty) the LESS THAN character < was appearing as &lt ; and GREATER THAN character > was appearing as &gt ;
    In the original code which we had sent to them has no problems with > or < characters.
    Original code
    Cursor feb_cur IS
      SELECT user_pwid
        FROM carton_hdr_dtl
       WHERE MODIFIED_DATE >= D_Last_Run_Date
       UNION
      SELECT user_pwid
        FROM carton_hdr_dtl_bkp
       WHERE (modified_date >= D_Last_Run_Date OR
              deleted_date >= D_Last_Run_Date);  But in the execution log file sent by our client, I can see &gt ; instead of > character.
    54   Cursor feb_cur IS
    55    SELECT user_pwid
    56        FROM carton_hdr_dtl
    57       WHERE MODIFIED_DATE &gt ;= D_Last_Run_Date
    58       UNION
    59    SELECT user_pwid
    60        FROM carton_hdr_dtl_bkp
    61       WHERE (modified_date &gt ;= D_Last_Run_Date OR
    62              deleted_date &gt;= D_Last_Run_Date);What are they doing wrong? They use putty. We use putty too but we don't have any issues.
    Edited by: Max on Dec 17, 2012 2:42 AM

    Thank you Blushadow, Nicosa for providing this clue.
    I checked with my client. They have put our scripts in Collabnet SVN version control and the implementor DBA will be provided the http URL .
    Apparently SVN is accessed using http protocol and yes you are right it is opened through a browser by typing an URL like below
    http://10.80.16.214:79839/svn/brcf/DBfiles/2012/WMHReleasel8/hrtb_pkt_wave.sqlFor most of the end users , the GREATER THAN character appears as > without any issues . For some users it appears as &gt ; . One potential cause is the difference in Internet Explorer version. They are currently looking into this.
    THANK YOU BLUSHADOW and NICOSA for shedding light on this.
    Hi Nicosa,
    A forum formatting question:
    How did you manage to get &gt_; (without the underscore) printed ? When I tried it the forums editor was converting it to > . This is why I placed a space/underscore between t and semi colon. Is there some escape character ?

  • Greater than operator in SQL

    Hi friends,
    A table has 2 colums A and B.How i can return a flag ,say 1 if A is greater than B or 0 if A is less than B,by using SQL.
    Can any one help me out.
    thanks and regards,
    Ajith

    select a,b,case when a > b then 1
                    when a=b   then 0
                    else -1
               end FLAG
    from table;                                                                                                                                                                                                                                                                               

  • How can a function returning character length greater than 4000 be selected in SQL

    Hi,
    I want to know if there is a way to write a select query on a function call which returns a varchar of more than 4000 characters.
    CREATE OR REPLACE FUNCTION FUNC1
    RETURN VARCHAR2
    IS
    str VARCHAR2(32767);
    BEGIN
         str := <some string greater than 4000 char>;
          RETURN str;
    END;
    SELECT FUNC1 from dual; ---- This gives an PL/SQL numeric or value error. Character string buffer too small.
    Is there any way to resolve this?
    Thanks

    32767 is not default. The default is still 4000 for VARCHAR2. You need to set the initialization parameter MAX_STRING_SIZE= EXTENDED for 32767.
    Text from Oracle documentation
    Extended Data Types
    Beginning with Oracle Database 12c, you can specify a maximum size of 32767 bytes for the VARCHAR2, NVARCHAR2, and RAW data types. You can control whether your database supports this new maximum size by setting the initialization parameter MAX_STRING_SIZE as follows:
    If MAX_STRING_SIZE = STANDARD, then the size limits for releases prior to Oracle Database 12c apply: 4000 bytes for the VARCHAR2 and NVARCHAR2 data types, and 2000 bytes for the RAW data type. This is the default.
    If MAX_STRING_SIZE = EXTENDED, then the size limit is 32767 bytes for the VARCHAR2, NVARCHAR2, and RAW data types.

  • Unit Testing  - Results greater than 0

    I am unit testing a PL/SQL function. The function has no inputs and one output (Interval Day to Second) . The output is the time it takes to run a query therefore a valid value for the output would be greater than 0.
    When I setup the test the result only takes a Interval Day to Second value. I want to be able to say any result greater than 0 is a success.
    How can I do this?
    tom

    I am unit testing a PL/SQL function. The function has no inputs and one output (Interval Day to Second) . The output is the time it takes to run a query therefore a valid value for the output would be greater than 0.
    When I setup the test the result only takes a Interval Day to Second value. I want to be able to say any result greater than 0 is a success.
    How can I do this?
    tom

  • CLOB Datatype (Assgin more than 32k fails)

    Dear All
    Can anyone tell me why i am getting this error if i assign more than 32k character to clob variable in pl/sql
    but i can assign it from table to a variable
    Pl/sql 1(ORA-06502: PL/SQL: numeric or value error: character string buffer too small)
    declare
    c clob;
    v varchar(32767);
    begin
    for i in 1..90000 (just assuming it as 90k)
    loop
    v:=v||'x';
    if length(v) > 31000 then
    c:=c||v; -- here iam getting error while assigning character to clob if it is more than 32k
    v:=null;
    end if;
    end loop;
    c:=v;
    end;
    Pl/sql 2 (works fine when assgin from table)
    declare
    c clob;
    begin
    select clob_data into c from x; -- clob data is more than 32k;
    end;
    But it works fine with database 9i rel2 but in 11g i am facing this problem.
    Regards

    hey U r getting the error because of v varchar(32767) , but clob data type can take large amont of data atleast 1000000 this much data can be stored in clob data type try it with this. or else see below
    Hi see the example below
    create table temp(col clob);
    declare
    v_string clob;
    begin
    for i in 1..1000000
    v_string:=v_string||'A';
    end loop;
    insert into temp values(v_string);
    end;
    now
    select length(col) from temp; you will get output as
    length(col)
    1000000
    this means that clob datatype can store minimum of 1000000 character.

  • Greater Than &gt in Hana?

    Context:
    I have a Ms Sql Statement inside a xml file and I have a conditional with a "Greater Than" comparison, so because this within a XML File I can't use the regular syntax for "Greater Than" ( > ) then I use the (&gt;)
    Ms Sql Server Statement
    <Query ID="some_query">
    if ( DATEDIFF(day,@fechaVencimiento, getdate() ) &gt; 0  OR  @Consecutivo_Inicial &gt; @Consecutivo)
           begin
              set @Consecutivo= @Consecutivo_Inicial
              set @seReinicio = 2
           end
    </Query>
    Question:
    What would be the equivalent syntax for ( &gt; ) in Hana?
    Thanks in advance.
    Message was edited by: Tom Flanagan

    Hi there,
    Was '>' or '<' not working from XML? I used a > operator in a calculated column  and then exported the HANA model to see the XML file of it. It has something like this below:
    <formula>IF(&quot;EMP NO &quot; >=3,&quot;EMPLOYEE NAME&quot;,&quot;GENDER&quot;)</formula>
    Regards,
    Krishna Tangudu

  • "Capacity must be greater than 0" error message

    Hi experts,
    I'm having some issues when trying to full optimize my application (on BPC 5.1). I get the following error:
    Capacity must be greater than zero. Parameter name: Capacity
    Save application and process from Analysis Services work without a complain but I'm not able to make it work from the application front-end.
    The application is partitioned on a monthly basis, with 11 dims. I created a K2ServerDebug.log file on websrvr/bin for debug purposes but it seems that it's not creating the 4 other files
    Any idea?
    Thanks,
    Ibai

    Hi Sorin,
    Partitions follow Fact<CubeName>_<TimeSlice> convention. I'm able to run the full optimize when there are few records (~100 records) on the fact tables to process but it keeps failing if I do the same test with ~ 1,000,000 records. 
    Surprisingly if I run the optimization with compression it will complete without errors but I believe this way all partitions are processed regardless the data is new or not. I'm interested in measuring performance so I would like to complete this test withou the compression option checked.
    I've run some queries on data to make sure that all the members exist and are not calculated and checked the source was equal to 0 .
    I'm running this test on a (dev) monoserver environment (sql server 2005 + SSAS + BPC 5.1)
    Regards,
    Ibai

  • Why buffer Hit greater than 100% in AWR

    hi,
    could anyone help explain why the buffer Hit is 376.58%, greater than 100% in my AWR. oracle version is 10.2.0.3.0. thanks!
    Instance Efficiency Percentages (Target 100%)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                Buffer Nowait %:  100.00       Redo NoWait %:  100.00
                Buffer  Hit   %:  376.58    In-memory Sort %:  100.00
                Library Hit   %:   89.27        Soft Parse %:   90.92
             Execute to Parse %:   52.41         Latch Hit %:   99.96
    Parse CPU to Parse Elapsd %:    4.24     % Non-Parse CPU:   99.59Edited by: user10091734 on Aug 1, 2009 10:57 PM
    Edited by: user10091734 on Aug 1, 2009 10:58 PM
    Edited by: user10091734 on Aug 1, 2009 10:59 PM

    sid.gd wrote:
    could anyone help explain why the buffer Hit is 376.58%, greater than 100% in my AWR. oracle version is 10.2.0.3.0. thanks!
    There are a couple of reasons why "physical reads" can exceed "logical reads" - one is a side effect of dynamic samplng, the other is a side effect of running dbms_stats. You could check the captured SQL to see if it offers any evidence for either of these activities during the snapshot interval.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk
    "For every expert there is an equal and opposite expert."
    Arthur C. Clarke

  • Bytes is greater than maxbytes in dba_data_files

    Hi,
    In what situation can the size of bytes be greater than the size of maxbytes in the dba_data_files?
    select bytes,user_bytes,maxbytes from dba_data_files where bytes > maxbytes
    BYTES     USER_BYTES     MAXBYTES
    10485760000     10485694464     6392119296
    6291456000     6288310272     5242880000
    6291456000     6291390464     5242880000
    6291456000     6291390464     5242880000
    10485760000     10485628928     7340032000
    33554432000     33552334848     0
    15728640000     15725494272     12582912000
    35357982720     35347496960     32212254720
    11534336000     11523850240     5242880000
    11534336000     11532238848     10485760000
    Regards,
    CT

    It's just mixing methods. Example follows.
    SQL> create tablespace bytes datafile 'bytes01.dbf' size 128K
    autoextend on maxsize 1000K;
    Tablespace created.
    SQL> select bytes/1024 kb, maxbytes/1024 maxkb, autoextensible
      2  from dba_data_files where tablespace_name='BYTES';
            KB      MAXKB AUT
           128       1000 YES
    SQL> create table dump (a varchar(4000)) tablespace bytes;
    Table created.
    SQL> insert into dump values ... ;
    1 row created.
    SQL> insert into dump select a from dump;
    SQL> /
    32 rows created.
    SQL> select bytes/1024 kb, maxbytes/1024 maxkb, autoextensible
      2  from dba_data_files where tablespace_name='BYTES';
            KB      MAXKB AUT
           192       1000 YES
    SQL> insert into dump select a from dump;
    SQL> /
    256 rows created.
    SQL> /
    insert into dump select a from dump
    ERROR at line 1:
    ORA-01653: unable to extend table TESTING.DUMP by 8 in tablespace BYTES
    SQL> select bytes/1024 kb, maxbytes/1024 maxkb, autoextensible
      2  from dba_data_files where tablespace_name='BYTES';
            KB      MAXKB AUT
           960       1000 YES
    SQL> alter database datafile 'bytes01.dbf' resize 1111K;
    Database altered.
    SQL> select bytes/1024 kb, maxbytes/1024 maxkb, autoextensible
      2  from dba_data_files where tablespace_name='BYTES';
            KB      MAXKB AUT
          1112       1000 YES
    SQL>Does this answer op's concern?

  • Greater than is giving me equal to's

    So I'm writing a procedure in PL/SQL that has the logic below:
    SELECT
    FROM
    WHERE
        CASE
            WHEN travel_time IS NULL THEN NULL
            WHEN travel_time = 0       THEN NULL
            ELSE miles/(travel_time/60)
        END >
        CASE
            WHEN (SUBSTR(id, 2, 3) BETWEEN '099' AND '200')
                THEN 60
            ELSE 45
        END;In the result set, I'm getting records where the result of the first and second case statement are both 60.
    So basically, if the result of the first case statement is GREATER THAN the result of the second case statement, the record is supposed to show up, but I'm getting records that are GREATER THAN OR EQUAL TO. I'm sure I could just change the second case statement to give 61 rather than 60, and I'm sure it would work. But shouldn't this logic work without having to do that?
    Thanks!
    Edited by: jjmiller on Mar 26, 2010 7:24 AM

    As Frank said, a small test case (with CREATE TABLE and INSERTs) would help.
    Works for me.
    SQL> select * from v$version ;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE     10.2.0.4.0     Production
    TNS for Solaris: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    SQL> create table travel(id varchar2(3), miles number, travel_time number) ;
    Table created.
    SQL> insert into travel values (1, 10, 10) ;
    1 row created.
    SQL> insert into travel values (2, 60, 10) ;
    1 row created.
    SQL> insert into travel values (3, 46, 10) ;
    1 row created.
    SQL> insert into travel values (4, 60, null) ;
    1 row created.
    SQL> commit ;
    Commit complete.
    SQL> select * from travel ;
    ID       MILES TRAVEL_TIME
    1         10            10
    2         60            10
    3         46            10
    4         60
    SQL> select id, miles, travel_time, case when travel_time is null then null when travel_time = 0 then null else miles/(travel_time/60) end cmp1, case when id between '1' and '4' then 60 else 45 end cmp2 from travel ;
    ID       MILES TRAVEL_TIME       CMP1       CMP2
    1           10          10         60         60
    2           60          10        360         60
    3           46          10        276         60
    4          600                                60
    SQL> select * from travel where case when travel_time is null then null when travel_time = 0 then null else miles/(travel_time/60) end > case when id between '1' and '4' then 60 else 45 end ;
    ID       MILES TRAVEL_TIME
    2           60          10
    3           46          10

  • Greater than operator for obiee analysis

    Hi ALL,
    Just want to ask if it is possible to use date for the greater than operator in creating obiee analysis?
    for example: I want to get months greater than January 2015 for specific measure.
    Thanks in advance

    but I'm using Oracle 9i r2
    The question is why greter than, lesser than, does not workWorks on 9.2.0.8:
    SQL> select * from v$version where rownum = 1
    BANNER                                                         
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
    1 row selected.
    SQL> with mydata as
       select xmltype('<Values><Value>data1</Value><Value>data2</Value></Values>') MyXmlColumn from dual
    select * from mydata t where existsNode(t.MyXmlColumn, '/Values/Value') < 3
    MYXMLCOLUMN                                                              
    <Values>                                                                 
      <Value>data1</Value>                                                   
      <Value>data2</Value>                                                   
    </Values>                                                                
    1 row selected.

  • Xpath query using greater than operator

    I'm trying to evaluate some xml to determine if it matches some criterium.
    MyXmlColumns contains the following kind of data "<Values><Value>data1</Value><Value>data2</Value><Values>"
    When I execute the following query I get zero rows returned when it should match some rows containing this data.
    select * from mydata
    where existsNode(MyXmlColumn, '/Values/Value[. > "data1"]') = 1
    The question is why greter than, lesser than, does not work, and if there is any alternative.
    If I use equals operator, or greater than but using a number it works.
    I know that I can use XmlExists function but I'm using Oracle 9i r2 so it's not an option.
    Thanks in advance for any suggestion.

    but I'm using Oracle 9i r2
    The question is why greter than, lesser than, does not workWorks on 9.2.0.8:
    SQL> select * from v$version where rownum = 1
    BANNER                                                         
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
    1 row selected.
    SQL> with mydata as
       select xmltype('<Values><Value>data1</Value><Value>data2</Value></Values>') MyXmlColumn from dual
    select * from mydata t where existsNode(t.MyXmlColumn, '/Values/Value') < 3
    MYXMLCOLUMN                                                              
    <Values>                                                                 
      <Value>data1</Value>                                                   
      <Value>data2</Value>                                                   
    </Values>                                                                
    1 row selected.

Maybe you are looking for

  • My app crashed and now I constantly get Photoshop quit unexpectedly even after reinstall...what to do?

    Was working on Lightroom and bringing an image into PS when it crashed and I constantly got "Photoshop quit unexpectedly", tried to reinstall a clean install also removing all preferences with no luck. For some reason I still get "Photoshop quit unex

  • Window error when loading iTunes

    This is what the error reads "iTunes has encountered a problem and needs to close. We are sorry for the inconvenience." I sent the error report to MS and they came back with this from Apple: iTunes 6 for Windows unexpectedly quits when opened Under s

  • SOAP XML Response in the form of JSP

    Hi, I am using a command in Websphere Commerce(WC) as "WebServices Provider " .For new users command is WC specific java program which takes input and throws back the result to the calling program. when a client sends a SOAP xml request to WC WebServ

  • Difference between zero and blank values

    Is there a way for the system to determine the difference between zero and blank values. One can have a zero allowed for the 0 value to actualy be there in the KF but is there a way that a macro can be written by which we can use the differentiation

  • My mbp won't power up after update.

    after running an app store update, (Xcode) my mbp won't power up and the battery lights are showing flat even though it was on charge over night. the update was taking a long time, and it had a message saying something like deleting old files. i went