Put results of dynamic sql into pl/sql table

Hi.
I tried to "google up" solution to my problem but in vain, so if possible could you give me a hint?
The test code which I will paste here is somewhat akward, it is part of bigger code and I tried to simplify and adjust it.
The problem is:
I have sql statement which I construct on the run, and I want to put results of this statement into collection.
With present code I get "ORA-00932: inconsistent datatypes".
The collection must be global, since later on I need to do selects from this collection using:
select col_1, col_2, col_3 from table(cast(v_pole_final as t_pole)))
And I do not want put constructors into sql statements (which i believe would help).
The select will always return columns types varchar, number, number.
I.e. the same structure as in type "t_zaznam".
I want to use "execute immediate", or "ref cursor - fetch bulk collect into collection".
Thanks for help.
Jan
-------------- My code:
create or replace type t_zaznam is object (col_1 varchar2(64), col_2 number, col_3 number);
create or replace type t_pole is table of t_zaznam;
create or replace function sulc_experim return number
is
s_sql_temp varchar2(6000):= 'select ''asdf asdf'', 7, 777 from dual '||
' union '||
' select ''yes boss'', 1, 111 from dual'||
' union '||
' select ''go home'', 9, 999 from dual';
v_pole t_pole:= t_pole();
v_pole_final t_pole:= t_pole();
begin
execute immediate s_sql_temp into v_pole;
return 0;
end sulc_experim;

user5714007 wrote:
Thank you.
I think this is what I meant by "And I do not want put constructors into sql statements (which i believe would help)."
It would be helpful to be able to select "on the fly" also multiple-columns and mainly multiple-rows results into collection.In case you didn't notice: The deciding difference that Karthik made was this line:
execute immediate s_sql_temp bulk collect into v_pole;
If that is not the trouble you have, then please explain you problem with a few samples. What works and what does not work.
Also there is always dbms_sql where you can create the paramters/output types "on the fly".

Similar Messages

  • Extracting the result of a query into a internal table

    Hi,
    Does anyone knows or have an idea how to extract the result of a query into a internal table, is there a function module or BAPI?
    Thanks in advance,
    CK

    So then normally I would use a statment like:
    IFunctionTemplate ftemplate = repository.getFunctionTemplate("<b>BAPI_SALESORDER_GETLIST</b>");
    to call a particluar function, but I tried using
    IFunctionTemplate ftemplate = repository.getFunctionTemplate("<b>BAPI_MDDATAPROVIDERBW_GETCATALOGS</b>");
    and it did not seem to work. I also tried -
    IFunctionTemplate ftemplate = repository.getFunctionTemplate("<b>MDDataProviderBW.GetCatalogs</b>");
    How do I format the function?
    Thanks
    Paul

  • How can I put form user exit logic into PL/SQL?

    I need to translate the following into a SQL query:
    SRW.USER_EXIT('FND FLEXSQL CODE ="GL#"
    OUTPUT ="&P_ACCT_SEG"
    APPL_SHORT_NAME="SQLGL"
    MODE ="SELECT"
    DISPLAY ="ALL"
    NUM = "&P_chart_of_accounts_id"
    TABLEALIAS ="GCC"');
    Where is this data stored in the database and how can I query it?

    you might have to check out what is the type of this concurrent program with short name 'SQLGL'.

  • Converting SQL into PL/SQL

    Hi All,
    I have emp table with data as below,
    SELECT EMPNO,MGR FROM EMP;
    EMPNO|MGR
    7369|7902
    7499|7698
    7521|7698
    7566|7839
    7654|7698
    7698|7839
    7782|7839
    7788|7566
    7839|
    7844|7698
    7876|7788
    7900|7698
    7902|7566
    7934|7782
    When ever new emp_id's are generated as shown below, I want to update them for MGR Id's as well, so I have written below query and am getting that and output is also attached,
    SELECT new_emp,new_mgr_id, SYSDATE
    FROM (WITH ngr AS
    (SELECT empno, (select max(empno) from emp) + rownum new_emp,mgr
    FROM emp e
    START WITH e.mgr is null
    CONNECT BY PRIOR e.empno=e.mgr)
    SELECT t1.*,
    NVL ((SELECT new_emp
    FROM ngr t2
    WHERE t2.empno = t1.mgr),
    99999
    ) new_mgr_id
    FROM ngr t1)
    NEW_EMP|NEW_MGR_ID|SYSDATE
    7935|99999|12/11/2009 12:57:16 AM
    7936|7935|12/11/2009 12:57:16 AM
    7937|7936|12/11/2009 12:57:16 AM
    7938|7937|12/11/2009 12:57:16 AM
    7939|7936|12/11/2009 12:57:16 AM
    7940|7939|12/11/2009 12:57:16 AM
    7941|7935|12/11/2009 12:57:16 AM
    7942|7941|12/11/2009 12:57:16 AM
    7943|7941|12/11/2009 12:57:16 AM
    7944|7941|12/11/2009 12:57:16 AM
    7945|7941|12/11/2009 12:57:16 AM
    7946|7941|12/11/2009 12:57:16 AM
    7947|7935|12/11/2009 12:57:16 AM
    7948|7947|12/11/2009 12:57:16 AM
    Now my problem is, I want to get the same requirement by replacing *(select max(empno) from emp) + rownum new_emp* with sequence,
    (or) the same logic in one Procedure, am trying but facing some difficulties, can any one help me in acheiving this,
    thanks,
    sunil

    Hi Munky and all,
    Sorry if I have not made you clear,
    ok let me tell my requirement clearly,
    I have EMP Table with Data as shown below,
    SELECT empno oldempno, emp_name NAME, mgr oldmgrno
    FROM emp;
    Output:
    OLDEMPNO|NAME|OLDMGRNO
    7369|SMITH|7902
    7499|ALLEN|7698
    7521|WARD|7698
    7566|JONES|7839
    7654|MARTIN|7698
    7698|BLAKE|7839
    7782|CLARK|7839
    7788|SCOTT|7566
    7839|KING|
    7844|TURNER|7698
    7876|ADAMS|7788
    7900|JAMES|7698
    7902|FORD|7566
    7934|MILLER|7782
    Now my requirement is when ever any empno is changed in the table and if that emp is a manager to any other employee, number of that employee should also change automatically with in a single query,
    and I have acheived the requirement by using the below query,
    SELECT new_emp, NAME, new_mgr_id
    FROM (WITH ngr AS
    (SELECT empno, *(SELECT MAX (empno)*
    FROM emp) + ROWNUM new_emp, emp_name NAME,
    mgr
    FROM emp e
    START WITH e.mgr IS NULL
    CONNECT BY PRIOR e.empno = e.mgr)
    SELECT t1.*, NVL ((SELECT new_emp
    FROM ngr t2
    WHERE t2.empno = t1.mgr), 99999) new_mgr_id
    FROM ngr t1)
    and so output is below,
    NEW_EMP|NAME|NEW_MGR_ID
    7935|KING|99999
    7936|JONES|7935
    7937|SCOTT|7936
    7938|ADAMS|7937
    7939|FORD|7936
    7940|SMITH|7939
    7941|BLAKE|7935
    7942|ALLEN|7941
    7943|WARD|7941
    7944|MARTIN|7941
    7945|TURNER|7941
    7946|JAMES|7941
    7947|CLARK|7935
    7948|MILLER|7947
    Now my problem/requirement is I want to use Sequence in place of this query *(SELECT MAX (empno) FROM emp) + ROWNUM new_emp,* but as with clause and subquery clause dosen't allow me to do that, am in vain how to implement that,
    So solution to my problem would be a SQL or PL/SQL that can do this operation
    Please let me know how to acheive it,
    Thanks,
    Sunil .N

  • How can I translate this from PL/SQL into embedded SQL!?

    CURSOR TEMP1 is
    SELECT emp.fname fname, emp.lname lname, emp.ssn, dname,emp.salary salary, emp1.fname supervisor_fname, emp1.minit supervisor_mdlname,emp1.lname supervisor_lname FROM employee emp, employee emp1,department d
    WHERE emp.superssn=emp1.ssn(+) and emp.dno=dnumber order by ssn;
    PNTR_TEMP1 TEMP1%ROWTYPE;
    --calcualting values for the cursor TEMP1
    for PNTR_TEMP1 in TEMP1 loop
    fname:= PNTR_TEMP1.fname;
    lname:= PNTR_TEMP1.lname;
    ssn := PNTR_TEMP1.ssn;
    dname:=PNTR_TEMP1.dname;
    sup_name:=PNTR_TEMP1.supervisor_fname||' '|| PNTR_TEMP1.supervisor_mdlname||' '||PNTR_TEMP1.supervisor_lname;
    salary := PNTR_TEMP1.salary;
    n_deps:=0 ;
    /* how can I translate this to embedded SQL...I'm using C++*/

    Hi,
    you can follow this link to use cursor in Pro*c /C++
    http://www.csee.umbc.edu/help/oracle8/server.815/a68022/sql.htm
    Regards

  • T-SQL to PL/SQL

    Hi,
    I'm trying to convert some code in T-SQL into PL/SQL (see below). The trouble is that my PL/SQL is mediocre and my T-SQL is almost non-existent.
    Short of spending the next couple of months learning T-SQL is there an easy way to convert the code below?
    A handy utility or a cross reference source?
    create procedure dbo.pca_ByPostcode(@postcode varchar(50), @account_code varchar(50), @license_code varchar(50), @machine_id varchar(50)) as
    begin
    declare @document int
    declare @url varchar(500)
    declare @error int
    declare @result int
    declare @error_number int
    declare @error_message varchar(100)
    set nocount on
    --Build the url
    set @url = 'http://services.postcodeanywhere.co.uk/dataset.aspx?'
    set @url = @url + '&action=lookup'
    set @url = @url + '&type=by_postcode'
    set @url = @url + '&postcode=' + @postcode
    set @url = @url + '&account_code=' + @account_code
    set @url = @url + '&license_code=' + @license_code
    set @url = @url + '&machine_id=' + @machine_id
    --Create the temporary table
    if object_id('tempdb..#xmltemp') is not null drop table #xmltemp
    create table #xmltemp(xml text null, xml2 text null)
    --Create the http object
    exec @result=sp_oacreate 'msxml2.serverxmlhttp',@error out
    if @result <> 0 exec sp_oageterrorinfo @error
    --Get the data from Postcode Anywhere
    exec @result=sp_oamethod @error, 'open',null,'GET',@url,'false'
    if @result <> 0 exec sp_oageterrorinfo @error
    exec @result=sp_oamethod @error,'send'
    if @result <> 0 exec sp_oageterrorinfo @error
    --Copy the response to a temporary table
    insert #xmltemp(xml) exec @result=sp_oagetproperty @error,'responsetext'
    if @result <> 0 exec sp_oageterrorinfo @error
    --Remove the quotes
    declare @counter int
    declare @chunk varchar(4000)
    declare @ptr binary(16)
    update #xmltemp set xml2=''
    select @ptr = textptr(xml2) from #xmltemp
    select @chunk = convert(varchar(1000),xml) from #xmltemp
    set @counter = 0
    while (len(@chunk) > 0) begin
    set @chunk = replace(@chunk, '''', '''''')
    updatetext #xmltemp.xml2 @ptr null 0 @chunk
    set @counter = @counter+1
    select @chunk = convert(varchar(1000),substring(xml, 1+@counter*1000,1000)) from #xmltemp
    end
    --Release the resources used by msxml
    exec @result=sp_oadestroy @error
    --Generate and execute the script which concatenates the xml and gets the xml document
    exec('
    declare @counter int
    declare @chunk varchar(4000)
    declare @declare varchar(8000)
    declare @assign varchar(8000)
    declare @concat varchar(8000)
    select @chunk = replace(convert(varchar(4000),xml2),'''','''''''') from #xmltemp
    select @declare = ''declare'', @concat = '''''''''''''''', @assign = '''', @counter = 0
    while (len(@chunk) > 0) begin
    select @declare = @declare + '' @chunk''+cast(@counter as varchar(15)) +'' varchar(8000),'', @assign = @assign + ''select @chunk''+convert(varchar(15),@counter) +''= substring(xml2,''+ convert(varchar(15), 1+@counter*8000)+ '', 8000) from #xmltemp '', @concat = @concat + ''+@chunk''+convert(varchar(15),@counter)
    set @counter = @counter+1
    select @chunk = replace(convert(varchar(4000),substring(xml2, 1+@counter*4000,4000)),'''','''''''') from #xmltemp
    end
    if (@counter = 0)
    set @declare = ''''
    else
    set @declare = substring(@declare,1,len(@declare)-1)
    set @concat = @concat + ''+''''''''''''''
    exec(@declare+'' ''+@assign+'' ''+''exec(''''declare @document_doc int exec sp_xml_preparedocument @document_doc out, ''+@concat+'' declare hdlcursor cursor for select @document_doc as dochandle'''')'')')
    --Get the reference to the xml document
    open hdlcursor
    fetch hdlcursor into @document
    deallocate hdlcursor
    --Drop the temporary table
    drop table #xmltemp
    --Check for an error and report that first
    select @error_number=errornumber, @error_message=message from openxml(@document, '/NewDataSet/Data', 1) with (ErrorNumber int 'error_number', Message varchar(300) 'message')
    if @error_number is not null
    begin
    --Release the resources use by the xml document
    exec sp_xml_removedocument @document
    --Throw the exception
    raiserror (@error_message,16,1)
    end
    else
    begin
    --Get the data from the xml document
    select * from openxml(@document, '/NewDataSet/Data', 1) with (id varchar(100) 'id', seq varchar(100) 'seq', description varchar(100) 'description')
    --Release the resources use by the xml document
    exec sp_xml_removedocument @document
    end
    end
    Cheers
    Yog

    Hi Justin,
    Tried the migration tool in Sql Developer and got the following:
    /* Translation Extracted DDL For Required Objects */
    CREATE TABLE tt_xmltemp (     
    XML CLOB ,     
    xml2 CLOB );
    CREATE OR REPLACE PROCEDURE pca_ByPostcode
    v_postcode IN VARCHAR2 DEFAULT NULL ,
    v_account_code IN VARCHAR2 DEFAULT NULL ,
    v_license_code IN VARCHAR2 DEFAULT NULL ,
    v_machine_id IN VARCHAR2 DEFAULT NULL
    AS
    v_document NUMBER(10,0);
    v_url VARCHAR2(500);
    v_error NUMBER(10,0);
    v_result NUMBER(10,0);
    v_error_number NUMBER(10,0);
    v_error_message VARCHAR2(100);
    BEGIN
    NULL/*TODO:set nocount on*/;
    --Build the url
    v_url := 'http://services.postcodeanywhere.co.uk/dataset.aspx?';
    v_url := v_url || '&action=lookup';
    v_url := v_url || '&type=by_postcode';
    v_url := v_url || '&postcode=' || v_postcode;
    v_url := v_url || '&account_code=' || v_account_code;
    v_url := v_url || '&license_code=' || v_license_code;
    v_url := v_url || '&machine_id=' || v_machine_id;
    --Create the temporary table
    IF NULL/*TODO:object_id('tempdb..#xmltemp')*/ IS NOT NULL THEN
    EXECUTE IMMEDIATE ' TRUNCATE TABLE tt_xmltemp ';
    END IF;
    --Create the http object
    v_result :=sp_oacreate('msxml2.serverxmlhttp',
    v_error);
    --Get the data from Postcode Anywhere
    --Copy the response to a temporary table
    /*Limitation:Syntax Not Recognized:XML ) */
    --Remove the quotes
    --Release the resources used by msxml
    --Generate and execute the script which concatenates the xml and gets the xml document
    --Get the reference to the xml document
    --Drop the temporary table
    --Check for an error and report that first
    --Release the resources use by the xml document
    --Throw the exception
    --Get the data from the xml document
    --Release the resources use by the xml document
    END;
    It pretty much just changes the declaration syntax and leaves the rest blank, i.e. the stuff I could probably have done myself.
    Is there such a thing as a library of t-sql functions with their equivalent pl/sql functions?
    Sort of like a Spanish-English phrasebook I suppose :-)
    Cheers
    Yog

  • Today's date dynamically entered into text field that user enters additional text into same field.

    Trying to have today's date dynamically entered into a repeating table row textfield when the button is clicked to create each repeating row. The user can then enter addtional text into the same text field next to the date.
    Example:
    [4/25/2012] This is the text the user entered.
    Today's date is populated in each update row created when the "Update Row" button is clicked.
    The following script works but only for the first instance, not the second, third, forth, etc...
    Click event: (JavaScript, client)
    this.resolveNode('Table2._RowB').addInstance(1);
    xfa.resolveNode("Table2.RowB.#subform.Update").rawValue
    Thank you,
    ~Don

    Hi Don,
    Does this solution cover the above problem? https://acrobat.com/#d=VjJ-YsXLKmV6QU84JrAAIw
    Niall

  • Read statement into an internal table

    Hi Experts,
    In my report i have several read statements, now my requirement is i want to put all the read statements into an internal table, how do i achieve it???
    Thank you!

    Hello Maya,
    i want to know how many number of times the read statement is used .
    Two ways:
    1. use a counter after each read statement in your program and increase it by 1 everytime there is read statement and display the final value of the counter in the report that you want.
    2. If you just want to know press (CNTRL + F) enter "READ" , select the radio button "In Main program" and then you will get all the read statement and can count it manually.
    Hope I have not answered your question wrong. But if I have, please be more specific about your requirement so that many an help you.
    Thanks,
    Jayant Sahu.

  • 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?

  • How to spool the result of an query into a file in sql 2000

    Hi All,
    I have an SQL query which iterates through number of times for checking on some conditions and will return results each time. I wants to save the results into an different xml file each time. I tried using below query:
    exec xp_cmdshell 'bcp "use Mimsadaptorlogs; select top 10 * from log order by logdate" queryout "D:\cdr_cg.xml" -T -c -t,'  ---> Its not working as expected.
    I got the Below output:
    NULL
    Starting copy...
    SQLState = 01000, NativeError = 5701
    Warning = [Microsoft][ODBC SQL Server Driver][SQL Server]Changed database context to 'MIMSAdaptorlogs'.
    NULL
    10 rows copied.
    Network packet size (bytes): 4096
    Clock Time (ms.): total       62
    NULL
    Could you anuone please suggest me on this.......
    Thanks and Regards, Bala

    You will need to write a client program to do this. SQL Server is not intended for writing files. People still do it by calling BCP through xp_cmdshell, but this is a dubious practice. Better is to write a CLR stored procedure for the task. However, you
    are on SQL 2000, and the CLR support was added in SQL 2005. Furthermore, there is no XML type in SQL 2000, and the only way to generate XML is with the FOR XML clause. But this output is not well understood by BCP. Then I try: [code} bcp "SELECT * FROM Northwind..Customers
    FOR XML RAW" queryout slask.bcp -c -T [/code] on SQL 2000, I get [code] 11 rows copied. [/code] which is complete hogwash, because there are 91 rows in that table, and the output should be a single XML document, and the output looks like this: [code] <row
    CustomerID="ALFKI"... Bouchers" City="Marseil... tomerID="DUMON" Company... 0.32.21.21" Fax="40.32.... los Hern ndez" ContactT... n Steel" ContactTitle="... e" ContactTitle="Market... ="Salzburg" PostalCode=... " Phone="(21) 555-3412"... ty="Charleroi" PostalCo...
    <row CustomerID="WARTH"... [/code] I have truncated the output on the right side, but the left side is authentic. It really is that bad.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Insert result of sql into table

    Hi all, how do I insert result of sql into table marco_ttmp ?
    I tried this, but it doesn't work, it returns "ORA-00928: missing SELECT keyword"
    insert into marco_ttmp (var_id,arcdate,contragentid,lpnd,lusd,lkk)
    with
    rrk as (
    select '01112010' as mydate FROM dual d
    union all
    select '01122010' as mydate FROM dual d
    rru as (
    select '33' contragentid from dual d
    union all 
    select '56' contragentid from dual d
    b as (
    select '01112010' as arcdate, '33' as contragentid, 'tt' as t from dual
    union all
    select '01122010' as arcdate, '56' as contragentid, 'un' as t from dual
    union all
    select '01122010' as arcdate, '33' as contragentid, 'kp' as t from dual
    union all
    select '01112010' as arcdate, '56' as contragentid, 'ur' as t from dual
    d as (
    select '01112010' as arcdate, '33' as contragentid, 'dr' as y from dual
    union all
    select '01122010' as arcdate, '56' as contragentid, 'rh' as y from dual
    union all
    select '01122010' as arcdate, '33' as contragentid, 'tr' as y from dual
    union all
    select '01112010' as arcdate, '56' as contragentid, 'wn' as y from dual
    v as ( select '555' as kkt from dual ),
    kkt as ( select count(*)+5 kkt from v )
    --insert into marco_ttmp (var_id,arcdate,contragentid,lpnd,lusd,lkk)
    select substr(rrk.mydate,4,2) || '.' || rru.contragentid var_id,
    rrk.mydate as arcdate,
    rru.contragentid as contragentid,
    count(b.arcdate) lpnd,count(d.arcdate) lusd,
    kkt.kkt lkk
    from kkt cross join rrk cross join rru
    left outer join b on b.arcdate = rrk.mydate and b.contragentid = rru.contragentid
    left outer join d on d.arcdate = rrk.mydate and d.contragentid = rru.contragentid
    group by rrk.mydate, rru.contragentid, kkt.kkt

    Moved "insert into" to the beginning of statement, everything works.
    insert into marco_ttmp (var_id,arcdate,contragentid,lpnd,lusd,lkk)
    with
    rrk as (
    select '01112010' as mydate FROM dual d
    union all
    select '01122010' as mydate FROM dual d
    rru as (
    select '33' contragentid from dual d
    union all 
    select '56' contragentid from dual d
    b as (
    select '01112010' as arcdate, '33' as contragentid, 'tt' as t from dual
    union all
    select '01122010' as arcdate, '56' as contragentid, 'un' as t from dual
    union all
    select '01122010' as arcdate, '33' as contragentid, 'kp' as t from dual
    union all
    select '01112010' as arcdate, '56' as contragentid, 'ur' as t from dual
    d as (
    select '01112010' as arcdate, '33' as contragentid, 'dr' as y from dual
    union all
    select '01122010' as arcdate, '56' as contragentid, 'rh' as y from dual
    union all
    select '01122010' as arcdate, '33' as contragentid, 'tr' as y from dual
    union all
    select '01112010' as arcdate, '56' as contragentid, 'wn' as y from dual
    v as ( select '555' as kkt from dual ),
    kkt as ( select count(*)+5 kkt from v )
    select substr(rrk.mydate,4,2) || '.' || rru.contragentid var_id,
    rrk.mydate as arcdate,
    rru.contragentid as contragentid,
    count(b.arcdate) lpnd,count(d.arcdate) lusd,
    kkt.kkt lkk
    from kkt cross join rrk cross join rru
    left outer join b on b.arcdate = rrk.mydate and b.contragentid = rru.contragentid
    left outer join d on d.arcdate = rrk.mydate and d.contragentid = rru.contragentid
    group by rrk.mydate, rru.contragentid, kkt.kkt

  • Save a dynamic sql into a column

    Hello,
    I need to save dynamic SQL into a column called STR in a table.
    I have a insert into table A( id, fname, lname)
    values(1, 'John', 'Smith');
    I have a requirement to save the DML statement that user executed such as this insert statement into table 'A'.
    I have to save this into anoter table called 'B' in the 'STR' column.
    I have to save that whole insert statement into a cloumn 'STR' in table 'B'
    How can do this?
    Thank you..

    This is not for auditing. The shop wants to save the DML statements in a table when a user does updates and inserts.. at the same time they want to build dynamic sql for this as a string such as update emp set where empno = 1 etc....
    could you give me an example please.
    Thanks a bunch....

  • Put some data form the databse of SQL Server into SAP and auto general PR?

    Dear all,
            Can you tell me how I can put some data from the databse of SQL Server into SAP and auto general PR?
    Best regards,
    Merryzhang
    Edited by: merry zhang on Feb 4, 2009 9:10 AM

    Hi Zhang,
    If i have understood your question properly, I guess you wanted to create Purchase Requistion automatically right?
    Then you have lots of option simpilest one would be create a couple of Z table with all the fields that you require for header and Item.
    create a Program and use BAPI function module to create the PR by reading the values from those Z tables. after creation delete the contents from the table. Schedule this program in Background periodically like everyday or weekly once however you would like it to be. So once the table has contents in it and when the program runs it will create the PR's (Purchase Requisition).
    You can also use a workflow with the Z table. Once the Z table is filled you can trigger a workflow based on the Table change. I'm not sure like how to do it but I nkow that this process can also be used.
    Hope this might have thrown some light upon.
    Thanks,
    Prashanth

  • Passing a string into an SQL query IN statement

    Hello,
    I need to connect to a database to pull some data to dynamically create a form based on the data I pull back. My SQL query works fine when I manually run it through a SQL client tool, but when I try to pass it through my workflow I'm having trouble with passing my string into the IN part of the statement. So if for example my SQL query is:
    SELECT Field1, Field2, Field3 FROM Table1 WHERE Field4 IN (?)
    I have a process variable that has the string I'm trying to pass into the ?, but I don't seem to be able to get the query to run. I have tried setting up my query to run as a Parameterized Query (passing my string process variable into the ?), and by setting the query up through xPath (where I am calling my process variable with an xPath declaration), but am not having any luck.
    The process variable I am trying to pass is formatted such that I'm passing 'Value1','Value2','Value3' but I can reformat this string if need be. Even with using test data I can't get the query to return anything. For test data I have tried: 'Value1','Value2','Value3' ; Value1','Value2','Value3 ; Value1,Value2,Value3 but the query never returns any data. I can't seem to see how to format the string to pass into the query. The Query will work with a single Value in the test data, but as soon as I try to pass multiple values within the string it fails. Any suggestions?

    The problem looks to be a limit on what I can pass into the SQL query component. My string is coming from data returned from another database. I take the xml output from that database call, pass it through a set variable component to remove my xml tags from the string, and then format the string in a script component (I have to do it this way because of the way the data coming out of my first database call). I've put in loggers, and can see that the string I'm passing into my query that is giving me problems, is formatted the same way as if I were to use the concat function Scott listed above. It looks like there is a limitation on what can be passed in my variable. I have tried creating my entire SQL query statement in a set variable component, and then just calling the process variable that holds that statement, but there is a character limit of 128 character for what can be passed in a variable through xpath in the SQL query component.
    The next thing I tried was changing my SQL where clause. Instead of passing my variable directly into the IN statement I set up a PATINDEX('%:'+countyname+ ':%', ?) > 0 call to check for the values in my database call. As you can see I took out the "," that I was passing as part of my string, thinking that the SQL component was getting confused by them, and placed ":" characters around my values being passed in my string variable. No matter what I try to do though I'm not able to get the query to run. The component looks like it is taking my string, and is seeing the whole thing as a string instead of passing it as individual values within a string.
    I think I'm getting close, but I keep getting a Content not allowed in prolog exception in the server logs.

  • Dynamic SQL within a SQL Query ?

    is there any possibility to do like this ?
    SELECT table_name, XXXXXXXX('SELECT Count(*) FROM '||table_name) tot_rows
      FROM dba_tables
    WHERE owner = 'SCOTT';or any other trick to run dynamic SQL within the SQL Query?
    Hoping....that it should be.
    Regards,
    Orapdev

    One small disadvantage: it is executing 202 SQL statements: 3 "user SQL statements" (the one above and the 2 "select count(*)..."), and 199 internal ones ...How did you get to those numbers?
    I just traced this statement and found completely different results:
    TKPROF: Release 10.2.0.3.0 - Production on Tue Jul 10 12:12:10 2007
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Trace file: diesl10r2_ora_5440.trc
    Sort options: default
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    declare  cursor NlsParamsCursor is    SELECT * FROM
      nls_session_parameters;begin  SELECT Nvl(Lengthb(Chr(65536)),
      Nvl(Lengthb(Chr(256)), 1))    INTO :CharLength FROM dual;  for NlsRecord in
      NlsParamsCursor loop    if NlsRecord.parameter = 'NLS_DATE_LANGUAGE' then  
         :NlsDateLanguage := NlsRecord.value;    elsif NlsRecord.parameter =
      'NLS_DATE_FORMAT' then      :NlsDateFormat := NlsRecord.value;    elsif
      NlsRecord.parameter = 'NLS_NUMERIC_CHARACTERS' then     
      :NlsNumericCharacters := NlsRecord.value;    elsif NlsRecord.parameter =
      'NLS_TIMESTAMP_FORMAT' then      :NlsTimeStampFormat := NlsRecord.value;   
      elsif NlsRecord.parameter = 'NLS_TIMESTAMP_TZ_FORMAT' then     
      :NlsTimeStampTZFormat := NlsRecord.value;    end if;  end loop;end;
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           1
    Fetch        0      0.00       0.00          0          0          0           0
    total        2      0.00       0.00          0          0          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50 
    SELECT NVL(LENGTHB(CHR(65536)), NVL(LENGTHB(CHR(256)), 1))
    FROM
    DUAL
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.01       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          0          0           1
    total        3      0.01       0.00          0          0          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50     (recursive depth: 1)
    Rows     Row Source Operation
          1  FAST DUAL  (cr=0 pr=0 pw=0 time=7 us)
    SELECT *
    FROM
    NLS_SESSION_PARAMETERS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          0          0          17
    total        3      0.00       0.00          0          0          0          17
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50     (recursive depth: 1)
    Rows     Row Source Operation
         17  FIXED TABLE FULL X$NLS_PARAMETERS (cr=0 pr=0 pw=0 time=124 us)
    select PARAMETER,VALUE
    from
    nls_session_parameters where PARAMETER in('NLS_NUMERIC_CHARACTERS',
      'NLS_DATE_FORMAT','NLS_CURRENCY')
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          0          0           3
    total        3      0.00       0.00          0          0          0           3
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50 
    Rows     Row Source Operation
          3  FIXED TABLE FULL X$NLS_PARAMETERS (cr=0 pr=0 pw=0 time=57 us)
    select to_char(9,'9C')
    from
    dual
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          0          0           1
    total        3      0.00       0.00          0          0          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50 
    Rows     Row Source Operation
          1  FAST DUAL  (cr=0 pr=0 pw=0 time=2 us)
    SELECT table_name,
           DBMS_XMLGEN.getxmltype ('select count(*) c from ' || table_name).EXTRACT
                                                                    ('//text').getstringval
                                                                          () tot
      FROM dba_tables
    WHERE table_name IN ('EMP', 'DEPT') AND owner = 'SCOTT'
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.01       0.02          0         48          0           2
    total        3      0.01       0.02          0         48          0           2
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50 
    Rows     Row Source Operation
          2  HASH JOIN  (cr=42 pr=0 pw=0 time=2952 us)
          2   MERGE JOIN CARTESIAN (cr=42 pr=0 pw=0 time=1206 us)
          2    NESTED LOOPS OUTER (cr=42 pr=0 pw=0 time=478 us)
          2     NESTED LOOPS OUTER (cr=36 pr=0 pw=0 time=421 us)
          2      NESTED LOOPS OUTER (cr=30 pr=0 pw=0 time=379 us)
          2       NESTED LOOPS OUTER (cr=30 pr=0 pw=0 time=365 us)
          2        NESTED LOOPS  (cr=22 pr=0 pw=0 time=312 us)
          2         NESTED LOOPS  (cr=16 pr=0 pw=0 time=272 us)
          2          NESTED LOOPS  (cr=8 pr=0 pw=0 time=172 us)
          1           TABLE ACCESS BY INDEX ROWID USER$ (cr=2 pr=0 pw=0 time=56 us)
          1            INDEX UNIQUE SCAN I_USER1 (cr=1 pr=0 pw=0 time=30 us)(object id 44)
          2           INLIST ITERATOR  (cr=6 pr=0 pw=0 time=111 us)
          2            TABLE ACCESS BY INDEX ROWID OBJ$ (cr=6 pr=0 pw=0 time=87 us)
          2             INDEX RANGE SCAN I_OBJ2 (cr=4 pr=0 pw=0 time=54 us)(object id 37)
          2          TABLE ACCESS CLUSTER TAB$ (cr=8 pr=0 pw=0 time=98 us)
          2           INDEX UNIQUE SCAN I_OBJ# (cr=4 pr=0 pw=0 time=26 us)(object id 3)
          2         TABLE ACCESS CLUSTER TS$ (cr=6 pr=0 pw=0 time=39 us)
          2          INDEX UNIQUE SCAN I_TS# (cr=2 pr=0 pw=0 time=13 us)(object id 7)
          2        TABLE ACCESS CLUSTER SEG$ (cr=8 pr=0 pw=0 time=37 us)
          2         INDEX UNIQUE SCAN I_FILE#_BLOCK# (cr=4 pr=0 pw=0 time=21 us)(object id 9)
          0       INDEX UNIQUE SCAN I_OBJ1 (cr=0 pr=0 pw=0 time=4 us)(object id 36)
          2      TABLE ACCESS BY INDEX ROWID OBJ$ (cr=6 pr=0 pw=0 time=33 us)
          2       INDEX UNIQUE SCAN I_OBJ1 (cr=4 pr=0 pw=0 time=23 us)(object id 36)
          2     TABLE ACCESS CLUSTER USER$ (cr=6 pr=0 pw=0 time=28 us)
          2      INDEX UNIQUE SCAN I_USER# (cr=2 pr=0 pw=0 time=12 us)(object id 11)
          2    BUFFER SORT (cr=0 pr=0 pw=0 time=716 us)
          1     FIXED TABLE FULL X$KSPPI (cr=0 pr=0 pw=0 time=661 us)
       1436   FIXED TABLE FULL X$KSPPCV (cr=0 pr=0 pw=0 time=1449 us)
    select count(*) c
    from
    EMP
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        2      0.00       0.00          0          1          0           1
    total        4      0.00       0.00          0          1          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50     (recursive depth: 1)
    Rows     Row Source Operation
          1  SORT AGGREGATE (cr=1 pr=0 pw=0 time=96 us)
         14   INDEX FULL SCAN EMP_IDX (cr=1 pr=0 pw=0 time=46 us)(object id 61191)
    select metadata
    from
    kopm$  where name='DB_FDO'
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          2          0           1
    total        3      0.00       0.00          0          2          0           1
    Misses in library cache during parse: 0
    Optimizer mode: CHOOSE
    Parsing user id: SYS   (recursive depth: 1)
    Rows     Row Source Operation
          1  TABLE ACCESS BY INDEX ROWID KOPM$ (cr=2 pr=0 pw=0 time=42 us)
          1   INDEX UNIQUE SCAN I_KOPM1 (cr=1 pr=0 pw=0 time=22 us)(object id 365)
    select count(*) c
    from
    DEPT
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        2      0.00       0.00          0          1          0           1
    total        4      0.00       0.00          0          1          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50     (recursive depth: 1)
    ALTER SESSION SET sql_trace=FALSE
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        2      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
    Parsing user id: 50 
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        5      0.00       0.00          0          0          0           0
    Execute      5      0.00       0.00          0          0          0           1
    Fetch        3      0.01       0.02          0         48          0           6
    total       13      0.01       0.03          0         48          0           7
    Misses in library cache during parse: 0
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        5      0.00       0.00          0          0          0           0
    Execute      5      0.01       0.00          0          0          0           0
    Fetch        7      0.00       0.00          0          4          0          21
    total       17      0.01       0.00          0          4          0          21
    Misses in library cache during parse: 0
        9  user  SQL statements in session.
        1  internal SQL statements in session.
       10  SQL statements in session.
    Trace file: diesl10r2_ora_5440.trc
    Trace file compatibility: 10.01.00
    Sort options: default
           1  session in tracefile.
           9  user  SQL statements in trace file.
           1  internal SQL statements in trace file.
          10  SQL statements in trace file.
          10  unique SQL statements in trace file.
         132  lines in trace file.
           0  elapsed seconds in trace file.I only see a ratio of 1:9 for user- to internal SQL statements?
    michaels>  select * from v$version
    BANNER                                                         
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production                         
    CORE     10.2.0.3.0     Production                                     
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production        
    NLSRTL Version 10.2.0.3.0 - Production  

Maybe you are looking for

  • Importing sets "part of compilation" all the time, even when it shouldn't.

    I've just instaled iTunes 9.01 and have been importing about 5 CDs worth of music. The problem is that iTunes seems to be setting the "part of a compilation" flag every time even though none of the CDs I've been importing are compilations CDs. I know

  • S_PLO_86000031 or S_PLO_86000030

    Hello SAP Guru's, Question.  I am trying to run a report that gives me transactions detail by account.  Is this the best report?  In addition, when I download this report (needed for auditors) it cuts off at 69,000 lines.  It appears that this is a p

  • HAS ANYONE TRIED THE BELKIN LEATHER CASE FROM THE APPLE STORE?

    Hey I was wondering if anyone had tried the new Belkin case from the apple store?Most of the reviews were good but does this case have a belt clip?Does it scratch the screen?How good is it?Worth buying? Any feedback will be greatly appreciated.

  • Install Base Table relationship

    Hi Expert, Could you plz explain me how to relate Install Base tables so that I can able to show data like the component structure and then their corresponding order, contract etc thanks

  • System Monitoring - CCMSPING - (Workcenter)

    Dear all, I have installed the CCSMPING in my SOLMAN system. From RZ21, when I select all systems, either ABAP standalone, Double-Stack, JAVA standalone, I start a "CCMSPING - Test Ping", it works. From SOLMAN_WORKCENTER - System Monitoring - System