query select sup

Hi friends,

I run the select statement below to insert into another table.

Select t1.ref_no

of tab1 t1, t2 tab2

where t1.loc_id = t2.loc_id

and t2.req_h =

(select t3.mig_id from)

tab2 t2, t3 tab 3

where t2.req_h = t3.mig_id);

I get the error ORA-01427: einreihig subquery returns more than one line.  When I use rownum = 1 in the select sub, the query works fine, but it returns a single line.  There are mutiple t1.ref_no for each t3.mig_id...

Please help to suggest different ways for this other than rownum = 1 sql...

Thank you all very much

Hello

2817195 wrote:

Hi friends,

I run the select statement below to insert into another table.

Select t1.ref_no

of tab1 t1, t2 tab2

where t1.loc_id = t2.loc_id

and t2.req_h =

(select t3.mig_id from)

tab2 t2, t3 tab 3

where t2.req_h = t3.mig_id);

I get the error ORA-01427: einreihig subquery returns more than one line.  When I use rownum = 1 in the select sub, the query works fine, but it returns a single line.  There are mutiple t1.ref_no for each t3.mig_id...

Please help to suggest different ways for this other than rownum = 1 sql...

Thank you all very much

The best way to get the desired results depends on the desired results.

What are the results that you want when the scalar subquery finds 2 or more lines?

Tags: Database

Similar Questions

  • Rewrite the query, select below or try to get the necessary O/P

    Hello..

    My example of data.,.

    Create table customer (name varchar2 (10), telephone1 telephone2 number (10), number of phone3 (10), (10) number, bitwisephone number (10));

    Insert into customer values('a',23456,67890,null,12345);

    Insert into customer values ('b', 67459,89760,null, 37689);

    create table do_not_call (dont_call number (10));

    insert into do_not_call values (67890);

    insert into do_not_call values (37689);

    Question: -.
    --------------

    Customer 'a' has value of numbers1 as 23456.check if telephone1 exists in the do_not_call table.
    In fact there is no, so set the bit for numbers1 as "o" like wise search telephone2
    & phone3.after update of the bitwisephone for each client should be as the output below.


    Need to O/P: -.
    -------------------

    name bitwisephone

    a 010
    b 001


    For that matter... I use "any" operator...



    SELECT name, case when numbers1 = all (SELECT dont_call FROM do_not_call) and then put an end to '1' other '0'.
    -case when telephone2 = all (SELECT dont_call FROM do_not_call) and then put an end to '1' other '0'.
    -case when phone3 = all (SELECT dont_call FROM do_not_call) then '1' other '0' end 'Bits '.
    OF THE customer;


    Is there any other way to get the necessary O/P?


    Thank you!!

    Kind regards
    VijayRajaram.

    Looks like one already answered Re: rewrite the query, select below or try to get the necessary O/P

    with
    customer(name,phone1,phone2,phone3,bitwisephone) as
    (select 'a',23456,67890,12345,null from dual union all
     select 'b',67459,89760,37689,null from dual
    ),
    do_not_call(dont_call) as
    (select 67890 from dual union all
     select 23456 from dual union all
     select 37689 from dual
    )
    select name,
           to_char(mod(trunc(sum(weight)/4),2))||
           to_char(mod(trunc(sum(weight)/2),2))||
           to_char(mod(sum(weight),2)) bitwisephone
      from (select name,phone1 phone,4 weight
              from customer
            union all
            select name,phone2,2
              from customer
            union all
            select name,phone3,1
              from customer
           ) c,
           do_not_call d
     where c.phone = d.dont_call(+)
       and d.dont_call is not null
     group by name
    

    Please do not duplicate messages

    Concerning

    Etbin

  • Insert the result of a query select in another table

    Hello

    I have a strange problem when I try to insert all the results of a query select in another table, using the declaration of the order.

    With the declaration of COMMAND it works fine
    Work:
    ------------------------------
    INSERT INTO ADART01 (SELECT (codart)
    "STOCK". "" CODART_STO ".
    Of
    "DB". ' ' 'ACTIONS');
    ------------------------------

    But if I try to sort the result using the declaration of the ORDER, I have the following error:
    Error: ORA-00907 missing right parenthesis
    ------------------------------
    INSERT INTO ADART01 (SELECT (codart)
    "STOCK". "" CODART_STO ".
    Of
    "DB". "" "ACTIONS"
    ORDER BY
    "STOCK". ("' CODART_STO ASC ');
    ------------------------------

    Any idea?

    Thank you for your help,
    Angel.

    delete "()" to select

    create table test1 (a number, b varchar2(100));
    
    insert into test1
        (a, b)
        select level, 'level ' || level from dual connect by level < 101;
    
    insert into test1
        (a, b)
        select level, 'level ' || level from dual connect by level < 101 order by to_char(sysdate - level, 'D');
    
    select * from test1;
    
    drop table test1;
    
  • help needed in query select

    Hello

    I use the apex of oracle 10g 3.2
    I use a select statement inside a cursor in an anonymous PL/SQL process. The output of the query is like that.

    Method_id patient_id result index_repeat
    39 123 12 0
    29 123 23 0
    39 123 32 1

    Now what I want, that is if there is more then a method_id as 39 occurs twice with index_repeat 0 and 1, then take only with index 39 repeat 1 I mean the output of what I want is the select query

    Method_id patient_id result index_repeat
    29 123 23 0
    39 123 32 1

    I use the following query

    Select method_internal_index, result, patient_id_code, index_repeat
    of t_files_data_exp
    where f_id =: P56_F_ID

    F_ID is the primary key.

    Thank you
    Olivier

    Don't know what exactly you need. When I read your condition sounds like all you need is the following;

    select  method_internal_index
           ,patient_id_code
           ,result
           ,index_repeat
    from    t_files_data_exp
    where   f_id=:P56_F_ID
    and     index_repeat = 1
    

    However, I suspect that what you need is the following;

    select * from
    (
      select  *
             ,row_number() over (partition by method_id order by index_repeat desc) rn
      from    t_files_data_exp
      where   f_id=:P56_F_ID
    )
    where rn = 1
    

    because I assume that the INDEX_REPEAT could be 2 or 3 or more!

  • Passing the value of the SQL query select list

    Hello

    In my application users have in their homepage to a region which has two simple things, a part of LIST SLECT lov function and a BUTTON

    There is also another page which has a normal life to report which shows the employees.


    Homepage the user can select certain number of Department in its 'SLECT-LIST' and click 'open '.


    For example: If the user has selected a DEP_NUM_5 and click on the BUTTON it will be redirected to the page of a report and gets only showed the employees belonging to the Department 5.


    The report page contains a simple SQL query, and I understand that somehow I must pass the value in the SELECT LIST, where I now have the '?


    How can I do this, where should I start?

    Of course I would really appreciate an example of code, if anyone has time to do a.

    
    select "EMP_ID", 
    "EMP_FORNAME",
    "EMP_SURNAME",
    "DEP_NUMBER"
    from EMP E
    where E.DEP_NUMBER = ????????
    
    

    Hi Sozua,

    1. create an item hidden on the page where you have the report.

    I say P2_DEPT_NO

    2 assign to that in your sql query

    select "EMP_ID",
        "EMP_FORNAME",
        "EMP_SURNAME",
        "DEP_NUMBER"
        from EMP E
        where E.DEP_NUMBER = :P2_DEPT_NO
    

    below the area source ther is also an option

    Elements of page to submit-> put this element in this.

    for example;

    Page to submit items: P2_DEPT_NO

    3. change your button

    Action: Redirecting to page of this application

    Page: 2 / / assuming that page 2 is the report page

    Place these items: P2_DEPT_NO

    with these values: & P1_SELECT_LIST.  assuming that selection list is on page 1

    Hope this helps you,

    Kind regards

    Jitendra

  • Hi I have a question about the unique row function executed a query "select lower ('test' |)» SYSDATE + 1) twice; "fails when as" Select lower (sysdate + 1 |) " (' test') twice; "is executed without error?

    SQL > select lower (sysdate + 1 |) (' test') twice;

    LOWER (SYSDATE + 1

    ---------------

    07 jul-2014test

    SQL > select lower ('test' | + 1 sysdate) twice;

    Select lower ('test' | sysdate + 1) of the double

    *

    ERROR on line 1:

    ORA-01722: invalid number

    The query fails because it cannot perform arithmetic (+ 1) on a channel not digital.  However, the query that successfully interpreted the arithmetic in the first place, that it concatenated the string 'test' to it...  Make sense?

  • Please help to write a complex query "select".

    Hello

    I am trying to write a query that retrieves information about attachments in HP ALM by referring to TestInstances, TestRun and TestSteps tables. For those who do not know HP ALM...

    I'm describing the structure of data in these tables (the names of tables and fields are changed for easy understanding).

    > > 1. In the "TestInstances" table key fields are I_InstanceID, I_HasAttachments and I_TestSetID

    1.1 I_InstanceID is the primary key for this table

    > > 2. Key in the table "TestRuns" fields are R_RunID, R_InstanceID, R_RunTime and R_HasAttachments

    2.1 R_RunID is the primary key for this table

    2.2 R_InstanceID is a foreign key to I_InstanceID in the TestInstances table

    2.3 all I_InstanceID in the TestInstances table may not have an entry in the table TestRuns

    2.4 an I_InstanceID in TestInstances can have multiple entries in the table TestRuns with different R_RunID

    > > 3. In the "TestSteps" table key fields are S_StepID, S_RunID and S_HasAttachments

    3.1 S_StepID is the primary key for this table

    3.2 S_RunID is a foreign key to R_RunID in the TestRuns table

    3.3 all R_RunID in the TestRuns table may not have an entry in the TestSteps table

    3.4 a R_RunID in TestRuns can have multiple entries in the table TestSteps with different S_StepID

    Entry to the query I want to write is a set of I_TestSetID in the TestInstances table (which I already have)

    The desired query output is -.

    1. all I_InstanceID have the values as shown in the entry I_TestSetID

    2 I_HasAttachments corresponding to I_InstanceID

    3. Earl of R_RunID against each I_InstanceID (may be 0 or a positive integer)

    4. only the last R_RunID corresponding to each I_InstanceID (later are using MAX (R_RunID) GROUP BY I_InstanceID)

    5 R_HasAttachment value of last R_RunID

    6 R_RunTime last R_RunID value

    7. County of S_StepID against each R_RunID (may be 0 or a positive integer)

    8. County of S_HasAttachment against each R_RunID (may be 0 or a positive integer and may differ from the County of S_StepID)

    Friends, could one of you give it a try and help out me?

    Thanks in advance!

    PS: This had been driving me crazy for 3 days. I'm not able to get unique entries and entries for which references to the TestRun and TestStep tables are empty.

    Try the bottom of correlated subquery

    SELECT i_instanceid,

    i_hasattachments,

    (SELECT COUNT (R_RunID)

    OF TestRuns tr

    WHERE tr.r_instanceid = ti.i_instanceid) cnt_runid;

    (SELECT MAX (R_RunID)

    OF TestRuns tr

    WHERE tr.r_instanceid = ti.i_instanceid) cnt_latestrunid;

    (SELECT I_HasAttachments

    OF TestRuns tr

    WHERE tr.r_instanceid = ti.i_instanceid

    AND tr.r_runid = (SELECT MAX (R_RunID)

    OF TestRuns tr

    WHERE tr.r_instanceid = ti.i_instanceid)) R_HasAttachments;

    (SELECT R_RunTime

    OF TestRuns tr

    WHERE tr.r_instanceid = ti.i_instanceid

    AND tr.r_runid = (SELECT MAX (R_RunID)

    OF TestRuns tr

    WHERE tr.r_instanceid = ti.i_instanceid)) R_RunTime;

    (SELECT COUNT (S_StepID)

    OF TestSteps ts

    WHERE the ts. S_RunID = (SELECT MAX (R_RunID)

    OF TestRuns tr

    WHERE tr.r_instanceid = ti.i_instanceid)) cnt_stepid;

    (SELECT COUNT (S_HasAttachments)

    OF TestSteps ts

    WHERE the ts. S_RunID = (SELECT MAX (R_RunID)

    OF TestRuns tr

    WHERE tr.r_instanceid = ti.i_instanceid)

    AND S_HasAttachments = 'Y') cnt_SHasAttachment

    OF ti TestInstances

    WHERE I_TestSetID IN (1190,1191,1192,1194,1195);

  • Problem with query select

    Hello

    Select transactionid, (TO_TIMESTAMP (endtime, "MON-DD-YYYY HH24:MI:SS)-TO_TIMESTAMP (starttime," MY - DD - YYYY HH24 timetaken:MI:SS))))

    from (select a.transactionid, MAX (TO_CHAR (HH24:MI:SS' a.time_stamp,'DD-MON-YYYY)) endtime, starttime MAX (TO_CHAR (a.time_stamp,'DD-MON-YYYY HH24:MI:SS')))))

    A newspaper, logaltkey b where a.time_stamp > TO_DATE ('29.01.2014:11:00:00 ',' DD.) MESSRS. ' YYYY:HH24:MI:SS)

    and

    a.time_stamp < TO_DATE ('30.01.2014:15:33:24 ',' DD.) MESSRS. ' YYYY:HH24:MI:SS)

    and interfaceid = 'Member '.

    and a.logid = b.logid

    and b.altkeyname = 'SXC');

    The query above returns the error below, some one please share your entries to make it work.

    ORA-00937: not a single group group function

    00937 00000 - 'not a single-group function.

    * Cause:

    * Action:

    Error on line: column 2:14

    You do not have to include group by clause in your query internal.

    Try it below:

    Select transactionid, (TO_TIMESTAMP (endtime, "MON-DD-YYYY HH24:MI:SS)-TO_TIMESTAMP (starttime," MY - DD - YYYY HH24 timetaken:MI:SS))))

    Of

    (

    Select a.transactionid,

    Endtime MAX (TO_CHAR (a.time_stamp, 'DD-MON-YYYY HH24:MI:SS')),

    StartTime MAX (TO_CHAR (a.time_stamp,'DD-MON-YYYY HH24:MI:SS'))))

    Of

    Journal of a,

    logaltkey b

    where a.time_stamp > TO_DATE ('29.01.2014:11:00:00 ',' DD.) MESSRS. ' YYYY:HH24:MI:SS)

    and

    a.time_stamp<>

    and interfaceid = 'Member '.

    and a.logid = b.logid

    and b.altkeyname ='SXC

    A.transactionid group

    )

  • LOV AF:Query selection is unsuccessful.

    I created a programmatic view object and created a display of criteria based on three attributes.

    In Panel of af: query these attributes are displayed as LOVs.  When I click the icon search LOV,

    a popup to search and select window opens.  When I select one of the lines by double clicking top popup

    is closed and instead of the selected value, the first value in the array is selected.

    Also, the window occupies the entire width of the browser and the table, inside the pop-up window, displaying the list of values in the LOV attribute is rendered with

    due to which the table must scroll all the way to the end, and then only OK button of horizontal scroll bar is displayed.

    Is there a way to control popup LOV window dimensions?

    Version: JDEV 11g Release 1

    Make sure you set 'Attributes of the key' you VO and VO LOV.

    To control the width of the entry of the parameters in the definition of VO, click on the variable binding, and in the Councils of the user interface, tab set the 'display width.

  • By default in "in order to" in the query select can be different in 11g 10g

    Hi, I wonder if, when you are querying a table 11g and that you use the order by clause and there are several occurrences with the same values in the order, if the default value of the 11g is different from 10g.  For example.

    DECLARE MHBulk CURSOR FOR

    Select invoice_nbr,

    customer_nbr,

    post_century,

    post_yymmdd,

    CUSTOMERS

    where customer_nbr = 1234

    order by

    post_century,

    post_yymmdd;

    If you have several occurrences of the same customer_nbr, post_century and post_yymmdd that it looks like the order by default for how 11g retrieves records is a little different from the default value of 10g.   Does anyone know why this is?

    "The mechanism in which database Oracle sorts character values for the ORDER BY clause, also known as the name of the collation is specified by the NLS_SORT parameter of session."

    If this parameter is not set, its default value is derived from the NLS_LANGUAGE parameter of the session. "

    http://docs.Oracle.com/CD/E11882_01/server.112/e41084/queries005.htm#SQLRF52348

    Perhaps these parameters are defined differently?

    The columns (post_century, post_yymmdd) always scare me, by the way...

  • ADF - BC: query select VO question of Action in function

    Hi Experts,

    I created a query based Vo that is displayed on the page as a table. It has 1 button on top of table - delete which should only be enabled if a row is selected.

    When I select a line, first of all, my entire table is refreshed then only the button is enabled. I'm not refreshing selectAction table. No idea why it's happening and what is possible to solve it.

    For reference, code for selectAction is-

    {} public void Actionselection (SelectionEvent selectionEvent)

    AdfFacesContext context = AdfFacesContext.getCurrentInstance ();
    if(Context == null)
    return;
    JfrInfoData.JfrInfo = selectedRowData
    (JfrInfoData.JfrInfo) table.getSelectedRowData ();
    setDelJfrDump (selectedRowData.getFileName ());
    setDownLoadFileName (selectedRowData.getFileName ());
    setDelJvmId (selectedRowData.getJvmid ());
    setDelPath (selectedRowData.getPath ());
    context.addPartialTarget (removeButton);

    }

    There was a double ppr of table for a message at the table box and message box. Removal of the ppr and the table began to work as expected.

  • In a single query SELECT top row?

    Hello

    Can someone help me write a query to get the first line after the clause order by using a single query only.
    Example:
    I can write after query to select the first line
    Select * from (select * from t by col1) where rownum = 1;

    But here I should not use view inline to get the result. Because my initial requirement must use this query in the selection list and he needs to use a column (of a table in the FROM clause) in which the query clause online. Because there are restrictions we cannot use the column (of a table in the FROM clause) more than one level of application online.

    Please help me.

    Used version of Oracle's Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production

  • Question from beginner on writing a query select box

    Hello

    I have a table called 'sites' that has 'site_number' column (data type: number) and area_ha (data type is also the number).

    I am trying to write a query that will give me a third column called 'area_description '. This column shows "small" If the site is less than 10 hecatres and 'medium', if the site is greater than 10 hectares:

    That's what I have so far:

    SELECT site_number, area_ha,
    CASE area_ha
    WHEN < 10
    THEN 'small '.
    ELSE "average."
    END AS area_description
    Sites;

    I get the error message is:

    ORA-00936: lack of expression
    00936 00000 - "missing expression.
    * Cause:
    * Action:
    Error on line: column 7:10

    So I know that it is the < that is the problem, but how to rewrite the query?

    I think this is right, but I don't have a system to test right now.

    SELECT site_number, area_ha,
    (CASE
    WHEN are_ha<>
    THEN 'small '.
    ELSE "average."
    Area_description END)
    Sites;

  • How do the query select outer join to a report of the APEX

    Hi all

    I'm Ann.

    I have a select statement that is used to calculate statistics for a month (October 2012 in this example)
    Select ph.phase_number
    sum ((case
    WHEN ph.date_finished IS NULL or ph.date_finished > last_day (TO_DATE (' ' Oct 2012 ', ' MY YYYY' "))
    THEN last_day (TO_DATE (' ' Oct 2012 ', ' MY YYYY' "))
    Of OTHER ph.date_finished
    END)
    (-ph.date_started + 1) / count (def.def_id) as avg_days
    Ph phase_membership
    inner join court_engagement this on ph.mpm_eng_id = ce.engagement_id
    join in-house defendant def on ce.defendant_id = def.def_id
    where def.active = 1
    and ph.date_started < = last_day (TO_DATE (' ' Oct 2012 ', ' MY YYYY' "))
    and ph.active = 1
    and UPPER (ce.court_name) LIKE '% '.
    Rollup Group (phase_number)
    ;

    The result is as below
    Phase_Number AVG_DAYS
    Phase One 8.6666666666666667
    Phase two 14.6
    Phase three 12
    11.4615365

    I have another list of selection mainly the list of months between two date value.
    Select to_char (which_month, 'LUN YYYY') as display_month
    de)
    Select add_months (to_date (' ' August 2012 ', ' MY YYYY' "), rownum-1) which_month
    of object
    where
    rownum < = months_between (to_date (' ' Oct 2012 ', ' MY YYYY' "), add_months (to_date (' ' August 2012", "MY YYYY"), - 1))
    order of which_month)

    The query result is as below

    DISPLAY_MONTH

    AUGUST 2012
    SEP 2012
    OCT 2012

    Is it possible I can join these two select statement above to generate a comparable result:

    Days of month Phase number Avg
    August 2012 Phase One 8.666
    Sep 2012 Phase One 7.66
    Oct 2012 Phase One 5,66
    August 2012 Phase two 8.666
    Sep 2012 Phase two 7.66
    Oct 2012 Phase two 5,66
    August 2012 Phase three 8.666
    Sep 2012 Phase three 7.66
    Oct 2012 Phase three 5,66

    Or
    Days of month Phase number Avg
    August 2012 Phase One 8.666
    August 2012 Phase two 7.66
    August 2012 Phase three 5,66
    Sep 2012 Phase One 8.666
    Sep 2012 Phase two 7.66
    Sep 2012 Phase three 5,66
    Oct 2012 Phase One 8.666
    Oct 2012 Phase two 7.66
    Oct 2012 Phase three 5,66

    And it can be controlled by Phase number or month.
    My other colleague suggested I should use a left outer join, but after having tried many ways, I'm still stuck.

    I tried select is
    Select a.display_month, b.* in)
    Select to_char (which_month, 'LUN YYYY') as display_month
    de)
    Select add_months (to_date (' ' August 2012 ', ' MY YYYY' "), rownum-1) which_month
    of object
    where
    rownum < = months_between (to_date (' ' Oct 2012 ', ' MY YYYY' "), add_months (to_date (' ' August 2012", "MY YYYY"), - 1))
    order which_month)) a left outer join

    (Select to_char (ph.date_finished, 'MY YYYY') as join_month, ph.phase_number)
    sum ((case
    WHEN ph.date_finished IS NULL or ph.date_finished > last_day (TO_DATE (a.display_month, 'MY YYYY'))
    THEN last_day (TO_DATE (a.display_month, 'MY YYYY'))
    Of OTHER ph.date_finished
    END)
    (-ph.date_started + 1) / count (def.def_id) as avg_days
    Ph phase_membership
    inner join court_engagement this on ph.mpm_eng_id = ce.engagement_id
    join in-house defendant def on ce.defendant_id = def.def_id
    where def.active = 1
    and ph.date_started < = last_day (TO_DATE (a.display_month, 'MY YYYY'))
    and ph.active = 1
    and UPPER (ce.court_name) LIKE '% '.
    To_char (ph.date_finished, 'MY YYYY'), group (phase_number) rollup) b
    On a.display_month = b.join_month

    but then I get an error
    SQL error: ORA-00904: "A." "" DISPLAY_MONTH ": invalid identifier

    I need to view a report on the APEX with option for people to download at least format CSV.
    Already 1 inteactive report in the page, so I don't think adds another interactive report without using the iframe trick.

    If any of you have any ideas, please help.

    Thank you very much.

    Ann

    Hello Ann,.

    Frank has done a very good job. I am also impressed.

    Is in regard to your correction to his question, the problem is on this replacement you did

    last_day(TO_DATE(am.which_month,'MON YYYY'))
    

    AM.which_month is already a date type, and you don't need to convert it to this day.
    Here is the correct way:

    last_day(am.which_month)
    

    There are also sometimes with the data you've posted have no line for this month. So I also added a function NVL to display 0 under avg_days for these cases.

    Here is my corrected query:

    DEFINE startmonth = "Aug 2012";
    DEFINE endmonth   = "Oct 2012";
    WITH  all_months  AS
    (
       SELECT ADD_MONTHS(to_date('&startmonth','MON YYYY'), ROWNUM-1) AS which_month
       ,      ADD_MONTHS(to_date('&startmonth','MON YYYY'), ROWNUM  ) AS next_month
       from all_objects
       where
       rownum <= months_between(to_date('&endmonth','MON YYYY'), add_months(to_date('&startmonth','MON YYYY'), -1))
    )
    SELECT TO_CHAR (am.which_month, 'Mon YYYY')  AS month
         , ph.phase_number
         , NVL(sum ( (CASE
                     WHEN ph.date_finished IS NULL OR ph.date_finished > last_day(am.which_month)
                     THEN last_day(am.which_month)
                     ELSE ph.date_finished
                  END
                 ) - ph.date_started + 1
               ) / count(def.def_id), 0) as avg_days
      FROM all_months am
           LEFT OUTER JOIN  a_phase_membership  ph  PARTITION BY (ph.phase_number)
              ON  am.which_month <= ph.date_started
              AND am.next_month  >  ph.date_started
              AND ph.date_started <= last_day(am.which_month)  -- May not be needed
              AND ph.active = 1
           LEFT OUTER JOIN  a_engagement  ce
              ON  ph.mpm_eng_id = ce.engagement_id
              AND ce.court_name IS NOT NULL  -- or something involving LIKE
           LEFT OUTER join  a_defendant     def
              ON  ce.defendant_id = def.def_id
              AND def.active = 1
     GROUP BY ROLLUP(phase_number, am.which_month)
     ORDER BY  am.which_month
            ,  ph.phase_number
    ;
    
    The output is:
    MONTH    PHASE_NUMBER           AVG_DAYS
    -------- -------------------- ----------
    Aug 2012 PHASE ONE                     0
    Aug 2012 PHASE THREE                   0
    Aug 2012 PHASE TWO                     0
    Sep 2012 PHASE ONE                    12
    Sep 2012 PHASE THREE                   1
    Sep 2012 PHASE TWO                     9
    Oct 2012 PHASE ONE                     8
    Oct 2012 PHASE THREE                   0
    Oct 2012 PHASE TWO                    14
             PHASE ONE                    11
             PHASE THREE                   1
             PHASE TWO                  11.5
                                  9.71428571
    

    I don't know if that's really what you want. In the case check it and let me know.

    Kind regards.
    Al

  • Placing values retuened to a cursor at the place where the clause of a query SELECT

    Hello
    I'm trying to accomplish a task of writing a SELECT statement where I have to query the table based on the values returned by a cursor.
    For example:
    SELECT a.operator_name, a.country_name, a.state_name FROM Table_A a WHERE a.country_id IN (values returned by cursor for country ID) AND the a.operator_name in (values returned by cursor for Operator_Id) AND a.state_id in (values returned by cursor State_ID for).

    Is it possible to make this request, my task is to write it in a stored procedure so that I can return a cursor reference with values as described above.
    Please let me know how to go about this request.

    PS: Cursors are used because it is a Wild-Card search for values where several records can be returned.

    Thanks in advance.

    Kind regards
    Priya

    Because your

    SELECT a.operator_name, a.country_name, a.state_name
      FROM Table_A a
     WHERE a.country_id IN (Values returned from cursor for Country ID's)
       AND a.operator_name IN (Values returned from Cursor for Operator_Id's)
       AND a.state_id IN (Values returned from Cursor for State_ID's)
    

    say something like (sliders deliberately avoided (see Tom Kyte mantra - http://asktom.oracle.com/pls/apex/f?p=100:11:0:::P11_QUESTION_ID:73891904732164))

    SELECT operator_name,country_name,state_name
      FROM Table_A
     WHERE country_id IN (select country_id
                            from countries
                           where upper(country_name) like 'U%?
                         )
       AND operator_name IN (select operator_id
                               from operators
                              where operator_name like 'A%'
                            )
       AND state_id IN (select state_id
                          from states
                         where state_name like 'C%'
                       )
    

    Concerning

    Etbin

Maybe you are looking for