NDS - Maximum Limit in SQL String

When executing NDS I usually just use EXECUTE IMMEDIATE, but now I've had to use the OPEN FOR statement and
execute a SQL string that I read in from a column in a table. Now I know I've encountered an error before that states
I've exceed a limit in the number of characters the SQL string can have before "opening" it via NDS.
Does anyone the max I should set my VARCHAR2 column that holds the SQL statements? I recall it was 255 bytes I
think.
Thanks,
Gio
null

Max of SQL statement length is 64K
more limitations here http://www.itsystems.lv/gints/oracle_limits.htm

Similar Messages

  • Maximum length of query string for functions return a SELECT

    Hi all,
    I have a report that gets it's SELECT statement from a function, instead of being coded into the region. All was well but I suspect now I'm blowing some kind of limit as I'm getting an error :
         ORA-06502: PL/SQL: numeric or value error
         Error      ERR-1101 Unable to process function body returning query.
    However if I run the procedure out of ApEx and grab the SELECT statement then it works fine. The length of the query is 8636 bytes (yup, it's a beauty!).
    Does anyone know if there is a hard limit to the size of the string that can be returned?
    I'm using ApEx 3.1.
    Thanks,
    Steve H

    I do have a similar painfull scenario - Although my query length is very less i.e 618 bytes only.
    I have defined a stored function, which returns an SQL query string, this return SQL string executes fantastic but when I tried to to call this function from a APEX report it gives error. the details are as follows. Please help.......
    The function code:
    CREATE OR REPLACE function PROD."TEST_C_QRY"
    return VARCHAR2
    is
    msql VARCHAR2(32767);
    Begin
    msql:='Select null,statusname,AgeInd, ';
    For m_stat in (select statusname from a02_status)
    loop
    msql:= msql || q'[decode(statusname,']';
    msql:= msql || m_stat.statusname;
    msql:= msql || q'[',count(id),0) ]';
    msql:= msql || m_stat.statusname|| ',';
    end loop;
    msql:=rtrim(msql,',');
    msql:= msql||' from ';
    msql:= msql||'( ';
    msql:= msql||'select a.id, round(sysdate-a.registeredon) TimeSpan,';
    msql:= msql||'case ';
    msql:= msql||q'[when round(sysdate-a.registeredon)<=7 then 'Week' ]';
    msql:= msql||q'[when round(sysdate-a.registeredon)>7 and round(sysdate-a.registeredon)<14 then 'Fortnight' ]';
    msql:= msql||q'[when round(sysdate-a.registeredon)>14 and round(sysdate-a.registeredon)<30 then 'Month' ]';
    msql:= msql||q'[else 'More...'  end ageind,]';
    msql:= msql||'a.status_id,b.statusname ';
    msql:= msql||'from a02_task a,a02_status b ';
    msql:= msql||'where b.id=a.status_id) ';
    msql:= msql||'group by statusname,AgeInd;';
    return msql;
    end TEST_C_QRY;
    The Output SQL comes from this is
    SQL> Select null,statusname,AgeInd, decode(statusname,'Scheduled',count(id),0) Scheduled,decode(statusname,'Executing',count(id),0) Executing,decode(statusname,
    'Completed',count(id),0) Completed from ( select a.id, round(sysdate-a.registeredon) TimeSpan, case when round(sysdate-a.registeredon)<=7 then 'Week' when round
    (sysdate-a.registeredon)>7 and round(sysdate-a.registeredon)<14 then 'Fortnight' when round(sysdate-a.registeredon)>14 and round(sysdate-a.registeredon)<30 then
    'Month' else 'More...' end ageind, a.status_id,b.statusname from a02_task a,a02_status b where b.id=a.status_id) group by statusname,AgeInd;
    The result that comes when I execute the above resultant SQL is as follows.
    N STATUSNAME AGEIND SCHEDULED EXECUTING COMPLETED
    Completed More... 0 0 4
    Completed Week 0 0 1
    Scheduled Week 1 0 0
    Completed Month 0 0 3
    Executing More... 0 1 0
    Executing Month 0 6 0
    Scheduled More... 1 0 0
    7 rows selected.
    But the surprising error that comes from Oracle XE when I use the following code for stacked bar chart
    Code:
    begin
    return TEST_D_QRY;
    end;
    Error thrown by XE report builder is as follows:
    1 error has occurred
    Failed to parse SQL query!
    Select null,statusname,AgeInd, decode(statusname,'Scheduled',count(id),0) Scheduled,decode(statusname,'Executing',count(id),0) Executing,decode(statusname,'Completed',count(id),0) Completed from ( select a.id, round(sysdate-a.registeredon) TimeSpan, case when round(sysdate-a.registeredon)<=7 then 'Week' when round(sysdate-a.registeredon)>7 and round(sysdate-a.registeredon)<14 then 'Fortnight' when round(sysdate-a.registeredon)>14 and round(sysdate-a.registeredon)<30 then 'Month' else 'More...' end ageind, a.status_id,b.statusname from a02_task a,a02_status b where b.id=a.status_id) group by statusname,AgeInd;
    Certain queries can only be executed when running your application, if your query appears syntactically correct, you can save your query without validation (see options below query source).
    Regards,
    Soumen

  • For loops and dynamic sql string syntax

    Hi
    is there a why to loop through a dynamic sql string
    normally you would have
    FOR cur IN (select * from emp) LOOP
    but I have a dynamic sql string called l_sql
    I have tried the following
    FOR cur IN l_sql LOOP
    but I get
    PLS-00456: item 'L_SQL' is not a cursorCompilation failed
    Any ideas?

    You will need to use ref cursors and the OPEN v_rc FOR '<your sql string'> and then loop through it as you would with any other OPEN, LOOP, EXIT WHEN, END LOOP syntax

  • Amount of data has exceeded maximum limit - Infopath form

    Hello, I am having a problem on O365 concerning an Infopath form.
    The warning goes like this : " The amount of data that was returned by a data connection has exceeded the maximum limit that was configured by the server administrator" 
    Solutions exist for other version of Sharepoint/Infopath. I see in SharePoint 2013, this value is 1500 kilobytes by default
    and we can increase the maximum size of that. However, in SharePoint Online, it cannot be changed.
    Can you guys please help? 
    Thanking you in advance.
    Regards,
    Nite

    Hi Nite,
    You should ask this question in the Office365 forums:
    http://community.office365.com/
    But as this question has been asked before, it is not possible to change the limit in O365. Please see this thread:
    http://community.office365.com/en-us/f/154/t/252391.aspx
    Nico Martens
    SharePoint/Office365/Azure Consultant

  • To generate sql string of desired row  using function.

    Hi l,
    I return the below query to get sum of vehicles which falls between the specific weight ranges.
    It returns 20 rows( As I selected 4 classification vehicles).I was expect only 4 rows .One row for each classification of vehicles.
    Is there a way if do some loop or decode in my function logic?
    will tht work?
    "(This is only smple. In my real appilication, if I use 15 classification vehicles it returns 320 rows. But i expect only 16 rows - 0 to 15 one row for each classification .Duirng runtime I'm getting an error as buffer string too small)"
    How could I solve this?
    I use this query inside a function and I call that function in a dynamic sql.
    SELECT 'SUM('
        || 'CASE '
        || 'WHEN weight_report_data.weight >=  '|| repo_range_param.min_value ||' 
            AND weight_report_data.weight   <       repo_range_param.max_value
            THEN weight_report_data.weight_count '   
        || 'ELSE 0 '
        || 'END '
        || ') "Class ' || repo_param.r_value || '" '   
          FROM repo_param
          JOIN repo_range_param
            ON repo_param.r_id = repo_range_param.r_id
         WHERE repo_param.r_id    = 1
           AND repo_param.r_group = 'class'
           AND repo_param.r_name  = 'class'
           AND repo_range_param.r_group = 'gvw'
           AND repo_range_param.r_name  = 'gvw'
         ORDER BY CAST(repo_param.r_value AS NUMBER) ASC;
    "sample sql string output when I run the above query "
    SUM(CASE WHEN weight_report_data.weight >=10
             AND weight_report_data.weight  <15
            THEN weight_report_data.weight_count ELSE 0 END ) "Class 0"
    SUM(CASE WHEN weight_report_data.weight >=15
             AND weight_report_data.weight  <20
            THEN weight_report_data.weight_count ELSE 0 END ) "Class 1"
    SUM(CASE WHEN weight_report_data.weight >=5
             AND weight_report_data.weight  <10
            THEN weight_report_data.weight_count ELSE 0 END ) "Class 2"
    SUM(CASE WHEN weight_report_data.weight >=20
             AND weight_report_data.weight  <25
            THEN weight_report_data.weight_count ELSE 0 END ) "Class 3"
    "sample data for the tables involved"
    CREATE  TABLE weight_report_data
    start_date_time       TIMESTAMP      NOT NULL,
    end_date_time         TIMESTAMP      NOT NULL,
    weight                NUMBER(12,0)   NOT NULL,
    weight_count          NUMBER(12,0)   NOT NULL
    INSERT INTO weight_report_data(start_date_time, end_date_time, weight, weight_count)
           VALUES('01-JUL-08 12:00:00','03-JUL-08 12:00:00',4,5);
    INSERT INTO weight_report_data(start_date_time, end_date_time, weight, weight_count)
           VALUES('01-JUL-08 12:00:00','03-JUL-08 12:00:00',3,1);
    INSERT INTO weight_report_data(start_date_time, end_date_time, weight, weight_count)
           VALUES('01-JUL-08 12:00:00','03-JUL-08 12:00:00',8,6);
    INSERT INTO weight_report_data(start_date_time, end_date_time, weight, weight_count)
           VALUES('01-JUL-08 12:00:00','03-JUL-08 12:00:00',25,9);
    CREATE  TABLE repo_param
    R_ID       NUMBER(12,0),
    R_GROUP     VARCHAR2(10),
    R_NAME     VARCHAR2(10),
    R_VALUE     VARCHAR2(10)
    INSERT INTO repo_param(r_id, r_group, r_name, r_value)
           VALUES(1,'class','class',0);
    INSERT INTO repo_param(r_id, r_group, r_name, r_value)
           VALUES(1,'class','class',1);
    INSERT INTO repo_param(r_id, r_group, r_name, r_value)
           VALUES(1,'class','class',2);
    INSERT INTO repo_param(r_id, r_group, r_name, r_value)
           VALUES(1,'class','class',3);
    CREATE  TABLE repo_range_param
    R_ID       NUMBER(12,0),
    R_GROUP     VARCHAR2(10),
    R_NAME     VARCHAR2(10),
    MIN_VALUE NUMBER(3,0),
    MAX_VALUE     NUMBER(3,0)
    INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
           VALUES(1,'gvw','gvw',0,5);
    INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
           VALUES(1,'gvw','gvw',5,10);
    INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
           VALUES(1,'gvw','gvw',10,15);
    INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
           VALUES(1,'gvw','gvw',15,20);
           INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
           VALUES(1,'gvw','gvw',20,25);
    Thanks in advance
    Edited by: user10641405 on Jun 18, 2009 4:10 PM
    Edited by: user10641405 on Jun 18, 2009 4:15 PM
    Edited by: user10641405 on Jun 18, 2009 4:15 PM
    Edited by: user10641405 on Jun 18, 2009 4:16 PM
    Edited by: user10641405 on Jun 18, 2009 4:17 PM
    Edited by: user10641405 on Jun 18, 2009 7:47 PM
    Edited by: user10641405 on Jun 19, 2009 4:15 PM

    Say you have a 3 tables
    Table name Description rowcount()
    ============================================================================
    weight_report_data report table having weights and counts 4
    repo_param having id column gives different classes 4
    repo_range_param is detail table of repo_param with id 4
              as foreign key and defines weight
              min max ranges.
    Now you need to report
    per class how many weights weights are there ?
    --not understood report id clearly in relation to weight_report_data
    step1:
    need to map each row of weight_report_data againist its class.
    select wrd.weight,wrd.weight_count,(select rp.class||rp.value
    from repo_range_param rrp,
              repo_param rp
    where rrp.id= rp.id
    and rp.id=1 -- add your other join condition
    and wrd.weight between rrp.min and rrp.max ) class_nm
    from weight_report_data wrd ;
    This will give 4 rows , i.e for each row in wrd it tells which class it falls.
    now you want to group by class_nm to get sum or count of weights.
    step2:
    select class_nm,sum(weight), count(weight), sum(weight_count)
    from (
    select wrd.weight,wrd.weight_count,(select rp.class||rp.value
    from repo_range_param rrp,
              repo_param rp
    where rrp.id= rp.id
    and rp.id=1 -- add your other join condition
    and wrd.weight between rrp.min and rrp.max ) class_nm
    from weight_report_data wrd ) wrd_classnm
    group by class_nm;
    I hope this helps .
    suggestion: first analyse and breakdown into stpes how you r going to do if you do by hand and then translate into sql and then optimise

  • How do I create a new apple store account when my phone tells me that I have exceeded the maximum limit on this phone

    How do I create a new apple store account when my phone tells me that I have exceeded the maximum limit on this phone

    http://support.apple.com/kb/HT4627

  • SQL Strings in Where Clause - single quotes issue

    All,
    I’m having issues related to SQL String literals when trying to deploy to flash. The complication works fine but I then get a message (see below) stating that a ; is missing. The SQL query and the iview runs fine when we use numeric values or do not apply a where clause on the table.
    I am using Visual Composer that has been packaged with NW2004sSP7_Preview
    VC & Flex Version: 645.7.0.3
    The Error message is get is;
    Error in executing a process for Flex compilation, Error 1033: ';' expected
          (C:usrsapJ2EJC01j2eeclusterserver0GUIMachine_Business_Packagestest_48731FLEX_COMPILATION_FOLEDRAADCN.mxml:269)
    Error 1205: The statement 'Test' is incomplete.
          (C:usrsapJ2EJC01j2eeclusterserver0GUIMachine_Business_Packagestest_48731FLEX_COMPILATION_FOLEDRAADCN.mxml:269)
    Failed to compile AADCN.mxml
    When I goto the deployment file – it has the below line;
    <i>'<Request type="EXECUTE_RELATIONAL" system="BI_JDBC" system_type="SAP_BI_JDBC" maxrows="500" templateid="BIR_SQL"><Objects type="INPUT" shape="OBJ" role="INPUT"><Object type="INPUT_FIELD" id="SQL_STATEMENT" appName="SQL" mapped="0" value=""/></Objects><Objects type="OUTPUT" shape="SET" role="OUTPUT"><Object type="OUTPUT_FIELD" id="name" appName="name"/></Objects><Objects id="1" type="TEMPLATE_PARAMETER"><Object id="2" type="SQL" value="select name from pub.srcompany where name ='Test Company'"/></Objects></Request>';</i>
    It seems that the parser for the flash deployment is prematurely finishing the parse when it hits the single quotation in the SQL string!
    We had a similar error where if we had a carriage return in the SQL (e.g. between the from & the where clause) then the deployment parser was stating that the line finished prematurely. In the deployment file the carriage return forced a new line thus making the message incomplete. Removing the carriage return resolve that issue
    The SQL Preview in the SQL Editor within VC works fine with the string literals in the where clause.
    The functionality compiles & deploys in web dynpro however it does not return the results to the table
    Questions
    1:> Has anyone successfully used flash with string literals in the SQL where clause or had seen this issue in the past?
    2:> Is there a setting to get the SQL working on Web dynpro for the information to be returned that I may have missed?
    Any assistance would be greatly appreciated.
    Best Regards,
    Ian.

    Hey,
    I have worked with SQL Editor a lot. Here's a how to guide I put together on it:
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/6339e7d4-0a01-0010-1c98-db00e52e989a
    Let me know if that helps...
    Prakash

  • Hard coded SQL string doesn't run with error PLS-00103

    I have created a package with 34 stored procedures [pre]to create some materialized view with hard coded SQL [pre]string (client required for this hard coding). The [pre]first part with 21 simple create statements has
    [pre]worked fine. 2nd part with 11 complicated create [pre]statements, only first one has worked. all others [pre]have  not worked.
    [pre]
    I used dbms_output.put_line (sql_string) to check the [pre]individual create statement, it has looked fine. I [pre]have run individual SP within package. I have got [pre]error message as ORA-06550: line 1, column 45:
    [pre]PLS-00103: Encountered the symbol "end-of-file" when [pre]expecting one of the following: ; [pre]
    <an identifier> <a double-quoted delimited-identifier> [pre]The symbol ";" was substituted for "end-of-file" to [pre]continue.
    [pre]I have checked SQL string between 1st part and 2nd [pre]part. They are the same and all with ';' to end SQL [pre]string and END SP name in the end. Please help me to [pre]identify where the problems are. Thanks. Followings [pre]are some sample SQL string:
    [pre]PROCEDURE sp_1st_string
    [pre]IS
    [pre]BEGIN
    [pre]    EXECUTE IMMEDIATE 'CREATE MATERIALIZED VIEW
    [pre]mv_name1 TABLESPACE space_name PARALLEL ( DEGREE [pre]DEFAULT INSTANCES DEFAULT ) BUILD IMMEDIATE REFRESH [pre]COMPLETE ON DEMAND WITH PRIMARY KEY AS SELECT col1, [pre]col2,col3, col4, col5 FROM tableone A, table_two B [pre]WHERE A.id = B.id';
    [pre]COMMIT;
    [pre]END sp_1st_string;
    [pre]PROCEDURE sp_2nd_string
    [pre]IS
    [pre]BEGIN
    [pre]   EXECUTE IMMEDIATE ' CREATE MATERIALIZED VIEW
    [pre]mv_name2 TABLESPACE PDE_DATA PARALLEL ( DEGREE [pre]DEFAULT INSTANCES DEFAULT ) BUILD IMMEDIATE REFRESH [pre]COMPLETE ON DEMAND WITH PRIMARY KEY AS select col1 .. [pre]col10 from tableone a, tabletwo b, tablethree c, [pre]tablefour d, tablefive e, tablesix f where clause;
    [pre]COMMIT;
    [pre]END sp_2nd_string;
    Message was edited by:
            citicbj
    Message was edited by:
            citicbj                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    stevencallan:
    Thanks for your advice. I have been thinking the above problem may be [pre]caused by this. If I run 'Create MV statement' in SQL PLUS or Toad, single quote [pre]will work. But when I put hard coded SQL string in package and stored [pre]procedure, it will cause compiling error. After I took off single quote, SP will be [pre][pre]compiled successfully. When I run package.sp, it will cause the problem. [pre]Here is the sample code:[pre]
    [pre]CREATE MATERIALIZED VIEW my_mv TABLESPACE space_name [pre][pre]PARALLEL (DEGREE DEFAULT INSTANCES DEFAULT) BUILD IMMEDIATE [pre]REFRESH COMPLETE ON DEMAND WITH PRIMARY KEY AS select A.ID , [pre]A.CNTL_NUM, C.XX_CODE, D.FIRST_NAME, D.MDL_NAME, [pre]D.LAST_NAME, H.XX_DESC, TO_DATE(TO_CHAR(C.CREAT_TS, [pre]'MM/DD/YYYY'),'MM/DD/YY'), F.STATE, CASE WHEN A.XX_CODE IS NOT NULL [pre]THEN X END, E.X_DESC  from TABLE1 A, TABLE2 B, TABLE3 C, TABLE4 [pre]D, TABLE5 E, TABLE6 F, TABLE7 G, TABLE8 H
    [pre]where D.X_SW = 'X' and B.X_SW = X' and G.X_SW = 'X' and B.CNTL_ID = [pre]A.CNTL_ID and B.CNTL_ID = D.CNTL_ID and B.X_ID = C.X_ID and B.X_ID = [pre]G.X_ID and B.X_ID = F.X_ID and G.X_CD = H.X_CD and B.X_CD = E.X_CD [pre]and E.X_CD = '25' and C.ENRLMT_ID NOT LIKE 'O%'; [pre]
    [pre]When I hard coded this statement in package and sp, I have to take off single [pre]quote ' ' form 'MM/DD/YYYY', 'MM/DD/YY', X_SW ='X', X_CD = '25' AND NOT [pre]LIKE 'O%', Then I can compile whole package successfully. This is why I [pre]mentioned that 1st part 21 simple create statement work because they don't have [pre]these single quote in the statement. In 2nd part with 13 complicated create [pre]statements, some of them have no single quote in the statement. They will [pre]run. Some of them with single quote in statement. They will have the problem [pre]to run if I take off single for compiling. [pre]
    [pre]Please give me some idea what is the reason. Thanks a lot.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to modify the pre generated SQL string in Db adapter

    Hello All,
    I am using a DB adapter to poll a database. So in the configuration of adapter, i have specified the option of logical delete, i want to update to a field PF as 'Y'. In my BPEL process, I want to update those records as 'Y' for their process_Completion field after i am done doing logic on those records.. Actually in the database adapter configuration, we get the SQL string right ?. So inorder to edit that SQL how should we go ahead ?
    I mean i want to poll the database, i want to get like 1000 records for my BPEL Process Instance, and after all those 1000 gets processed and completed. Iwant to get the next 1000. So i want to write a query something like...
    select seqid, id, field1, field2..... from STable a where a.PF = 'N' and exists(select 1 from STable b where b.seqid = a.seqid - 1 and b.PF = 'Y' and b.process_Completion = 'Y')
    So, how to write my custom quesries while polling the database. cant we write custom quesries while we are doing Inbound operation with Dbadapter. Please help me with this thing.
    Thanks,
    N

    Whenever you use a JCA DB Adapter in JDeveloper it creates an OR mapping xml that contains the select/polling query that you might have.
    Below is an example of one such query. You can edit the sql here manually and redeploy your process.
    <querying xsi:type="query-policy">
    <queries>
    <query name="DBConnSelect" xsi:type="read-all-query">
    <call xsi:type="sql-call">
    <sql>SELECT MESSAGE_ID,BU_ID,CREATED_BY FROM MESSAGE_BUFFER where BU_ID IN (3232,4747) and 3 > rownum</sql>
    </call>
    <reference-class>DBConn.MessageBuffer</reference-class>
    <container xsi:type="list-container-policy">
    <collection-type>java.util.Vector</collection-type>
    </container>
    </query>
    </queries>
    In case you need to add parameters to your query you should be able to do that as well while you are creating your DB Adapter.
    Edited by: Arun Pareek on Jun 15, 2011 9:34 AM

  • Converting XML structure to SQL string

    Hi,
    how can I convert an existing XML structure into a SQL string? It's important to do this manually, because there are additional data necessary to complete the recordset.
    The XML structure is:
    <File>
    <Recordset>
    <Column>Data</Column>
    </Recordset>
    </File>
    The additional data are 4 columns for each recordset to implement into the SQL string.
    The SQL string should be something like
    "INSERT INTO table (Add_Column, Column, Column, Column) VALUES (Add_Data, Data, Data, Data)"
    If anyone has source code performing operations like that I'd be grateful 'cause I'm quite new to Java and have not the experience in such transform ops.

    Which package includes xml sax?You can download it from,
    http://java.sun.com/xml/download.html.
    I can send you some sample pgms too, if you want.If you would, I'd be grateful.
    Marko

  • How to use Native SQL String

    Hi all,
    How do i use Native SQL String in the Reciver JDBC Adapter.
    Do i need to change the message format could u suggest me some blogs on the same.
    Also please can anyone let me knw if i can use this for stored procedure.

    hi aditya,
    there shud be no format as such. for sql xml format there are specific structure. but for native sql there shudnt be any specific structure.
    as pointed in sap documentaion:
    Instead of an XML document format, a text is expected that represents any valid SQL statement.
    When inserting a line into a table the corresponding document looks as follows:
    INSERT INTO tableName  (column-name1, column-name2, column-name3) VALUES(‘column-value1’, ‘column-value2’, ‘column-value3’)
    so jus make sure that u give a valid sql statement becoz if will be passed as it is to the database and try ur scenario.
    regards,
    latika.

  • Turning sql  string (with dynamic columns) into a pipelined function

    Hi guys,
    I was working on an apex report the other day, and wrote the sql below (for those who don't know apex well, in an apex report you can define the columns at runtime.) When I was finished, I said to myself: "It would be great to have a pipeline function with this capability." So, the idea would be to have a sql string where the columns are created dynamically, depending on input parameters - and then be able to use this sql everywhere (oracle reports, sqlplus) through a pipelined function.
    Here's the sql (simplified, of course, the data itself is actually not important - the LOOP is the key)
    declare
    v_sql varchar2(4000);
    begin
    v_sql := 'select client, ';
    for i in (select employee from company_employees_view where condition = pi_parameter order by 1) loop
    v_sql := v_sql || sum(decode(employee,''' || i.employee || ''', total)) "' || i.employee || '"';
    end loop;
    v_sql := v_sql || ', sum(total) "Total"';
    v_sql := v_sql || ' from company_employees_view group by client';
    end;
    This sql would result in a final product like:
    select client
    , sum(decode(employee,'John',total) "John"
    , sum(decode(employee,'Paul',total) "Paul"
    , sum(decode(employee,'George',total) "George"
    (and so on... this sql could have more or less columns depending on the input parameters of the function)
    from company_employees_view
    group by client;
    I have tried feeding this sql into a ref cursor and an object, but always received an "inconsistent datatypes" message.
    The object would be something like:
    create or replace object rt_employee as (total number);
    create or replace tt_employee as table of rt_employee;
    create or replace object rt_client as (
    client varchar2(100),
    employee tt_employee);
    create or replace tt_client as table of rt_client;
    (I am not paying too much attention to syntax here.)
    By the way, no hurry whatsoever, this is just for fun, take your time. I am using database XE with apex 2.1 and sql developer 1.2.
    Thanks, Roger

    This is the only solution I've ever seen to dynamic pipelined columns...
    How to pipeline a function with a dynamic number of columns?

  • Native SQL string  in Receiver JDBC

    Hi All,
    I have a requirement where in i have to make us of message protocol : Native SQL String .
    SDN explanation is as follow :
    When inserting a line into a table the corresponding document looks as follows:*
    "INSERT INTO tableName  (column-name1, column-name2, column-name3) VALUES(u2018column-value1u2019, u2018column-value2u2019, u2018column-value3u2019) "
    I tried to pass the data as shown below :
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_SrcProxy xmlns:ns0="http://infosys.com/pi/projects/pepsi/n1">
       <Record>
         <input> "INSERT INTO Emp (EmpNO,FirstName,LastName,DOJ,BaseLocation)VALUES('103','abc','xyz','NULL','Blore')" </input>
       </Record>
    </ns0:MT_SrcProxy>
    I am getting the following error in communication channel :
    Message processing failed. Cause: com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error 'com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '<'.' executing service raw2sql with SQL statement '<?xml version="1.0" encoding="UTF-8"?> <ns0:MT_SrcProxy xmlns:ns0="http://infosys.com/pi/projects/pepsi/n1">   <Record>     <input>"INSERT INTO Emp (EmpNO,FirstName,LastName,DOJ,BaseLocation)VALUES('103','abc','xyz','NULL','Blore')"</input>   </Record> </ns0:MT_SrcProxy>'
    Can anyone please help me in this regard

    Hi Vinay,
    I have not tried on this  but looks like the output that needs to be passed must be a Non XML and not an XML output.
    Please refer this thread to get more clear idea on this.
    Re: How to use Native SQL String.
    Thanks
    Amit

  • How can i pass sql string in proc as in parameter and use in cursor forloop

    Dear Experts ,
    Please help me in below code.
    create or replace PROCEDURE Sample_Spool_Data (SQLSTRING IN VARCHAR2, FILENAME in VARCHAR2) IS
    v_spool_file UTL_FILE.FILE_TYPE ;
    SQLSTRING VARCHAR2(1000);
    BEGIN
    v_spool_file := UTL_FILE.FOPEN('MPLD_DQMT',FILENAME,'w');
    UTL_FILE.PUT_LINE(v_spool_file,'Start: '||to_char(sysdate,'dd/mm/yyyy hh:mi s'));
    FOR c1_rec in SQLSTRING
    LOOP
    UTL_FILE.PUT_LINE(v_spool_file,c1_rec.rec);
    end loop;
    UTL_FILE.PUT_LINE(v_spool_file,'End: '||to_char(sysdate,'dd/mm/yyyy hh:mi s'));
    SQL String is having like select col1, col2, col3 from table_name;

    Looks like you're tring to write a generic way of outputting the results of a query to a file.
    You won't do it the way you're trying to, because your dynamic SQL means that you don't know the resultant columns of the query so that you can output them. To do that you need to use the DBMS_SQL package to describe the query and fetch the returned columns by position e.g.
    As sys user:
    CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
    GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
    /As myuser:
    CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
                                         ,p_dir IN VARCHAR2
                                         ,p_header_file IN VARCHAR2
                                         ,p_data_file IN VARCHAR2 := NULL) IS
      v_finaltxt  VARCHAR2(4000);
      v_v_val     VARCHAR2(4000);
      v_n_val     NUMBER;
      v_d_val     DATE;
      v_ret       NUMBER;
      c           NUMBER;
      d           NUMBER;
      col_cnt     INTEGER;
      f           BOOLEAN;
      rec_tab     DBMS_SQL.DESC_TAB;
      col_num     NUMBER;
      v_fh        UTL_FILE.FILE_TYPE;
      v_samefile  BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
    BEGIN
      c := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      d := DBMS_SQL.EXECUTE(c);
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      FOR j in 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
          WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
          WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
          WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
        END CASE;
      END LOOP;
      -- This part outputs the HEADER
      v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
      FOR j in 1..col_cnt
      LOOP
        v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
      END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
      UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      IF NOT v_samefile THEN
        UTL_FILE.FCLOSE(v_fh);
      END IF;
      -- This part outputs the DATA
      IF NOT v_samefile THEN
        v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
      END IF;
      LOOP
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        EXIT WHEN v_ret = 0;
        v_finaltxt := NULL;
        FOR j in 1..col_cnt
        LOOP
          CASE rec_tab(j).col_type
            WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                        v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
            WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                        v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
            WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                        v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
          ELSE
            v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
          END CASE;
        END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
        UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      END LOOP;
      UTL_FILE.FCLOSE(v_fh);
      DBMS_SQL.CLOSE_CURSOR(c);
    END;This allows for the header row and the data to be written to seperate files if required.
    e.g.
    SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
    PL/SQL procedure successfully completed.Output.txt file contains:
    empno,ename,job,mgr,hiredate,sal,comm,deptno
    7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
    7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
    7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
    7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
    7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
    7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
    7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
    7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
    7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
    7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
    7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
    7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
    7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
    7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10The procedure allows for the header and data to go to seperate files if required. Just specifying the "header" filename will put the header and data in the one file.
    Adapt to output different datatypes and styles are required.

  • Maximum limit of characters in the "IN" caluse

    Hi,
    Could any one please tell me what is the maximum limit of characters I can use in the “IN” clause?
    I am getting the error when executing the query by using more than 1000 items ids in "IN" clause:
    "SELECT * from test where item_id IN ('4a00dec880003900', '4a00dec88000259a','4a00dec88000259a','4a00dec880000518’, ............................., up to more than 1000 item ids)”
    Thanks in advance.
    Regards,
    Ashok

    You are limited to 1000 elements. There is no character limit, other than the one imposed by the limit on the number of elements.
    If you have more than a couple dozen elements, I would generally suggest throwing them in a table and doing
    WHERE item_id IN (SELECT item_id FROM <<new table>>)which can have an unlimited number of elements.
    Additionally, note that when you start having a large number of elements, you are often better served using an EXISTS clause rather than an IN clause.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

Maybe you are looking for