Dbms_xmlgen.newcontext query from multiple tables and ||

I have two questions
How do I get a dbms_xmlgen.context to query from multiple tables? I have been able to make it work with using one table only, but not with multiple tables.
And how to get the || (concat) to work within my query for my output to an xml file?
Here is my current query:
create or replace function get_xml return clob is
result clob;
qryctx dbms_xmlgen.ctxHandle;
SELECT DBMS_XMLGEN.getxml('select prefix, suffix, fiscal_yr
FROM rcv.recv_accessions ra
where ra.prefix = 8 and ra.fiscal_yr = 11')xml into result FROM dual;
result := DBMS_XMLGEN.getXML(qryCtx);
This is what I desire:
SELECT DBMS_XMLGEN.getxml('select ra.prefix||'-'|| ra.suffix||'-'|| ra.fiscal_yr accession, ss.date_in, st.test
FROM rcv.recv_accessions ra, ser.sero_samples ss, ser.sero_tests st
where ra.prefix = 8 and ra.fiscal_yr = 11 and ss.raid = ra.id and st.ssid = ss.id')xml into result FROM dual;
On this both the reference to multiple tables and the concat function cause errors.
Thank you
Edited by: user583094 on Mar 2, 2011 3:36 PM

Hi,
for the concat do I use xmlconcat?No, XMLConcat is used to concatenate XMLType fragments.
The || operator will do fine, but you must escape any single quote inside the string :
SELECT DBMS_XMLGEN.getxml(
'SELECT ra.prefix ||''-''|| ra.suffix ||''-''|| ra.fiscal_yr as accession,
        ss.date_in,
        st.test
FROM rcv.recv_accessions ra,
      ser.sero_samples ss,
      ser.sero_tests st
WHERE ra.prefix = 8
AND ra.fiscal_yr = 11
AND ss.raid = ra.id
AND st.ssid = ss.id'
INTO result
FROM dual;Or, use the quoting operator to define a custom string delimiter :
SELECT DBMS_XMLGEN.getxml(
q'{SELECT ra.prefix ||'-'|| ra.suffix ||'-'|| ra.fiscal_yr as accession,
        ss.date_in,
        st.test
FROM rcv.recv_accessions ra,
      ser.sero_samples ss,
      ser.sero_tests st
WHERE ra.prefix = 8
AND ra.fiscal_yr = 11
AND ss.raid = ra.id
AND st.ssid = ss.id
INTO result
FROM dual;BTW, a good practice would be to use bind variables for the query. DBMS_XMLGEN can handle them nicely :
CREATE OR REPLACE FUNCTION get_xml
RETURN CLOB
IS
qryctx   DBMS_XMLGEN.ctxHandle;
v_out    CLOB;
qrystr   VARCHAR2(4000) :=
'SELECT ra.prefix ||''-''|| ra.suffix ||''-''|| ra.fiscal_yr as accession,
        ss.date_in,
        st.test
FROM rcv.recv_accessions ra,
      ser.sero_samples ss,
      ser.sero_tests st
WHERE ra.prefix = :b_prefix
AND ra.fiscal_yr = :b_fiscal_yr
AND ss.raid = ra.id
AND st.ssid = ss.id';
BEGIN
qryctx := DBMS_XMLGEN.newContext(qrystr);
DBMS_XMLGEN.setBindValue(qryctx, 'b_prefix', '8');
DBMS_XMLGEN.setBindValue(qryctx, 'b_fiscal_yr', '11');
-- to generate empty elements if necessary :
DBMS_XMLGEN.setNullHandling(qryctx, DBMS_XMLGEN.EMPTY_TAG);
v_out := DBMS_XMLGEN.getXML(qryctx);
DBMS_XMLGEN.closeContext(qryctx);
RETURN v_out;
END;

Similar Messages

  • How to use one query against multiple table and recieve one report?

    I have duplicate tables, (except for their names of course) with commodities prices. They have the same column headings, but the data is different of course. I have a query that gives me a certain piece of information I am looking for but now I need to run this query against every table. I will do this every day as well, to see if the buying criteria is met. There are alot of tables though (256). Is there a way to say run query in all tables and return the results in one place? Thanks for your help.

    hey
    a. the all 256 tables whuld be one big partitoned table
    b. you can use all_tables in order to write a select that will write the report for you:
    SQL> set head off
    SQL> select 'select * from (' from dual
      2  union all
      3  select 'select count(*) from ' || table_name || ' union all ' from a
      4  where table_name like 'DB%' AND ROWNUM <= 3
      5  union all
      6  select ')' from dual;
    select * from (
    select count(*) from DBMS_LOCK_ALLOCATED union all
    select count(*) from DBMS_ALERT_INFO union all
    select count(*) from DBMS_UPG_LOG$ union all
    remove the last 'union all', and tun the generated quary -
    SQL> set head on
    SQL> select * from (
      2  select count(*) from DBMS_LOCK_ALLOCATED union all
      3  select count(*) from DBMS_ALERT_INFO union all
      4  select count(*) from DBMS_UPG_LOG$
      5  );
      COUNT(*)
             0
             0
             0
    Amiel

  • ALV for fields from multiple tables and make them editable

    Hi,
    I am working on a forecasting report. We have created few custom table e.g. store forcaset detail for whole year month wise. tables are say sales data, budget data, forcast data etc.
    Now i need to make a report based on monthwise based on above mention table.
    eg.o/p looks like:
    column name                     type desc monthapr monthmay .......
    table forcast                      Qty  sales    100          150
    table budget/sales             amt   amou    20.50    130.50
    table sales vs forcast       amt   amount  3000     50000
    -Now i don't know how to display data from multiple table in single ALV list that to with different field type.
    -2nd issue is i need to make only perticuler row editable so that user can chage data.
    -3rd when user change data and press calulate button - it should calculate data for future month - i got formula for that and disply the calulated data.
    - 4th if user like the forcast data then when press save - change data should update dbtable.
    Is this all possible with simple abap FM Or need to use ABAPOO.
    I will appericiate all expert help.
    Many thanks in advance.
    KDE.
    Edited by: kde_test on Jun 4, 2010 5:44 PM

    Hi,
    Solutions :
    1. You can use  FM REUSE_ALV_HIERSEQ_LIST_DISPLAY as guided by Ashutosh.
    You can also check out this
    [http://www.sap technical.com/Tutorials/ABAP/3DGraph/demo.htm]  change link to saptechnical without space
    2. [How to make certain rows in ALV grid editable...;
    3 & 4. Use two importing paramaters 'PF_STATUS_SET' 'USER_COMMAND' of  REUSE_ALV_GRID_DISPLAY.
    create two function codes 'CALC and 'SAVE' in pf-status and provide your required functionality to these function codes using User-Command.
    Sorry am unable to provide you with supporting code, but you can search for it and It can solve your problem
    Regards,
    Rohit

  • I need to query from db table and static VO in same time

    I have query VO which returns user roles
    so the result will be something like 1,5,6,3,1
    and i have static list contains the role names with their codes
    1 ------> administrator
    2 -------> user
    3 --------> system manager
    I used the first VO to build ADF select one choice contains the code of roles
    how can I display the role name instead of its code

    thank you john for explaining
    if I put the static list in data base the problem is solved, I can get the role names by my query, but NO I can't but it in database
    I am now trying to do that by java code but I want to know if that can be done without writing codes

  • Delete records from multiple tables and add delay in execution

    Dear All,
    My Database is Oracle 11gR2 on Linux.
    I have to schedule delete in 5 tables. For this i will write a procedure with delete queries and schedule the procedure to run daily in night.
    I want to give delay in the execution of delete queries within procedure? How can i add this functionality within a procedure?
    I don't want to lock the tables as other queries may be accessing the same table meanwhile.
    Looking for your help.
    Regards,
    Imran

    Duplicate thread - see https://forums.oracle.com/thread/2553380 for answer.

  • Records from multiple tables

    Hi,
    I have a method that has to access records from multiple tables and store them all in a file. It's something like this:
    switch (tableId){
    case 'A' : query="SELECT * FROM TABLE_A
    WHERE ID = '" + tempId + "'";
    ResultSet rs = stmt.executeQuery (query);
    rs.close();
    break;
    case 'B' : query="SELECT * FROM TABLE_B
    WHERE ID = '" + tempId + "'";
    rs = stmt.executeQuery (query);
    rs.close();
    break;
    case 'C' : query="SELECT * FROM TABLE_C
    WHERE ID = '" + tempId + "'";
    rs = stmt.executeQuery (query);
    rs.close();
    break;
    My problem is that I get an "Invalid cursor" error the second time I enter the loop. I've been reading up on cursors but I still don't know what to do. Can I use ResultSet to return multiple rows from multiple tables? If not, what can I use? Please help!
    Thanks in advance.

    remove the "rs.close()" from the switch statement. use "rs.close()" after your loop ends.
    prem

  • XDK Export in XML from multiple tables

    Hello everybody,
    I have to export data from an Oracle database to a XML file and then generate the Java classes.
    1)
    I used XSU successfully with one table. My problem is to retrieve data not from a unique table but from multiple tables linked by relations.
    I wanted to do this using XSU to retrieve data from the database and create the corresponding XML schema.
    That seems to be possible but I need help for database relations.
    Can someone help me to explain if it is possible to export from multiple tables (and if yes how)?
    2)
    Having my XML schema then I will have to generate Java objects. How is it possible with the XML Class Generator for Java?
    Does anybody have experience and samples?
    Many Thanks in advance!

    Hi Elodie,
    Please refer the Product Order sample on OTN that describes the usage of XML Class Generator for Java.
    The URL for it is:
    http://otn.oracle.com/tech/xml/xdk_sample/ProductOrdersSample.html
    Hope it helps
    Shefali

  • Building index from multiple master and child relationship tables

    Hello,
    My question is:
    Is it possible to create the index for master and child tables?
    If yes, can you please point me out to any links or give me an example.
    Actually i just followed this below link to create the index using multiple tables
    Building index from multiple tables for text search
    I am able to create the index using above link,but problem accured , when i search for one master data column value then it is returning many rows with same master data for each child row.
    for example
    SELECT
    a.conc_program_name,
    a.conc_program_desc,
    b.param_name
    FROM a_master a, b_child b
    WHERE b.report_dtls_id = a.report_id
    AND CONTAINS (a.dummy, 'PAY') > 0
    Which retruns
    PAY Master A
    PAY Master B
    PAY Master C
    Please let me know is there any way i can restrict this to single row with concatination of child data like
    PAY Master A B C
    Another doubt is ,i have the column value like p_consolidation_set_id,when i give this in CONTAINS (a.dummy, 'p_consolidation_set_id') > 0 ,then not able to get the any results.
    please let me what shall i do for this issue.
    Thanks
    Message was edited by:
    user496798

    There are various ways to concatenate the values. One nice generic solution is to use Tom Kyte's stragg function:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:2196162600402
    If p_consolidation_set_id is a variable name, not a value, then do not put quotes around it.
    Message was edited by:
    Barbara Boehmer

  • Count(*) , group by with multiple columns from multiple tables involved

    Hi all,
    I am relatively new to SQL.
    Currently I have these few requirements, to display quite a number of fields from 3 tables for display of report.
    In my query I need to:
    1.) count(*)
    2.) select quite a number of fields from table 1,2,3
    However when count(*) is used, grouped by has to be used to.
    How do I actually use group by with so many columns to be selected?
    I have actually used the query below, but the count(*) returns 1, the correct output should be 3 instead.
    select count(*), table1.col1, table1.col2, table1.col3, table2.col3, table2.col4, table2.col6, table3.col1, table3.col4, table3.col5
    from table1, table2, table3
    where
    <conditions>........................
    group by table1.col1, table1.col2, table1.col3, table2.col3, table2.col4, table2.col6, table3.col1, table3.col4, table3.col5
    I know this group by statement looks very unrefined. How can I select multiple fields from different tables, and yet get the count(*) correctly?
    Thank you so much for your time.

    Hmm yes it actually does return count as 1 for each row. But there are 3 rows returned. E.g.
    ctr table1.col1 table1.col2 ..........
    1 value1 value1
    1 value2 value3
    1 value3 value4
    If I put the count(*) outside, it returns 3 , the correct output
    ctr
    3
    select count(*) from
    select table1.col1, table1.col2, table1.col3, table2.col3, table2.col4, table2.col6, table3.col1, table3.col4, table3.col5
    from table1, table2, table3
    where
    <conditions>
    group by table1.col1, table1.col2, table1.col3, table2.col3, table2.col4, table2.col6, table3.col1, table3.col4, table3.col5
    Thus I was wondering if it was the group by of multiple colns that resulted in the count stucked at value 1.

  • Selecting from multiple tables, into one internal table

    Hi,
    What is the best & most efficient method of selecting from multiple table (in my case 6,) into one internal table?
    Thanks,
    John
    Points will be rewarded and all responses will be highly appreciated.

    I have simple example :
    First one - Join 5 tables
    data : f1 type i,
              f2 type i,
              f3 type i.
    start-of-selection.
    get run time field f1.
    write the query 4 or 5 tables join.
    get run time field f2.
    f3 = f2 - f1 ( Total time).
    Second one - joins 3 table and use for all entries
    data : f1 type i,
              f2 type i,
              f3 type i.
    start-of-selection.
    get run time field f1.
    write the query 3 tables join and use for all entries
    get run time field f2.
    f3 = f2 - f1. ( Total time )
    Finally you can have time diffrence between the both sql statement.

  • Displaying data from multiple table/column

    hello ..
    anybody can help me how to diplaying data from multiple table/ column in PHP. TQ

    Follow the "How do I SELECT, INSERT, UPDATE and DELETE data from PHP?" example from http://wiki.oracle.com/page/PHP+Oracle+FAQ and change the "select ..." query to your favourite join, e.g.
    select country_name, region_name from countries, regions where countries.region_id = regions.region_id;

  • Jdbc getting data from multiple tables

    hi guys
    how can i get data from multiple tables in MSAccess
    please help

    >
    here is code thata i want to do
    i have 3 tables in my MSAccess databace
    Stud_O which consist name,surname fields
    Stud_I consist address,tel
    Stud_E department,faculty fields
    Based on this I would guess that you are missing a key field. There is no way to connect the tables.
    I make the class to insert data to the tables. But
    cant do getting datas from this tables.
    can anybody help me in making query
    and method that displays reultset strings to the
    textBoxes
    A select ...
    select name,surname from Stud_O. Use the executeQuery() method.

  • ** Is it possible to give select command from multiple tables in JDBC

    Hi Friends,
    Is it possible to give the select command to select data from multiple tables directly in the 'Query SQL statement' in JDBC sender communication channel ? (Instead of Stored Procedure)
    Thanking you.
    Kind Regards,
    Jeg P.

    Hi,
    here is a sample:
    Table #1
    Header
    Name EmpId Status
    Jai 5601 0
    Karthik 5579 0
    Table #2
    Name Contactnumber
    Jai 9894268913
    Jai 04312432431
    Karthik 98984110335
    Karthik 04222643993
    select Header.Name, Header.EmpId, Item.Contactnumber from Header,Item where Header.Name = (select min(Header.Name) from Header where Header.Status = 0) and Header.Name = Item.Name
    Regards Mario

  • POWL accessing data from multiple tables/objects

    Hello,
    I have a query on the POWL applications.
    If the powl application has to access data from multiple tables/objects, then the solution would be creating a data structure of those tables/objects and referring to that structure in GET_OBJECT_DEF methods.
    Is there any other soln? or I am right here?
    The queries which are saved for a particular user are transportable? if not, how can they be made transportable?
    Thanks & regards,
    Ravish

    you are right, you can do in get_objects method.
    POWL_QUERIES are transportab;e, you can save them in POWL_QUERY transaction.
    Best regards,
    Rohit
    http://wiki.sdn.sap.com/wiki/display/WDABAP/POWL

  • Update data provider queryspecification wiith columns from multiple tables

    Hi
    I have scenario like I need  updated a queryspecificaiton with columns from multiple tables
    1. Ex:
      <bOQuery name="Query">
              <resultObjects identifier="DS0.DO1" name="A$Application_ID"/>
              <resultObjects identifier="DS0.DO2" name="A$Column_Name"/>
    A$Application_ID is from Table A and A$Column_Name from table B
    The query is not adding to dataprovier when I am trying to updated from REST API.
    Please help me.
    Thanks
    Kalyan

    Have a look at the Business Intelligence platform RESTful Web Service Developer Guide, section 3.4.7 (p. 197) - Report structure: getting and updating the structure (specifications) of a report, may be a good place to start(?). Also see KBA 1952419 - How to update the properties of a web intelligence report using RESTful web service SDK .
    - Ludek
    Senior Support Engineer AGS Product Support, Global Support Center Canada
    Follow us on Twitter

Maybe you are looking for

  • Date Object Issue in WebI

    Hello All, Currently I am facing an issue with Date Object in WebI. The data type of this specific object in Oracle (11g) is TimeStamp. If I use this object as one of the query filters in my report, I get "ORA-01843: not a valid month" error. I tried

  • Random quiting and closing

    I was having problems yesterday. Heres an unneccesary story detailing everything. I was downloading a video from iTunes (and playing music), and converting a video with MPEG streamclip. (I deal with music and video primarily) For some reason when I o

  • Apex and database links

    Hi, How does Apex perform using database links. We are currently on version 3.1.1.00.09 of Applicatiion Express and have all of our data in one database. We will soon be upgrading our environment to Oracle Database Appliance. We are thinking about sp

  • Deskjet 6940 pdf docs are printing as jumbled up letters and symbols

    I have a deskjet 6940. When I print pdf docs they are a jumbled up mess of letters and or symbols. I have uninstalled and reinstalled the adobe program more than once and the problem is still ongoing.

  • URGENT! Having problem with while statement and other syntax errors

    I am trying to teach myself JSP for a school project due very soon. But I keep receiving errors surrounding my while statement. The errors are: Syntax: ";" inserted to complete BlockStatements Syntax: "}" inserted to complete Block I have checked it