Loop query

i have a simple loop query. I want to get same data from 3 different tables into a single internal table like
if tab1 data is not available then tab2 then tab3.
now when i use my internal table how do i fill data into my internal table and what will be my loop condition.
i have already written select statement.
a sample code will be of great help

Hi,
The above said code I think it doesn't work properly because in the select statement from table name placed after the internal table and also no need of append statement.
Use like this...(itab-Internal table name)
Select * from tab1 into table itab
    where (condition).
if sy-subrc <> 0.
  Select * from tab2 into table itab
     where(condition).
  if sy-subrc <> 0.
    Select * from tab3 into table itab
       where (condition).
  endif.
endif.
Now you will get value in the internal table itab.Three different tables where tab1,tab2,tab3.
Thanks,
Sakthi C
*Rewards if useful--*

Similar Messages

  • Cfmail loop query

    can some one help me with this query please
    i have a cfmail running off a query
    i want to be able to send mail to a list of recipietns from
    my database
    the query below works but only sends emails to the first
    contact in the list
    what can i do to my query to change this?
    <CFQUERY datasource="#application.ds#" Name="GetSch">
    SELECT cc.Code, gg.PlayerPhone, dd.Message, cc.Club_Abbrev
    FROM appoint_table dd, SMS_Players_Table gg, SMS_Clubs_Table
    cc
    WHERE ServerSMS <= #CreateODBCDateTime(Now())# AND
    dd.App_ClientID = gg.PlayerID AND dd.LoginID = cc.ClubID
    AND ServerSMS <> ''
    </cfquery>
    <cfmail to = "[email protected]" query="GetSch"
    from = "test"
    subject="">
    to:#Code##PlayerPhone#
    text:#Message#
    from:#Club_Abbrev#
    </cfmail>

    ok thank i just realised what i need
    just to go to one email as the cfmail is at the min
    but i need to loop through the mail output so it send 30
    emails to the same email
    with the different
    to:#Code##PlayerPhone#
    text:#Message#
    from:#Club_Abbrev#
    for each record retreved form the query

  • Exception statement for looping query

    Hi this is my query to date:
    declare   
        cursor curs is
         select name_id_no, incident_date
         from MICHAELC.Food_Nov_01_final t
         --where rownum < 6
         for update of cat_latest;
        w_cat_latest        number(4,0);
        w_cat_latest_date   date;
        w_cat_max           number(4,0);
        w_cat_max_date      date;
        w_cat_min           number(4,0);
        w_cat_min_date      date;
    begin
        for i in curs loop
            -- get latest cat date
            select max(cat_score_date) into w_cat_latest_date
            from rbn_cat
            where customer_no = i.name_id_no
            and   cat_score_date <= i.incident_date;
            -- get latest cat score
            select cat_score into w_cat_latest
            from rbn_cat
            where customer_no = i.name_id_no
            and cat_score_date = w_cat_latest_date
            and rownum = 1;
            --get maximum cat score
            select max(cat_score) into w_cat_max
            from rbn_cat
            where customer_no = i.name_id_no
            and   months_between(i.incident_date,cat_score_date) between 0 and 12;
            --get maximum cat date
            select cat_score_date into w_cat_max_date
            from rbn_cat
            where customer_no = i.name_id_no
            and   cat_score = w_cat_max
            and   months_between(i.incident_date,cat_score_date) between 0 and 12
            and   rownum = 1;
            --get minimum cat score
            select min(cat_score) into w_cat_min
            from rbn_cat
            where customer_no = i.name_id_no
            and   months_between(i.incident_date,cat_score_date) between 0 and 12;
            --get minimum cat date
            select cat_score_date into w_cat_min_date
            from rbn_cat
            where customer_no = i.name_id_no
            and   cat_score = w_cat_min
            and   months_between(i.incident_date,cat_score_date) between 0 and 12
            and   rownum = 1;
            update MICHAELC.Food_Nov_01_final
                set cat_latest = w_cat_latest
                   , cat_latest_date = w_cat_latest_date
                   , cat_max  = w_cat_max
                   , cat_max_date = w_cat_max_date
                   , cat_min    = w_cat_min
                   , cat_min_date = w_cat_min_date
            where current of curs;
        end loop;
    end;
    I receive the following error:
    Error report:
    ORA-01403: no data found
    ORA-06512: at line 37
    01403. 00000 - "no data found"
    *Cause:   
    *Action:
    I want to use an exception statement, something along the lines of
    exception when no_data_found then
                w_cat_latest_date     := NULL;
                w_cat_latest          := NULL;
                w_cat_max             := NULL;
                w_cat_max_date        := NULL;
                w_cat_min             := NULL;
                w_cat_min_date        := NULL;I'm just not really sure how to use the exception statement correctly and if it is the best way to handle this error. Thank-you for your time and help.
    Banner:
    Oracle Database 11g Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    "CORE 11.2.0.2.0 Production"
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production

    Like this;-
    declare   
        cursor curs is
         select name_id_no, incident_date
         from MICHAELC.Food_Nov_01_final t
         --where rownum < 6
         for update of cat_latest;
        w_cat_latest        number(4,0);
        w_cat_latest_date   date;
        w_cat_max           number(4,0);
        w_cat_max_date      date;
        w_cat_min           number(4,0);
        w_cat_min_date      date;
    begin
        for i in curs loop
            -- get latest cat date
    BEGIN
            select max(cat_score_date) into w_cat_latest_date
            from rbn_cat
            where customer_no = i.name_id_no
            and   cat_score_date <= i.incident_date;
    EXCEPTION
    when no_data_found then
                w_cat_latest_date     := NULL;
    END;       
    BEGIN
            -- get latest cat score
            select cat_score into w_cat_latest
            from rbn_cat
            where customer_no = i.name_id_no
            and cat_score_date = w_cat_latest_date
            and rownum = 1;
    EXCEPTION
    when no_data_found then
                w_cat_latest
         w_cat_latest:= NULL;
    END;       
    /*   you get the idea
            --get maximum cat score
            select max(cat_score) into w_cat_max
            from rbn_cat
            where customer_no = i.name_id_no
            and   months_between(i.incident_date,cat_score_date) between 0 and 12;
            --get maximum cat date
            select cat_score_date into w_cat_max_date
            from rbn_cat
            where customer_no = i.name_id_no
            and   cat_score = w_cat_max
            and   months_between(i.incident_date,cat_score_date) between 0 and 12
            and   rownum = 1;
            --get minimum cat score
            select min(cat_score) into w_cat_min
            from rbn_cat
            where customer_no = i.name_id_no
            and   months_between(i.incident_date,cat_score_date) between 0 and 12;
            --get minimum cat date
            select cat_score_date into w_cat_min_date
            from rbn_cat
            where customer_no = i.name_id_no
            and   cat_score = w_cat_min
            and   months_between(i.incident_date,cat_score_date) between 0 and 12
            and   rownum = 1;
            update MICHAELC.Food_Nov_01_final
                set cat_latest = w_cat_latest
                   , cat_latest_date = w_cat_latest_date
                   , cat_max  = w_cat_max
                   , cat_max_date = w_cat_max_date
                   , cat_min    = w_cat_min
                   , cat_min_date = w_cat_min_date
            where current of curs;
        end loop;
    end;
    /

  • XSL Looping Query for Short Text PO Attachments

    I am using XML Publisher to revise a custom Purchase Order.
    This is a sample skeleton layout of the XML data:
    <PO_DATA>
    <LINES>
         <LINES_ROW>
              <LINE_NUM>1</LINE_NUM>
              <ITEM_DESCRIPTION>blah1.</ITEM_DESCRIPTION>
              <PO_HEADER_ID>535404</PO_HEADER_ID>
              <PO_LINE_ID>879135</PO_LINE_ID>
              <LINE_SHORT_TEXT>
                   <LINE_SHORT_TEXT_ROW>
                        <PO_LINE_ID>879135</PO_LINE_ID>
                        <SHORT_TEXT>Attachment for line 1</SHORT_TEXT>
                   </LINE_SHORT_TEXT_ROW>
                   <LINE_SHORT_TEXT_ROW>
                        <PO_LINE_ID>879135</PO_LINE_ID>
                        <SHORT_TEXT>Another Attachment for line 1</SHORT_TEXT>
                   </LINE_SHORT_TEXT_ROW>
                   <LINE_SHORT_TEXT_ROW>
                        <PO_LINE_ID>879135</PO_LINE_ID>
                        <SHORT_TEXT>Header Attachment</SHORT_TEXT>
                   </LINE_SHORT_TEXT_ROW>
              </LINE_SHORT_TEXT>
         </LINES_ROW>
         <LINES_ROW>
              <LINE_NUM>2</LINE_NUM>
              <ITEM_DESCRIPTION>Blah2</ITEM_DESCRIPTION>
              <PO_HEADER_ID>535404</PO_HEADER_ID>
              <PO_LINE_ID>879136</PO_LINE_ID>
              <LINE_SHORT_TEXT>
                   <LINE_SHORT_TEXT_ROW>
                        <PO_LINE_ID>879136</PO_LINE_ID>
                        <SHORT_TEXT>Attachment for line 2</SHORT_TEXT>
                   </LINE_SHORT_TEXT_ROW>
                   <LINE_SHORT_TEXT_ROW>
                        <PO_LINE_ID>879136</PO_LINE_ID>
                        <SHORT_TEXT>Header Attachment</SHORT_TEXT>
                   </LINE_SHORT_TEXT_ROW>
              </LINE_SHORT_TEXT>          
         </LINES_ROW>
    </LINES>
    </PO_DATA>I would like to be able to list the bold lines (text attachments) on the PO.
    I have been able to list the first <SHORT_TEXT> attachment for the 1st line, but then all of the other attachments are not listed, and I can't work out why.
    This is the xsl / codey bits from the rtf template:
    <xsl:variable name="lineID" select="../../PO_LINE_ID" />  
    <xsl:for-each select="/PO_DATA/LINES/LINES_ROW/LINE_SHORT_TEXT/LINE_SHORT_TEXT_ROW/PO_LINE_ID">
    <xsl:if test="$lineID = .">
    <xsl:variable name="lineID" select="position()" />
    <xsl:value-of select="/PO_DATA/LINES/LINES_ROW/LINE_SHORT_TEXT/LINE_SHORT_TEXT_ROW/SHORT_TEXT[$lineID]" />
    </xsl:if>
    </xsl:for-each>I don't understand why the attachment for line1 (Attachment for line 1) is listed, but then none of the others are. Presumably I'm doing something stupid, but I can't work out what.
    edit - I've printed some of the variables out as the loop is incremented - the problem seems to be that the PO_LINE_ID is not incremented for the line in bold above. It just stays the same - hence why it works for the first line, where the PO_LINE_ID matches, and not for any of the other lines. So the problem is how to get that bold line to increment the PO_LINE_ID?Thanks
    null

    Sorry to labour the point.
    When I used this code against the XML:
    <xsl:for-each select="/PO_DATA/LINES/LINES_ROW">
    <xsl:value-of select="PO_LINE_ID" />
    <xsl:for-each select="./LINE_SHORT_TEXT/LINE_SHORT_TEXT_ROW">
    <xsl:value-of select="SHORT_TEXT" />
    </xsl:for-each></xsl:for-each>
    It generated this against every line:
    879135
    Attachment for line 1
    Another Attachment for line 1
    Header Attachment
    879136
    Attachment for line 2
    Header Attachment
    879137
    Attachment for line 3
    Header Attachment
    This is my reasoning for the code that works:
    <xsl:variable name="bobby1" select="../../PO_LINE_ID" />
    Make up a variable name, and give it the value of the current lines PO_LINE_ID
    <xsl:for-each select="/PO_DATA/LINES/LINES_ROW/LINE_SHORT_TEXT/LINE_SHORT_TEXT_ROW">
    Loop through XML structure e.g.:
    <LINE_SHORT_TEXT>
         <LINE_SHORT_TEXT_ROW>
              <PO_LINE_ID>879135</PO_LINE_ID>
              <SHORT_TEXT>Attachment for line 1</SHORT_TEXT> 
         </LINE_SHORT_TEXT_ROW>
         <LINE_SHORT_TEXT_ROW>
              <PO_LINE_ID>879135</PO_LINE_ID>
              <SHORT_TEXT>Another Attachment for line 1</SHORT_TEXT> 
         </LINE_SHORT_TEXT_ROW>
         <LINE_SHORT_TEXT_ROW>
              <PO_LINE_ID>879135</PO_LINE_ID>
              <SHORT_TEXT>Header Attachment</SHORT_TEXT> 
         </LINE_SHORT_TEXT_ROW>
    </LINE_SHORT_TEXT><xsl:variable name="bobby2" select="PO_LINE_ID" />
    And each time through the loop, assign the 'bobby2' variable the value of the PO_LINE_ID.
    <xsl:if test="$bobby1=$bobby2">
    This condition is neeed - because lets say that the 'PO_LINE_ID' of the current line is 879135, and the value of the 'PO_LINE_ID' listed in the LINE_SHORT_TEXT_ROW is 879136, then I don't want to output the value of the 'SHORT_TEXT' because it doesn't relate to the PO_LINE_ID of the line currently being checked. In your shorter code version, there is no checking to see if the PO_LINE_ID in the LINE_SHORT_TEXT_ROW section matches the parent PO_LINE_ID, so it just lists all LINE_SHORT_TEXT_ROW data, regardless of whether it is related to the parent line or not.
    <xsl:value-of select="SHORT_TEXT" />
    </xsl:if>
    </xsl:for-each>
    I'd be happy to email you over the .rtf and .xml file so you can see what I'm talking about.
    Thanks again for your time and help with this. As I said, without your initial help with the for-each loop I would not have fixed it.

  • Loopie Query

    Oh save me please.
    I have two computers running Logic Pro X on both with Yosemite. One of them seems to have a more extensive drum loop collection than the other - there were vintage drum machine loops which I adored on my first computer (a tower) and unfortunately these are absent when I open up the loops from my more recent installation of LPX on my laptop. What should I do to "locate" these other loops which I assumed were factory presets. There are drum loops present just not all and the ones I found especially useful are the ones not on the second computer.
    Do I make any sense to you who might be way more knowledgeable?
    thanks
    nt

    I think you are getting a little confused....
    Kontakt (I assume thats what you meant by Contact?) isn't part of Logic Pro X nor it's content...
    It's a 3rd party plugin from Native Instruments that uses it's own libraries you must purchase unless they came free with Kontakt....
    So, download and install those libraries  the same way as they were installed on your other Mac.... from whatever source you got them from.
    Additional:
    If you mean the Drum Machine you see in the Additional Content in Logic.. highlighted in this screenshot
    That isn't a collection of loops.... its a plugin found by opening up Logic's Library.... and selecting it from there...

  • Looping Query logic Needed

    Hi Team
    I have requirement below , can you please help me with sql logic
    My input table is below
    INC_NUM
    FA_ADD
    HZ_ADD
    PARENT_INC_NUM
    ID
    A0001
    A
    A
    A0001-02
    A
    A
    A0001
    1
    A0001-04
    B
    C
    A0001
    1
    A0001-05
    B
    C
    A0001
    1
    A0001-09
    B
    S
    A0001
    1
    A0001-07
    D
    A
    A0001
    1
    B0001
    J
    K
    B0001-03
    L
    M
    B0001
    2
    B0001-04
    J
    K
    B0001
    2
    B0001-05
    A
    B
    B0001
    2
    B0001-06
    A
    B
    B0001
    2
    B0001-07
    A
    B
    B0001
    2
    C0001-02
    A
    B
    C0001-03
    A
    C
    C0001-02
    3
    C0001-05
    A
    B
    C0001-02
    3
    My output
    INC_NUM
    FA_ADD
    HZ_ADD
    PARENT_INC_NUM
    A0001
    A
    A
    A0001-02
    A
    A
    A0001
    A0001-04
    B
    C
    A0001-05
    B
    C
    A0001-09
    B
    S
    A0001-07
    D
    A
    B0001
    J
    K
    B0001-03
    L
    M
    B0001-04
    J
    K
    B0001
    B0001-05
    A
    B
    B0001-06
    A
    B
    B0001-07
    A
    B
    C0001-02
    A
    B
    C0001-03
    A
    C
    C0001-05
    A
    B
    C0001-02
    Here i n considering  null values of parent_inc_num or null values of ID as Parent record  ID
    And i m comparing this record  FA_ADD and HZ_ADD with its child records FA_ADD and HZ_ADD ,If they matches then i m assigning Parent_INC_NUM else null
    Let me take example of record C0001-02, it has null values of PARENT_INC_NUM (or null for ID)
    So C0001-02 is considered as base record ,
    Now i m comparing FA_ADD and HZ_ADD values of C0001-02 with its child records FA_ADD and HZ-ADD (ie C0001-03,C0001-05 )
    C0001-03 doesnt match so i m assigning null in target else i m assigning its base record ie C0001-02
    Below is table sample data
    could you please help
    with t as
    (select 'A0001' as INC_NUM,'A' as FA_ADD,'A' as HZ_ADD ,null as PARENT_INC_NUM ,null as ID from dual
    union all
    select 'A0001-02' as INC_NUM,'A' as FA_ADD,'A' as HZ_ADD ,'A0001' as PARENT_INC_NUM ,1 as ID from dual
    union all
    select 'A0001-04' as INC_NUM,'B' as FA_ADD,'C' as HZ_ADD ,'A0001' as PARENT_INC_NUM ,1 as ID from dual
    union all
    select 'A0001-05' as INC_NUM,'B' as FA_ADD,'C' as HZ_ADD ,'A0001' as PARENT_INC_NUM , 1 as ID from dual
    union all
    select 'A0001-09' as INC_NUM,'B' as FA_ADD,'S' as HZ_ADD ,'A0001' as PARENT_INC_NUM,1 as ID from dual
    union all
    select 'A0001-07' as INC_NUM,'D' as FA_ADD,'A' as HZ_ADD ,'A0001' as PARENT_INC_NUM,1 as ID from dual
    union all
    select 'B0001' as INC_NUM,'J' as FA_ADD,'K' as HZ_ADD ,null as PARENT_INC_NUM , null as ID from dual
    union all
    select 'B0001-03' as INC_NUM,'L' as FA_ADD,'M' as HZ_ADD ,'B0001' as PARENT_INC_NUM,2 as ID from dual
    union all
    select 'B0001-04' as INC_NUM,'J' as FA_ADD,'K' as HZ_ADD ,'B0001' as PARENT_INC_NUM ,2 as ID from dual
    union all
    select 'B0001-05' as INC_NUM,'A' as FA_ADD,'B' as HZ_ADD ,'B0001' as PARENT_INC_NUM,2 as ID from dual
    union all
    select 'B0001-06' as INC_NUM,'A' as FA_ADD,'B' as HZ_ADD ,'B0001' as PARENT_INC_NUM,2 as ID from dual
    union all
    select 'B0001-07' as INC_NUM,'A' as FA_ADD,'B' as HZ_ADD ,'B0001' as PARENT_INC_NUM,2 as ID  from dual
    union all
    select 'C0001-02' ,'A','B',null,null from dual
    union all
    select 'C0001-03','A','C','C0001-02',3 from dual
    union all
    select 'C0001-05','A','B','C0001-02',3 from dual
    select * from t
    I have 100 thousands of records of this  data ,so need to take care of performance as well
    Thank you
    Sumanth

    with t as
    (select 'A0001' INC_NUM,'A' FA_ADD,'A' HZ_ADD ,null as PARENT_INC_NUM ,null as ID from dual union all
    select 'A0001-02','A','A','A0001',1 from dual union all
    select 'A0001-04','B','C','A0001',1 from dual union all
    select 'A0001-05','B','C','A0001',1 from dual  union all
    select 'A0001-09','B','S','A0001',1 from dual union all
    select 'A0001-07','D','A','A0001',1 from dual union all
    select 'B0001','J','K',null,null from dual union all
    select 'B0001-03','L','M','B0001',2 from dual union all
    select 'B0001-04','J','K','B0001',2 from dual union all
    select 'B0001-05','A','B','B0001',2 from dual union all
    select 'B0001-06','A','B','B0001',2 from dual union all
    select 'B0001-07','A','B','B0001',2 from dual union all
    select 'C0001-03' ,'A','B',null,null from dual union all
    select 'C0001-02','A','C','C0001-03',3 from dual union all
    select 'C0001-05','A','B','C0001-03',3 from dual union all
    select 'C0001-06','A','B','C0001-03',3 from dual
    select INC_NUM,FA_ADD,HZ_ADD,
           case when fa_add = connect_by_root fa_add
                 and hz_add = connect_by_root hz_add
                then parent_inc_num
           end parent_inc_num
      from t
    start with parent_inc_num is null
    connect by prior inc_num = parent_inc_num
    INC_NUM
    FA_ADD
    HZ_ADD
    PARENT_INC_NUM
    A0001
    A
    A
    A0001-02
    A
    A
    A0001
    A0001-04
    B
    C
    A0001-05
    B
    C
    A0001-07
    D
    A
    A0001-09
    B
    S
    B0001
    J
    K
    B0001-03
    L
    M
    B0001-04
    J
    K
    B0001
    B0001-05
    A
    B
    B0001-06
    A
    B
    B0001-07
    A
    B
    C0001-03
    A
    B
    C0001-02
    A
    C
    C0001-05
    A
    B
    C0001-03
    C0001-06
    A
    B
    C0001-03
    Regards
    Etbin

  • Query or Loop

    Hi,
    I need help or suggestions in writing a pl/sql loop query against the data in Table A in order to get the output of Table B.
    Table A               
    id     type     valu     
    1     a     x     
    1     a     y     
    1     a     x     
    1     b     3     
    1     c     33     
    2     a     x     
    2     b     55     
    2     c     33     
    The output should be inserted in a new table.The expected output
    Table B output               
    id     list_a     List_B     List_C
    1     x,y,x     3     33
    2     x     55     33
    Thanks

    Try this
    SQL> with t
      2  as
      3  (
      4  select 1 id, 'a' type, 'x' value from dual union all
      5  select 1 id, 'a' type, 'y' value from dual union all
      6  select 1 id, 'a' type, 'x' value from dual union all
      7  select 1 id, 'b' type, '3' value from dual union all
      8  select 1 id, 'c' type, '33' value from dual union all
      9  select 2 id, 'a' type, 'x' value from dual union all
    10  select 2 id, 'b' type, '55' value from dual union all
    11  select 2 id, 'c' type, '33' value from dual
    12  )
    13  select id, max(decode(type, 'a', value)) list_a, max(decode(type, 'b', value)) list_b, max(decode(type, 'c', value)) list_c
    14    from (
    15            select id, type, max(value) value
    16              from (
    17                      select id, type, ltrim(sys_connect_by_path(value, ','),' ,') value
    18                        from (
    19                               select t.*, row_number() over(partition by id, type order by 1) rno
    20                                 from t
    21                             )
    22                       start with rno = 1
    23                      connect by rno = prior rno + 1
    24                         and id = prior id
    25                         and type = prior type
    26                   )
    27             group by id, type
    28         )
    29   group by id
    30  /
            ID LIST_A     LIST_B     LIST_C
             1 x,y,x      3          33
             2 x          55         33
    SQL>

  • Simple Query Help Needed

    I must not be in the right mode today, because this is giving
    me a hard time...
    I have a SQL Server database with 250,000 records. Each
    record represents a medical visit.
    Each record has 25 fields that contain patient diagnosis. A
    visit may show one diagnosis, or it may show as many as 25. Any
    specific diagnosis (250.00 for example) may appear in a field
    called Code1, or a field called Code2.... Code25.
    There are a total of about 500 patients that make up the
    250,000 visits.
    What I need is a report that shows each DISTINCT diagnosis,
    and a listing (and count) of people that have been assigned that
    diagnosis.
    My thought is to first query the table to arrive at the
    unique list of diagnosis codes. Then, in a nested loop, query the
    database to see who has been assigned that code, and how many
    times.
    This strikes me as an incredibly database intensive query,
    however.
    What is teh correct way to do this?

    The correct way to do this is to normalize your database.
    Rather than having 25 separate colums that essentially
    contain the same data (different codes), break that out into a
    separate table.
    Patient
    patientid
    Visit
    patientid (foreign key referencing Patient)
    visitid
    Diagnosis
    visitid (foreign key referencing visitid in Visit)
    diagnosiscode
    order (if the 1-25 ordering of diagnosis codes is important)
    Once you correct your datamodel, what you're trying to do
    becomes simple.
    -- get all diagnosis codes
    select distinct(diagnosiscode) from diagnosis
    -- get a breakdown of diagnosis codes, patients, and counts
    for that diagnosis
    select diagnosiscode, patient.name, count(diagnosiscode) from
    patient left join visit on (patient.patientid =
    visit.patientid)
    left join diagnosis on (visit.visitid = diagnosis.visitid)
    group by diagnosiscode, patient.name

  • Using XML clob in loop

    Hi,
    I need to extract data from a given piece of XML. If I pass the xml to the procedure as clob and query it in a loop, it returns no rows. However if I include the actuall xml in the loop query it returns the data I'm looking for. Why doesn't it return data when using the clob?
    1. Example code below works with xml included in the loop query:
    BEGIN
       FOR x IN (    SELECT x.*
                       FROM XMLTABLE (
                               xmlnamespaces (
                                  'http://schemas.xmlsoap.org/soap/envelope' AS "x",
                                  'http://www.w3.org/2001/XMLSchema-instance' AS "xsi"),
                               PASSING xmltype (
                                          '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <soapenv:Body>
          <loadServiceListResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
             <loadServiceListReturn href="#id0"/>
          </loadServiceListResponse>
          <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns1:ExternalSystemOutput" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="java:ExternalSystemOutput.TestIPA.nhsia.nhs">
             <standardOutput href="#id1"/>
             <systemData soapenc:arrayType="ns2:ExternalSystemData[2]" xsi:type="soapenc:Array" xmlns:ns2="java:ExternalSystemData.TestIPA.nhsia.nhs">
                <systemData href="#id2"/>
                <systemData href="#id3"/>
             </systemData>
          </multiRef>
          <multiRef id="id3" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:ExternalSystemData" xmlns:ns3="java:ExternalSystemData.TestIPA.nhsia.nhs" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
             <description xsi:type="soapenc:string">Prescription</description>
             <url xsi:type="soapenc:string">http://192.168.21.131:8080/nhsia/TestIPA/validate.jsp?sdwlhqw@5)vhuylfh@Suhvfulswlrq33509</url>
          </multiRef>
          <multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns4:StandardOutput" xmlns:ns4="java:StandardOutput.TestIPA.nhsia.nhs" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
             <auditID xsi:type="soapenc:string"/>
             <statusID xsi:type="soapenc:string">0</statusID>
             <systemAvailability xsi:type="soapenc:string">Available</systemAvailability>
          </multiRef>
          <multiRef id="id2" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns5:ExternalSystemData" xmlns:ns5="java:ExternalSystemData.TestIPA.nhsia.nhs" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
             <description xsi:type="soapenc:string">Appointment</description>
             <url xsi:type="soapenc:string">http://192.168.21.131:8080/nhsia/TestIPA/validate.jsp?vgzoktzC8,ykx|oikCGvvuotzsktz61409</url>
          </multiRef>
       </soapenv:Body>
    </soapenv:Envelope>').
                                       EXTRACT (
                                          '//multiRef',
                                          'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
                               COLUMNS description VARCHAR2 (30) PATH 'description',
                                       url VARCHAR2 (250) PATH 'url') x)
       LOOP
          DBMS_OUTPUT.PUT_LINE('Rec:  '||x.description||' '||x.url);
       END LOOP;
    END;
    /Returns:
    Rec:  
    Rec:  Prescription http://192.168.21.131:8080/nhsia/TestIPA/validate.jsp?sdwlhqw@5)vhuylfh@Suhvfulswlrq33509
    Rec:  
    Rec:  Appointment http://192.168.21.131:8080/nhsia/TestIPA/validate.jsp?vgzoktzC8,ykx|oikCGvvuotzsktz614092. If I assign the XML to CLOB variable and reference the clob variable in loop query it returns no data:
    DECLARE
       resp   CLOB :=             
                       '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <soapenv:Body>
          <loadServiceListResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
             <loadServiceListReturn href="#id0"/>
          </loadServiceListResponse>
          <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns1:ExternalSystemOutput" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="java:ExternalSystemOutput.TestIPA.nhsia.nhs">
             <standardOutput href="#id1"/>
             <systemData soapenc:arrayType="ns2:ExternalSystemData[2]" xsi:type="soapenc:Array" xmlns:ns2="java:ExternalSystemData.TestIPA.nhsia.nhs">
                <systemData href="#id2"/>
                <systemData href="#id3"/>
             </systemData>
          </multiRef>
          <multiRef id="id3" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:ExternalSystemData" xmlns:ns3="java:ExternalSystemData.TestIPA.nhsia.nhs" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
             <description xsi:type="soapenc:string">Prescription</description>
             <url xsi:type="soapenc:string">http://192.168.21.131:8080/nhsia/TestIPA/validate.jsp?sdwlhqw@5)vhuylfh@Suhvfulswlrq33509</url>
          </multiRef>
          <multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns4:StandardOutput" xmlns:ns4="java:StandardOutput.TestIPA.nhsia.nhs" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
             <auditID xsi:type="soapenc:string"/>
             <statusID xsi:type="soapenc:string">0</statusID>
             <systemAvailability xsi:type="soapenc:string">Available</systemAvailability>
          </multiRef>
          <multiRef id="id2" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns5:ExternalSystemData" xmlns:ns5="java:ExternalSystemData.TestIPA.nhsia.nhs" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
             <description xsi:type="soapenc:string">Appointment</description>
             <url xsi:type="soapenc:string">http://192.168.21.131:8080/nhsia/TestIPA/validate.jsp?vgzoktzC8,ykx|oikCGvvuotzsktz61409</url>
          </multiRef>
       </soapenv:Body>
    </soapenv:Envelope>';
    BEGIN
       FOR x IN (    SELECT x.*
                       FROM XMLTABLE (
                               xmlnamespaces (
                                  'http://schemas.xmlsoap.org/soap/envelope' AS "x",
                                  'http://www.w3.org/2001/XMLSchema-instance' AS "xsi"),
                               PASSING xmltype (resp).
                                       EXTRACT (
                                          '//multiRef',
                                          'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
                               COLUMNS description VARCHAR2 (30) PATH 'description',
                                       url VARCHAR2 (250) PATH 'url') x)
       LOOP
          DBMS_OUTPUT.PUT_LINE('Rec:  '||x.description||' '||x.url);
       END LOOP;
    END;
    /I would appreciate any help this one.
    Cheers,
    Andy.

    Why do you have 4 rows? I don't understand why you have two rows for 100 bottles?
    Building on Odie's answer and my example plus adding in the needed outer join we have, using Oracle's outer join syntax of (+)
    SQL> with my_sample_table as (
      2      select xmltype('<?xml version="1.0" encoding="UTF-8" ?>
      3  <request>
      4  <identification>
      5  <requestid>12345</requestid>
      6  <periodunit>DAY</periodunit>
      7  <days>MONDAY</days>
      8  </identification>
      9  <product>
    10  <productname>ABC PRODUCT</productname>
    11  <brand>
    12  <brandname>CELL</brandname>
    13  <ndccode>A58048</ndccode>
    14  <ndccode>A49210</ndccode>
    15  </brand>
    16  </product>
    17  <product>
    18  <productname>100 bottles</productname>
    19  </product>
    20  </request>') xmldoc
    21      from dual
    22    )
    23  select x.*, y.*
    24    from my_sample_table t
    25       , xmltable(
    26          'let $e := $d/request/identification
    27           for $i in $d/request/product
    28           return element r {
    29             $e/requestid
    30           , $e/days
    31           , $e/periodunit
    32           , $i/productname
    33           , $i/brand/brandname
    34           , $i/brand/ndccode
    35           }'
    36          passing t.xmldoc as "d"
    37          columns requestid  number       path 'requestid'
    38                , days       varchar2(30) path 'days'
    39                , periodunit varchar2(10) path 'periodunit'
    40                , prductname varchar2(20) path 'productname'
    41                , brandname  varchar2(20) path 'brandname'
    42                , ndccodexml xmltype      path 'ndccode'
    43         ) x,
    44         xmltable('/ndccode'
    45                  PASSING x.ndccodexml
    46                  COLUMNS
    47                  ndccode    VARCHAR2(10) PATH '.') (+) y;
    REQUESTID DAYS                           PERIODUNIT PRDUCTNAME           BRANDNAME            NDCCODEXML                                                                       NDCCODE
         12345 MONDAY                         DAY        ABC PRODUCT          CELL                 <ndccode>A58048</ndccode><ndccode>A49210</ndccode>                               A58048
         12345 MONDAY                         DAY        ABC PRODUCT          CELL                 <ndccode>A58048</ndccode><ndccode>A49210</ndccode>                               A49210
         12345 MONDAY                         DAY        100 bottles                                                                                                                If you prefer the ANSI syntax it would be (just showing changed section)
           ) x
           LEFT OUTER JOIN
           xmltable('/ndccode'
                    PASSING x.ndccodexml
                    COLUMNS
                    ndccode    VARCHAR2(10) PATH '.') y
           ON 1=1;

  • Sort problem on dynamic query !!

    Hi,
    I have a dynamic query written in pl/sql, when I check "Sort" for each field in Report Attribute, error message raised up as "ORA-01785: ORDER BY item must be the number of a SELECT-list expression".
    If I do not check Sort, it works fine. In my apps I need all fields sorted by user, how to fix this problem?
    My query as below:
    declare
    query varchar2(2000):='select';
    s_class varchar2(1000);
    cursor c1 is select * from demo_preference;
    begin
    for c1_val in c1 loop
    if c1_val.login is not null then
    query := query ||' ' || 'login' || ',';
    end if;
    if c1_val.id is not null then
    query := query ||' ' || 'id' || ',';
    end if;
    end loop;
    query := SUBSTR(query, 1, length(query)-1);
    s_class := '(NVL(:P2_class, ''%'' || ''null%'') = ''%'' || ''null%'' OR
    EXISTS (SELECT 1 FROM apex_collections WHERE collection_name = ''P2CLASSCOL'' AND c001 = class))';
    query := query ||' ' || 'from ming.reg_report_view1 where'
    || ' ' || s_class;
    return(query);
    end;

    Maybe the internally mapped column used when you clicked on sort is not shown in the report. Try using aliases when you construct the query string, it could help apex internally in identifying a column even if its order changes for a different user. After all the column order in the code is dynamic and I guess even the no of columns displayed might vary both of which could make sorting on a column identified with a number, invalid.
    How about displaying the report query somewhere, so that you know what is the exact query being processed, it might give you better information about the problem.
    If the problem persists, then use a collection that is fetched those record using the same query string and change the report to refer the collection and then set column sorting on. This way apex would get confused on what columns are being sorted and it would just sort on a c001..c050 column as though it was a string(yes problems with number columns sorting when you do this).

  • How u guys build query in program

    Hey guys,
    i was wondering how u guys build queries in the program. i mean if you use String or StringBuffer. e.g.
    SELECT * FROM MY_TABLE WHERE X=someValue and Y=someValue and Z= someValue. if i use String i have to use + operator to get the values at runtime and which causes problem with performence. and when i use StringBuffer its kind of cumbersome. whats the best way you guys find for building queries at run time.
    appreciate the time you have taken to read this.
    take care and have a good day.

    Hi
    yes i'm creating the query in a loop. query is very
    big like 2 page long. basically i've to join data from
    many tables and many filter criteria entered by the
    clients which i put in the where clause. we r running
    optimizers on our application and it shows query
    building processes are making the overall performence
    slow.
    First you limit the query in some fashion (if you don' t then you might as well just give them a text box and let them type SQL.)
    In your case that might be limiting it to a query on all of the five tables.
    Second you produce a query DTO.
    A standard DTO might look like this....
           class CustomerDTO
             public String customerName;
             public double accountBalance;
      A query DTO, built to match the above, would look like this....
           class CustomerQueryDTO
             public String customerName1;
             public String customerName2;
             public OperatorType customerNameOperator;
            public double accountBalance1;
            public double accountBalance2;
            public OperatorType accountBalanceOperator;
          }And OperatorType would allow equality, between (which is why there are two parameters), greater than, etc
    You build the query string as follows
           CustomerQueryDTO query = ...
           StringBuffer b = new StringBuffer();
           b.append("select ");
           b.append(fieldList);
           b.append(" from ");
           b.append(tableList);
           b.append("where 1=1");
           if (query.customerNameOperator != null)
                b.append(" and ");
                String exp = createExpression(query.customerName1,
                                       query.customerName2,
                                       query.customerNameOperator );
                b.append(exp);
         String sql = b.toString(); 
    You also want to make sure that a query actually is limited by something. So the query must have at least one clause.

  • Inserting a list with 1 query

    Hi
    I have a list of email addresses seperated by a comma.
    I want to insert all of those email address into a table using 1 query.
    Is that possible?
    Here is my the list i have...
    <Cfset mylist = "[email protected],[email protected],[email protected],[email protected],[email protected]">
    Is it possible to insert using 1 query?
    Thanks in advance.
    Regards
    Delon

    Hi Delon
    I see now exactly what you're getting at and I see what you mean by only wanting to do one insert.
    People have different styles and I always believe that if it works then it's a successful solution, but just to make you aware of other options: If it were me (and I know it's not, but this is my opinion and there's no-one here to stop me ) I'd do the following:
    Get emails
    Loop query (very efficient in CF)
      Try
        Do whatever processing necessary, REFinds, auditing etc
        Do an insert into your database - also very efficient
        Delete email from inbox
      Catch
        Error handler
      End try
    /End Loop query
    So yes you're doing lots of inserts but you're not using any List functionality. Bear in mind lists aren't like Arrays or Querysets - there are no fixed memory points CF can index in order to find the next value, it has to scan through character by character looking for your delimiter. I've always been advised to keep away from lists for this very reason, especially if they get quite long as in this case.
    This method also allows for error handling on an email-by-email basis - say you use a list; you loop however many emails and something goes wrong at the last index. Your script falls over and has to start again from the start. Using the try/catch methodology gets around this and means you don't end up reprocessing the same emails more than once.
    As I say it largely ends up the same, but the whole point of these forums is to make people aware of what's possible, not to tell them what to do.
    Hope that helps.
    O.

  • URL varible into loop list

    I have a looped query that needs to receive a value from a url string, but I don't know how to reference the string variable in the loop. I get an error with my method.
    ?p1=open
    ?p2=open
    ?p3=open
    etc. etc.
    I loop through my query <cfloop from="1" to="#menu.RecordCount#" index="i">
    but, I want place the url variable into the loop as well
    <ul rel="#URL.p[i]#">  <!--- this gives me an error.---> I can do this <ul rel="#URL.p1#"> and it works, but i need it to function based on the p1, p2, p3 etc.
    How would I reference this variable in a loop?

    #URL.p[i]#
    Almost.  If your url variables are named p1, p2, etcetera, the syntax is:
    #URL["p#i#"]#  ... OR
    #URL["p"& i]#

  • Sorting report columns for PL/SQL report

    I have created a report of type "Pl/Sql function body returning Sql query" in which I am generating the column names within the query. I would now like to make the first three of these columns sortable. But when I click on the "sort" box for the first three columns, all my column names suddenly switch to "Col 1", "Col 2" etc.
    As you can see by the following snippet from the PL/SQL that generates the query, the column names are data driven, so I'm not in a position to declaratively rename each column. As it happens, the first three columns names are fixed, but all the subsequent column names are data driven.
    Suggestions on how to make the first three columns sortable while preserving the generated column names of the remaining columns?
    thanks
    susan weber
    declare
    query varchar2(4000); -- query
    begin
    query := 'select first_name "First Name", last_name "Last Name", encounter_date "Encounter Date" ';
    for c1 in (select distinct attr_src, attr_code, attr_text, sequence_number from finding_vt)
    loop
    query := query || ', (select val_text from finding_vt vt where vt.encounter_id = e.encounter_id and vt.attr_src = ''' || c1.attr_src || ''' and vt.attr_code = ''' || c1.attr_code || ''' and sequence_number = ' || c1.sequence_number || ') "' || substr(c1.attr_text,0,30) || '"';
    END LOOP;
    query := query || ' from patient pat, encounter e where pat.patient_id = e.patient_id';
    return query;
    end;

    This turns out to be related to the choice of "use generic column names" v. "use query specific column names".
    I had chosen "use generic column names" just to get past the initial creation page. I then debugged the query creation sql, but never changed that setting back to "use query specific column names". The fix is to choose "use query specific column names".

  • How to Use a Boolean Vector To Index an Array

    Say I have an array A = [1 2 3 4 5 6 7 8 9 10].
    I also have a boolean array B = [1 1 0 0 0 0 0 0 0 1].
    I want to use the boolean array B to pick out elements in A, creating a new array C = [1 2 10]. In MATLAB, I would just type C = A(B).
    I'm scratching my head trying to figure out how to do this. One solution would be to run through a for loop, querying B(i), and deleting A(i) if B(i) = 1. But this would change the size of A, so that the second time I did this, my index would be wrong.
    Anyone know a clean way of doing this?
    BONUS: If I have a 2D AA, with multiple columns, it would be nice to use B to pick out multiple columns of AA (in MATLAB, this would be CC = AA(:,B).
    Solved!
    Go to Solution.

    This can be done with auto-indexing with conditional tunnels.  The same approach could easily be applied to a 2D array, as well:

Maybe you are looking for

  • I've lost the menu bar and want to get it back

    I used the task bar to remove the menu bar and now it is gone and I can't use the menu to get it back. I've lost the web address bar everything so can't use the webpage. I would uninstall but it doesn't come up in my list of programs. I tried deletin

  • Can I use click boxes and text entry boxes instead of quizzes to populate a certificate?

    I have set up an assessment module in my project and i have enabled the reporting as follows: Standard SCORM Reporting Status: Pass/Fail and Percent choose Report Data: Quiz results and slide view Reporting level: Interactions and score. I have uploa

  • Cannot resize image

    I opened up PSE 4.0 today and I resized an image and it said that it was resized (6x9 became 5x7, for example), but when I dragged it to my project, it was still the same size (not smaller)! Prior to today, it has always been the size that I wanted i

  • Photoshop CS5 is keep crashing

    Hello, Whenever I import picture and select the specific region and transform (ctrl+T) to rotate the selected image, CS5 keeps crashing. I have no idea what's going on. This weird crash just occured today. My system: Q9400 CPU and 4gb ram, ATI Radeon

  • Review: iSkin Revo a Leader Among Best Cases

    After reading the hundreds of posts about cases--good and bad--I think I concur that the one of the best cases so far is the Revo from iSkin. The difference is: iSkin really put a lot of thought into their product. The combination of rubber along the