Dataset from two set of tables based on condition

I have two queries that will return same columns from two different set of tables ( column mapping has been taken care of). The return type is out ref cursor. (P_SUPPLY_REORDER )
Query 1-SO
select
so.SMO_NO,
so.SPLY_ORD_DT,
so.fk_CUST_ID as CUST_ID,
so.CUST_PO_NO,
so.ATTENTION_NAME,
sum(sol.SPLY_ORD_QTY) as SPLY_ORD_QTY,
--sum(sol.sply_shp_qty),
so.ST_NAME,
so.ADDR_LN_2,
so.ADDR_LN_3,--sta.SHIP_TO_ADDRESS_LINE_3,
so.CITY_NAME,
so.ST_TERR_CD,
so.ZIP_CD,
so.SPCL_SHP_INSTR_TXT,
so.SHP_CNFRM_DT
,XCOM_ORDER_NO
from
supply_order so,
supply_order_line sol,
XCOM_ORDER_HEADER
where
so.FK_CUST_ID =in_cust_id
and so.pc_ord_no = sol.fk_pc_ord_no and
XCOM_ORDER_HEADER.FK_PC_ORD_NO = so.PC_ORD_NO
group by so.SMO_NO, so.SPLY_ORD_DT, so.fk_CUST_ID,
so.CUST_PO_NO, so.ATTENTION_NAME,
so.ST_NAME, so.ADDR_LN_2, so.ADDR_LN_3, so.CITY_NAME, so.ST_TERR_CD,
so.ZIP_CD, so.SPCL_SHP_INSTR_TXT, so.SHP_CNFRM_DT, XCOM_ORDER_NO;
Query-2 Xcom
select
null as sMO_NO,
xso.created_date as SPLY_ORD_DT,
xso.fk_cust_id as cust_id,
cust.cust_po_no as cust_PO_NO
,(sta.SHIP_TO_ATTN_FIRST_NAME||''||sta.SHIP_TO_ATTN_LAST_NAME) as attention_name,
xsol.CARTONS_ORDERED as SPLY_ORD_QTY,
--sum(sol.sply_shp_qty),
sta.SHIP_TO_ADDRESS_LINE_1 as ST_NAME,
sta.SHIP_TO_ADDRESS_LINE_2 as ADDR_LN_2,
--sta.SHIP_TO_ADDRESS_LINE_3,
NULL as ADDR_LN_3,
sta.ship_to_city as CITY_NAME,
sta.SHIP_TO_STATE as ST_TERR_CD,
sta.SHIP_TO_POSTAL_CODE as ZIP_CD,
sta.SHIPPING_INSTRUCTIONS as SPCL_SHP_INSTR_TXT,
null  as SHP_CNFRM_DT,
xso.XCOM_ORDER_NO as XCOM_ORDER_NO
from
XCOM_ORDER_HEADER xso,
XCOM_ORDER_LINES xsol,
customer cust,
ship_to_address sta
where
cust.cust_id = xso.fk_cust_id and
sta.fk_cust_id = xso.fk_cust_id
and xso.FK_CUST_ID =in_cust_id
and xso.FK_PC_ORD_NO is null
and xso.xcom_order_no = xsol.fk_xcom_order_no;Now the requirement is
One of four conditions are possible for each Supply Reorder Number:
•     Both table queries return no records
-     Populate all the P_SUPPLY_REORDER output fields with nulls
•     SUPPLY_ORDER returns a record, but XCOM_ORDER_HEADER returns no records
-     Populate output fields with values from the join of SUPPLY_ORDER and SUPPLY_ORDER_LINE.
•     SUPPLY_ORDER returns no records, but XCOM_ORDER_HEADER returns one record
-     Populate output fields with values from the join of XCOM_ORDER_HEADER and XCOM_ORDER_LINES.
•     SUPPLY_ORDER returns a record, and XCOM_ORDER_HEADER returns a record; find out the latest order by comapring max(SPLY_ORD_DT)
from SUPPLY_ORDER with max(CREATED_DATE) from XCOM_ORDER_HEADER.
-     If the latest order is in SUPPLY_ORDER, then populate output fields with values from the join of SUPPLY_ORDER and SUPPLY_ORDER_LINE.
-     If order dates are equal from both join results, then populate output fields with values from the join of SUPPLY_ORDER and SUPPLY_ORDER_LINE.
-     If the latest order is in XCOM_ORDER_HEADER, then populate output fields with values from the join of XCOM_ORDER_HEADER and XCOM_ORDER_LINES.
Question is how can we switch over the queries to pull respective dataset based on these conditions ( checking that which table join is going to return a row and then based upon latest order if both tables return a row) and all this logic as part of single SQL statement that is returned as OUT Ref Cursor.
Your help will be really appreciated. Thanks much in advance.

It would be easier if you would supply a dataset we can work with. And I assume the queries are called within a other cursor which returns in_cust_id right?
The best/fasters way would be to say goodbye to nested cursors.
You need:
the in_cust_id_query
extend SUPPLY_ORDER with a new field
max(CREATED_DATE) over (partiontion by cust_id) max_created_dateextend XCOM_ORDER_HEADER with a new field
max(SPLY_ORD_DT)over (partiontion by cust_id) max_sply_ord_dateThen you make a 3 level SELECT
the innerst () join all 3 sources
the second level names the rule
the outermost level applies the rule to each field:
SELECT
-- case statement to each field:
CASE rule
WHEN 1 THEN null
WHEN 2 THEN s_smo_no
WHEN 3 .... END  SMO_NO,
SELECT
-- check all rules:
case
--• Both table queries return no records
when s_in_cust_id IS NULL and h_in_cust_id IS NULL then 1
--• SUPPLY_ORDER returns a record, but XCOM_ORDER_HEADER returns no records
when s_in_cust_id IS NOT NULL and h_in_cust_id IS NULL then 2
--• SUPPLY_ORDER returns no records, but XCOM_ORDER_HEADER returns one record
when s_in_cust_id IS NULL and h_in_cust_id IS NOT NULL then 3
ELSE 4 end rule_id,
i.*
(SELECT c.in_cust_id,
             s.*, (with alias of course eg. s_...)
            h.*, (with alias of course  e.g. h_...)
from  in_cust_id_query c
  LEFT JOIN SUPPLY_ORDER s
   on (c.in_cust_id = s.in_cust_id)
LEFT XCOM_ORDER_HEADER h
  on (c.in_cust_id = h.in_cust_id) i;I hope you get it.
Of course you can do what you probable currently do. Open both cursors one by one and compare the results. But when you have 10000 in_cust_ids you start 20000 queries and you have a lot of code.
This method I'm showing need these roles coded as well, but you'll have ONE single query and that will be as fast as ORACLE can be. And I believe it's easier to read too. (But not simple!)
If you need more help, try to supply an example we can work on.
-- andy

Similar Messages

  • Extracting from table based on conditions from two internal tables

    Hi,
         i to have select few records from  a table based on conditions from two different internal tables. How can I achieve this.?
    ex:
          select objid from HRVPAD25 into table t_pad25
                                                    where PLVAR = 01
                                                                OTYPE = E
                                                                OBJID = itab1-sobid
                                                                sobid = itab2-pernr.
    How can this be written? can i use "for all entries..." addition with 2 tables?

    Hi Maansi_SAP,
    you can use exactly one internal table in the FOR ALL ENTRIES clause. Consider this alternative:
    data:
      itab_sobid_hash like itab1 with unique key sobid,
      ls_pad25  like line of  t_pad25.
    sort itab1.
    delete adjacend duplicates from itab1 comparing sobid.
    itab_sobid_hash = itab1.
    select objid
      into ls_pad25
      from HRVPAD25
      for all entries in itab2
      where PLVAR = '01'
        and OTYPE = E
        and sobid = itab2-pernr..
    read table itab_sobid_hash with table key sobid = ls_pad25-objid.
    check sy-subrc = 0.
    append ls_pad25 to t_pad25.
    endselect.
    You may decide if itab1 or itab2 is better used as hashed table. Make a performance test.
    The critics will tell you that SELECT ... ENDSELECT is not performant. That was very true, back in last milleniums's 90ies
    Regards,
    Clemens

  • EHS: Set up Table-based Value assignment Error.

    Hi all,
    We are customizin Basic Data & Tools and when trying to set table based assignments (table TCG11_VAI; program RC1TCG11_02) we are getting no entries in the table. The message shown is always <i>"0 unchanged entries, 0 new entries, 0 entries deleted"</i> independant on the entry criteria
    The problem is that we can create those entries manually but it will be endless
    Has this happened to anyone before? Any idea?
    Many thanks and regards,
    Alberto

    Hi all,
    We have just find the solution.
    Just for your information the problem was that the IMG activity "Adopt
    Standard Specification Database" was executed but not working properly
    because no data can be copied from client 000. Then when executing "Set
    Up table Based Value Assignment" no entries were made in the table. We
    have just change the client, execute "Adopt Standard Specification
    Database" and then "Set Up table Based Value Assignment" and now is
    working properly
    Alberto

  • Is it possible to show data from two different sql tables?

    Is it possible to show data from two different sql tables? Either to show combined data by using a join on a foreign key or showing a typical master detail view?
    I have one table With data about a house, and another table With URL's to images in the blob. Could these two be combined in the same Gallery?
    Best regards Terje F - Norway

    Hi Terje,
    If you have a unique key, you could use one of the following functions for your scenarios:
    If you only have one image per house, you can use LookUp:
    http://siena.blob.core.windows.net/beta/ProjectSienaBetaFunctionReference.html#_Toc373745501
    If you have multiple images per house, you can use Filter:
    http://siena.blob.core.windows.net/beta/ProjectSienaBetaFunctionReference.html#_Toc373745487
    Thanks
    Robin

  • Reading data from a set of tables

    Hi,
    I am writing code to extract the data from several tables in a database. For each table, I am dynamically getting the number of fields or columns in the table and using Resultset obtaining the data in every field for each row. I do this using the getObject() method. Once I get the data for every field, I then want to insert this data into another table and for this I am using setObject() method. I am using these methods because the type of each field will be known only at runtime. After I do this, I do executeUpdate() in order to insert the data into the new table.
    The problem is here -
    At times it just inserts a few rows / records in the new table or it just gets and sets the Object for the first Row/Record in the table and then it freezes.
    Is there any problem with the getObject() and setObject() methods?
    while(rs.next())
    for (int i =1; i <= rsmd.getColumnCount(); i++)
    obj = rs.getObject(i);
    System.out.println("Object received " + obj);
    pstmt.setObject(i,obj);
    System.out.println("Object set : "+ obj);
    pstmt.executeUpdate();
    } // end of while
    Thanks in advance,
    Nik

    I don't know which DBMS/JDBC driver you are using. But there are drivers out there which do not permit two open Statements on the same connection. Maybe that is your problem. Try to close the ResultSet and the SELECT statement before the executeUpdate() of the second statement
    Another thing to check: are you sure the column order for the SELECT and the INSERT is identical (in other words, are you building the INSERT based on the information received from the ResultSet?)
    When it freezes, what do you mean with that? Where exactly does it "freeze"?
    This might be a DB lock which your program is waiting for - some DBMS do a page/table lock when updating, so a different statement could block your statement.
    Thomas

  • Update one table based on condition from another table using date ranges

    Hello!
    I have two tables:
    DateRange (consists of ranges of dates):
    StartDate            FinishDate
            Condition
    2014-01-02
          2014-01-03           true
    2014-01-03     
     2014-01-13          
    false
    2014-01-13      
    2014-01-14           true
    Calendar (consists of three-year dates):
    CalendarDate    IsParental
    2014-01-01
    2014-01-02
    2014-01-03
    2014-01-04
    2014-01-05
    2014-01-06
    2014-01-07
    2014-01-08
    2014-01-09
    2014-01-10
    I want to update table Calendar by setting  IsParental=1
      for those dates that are contained in table DateRange between
    StartDate and FinishDate AND Condition  IS TRUE.
    The query without loop should look similar to this but it works wrong:
    UPDATE
    Calendar
    SET IsParental = 1
     WHERE
    CalendarDate   BETWEEN
    (SELECT
    StartDate 
    FROM  DateRange
    WHERE Calendar.  CalendarDate   = DateRange. StartDate
               AND   
    (SELECT StartDate 
    FROM  DateRange
    WHERE Calendar.  CalendarDate   = DateRange. FinishDate
    AND Condition
     IS TRUE
    Is it possible to do without loop? Thank you for help!
    Anastasia

    Hi
    Please post DDL+DML next time :-)
    -- This is the DDL! create the database structure
    create table DateRange(
    StartDate DATE,
    FinishDate DATE,
    Condition BIT
    GO
    create table Calendar(
    CalendarDate DATE,
    IsParental BIT
    GO
    -- This is the DML (insert some sample data)
    insert DateRange
    values
    ('2014-01-02', '2014-01-03', 1),
    ('2014-01-03', '2014-01-13', 0),
    ('2014-01-13', '2014-01-14', 1)
    GO
    insert Calendar(CalendarDate)
    values
    ('2014-01-01'),
    ('2014-01-02'),
    ('2014-01-03'),
    ('2014-01-04'),
    ('2014-01-05'),
    ('2014-01-06'),
    ('2014-01-07'),
    ('2014-01-08'),
    ('2014-01-09'),
    ('2014-01-10')
    select * from DateRange
    select * from Calendar
    GO
    -- This is the solution
    select CalendarDate
    from Calendar C
    where EXISTS (
    select C.CalendarDate
    FROM DateRange D
    where C.CalendarDate between D.StartDate and D.FinishDate and D.Condition = 1
    UPDATE Calendar
    SET IsParental = 1
    from Calendar C
    where EXISTS (
    select C.CalendarDate
    FROM DateRange D
    where C.CalendarDate between D.StartDate and D.FinishDate and D.Condition = 1
    [Personal Site] [Blog] [Facebook]

  • Two or more table based forms on a single page

    Hi,
    Is it possible to have two or more forms fetching their respective tables on the same page ? I mean , to have two Automated fetching processes . I tried to change each page item source from ('DB Column' ... column_name) into ('DB Column' ... "TABLE".column_name) but is not working.
    Any idea ?
    Thanks.

    Actually I am trying to give you a solution but not 100% sure what you exactly you want?
    According to your subject, i understood that you have a page based on two more tables so if it is then
    create a view on these tables and create a page on view and then create a trigger (Instead of triggers)
    for insert /update into the columns related tables.
    hope it work!
    Regards

  • Joining Two Tables based on Conditions.

    Hi All,
    i would like to join two tables emp and dept with conditional join like
    for example: select emp.column1...............
    left outer join DEPT ON if Dept.column1='A" then emp.column1=dept.column1
    else emp.column2=dept.column3
    i know that bu using the UNION we can dothis, but i donot want to USE UNION.
    please let me know if any workaround for this.
    Thanks,
    Kalyan

    SQL> select * from etl
      2  /
         EMPNO ENAME      JOB              MGR        SAL       COMM     DEPTNO AAA                     DEPT_NO
          7566 JONES      MANAGER         7839       2975                    20 2                         20
          7654 MARTIN     SALESMAN        7698       1250       1400         30 3                         10
          7698 BLAKE      MANAGER         7839       2850                    30 3                         10
          7782 CLARK      MANAGER         7839       2450                    10 1                         20
          7788 SCOTT      ANALYST         7566       3000                    20 2                         20
          7839 KING       PRESIDENT                  5000                    10 1                         20
          7844 TURNER     SALESMAN        7698       1500                    30 3                         10
          7876 ADAMS      CLERK           7788       1100                    20 2                         20
          7900 JAMES      CLERK           7698        950                    30 3                         10
          7902 FORD       ANALYST         7566       3000                    20 2                         20
          7934 MILLER5    CLERK           7782       1300                    10 1                         20
          7936 MILLER7    CLERK           7782       1300                    10 1                         20
    12 rows selected.
    SQL> select * from dept;
        DEPTNO DNAME          LOC
            10 ACCOUNTING     NEW YORK
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTON
    SQL> ed
    Wrote file afiedt.buf
      1  select
      2     e.empno,
      3     e.ename,
      4     e.deptno,
      5     aaa,
      6     e.dept_no,
      7     d.deptno,
      8     d.dname
      9  from
    10     etl e ,
    11     dept d
    12  where
    13     (e.aaa =1 and e.deptno = d.deptno) or
    14*    (e.aaa =2 and e.dept_no =d.deptno)
    SQL> /
         EMPNO ENAME          DEPTNO AAA                     DEPT_NO     DEPTNO DNAME
          7566 JONES              20 2                            20         20 RESEARCH
          7788 SCOTT              20 2                            20         20 RESEARCH
          7876 ADAMS              20 2                            20         20 RESEARCH
          7902 FORD               20 2                            20         20 RESEARCH
          7782 CLARK              10 1                            20         10 ACCOUNTING
          7839 KING               10 1                            20         10 ACCOUNTING
          7934 MILLER5            10 1                            20         10 ACCOUNTING
          7936 MILLER7            10 1                            20         10 ACCOUNTING
    8 rows selected.Regards
    Singh

  • Restoring from TWO sets of backups

    I had ALL iTUNES music / playlists on an external hard drive that crashed. I have MOST of my purchased music (and other) on a backup from Feb 2008. I backed up the remaining files today (17 April 2008). What happens if I restore the old backup first THEN the newer one? Will I be able to recover the missing tunes?
    HELP!!!

    Never mind! I got help directly from Apple

  • Compare two columns and formate based on condition

    I know this dead horse has been beaten and I've read my fair share of threads and manuals to no avail..  I have two list that consist of movie titles, holiday movies to be exact.  I'm creating a holiday movie schedule which consist of three(3) columns...A,B and C.  Column A is the Date, Sat, November 17 2012 thru Monday, Dec 24, 2012.  Column C consist of a movie list divided into 2 sections with three subsections each.  Section 1 is animated movies and Section 2 is live action, each subsection, 1.1, 1.2, 1.3, 2.1, 2.2 and 2.3 are lists based on popularity with the kids...low, medium and high respectively.  And finally column B is the movie list relative the column A...the schedule.
    As I write a movie title in column B, I'd like the cell fill to be light red and the corresponding title in column C change to strike through font type.  This way I know I've added the movie title to the schedule...this comes in handy when I ask the kids to help so we have no duplicates in the schedule.  I'm assuming this would take a combination of; Conditional Formatting, cell formulas and perhaps an additional blank column for trigger results.
    I'm including the table, which include an experimental column I was working on.  As an FYI, this has been completed in Excel already, just hoping to get it done in Numbers.
    Thanks for any help anyone can give.
    Date
    Movie Name
    Class
    Sat, Nov 17, 2012
    Animated Christmas Movies
    TRUE
    Lowest Priority Animation
    TRUE
    Frosty Returns
    TRUE
    Sun, Nov 18, 2012
    The Nightmare Before Christmas
    Rudolph and Frosty's Christmas in July
    TRUE
    Rudolph the Red-Nosed Reindeer & the Island of Misfit Toys
    TRUE
    Rudolph's Shiny New Year
    TRUE
    Mon, Nov 19, 2012
    Nothing Like the Holidays
    TRUE
    Medium Priority Animation
    TRUE
    Jack Frost Animation
    TRUE
    Tue, Nov 20, 2012
    Home for the Holidays
    It's Christmas Time Again, Charlie Brown
    TRUE
    Christmas in South Park
    TRUE
    Cartoon Network Christmas Rocks
    TRUE
    Wed, Nov 21, 2012
    Planes, Trains and Automobiles
    Cartoon Network Christmas Yuletide Follies
    TRUE
    Cartoon Network Christmas Vol3
    TRUE
    Twas the Night Before Christmas
    TRUE
    Thu, Nov 22, 2012
    Planes, Trains and Automobiles
    The Little Drummer Boy
    TRUE
    TRUE
    Highest Priority Animation
    TRUE
    Fri, Nov 23, 2012
    Trapped in Paradise
    The Simpson's Christmas
    TRUE
    A Very Special Family Guy Freakin' Christmas
    TRUE
    Family Guy: Road To The North Pole
    TRUE
    Sat, Nov 24, 2012
    American Dad! The Most Adequate Christmas Ever
    TRUE
    A Charlie Brown Christmas
    TRUE
    The Nightmare Before Christmas
    FALSE
    Sun, Nov 25, 2012
    Die Hard
    Frosty the Snowman
    Die Hard 2
    Hooves of Fire
    How the Grinch Stole Christmas
    Mon, Nov 26, 2012
    Gremlins
    Santa Claus is Comin' to Town
    The Year Without a Santa Claus
    Rudolph, the Red-Nosed Reindeer
    Tue, Nov 27, 2012
    The Ice Harvest
    Live Action Christmas Movies
    Lowest Priority
    Wed, Nov 28, 2012
    Reindeer Games
    National Lampoon's Christmas Vacation 2: Cousin Eddie's Island Adventure
    Chasing Christmas
    The Nativity Story
    Thu, Nov 29, 2012
    Bad Santa
    Unaccompanied Minors
    Jingle All the Way
    Jack Frost Live
    Fri, Nov 30, 2012
    The Shop Around the Corner
    The Santa Clause 3: The Escape Clause
    The Santa Clause 2: The Mrs. Clause
    Sat, Dec 1, 2012
    The Bishop's Wife
    Medium Priority
    0
    Bad Santa
    Bad Santa
    Mixed Nuts
    Mixed Nuts
    Sun, Dec 2, 2012
    The Chronicles of Narnia: The Lion, the Witch and the Wardrobe
    Reindeer Games
    Reindeer Games
    The Ice Harvest
    The Ice Harvest
    The Shop Around the Corner
    The Shop Around the Corner
    Mon, Dec 3, 2012
    Miracle on 34th Street B&W
    The Bishop's Wife
    The Bishop's Wife
    Christmas in Connecticut
    Christmas in Connecticut
    The Chronicles of Narnia: The Lion, the Witch and the Wardrobe
    The Chronicles of Narnia: The Lion, the Witch and the Wardrobe
    Tue, Dec 4, 2012
    Mixed Nuts
    Nothing Like the Holidays
    Nothing Like the Holidays
    Home for the Holidays
    Home for the Holidays
    The Family Man
    The Family Man
    Wed, Dec 5, 2012
    Scrooged
    Miracle on 34th Street 1994
    Miracle on 34th Street 1994
    Miracle on 34th Street B&W
    Miracle on 34th Street B&W
    Just Friends
    Just Friends
    Thu, Dec 6, 2012
    Just Friends
    Trapped in Paradise
    Trapped in Paradise
    0
    Highest Priority
    0
    Fri, Dec 7, 2012
    Miracle on 34th Street 1994
    Die Hard
    Die Hard
    Die Hard 2
    Die Hard 2
    Gremlins
    Gremlins
    Sat, Dec 8, 2012

    Hi Stephen,
    Both of these are solvable, and the Date solution cold be similar to that used for the 'stock list' in column C. The Movie Title solution is a different case, though.
    The stock list is edited only occasionally, so requiring the user to unhide column C, add a title, then rehide the column is workable.
    The same is true of the date list, so this too would work with the dates entered into a column that will be hidden, then copied into a visible column with a formula that introduced a detectable difference into the copied version, dependent on the weekday of each date. That difference would be used to trigger the conditional formatting of the cell containing the calculated date as text value. See the example below.
    But the (scheduled) Movie Title column doesn't fit nicely into that mode of operation, as it is edited quite often. As editing, usng the model described, requires making the data column visible, editing the entry (or entries) in that column, then rehiding the column, the hassle factor soon becomes insufferable, if nothing else.
    The first solution I considered (see earlier reply) is workable only if the the formatted table starts and remains the same size in all details (ie. individual row height) as the main table.Any change in row height in the main table not reflected in the auxiliary table immediately destroys the impression of formatting applying to the correct cells. With cells set to wrap text and varying lengths of movie titles, wrapped lines changing the height of individual rows is pretty much unavoidable.
    Best practice here would seem to be to use a separate column to flag the titles already in the "Class" list with a "√" (or flag those not in the list with an "X"), and use conditional formatting to change the background colour of the flagging cell.
    Here's a sample, using "W" to flag the weekend dates in the new column B, and "√" to flag the titles that are on the list already in the new column D.
    I've added two titles to the weekend date, November 18. One is non-existent (as far as I know), so it doesn't appear in the list and doesn't get flagged; the other is chosen from a visible part of the list to show the highlighting of the title in that list. Column "C" (now column "F" due to the insertion of two new columns) is hidden. G, labelled .Class, is the calculated column (D) from the previous message.
    Regards,
    Barry

  • How to call or not call a Trigger in same table based on condition?

    Hi
    How to call or not call a Trigger in below situations..
    If a table contains a record of same value i.e,
    [i[u]]ID
    1
    1
    3
    In above ID 1 is repeated for two times.
    In this situations i don't want to call a trigger..
    But, the value ID is for 3, now i want to fire a trigger.
    Based on this i want to delete in another table.
    How can I check it?
    Thanks

    Thanks for ur reply..
    The below is my scnario..
    I am having two table
    employee
    Id empcol
    101 111
    101 222
    102 444
    Department
    id deptcol
    101 457
    101 678
    102 543
    The above is my table structure no one column is PK, so i m not able create FK.
    When I am deleting from employee where id =101 and empcol=111,
    the above record is deleted.
    At present I am using After Update Trigger..
    So trigger is called and delete the id 101 in Department table.
    In my scenario i can't delete a record in Department table
    bcoz i am having id morethan 101 in employee table.
    If employee table contains one ID like 102 the Trigger should works.
    How can I check the condition After delete on employee table it contains morethan same employee id?
    The below is my Trigger..
    CREATE OR REPLACE TRIGGER CALL_TRIGGER
    AFTER DELETE ON Employee
    FOR EACH ROW
    DECLARE
    count_id pls_integer;
    BEGIN
    SELECT COUNT(*) INTO count_id from Employee WHERE ID <>:new.ID;
    IF( count_id >1) THEN
    DELETE FROM Depratment where ID=:old.ID;
    END IF;
    END;
    I am geting an error ORA-04091 table is mutuating, trigger cannot seen it.
    I had tried with package and package body also.. But no luck.
    Thanks

  • SELECT TABLE BASED ON CONDITION

    hi every one , i need your help in resolving this issue . if you look at the last column service_id in the select the value of the service_id is derived from by the source_system.
    each source system can have 1 to multiple service_ids . the below query returns same data set with different service_ids. my question is
    for example when source_system is 'COMS' the i have included table ref_coms_circuit to get multiple service ids. so if i have to include another source_system 'ESP' then how will i do that.
    WITH t AS
         (SELECT   so.tin, so.o_seq, so.order_type,
                   so.customer_req_due_date customer_due_date,
                   MAX (soplm1.milestone_date) order_date,
                   MAX (soplm2.milestone_date) hold_begin_date,
                   MAX (soplm3.milestone_date) hold_end_date
              FROM s_order so,
                   s_order_product_leg_milestone soplm,
                   s_order_product_leg_milestone soplm1,
                   s_order_product_leg_milestone soplm2,
                   s_order_product_leg_milestone soplm3
             WHERE                                    -- so.order_status = 'A' AND
                   so.contract_id IN ('157798', '157800')
               --  AND soplm.milestone_id = 4350
               AND soplm.source_system_name = 'OPRO'
               AND soplm.o_seq = so.o_seq
               AND soplm.last_modified_date >=
                      TO_DATE ('07/01/2007 00 :00:00', ' MM/DD/YYYY HH24: MI: SS')
               AND soplm.last_modified_date < SYSDATE
               AND soplm.tin = 'OPRO.670148'
               AND soplm1.tin(+) = so.tin
               AND soplm1.o_seq(+) = so.o_seq
               AND so.tin = soplm2.tin(+)
               AND so.tin = soplm3.tin(+)
               AND so.o_seq = soplm2.o_seq(+)
               AND so.o_seq = soplm3.o_seq(+)
               AND soplm1.milestone_id(+) = 100
               AND soplm1.source_system_name(+) = 'OPRO'
               AND soplm2.milestone_id(+) = 1650
               AND soplm2.source_system_name(+) = 'NPRO'
               AND soplm3.milestone_id(+) = 1690
               AND soplm3.source_system_name(+) = 'NPRO'
          GROUP BY so.tin, so.o_seq, so.order_type, so.customer_req_due_date)
    SELECT DISTINCT soplm4.tin, soplm4.VERSION, soplm4.product_serial_number,
                    soplm4.node_id, t.order_type, sopl.product_id,
                    rp.product_id_desc product_desc, NULL AS product_catalog_id,
                    soplm4.source_system_name, t.order_date, t.customer_due_date,
                    NULL AS asrn, NULL AS service_typ_seq, t.hold_begin_date,
                    t.hold_end_date,
                    DECODE (soplm4.source_system_name,
                            'COMS', 'COMS CIRCUIT ID',
                            'FE', 'FE CIRCUIT ID',
                            'VDDS', 'PVC ID',
                            'ESP', 'ESP Product Billing Key',
                            'OTS', 'OTS SITE ID',
                            'UCLP', 'K - Number',
                            'NCAP', 'NETCAP 800# ',
                            'IASA', 'IASA ANI ',
                            'COMP', 'COMMONPLACE AUTH CODE',
                            soplm4.source_system_name
                           ) neid_type,
                    CASE soplm4.source_system_name
                       WHEN 'COMS'
                          THEN rcc.circuit_number
                       WHEN 'VDDS'
                          THEN sopl.pvc_id
                       WHEN 'OTS'
                          THEN sopl.site
                       WHEN 'IASA'
                          THEN sopl.iasa_account_id
                       WHEN 'COMP'
                          THEN sopl.pin
                       WHEN 'UCLP'
                          THEN sopl.billing_identifier
                       WHEN 'NCAP'
                          THEN sopl.toll_free_num
    --          WHEN 'ESP' THEN soed.product_billing_key
    --             WHEN 'FE' THEN
                    ELSE NULL
                    END service_id
               FROM t,
                    s_order_product sop,
                    s_order_product_leg sopl,
                    s_order_product_leg_milestone soplm4,
                    ref_product rp,
                    ref_coms_circuit rcc
              WHERE soplm4.tin = t.tin
                AND soplm4.o_seq = t.o_seq
                AND soplm4.source_system_name IN (SELECT source_system_name
                                                    FROM com_calnet_systems)
                AND sop.tin = t.tin
                AND sop.o_seq = t.o_seq
                AND sopl.tin = t.tin
                AND sop.op_seq = soplm4.op_seq
                AND sopl.o_seq = t.o_seq
                AND sopl.opl_seq = soplm4.opl_seq
                AND rp.product_id = sopl.product_id
                AND rcc.coms_service_number = sop.coms_service_number;

    Either union all of them before or after the join, i.e.,
    Solution 1:
    SELECT DISTINCT soplm4.tin, soplm4.VERSION, soplm4.product_serial_number,
               FROM t,
                    ref_coms_circuit rcc
              WHERE soplm4.tin = t.tin
                AND rcc.coms_service_number = sop.coms_service_number
    union all
    SELECT DISTINCT soplm4.tin, soplm4.VERSION, soplm4.product_serial_number,
               FROM t,
                    ref_vdds_circuit rvc
              WHERE soplm4.tin = t.tin
                AND rvc.coms_service_number = sop.coms_service_number
    union all
    SELECT DISTINCT soplm4.tin, soplm4.VERSION, soplm4.product_serial_number,
    ...Solution 2:
    SELECT DISTINCT soplm4.tin, soplm4.VERSION, soplm4.product_serial_number,
               FROM t,
               (select 'COMS' source, circuit_number data, coms_service_number
                -- any column you need in your output
                from ref_coms_circuit
                union all
                select 'VDDS', pvc_id, coms_service_number
                -- any column you need in your output
                from ref_vdds_circuit
                union all...) bigunion
              WHERE soplm4.tin = t.tin
                AND soplm4.source_system_name = bigunion.source
                AND rcc.coms_service_number = sop.coms_service_number;Edited by: thtsang on Oct 20, 2009 10:28 PM
    Edited by: thtsang on Oct 20, 2009 10:44 PM

  • Calcullating no. of records in an internal table based on condition

    Hi,
    i have several records in an internal table. i need to calculate the number of records which meets a condition. is there any simple logic to find the records which meet the required criteria apart from looping into the internal table.
    your help would be appreciated.
    Thanks,
    kranthi.

    Hi,
    U can use sy-dbcnt after the select querry.
    DBCNT  Number of elements in edited dataset with DB operations
    WRITE: /12 'Number of selected records:', SY-DBCNT CENTERED.
    REPORT ZZZ_TEST1 .
    Tables: mara.
    Types: begin of ty_mara,
           matnr like mara-matnr,
          end of ty_mara.
    DATA: i_mara TYPE STANDARD TABLE OF ty_mara.
    DATA: v_cnt like sy-dbcnt.
    SELECT-OPTIONS: s_matnr FOR MARA-matnr.
    SELECT matnr from mara into table i_mara.
    if sy-subrc = 0.
    v_cnt = sy-dbcnt.
    WRITE: /12 'Number of selected records:', v_cnt CENTERED.
    endif.
    Hope this helps u.
    Thanks & Regards,
    Judith.

  • Inserting millions of records into new table based on condition

    Hi All,
    We have a range partitioned table that contains 950,000,000 records (since from 2004) which is again list sub-partitioned on status. Possible values of stauts are 0,1,2,3 and 4.
    The requirement is to get all the rows with status 1 and date less than 24-Aug 2011. (Oracle 11g R2).
    I trying below code
    CREATE TABLE RECONCILIATION_TAB PARALLEL 3 NOLOGGING  
    AS SELECT /*+ INDEX(CARDS_TAB STATUS_IDX) */ ID,STATUS,DATE_D
    FROM CARDS_TAB
    WHERE DATE_D < TO_DATE('24-AUG-2011','DD-MON-YYYY')
    AND STATUS=1; CARDS_TAB has tow global indexes one on status and another on date_d.
    Above query is running for last 28Hrs! Is this the right approach?
    With Regards,
    Farooq Abdulla

    You said the table was range partitioned but you didn't say by what. I'm guessing the table is range partitioned by DATE_D. Is that a valid assumption?
    You said that the table was subpartitioned by status. If the table is subpartitioned by status, what do you mean that the data is randomly distributed? Surely it's confined to particular subpartitions, right?
    What is the query plan without the hint?
    What is the query plan with the hint?
    Why do you believe that adding the hint will be beneficial?
    Justin

  • Mailing from XI to different groups based on Condition

    Hi Experts,
    I have a scenario where i have an incoming XML Invoice document which i need to map with Invoic02 idoc and to send to R/3.
    While sending it to R/3 i also need to put conditions on certain special links,when fails sends out mails to a
    respective mail group .
    When i get a wrong field/condition the map fails.Based on the condition which failed the map,XI should be mailing to
    the respective group .
    I will be having around 4-5 mailing groups in the single map .
    Please suggest me some helpful blogs and inputs for this scenario.
    Thanks,
    Sudhansu

    B'cos you are failgn the mapping at deisgn time (by various conditions), you can configure diff ALERTCategories & invoke them appropriately from your UDF.
    /people/bhavesh.kantilal/blog/2006/07/25/triggering-xi-alerts-from-a-user-defined-function
    For each of these AlertCategories, you will configure your respective recepients.
    Regards,
    siva Maranani

Maybe you are looking for

  • IPhoto 6 library problem

    I just recently installed iLife 06 on a friends laptop here at school. She is a heavy iPhoto user and her library is quite large. The install went through fine, and everything works, except for iPhoto. When I open iPhoto is says that the iPhoto libra

  • P780 smartphone: many PROBLEMS

    Hello, I've just received my new Lenovo P780 ordered on-line in Hong Kong. I live in Italy. Model: P780_ROW  android 4.2.1 verison P780.V20, 2013/07/31 Build: P780_ROW_S116_130828 I have many problems, I think caused by firmware/software. 1) If I try

  • Rmi ClassDefNotFound Exception

    When the Applet client call the server, I got this error "classdefnotfound", but if I put the whole application to system classpath, this error go away, any clue?

  • Need Help in installing Acrobat Adobe reader XI

    I have downloaded XI latest version on to my computer. Startet intallation. After "Intalling Files are extracting" the window is closed and nothing happenss. I am using XP SP3 / Antivirus AVG Free was deactivatet for 15 minutes. What shall I do else?

  • My iPhoto suddenly crashes on opening...

    My MacBook Pro w/10.6.8 suddenly has a defective iPhoto. Upon iPhoto opening, first I get a blank iPhoto window, then the swirling rainbow dot for appx. 1 min., then it crashes & closes [2 error codes displayed are "EXC-BAD-ACCESS" & "THREAD 0 CRASHE