Get elements of the other table

Hi all

I have a table with a few lines like:

create the table myTABLE

(number of myID,

VARCHAR2 (20) itemID.

fieldA varchar2 (10),

fieldB varchar2 (10),

fieldC varchar2 (10)

);

I have a query that contains the itemID as

Select c.myID, c.itemID, c.sourceA, a.sourceDescA, b.sourceDescB

Cuttable c

Join the tableA an a.myID on c.myID =

Join tableB b on b.myID = c.myID and b.sourceID = a.sourceID

What is the effective way for the description of the elements of the query based on itemID from myTable? Keep the same number of rows in myTABLE

myTABLE.myID, myTABLE.itemID, myTABLE.fieldA, myTABLE.fieldB, myTABLE.fieldC, query.sourceA, query.sourceDescA, query.sourceDescB

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0

Thank you

Hello

user9542267 wrote:

...

How can I choose the first itemID if I have two itemID with a different description than my new sample data.

Remember, the rows of a table are not in any particular order.  If you talk about the 'first' line, you must clearly indicate what means 'first' to you.

Do you really need to take the first itemID?   And the problem is really two itemIDs with a different description.  Don't expect different itemIDs for different descriptions?

It seems that the problem occurs when 1 (not 2) itemID has different descriptions, and you want to choose only 1 line by itemID, regardless if this itemID is 1st, 2nd 3rd or Nth itemID.  For example, in the sample data you posted in response #8, there are 2 distinct values for source (and sourceDescB and sourceDescC, but the problem would be the same if any 1 of them were only different) who have itemID = '23'.  I don't know if consider you "23" to be the itemID 1st or 2nd, but I don't think it really matters.  It seems to me that the problem would be the same if "24 K" was considered the first itemID or if 'F25' was.

Here's a way to ensure that you get only the 'first' line each Itemid of sourceTABLE, where "first" means in order by sourceID:

WITH source_with_r_num AS

(

SELECT itemID, source, sourceDescA, sourceDescB

ROW_NUMBER () OVER (PARTITION BY itemID

ORDER BY ID source

) AS r_num

FROM sourceTABLE

)

SELECT m.myID, m.itemID, m.fieldA, m.fieldB, m.fieldC

s.sourceA, s.sourceDescA, s.sourceDescB

MYTABLE m

JOIN source_with_r_num s ON s.itemID = m.itemID

WHERE r_num = 1

ORDER BY m.myID

;

Results of the sample data in the #8 response:

MYID ITEMID FIELDA, FIELDB, FIELDC SOURCE SOURCEDESC SOURCEDESC

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

1 23 an ABC AB 23 Source 23 Desc has 23 B Desc

2 24K B BC BCD 24K Source 24K Desc has 24K Desc B

3 F25 C CD CRC Source Desc F25 F25 F25 Desc B

If there is a tie for the 'first' line for a given itemID, ROW_NUMBER arbitrarily call one of them 'first '.  If this isn't what you want (that is, if it is important which one is selected), you can add playoff expressions in the ORDER BY clause analytical ROW_NUMBER.

Tags: Database

Similar Questions

  • How to join tables and get ppl not in the list of the other table

    Hi, I have 2 tables

    Table (girlscoutid, quarter, point)

    Table b (girlscoutid, fname lname)

    I want to get the names of ppl who didn't sell any point/s for Q4

    girlscoutid agenda quarter
    7771drinks4QS
    9000Tickets4QW
    7771Cookies2QS
    5085books3QF
    3010Tickets3QW
    5085Cookies1QF

    lscoutid fname lname
    7771JennRichochet
    9000LauraWilkins
    5085SallyMae
    3010DoraMcKenzie

    That's what I have, however, I get duplicates and also 7771 appears on the list even if she sold something on the 4th quarter. Any suggestions?

    SELECT fname, lname, a.girlscoutid

    Of a, b

    WHERE a.girlscoutid = b.girlscoutid

    AND the term NOT AS "4Q_";

    Hello

    So, all the information that you want to see figure in table b, but if you want to see it depends on the table has.

    This looks like a job for a semi Join.  Here's a way to do it:

    SELECT b.fname

    b.lname

    b.girlscoutid

    B

    LEFT OUTER JOIN has IT a.girlscoutid = b.girlscoutid

    AND a.quarter NOT AS "4Q_" - or a.TERM, if it is the column

    WHERE a.girscoutid IS NULL

    ;

    What you posted was an INNER join, where the rows of each table are included in the only game that if they have a corresponding row in the other table.

    An OUTER join includes all the rows in a table (table b in this case) if they have a match in the other table.  If a line of b has no corresponding row in a, then all the columns that are supposed to come from table will be NULL in the result set.  Given that the join condition includes = b.girlscoutid a.girlscoutid, this means that the only way to a.girlscoutid can be NULL in the result set is if the b line is included although it has no corresponding line one, which are exactly the lines that we want to display.  (You can try to run the query above with the WHERE clause, deleted, just to see how it works.)

    Alternatively, you can get the desired results by using a subquery NOT EXISTS, a NOT IN subquery or analytical functions.  The semi join, supra, is probably the most effective solution.

  • a table are in the other table without duplicate

    How to check the records in a table are in the other table without duplicate.

    for example, in the tables below, the records from the Table A are in Table B1. But the B2 table has duplicate and one record is missing.
    I want to know which records are not in table B, records that have two copies.
    as A and B2, 1 2 is not in B2, 1 1 a 2 folders in B2

    A and B1, nothing should be returned.

    Table A
    -----------
    A1 A2
    -----------
    1 1
    1 2
    1 3
    -----------

    Table B1
    -----------
    A1 A2
    -----------
    1 1
    1 4
    1 2
    1 3
    2 2
    -----------


    Table B2
    -----------
    A1 A2
    -----------
    1 1
    1 4
    1 3
    2 3
    1 1
    -----------

    version is the database of Oracle 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production

    Thank you!!

    Two standard methods to compare the tables are either to use DEFINED such as UNION, UNION operations or LESS.
    Or use a FULL OUTER JOIN.

    If the structure of the table is the same and that you want to compare all the columns, then set them operators are the best way.

    If you want to compare only on one or more columns and want to see the other columns, then a FULL OUTER JOIN is the best way.

    Here is an example

    select A1, A2,
          count(distinct sourcetable) cnt_tables,
          count(sourcetable) cnt_records,
          count(case when sourcetable = 'A'  then 1 end) record_is_in_A,
          count(case when sourcetable = 'B1'  then 1 end) record_is_in_B1,
          count(case when sourcetable = 'B2'  then 1 end) record_is_in_B2
       (select 'A' sourceTable, a.* from tableA a
        union all
        select 'B1' sourceTable, b1.* from tableB1 b1
        union all
        select 'B2' sourceTable, b2.* from tableB2 b2
       )
    group by A1, A2
    having  count(distinct sourcetable) < count(sourcetable) ;
    

    It is an example. It will show you the records that have duplicate data in the following tables.
    If you want to display all records that are in A but not in B1, you can add a few other checks.

    Published by: Sven w. on August 13, 2010 17:23

  • How to update the password on the other table based on the mod

    Hello

    I need to update the password for the other table based on the mod.

    I have two table 'user' and 'reset '.


    User:

    Username username password date_exp

    s232322 Bobby John sdds4545df4r 10/12/2010
    s454566 George Bill f444556gh76 07/14/2010
    s343466 Bill Clinton fgf54tyujkkkhj 06/12/2011
    .
    .
    .


    Reset:

    Series encrypt decrypt

    fgf5656fg 0 Watellemon
    1 dfggf5665 lime juice
    dfdffd545 2 applesalad
    3 54r4gggt airlines
    construction of 4 hg44hh63
    5 fgf4343yh security
    .
    .
    .

    How can I update the password of a table to another table "reset"?

    Ex: query

    Update user set password = (select Encrypt reset where mod (length (username), 10))


    If mod (length (username), 10) is 0, it should take series "0" encrypt the password and update the password in the table "user".
    If mod (length (username), 10) is 1, it should take serial '1' encrypt the password and update the password in the table "user".
    If mod (length (username), 10) is 2, it should take series '2' encrypt the password and update the password in the table "user".
    If mod (length (username), 10) is 3, it should take series '3' encrypt the password and update the password in the table "user".
    If mod (length (username), 10) is 4, it should take series '4' encrypt the password and update the password in the table "user".
    ....


    Please help me write an update query.




    Thank you
    Nihar

    Hi, Nihar,

    You almost had it! You just need to correlate the subquery for the main UPDATE statement, like this:

    UPDATE     user_table     u     -- USER is a built-in function; it's not a good table name
    SET     password = ( SELECT  encrypt
                   FROM    reset     -- RESET isn't a very good table name, either
                   WHERE   serial     = MOD ( LENGTH (u.username)
                                             , 10
                                   )
                 );
    
  • get information from inside a trigger of the other tables in the schema even

    Addendum:

    ... Sorry I forgot: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64 bit

    *******************

    Hello

    I'm trying for a few hours to get information from inside a trigger to another table in the same pattern.

    My trigger is PSE_BKB. NUM_PHANTOM_BP

    I first tried a simple solution...


    CREATE OR REPLACE TRIGGER PSE_BKB. NUM_TR_PHANTOM_BP
    BEFORE DELETING, INSERTION OR UPDATE
    ON PSE_BKB. NUM_PHANTOM_BP
    REFERRING AGAIN AS NINE OLD AND OLD
    FOR EACH LINE
    DECLARE

    v_recht NUMBER (1): = 0;
    v_recht2 NUMBER (1): = 0;
    v_change_mitarbeiter NUMBER (1): = 0;
    v_recht_mitarbeiter NUMBER (1): = 0;
    v_typ varchar2 (20);
    v_obj_key varchar2 (11): = "gugus";
    v_ph_key varchar2 (11);
    -ph_key varchar2 (11);
    v_obj_keys varchar2 (4000): = ', ';

    anz_num NUMBER: = 0;
    anz_num_tmp NUMBER: = 0;
    anz_st_si NUMBER: = 0;


    BEGIN

    ...
    Select count (*)
    in anz_num
    of pse_bkb.num_objekt o
    where o.obj_key in
    (select distinct (ov.obj_key)
    of pse_bkb.num_objekt_verb ov
    where ov.phantom_key =: old.phantom_key
    )
    and o.typ = "NUM";

    ...

    Explanation: my trigger table is PSE_BKB. NUM_PHANTOM_BP.

    On the pse_bkb.num_objekt_verb of the table, I have a relationship 1: n to one or several object-key (field named obj_key!) on my referenced key: old.phantom_key. With this obj_key, I want to watch the weather, I have one or more lines in the table type num_objekt "NUM". So the internal selection gives me all the num_objekt_verb obj_key with my: old.phantom_key and with whom I count the number of lines I have on num_objekt with type "NUM".

    The problem is that the trigger does not see the table.

    I tried many variations.

    The latest version I tried was with a cursor inside the trigger definition as in the block of code below.

    For debugging purposes, I inserted a RAISE_APPLICATION_ERROR in the inner loop - see below. The v_obj_key variable is never defined, as in all the other variations, I tried-, I still see the predefined "gugus" in the declare section.

    It seems that oracle can not read other tables at this point. La: old.phantom_key is defined (in this simple example there would come a return obj_key).

    Thanks in advance for your help - and excuse my English.

    Trigger code:

    CREATE OR REPLACE TRIGGER PSE_BKB. NUM_TR_PHANTOM_BP
    BEFORE DELETING, INSERTION OR UPDATE
    ON PSE_BKB. NUM_PHANTOM_BP
    REFERRING AGAIN AS NINE OLD AND OLD
    FOR EACH LINE
    DECLARE

    v_recht NUMBER (1): = 0;
    v_recht2 NUMBER (1): = 0;
    v_change_mitarbeiter NUMBER (1): = 0;
    v_recht_mitarbeiter NUMBER (1): = 0;
    v_typ varchar2 (20);
    v_obj_key varchar2 (11): = "gugus";
    v_ph_key varchar2 (11);
    -ph_key varchar2 (11);
    v_obj_keys varchar2 (4000): = ', ';

    anz_num NUMBER: = 0;
    anz_num_tmp NUMBER: = 0;
    anz_st_si NUMBER: = 0;


    BEGIN


    Start
    declare

    cursor nums is

    Select obj_key
    of PSE_BKB.num_objekt_verb
    where phantom_key =: old.phantom_key;

    Start

    for the RC looping nums
    v_obj_key: = cr.obj_key;

    RAISE_APPLICATION_ERROR (-20099,' AGAIN 9 v_obj_key: ' | v_obj_key |) ': old.phantom_key ' | (: old.phantom_key);

    When the exit nums % NOTFOUND;

    Select count (*) in the pse_bkb.num_objekt anz_num_tmp where obj_key = v_obj_key and type = "NUM";
    anz_num: = anz_num + anz_num_tmp;
    end loop;

    end;
    end;

    Published by: user832075 on 14.01.2013 06:18

    The reason why you get count_n = 0 in tr_c is that there is no line in B with key_c = 17, to the moment you arrive at tr_c. The removal of B has already occurred, and since you're in a single transaction, the application for tr_c:

    select count(*)
      into   counter_n
      from   a aa
      where  aa.key_a in (select distinct(bb.key_a)
                          from   b bb
                          where  bb.key_c = v_ph_key
                         )
      and    aa.typ = 'n';
    

    'knows' that the row has been deleted then gets a number of 0.

    I added a set of instructions dbms_output to show the order in which triggers run, and that's what I get:

    SQL> delete from b_vw where key_a = 1 and key_c = 17 ;
    in trigger b_tr_vw
    In tr_b
    in tr_c
    delete from b_vw where key_a = 1 and key_c = 17
                *
    ERROR at line 1:
    ORA-20077: Remark: counter_n: 0 counter_s: 0 v_ph_key: 17 old.key_c: 17
    new.key_c:
    ORA-06512: at "OPS$ORACLE.TR_C", line 38
    ORA-04088: error during execution of trigger 'OPS$ORACLE.TR_C'
    ORA-06512: at "OPS$ORACLE.B_TR_VW", line 17
    ORA-04088: error during execution of trigger 'OPS$ORACLE.B_TR_VW'
    

    Thus b_tr_vw trigger is triggered first and deletes a B. trigger fires tr_b as part of this statement to remove and check against A, happening apparently so no error is triggered and succeeds the removal of B. Now tr_b_vw takes back control and deletes C. Since the B line which has key_c = 17 already deleted a control for counter_n > 0 and counter_s = 0 fails and raise you the-20002 error. Note that I'm assuming that the error of-20077 you lift is just to see the values and is not intended to be part of your actual code.

    Because I have really no idea what you're trying to accomplish here I can't offer a lot of advice that you might want to try entering two tr_c of the tr_b_vw trigger validation queries before deliver you the removal of b and put the counter_n > 0 and counter_s = 0 control under tr_b_vw to decide whether or not you want to remove.

    John

  • missing parenthesis in insertion into separate lines select the table from the other table

    Hello

    could you help me with the following question?

    I have the following tables

    CREATE TABLE table1)

    ID varchar (12),

    col2 varchar (10),

    COL3 varchar (10),

    level varchar (10))

    CREATE TABLE table2)

    Id2 varchar (12)

    A varchar (10),

    B number (1)

    CONSTRAINT PRIMARY KEY PK (ID2, is));

    INSERT INTO table2 (ID2, A, B) SELECT ID, col2

    MAX (CASE WHEN level = "level 1" then 1

    level = 'level 2' then 2

    Level = 3 then 'niveau3') as colIN3)

    FROM table1 GROUP BY ID2, a.;

    the first table have duplicates as follows:

    Id2 COL2 COL3 level

    A1 pepe football level1

    A1 pepe football level2

    A1 pepe football level1

    A1 pepe basket level2

    A1 pepe pingpong level3

    the output should be selected with unique key (ID2, col3) lines and the level must be the greatest.

    Id2 COL2 COL3 level

    A1 pepe football level2

    A1 pepe basket level2

    A1 pepe pingpong level3

    The output of the script tells me the following messages:

    -lack of right parenthesis referring to the max function.

    Thanks adavance.

    Kind regards

    Hello

    Remember the ABC's of the GROUP BY:

    When you use a GROUP BY clause or in an aggregate function, then all in the SELECT clause must be:

    (A) a ggregate function,

    (B) one of the expressions "group By."

    (C) adding to C, or

    (D) something that Depends on the foregoing.  (For example, if you "GROUP BY TRUNC (dt)", you can SELECT "TO_CHAR (TRUNC (dt), 'Mon - DD')").

    To ask him, there are 5 columns in the SELECT clause.  The last one is a function MAX (...); It is an aggregate, is not serious.

    The first 2 columns are also named in the GROUP BY clause, so that they are well.

    The other 2 columns, country and internal_Id do not match any of the above categories.  These 2 columns cause the error.

    There are many ways to avoid this error, each producing different results.  You could

    • remove these 2 columns in the SELECT clause
    • Add these 2 columns in the GROUP BY clause
    • use the aggregation such as MIN, 2-column functions
    • remove the country from the SELECT clause and add internal_id to the GROUP BY clause
    • remove the internal_id from the SELECT clause, and add countries to the GROUP BY clause
    • ...

    What are the results you want?

    Whenever you have a question, please post a small example of data (CREATE TABLE and INSERT statements) for all the tables involved, so people who want to help you can recreate the problem and test their ideas.  Also post the results you want from this data, as well as an explanation of how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • Mobile based on the size and the position of the other table

    I have the impression that there is an easy solution for this... or it there is no solution at all... but here goes:

    I want to use table 2 to indicate 'total time' as the sum of all time in table 1. Table 1 is set to automatically filter some lines (basically, it creates a dynamic playlist based on certain criteria). What I wish is to table 2 'float' a certain number of Table 1 below, so that as table 1 grows or shrinks according to the filtered content, table 2 remains the same distance from the bottom of table 1. Is - this unreasonable? It seems I've seen tables 'hustles' other tables according to size changes (not the desired effect in these cases, but what I DO want to here).

    Hi mikey,.

    This seems to be the default behavior in Numbers ' 09, but the function may not have been included in 3 numbers. I'm sure someone will test and report on it before long.

    Demo below is in Numbers ' 09.

    Coffee table is a double to the top. After positioning the lower level of the original table, I inserted two rows in the original and watched 'push' that the lowest low, keeping the space between them.

    I reformatted the cells in column B, CheckBox and verified that a few of them.

    Then I opened the Reorganize pane. and the filter rule (see the lines "... ") displayed the value:

    By clicking on "see the lines...". "box produces this result:

    Note: I had selected all the header cells in column B before starting the filter. The first image was captured after unchecking the checkbox 'display lines... '. "developing the table and leaving only the cells in the (previously) selected filtered lines.

    As mentioned, the example is in Numbers ' 09 / numbers 3 behavior may be different.

    Kind regards

    Barry

  • subqueries, nested, using elements of the other party of the request

    Hi all
    I have a delicate problem, and I'll try to explain my best:

    DB version is 11.2.0.3.0
    create table product_list (product_id number,
                    project_name varchar2(30))
    
    create table products (product_id number,
                    project_desc varchar2(30))
    
    create table total_counts (product_id number,
                    total_count number,
                    project_name varchar2(30))
    
    create table fixed_counts (product_id number,
                    fixed_count number,
                    project_name varchar2(30).
                        fixed_date date)
                        
    create table product_rating (product_id number,
                    rating number,
                    quarter_last_updated number)
                        
    create table quarters (quarter_id number,
                    quarter_end_date date)
    
    
    insert into product_list values (1, 'Prod 1');
    insert into product_list values (2, 'Prod 2');
    insert into product_list values (3, 'Prod 3');
    
    insert into products values (1, 'Prod 1');
    insert into products values (2, 'Prod 2');
    insert into products values (3, 'Prod 3');
    
    insert into total_counts values (1, 2000, 'Prod 1');
    insert into total_counts values (2, 1000, 'Prod 2');
    insert into total_counts values (3, 500, 'Prod 3');
    
    insert into fixed_counts values (1, 1, 'Prod 1', to_date('01/01/2013','DD/MM/YYYY'));
    insert into fixed_counts values (1, 3, 'Prod 1', to_date('01/01/2013','DD/MM/YYYY'));
    insert into fixed_counts values (2, 50, 'Prod 2', to_date('01/01/2013','DD/MM/YYYY'));
    insert into fixed_counts values (2, 2, 'Prod 2', to_date('01/01/2013','DD/MM/YYYY'));
    insert into fixed_counts values (2, 3, 'Prod 2', to_date('01/01/2013','DD/MM/YYYY'));
    insert into fixed_counts values (2, 3, 'Prod 2', to_date('01/01/2013','DD/MM/YYYY'));
    insert into fixed_counts values (3, 8, 'Prod 3', to_date('01/01/2013','DD/MM/YYYY'));
    insert into fixed_counts values (3, 3, 'Prod 3', to_date('01/03/2013','DD/MM/YYYY'));
    
    insert into product_rating values (1, 1, 1);
    insert into product_rating values (3, 2, 2);
    
    insert into quarters values (1, to_date('01/10/2012','DD/MM/YYYY'));
    insert into quarters values (2, to_date('01/02/2013','DD/MM/YYYY'));
    My current query joins actually 2 tables 'TOTAL_COUNTS' and 'FIXED_COUNTS '. The FIXED_COUNTS table is updated every day when a product has a patch against it and the query returns a list of all products and their "fixed" rate percentage (used in an interactive report of the APEX).
    select A.PRODUCT, A.TOTAL, B.FIXED, a.PROD_ID, round((FIXED/TOTAL) * 100,  2) percent
    from (
    select sum(a.total_count) TOTAL, a.product_id PROD_ID, d.Product_desc PRODUCT
    from total_counts a, product_list c, products d
    where a.product_id = c.product_id
    and lower(a.project_name) = lower(c.project_name) 
    and c.product_id = d.product_id
    group by a.product_id, d.product_desc
    ) A
    JOIN 
    (
    select sum(b.fixed_count) FIXED, b.product_id PROD_ID, d.Product_desc PRODUCT
    from fixed_counts b, product_list c, products d
    where b.product_id = c.product_id
    and lower(b.project_name) = lower(c.project_name) 
    and c.product_id = d.product_id
    group by b.product_id, d.product_desc
    ) B
    on A.PROD_ID = B.PROD_ID and A.PRODUCT = B.PRODUCT 
    It gives me a result like:
    PRODUCT     TOTAL     FIXED     PROD_ID     percent
    Prod 1     2000     4     1     0.2
    Prod 2     1000     58     2     5.8
    Prod 2      500     11     3     2.2
    The application works very well and does exactly the job I need. However, I now a requirement that when a product gets a percentage rate 'fixed' more than 1% of the product gets a point added against her in a table 'product_rating' and I have to recalculate the percentage of the date, the item has been added (so no points added we take all 'fixed').

    To do this, I added 2 new tables: "product_rating" and "quarters". The "product_rating" table contains the Product_id and points, he has accumulated so far. It is updated once a quarter. 'Quarters' table simply contains the dates for us to use for calculations again.

    Actually, I need to replace this:
    sum(b.fixed_count) FIXED
    with something like this:
    if a product has a point against it in the "product_rating" table then we just show fixes from the date the point was added i.e. 
    select sum(b.fixed_count) from fixed_counts b, product_rating c, quarters d
    where b.product_id = c.product_id and c.quarter_last_updated = d.quarter_id
    and b.product_id = PROD_ID
    and b.fixed_date > (select quarter_end_date from quarters where quarter_id = the_last_quarter_updated)
    Based on the values in the tables above the percentages for "3 Prod' should now be 0.6.» It is because he received a product_rating the quarter 2, then the new calculation is based on all the "corrections" after this date (only the last March 1 13').

    I tried many ways to integrate this into the current query, but I can't make it work. Sorry for not adding the info from the entire table, but the tables total_counts and fixed_counts have many more columns that I removed the query so it would be easier to observe. Thanks in advance for your help. If I can add more info ask please.
    Tom

    Published by: on May 14, 2013 TomH 08:54

    Published by: on May 14, 2013 TomH 08:58

    TomH wrote:
    of course, to the right, thank you.
    I added some info table and data that will hopefully a little easier to understand.

    OK, thank you... to the future but please try and run the commands yourself for you sure they work. What you provided is close, but it has not executed immediately without modifications.

    I will start by expressing my concerns for your data model, it seems... well, for lack of a better word. Although you said you deleted a bunch of stuff to make the example. You have someone, you you work who can look at the model for you?

    With respect to the query, it's not pretty (I'm in a bit of a rush here) so you can probably clean it considerably. I just tried to show the basics of what you're going to have to do.

    ME_XE? with base_data as
      2  (
      3     select
      4        b.fixed_date,
      5        b.fixed_count,
      6        b.product_id ,
      7        d.project_desc
      8     from fixed_counts b, product_list c, products d
      9     where b.product_id = c.product_id
     10     and lower(b.project_name) = lower(c.project_name)
     11     and c.product_id = d.product_id
     12  ),
     13     final_base_data as
     14  (
     15     select
     16        b.product_id      PROD_ID,
     17        b.project_desc    PRODUCT,
     18        sum
     19        (
     20           case
     21              when b.fixed_date >= stuff.quarter_end_date or stuff.quarter_end_date is null
     22              then
     23                 b.fixed_count
     24              else
     25                 0
     26           end
     27        )  as FIXED
     28     from base_data b
     29     left outer join
     30     (
     31        select
     32           pr.product_id,
     33           qr.quarter_end_date
     34        from product_rating pr , quarters qr
     35        where pr.quarter_last_updated = qr.quarter_id
     36     )  stuff
     37     on (stuff.product_id = b.product_id)
     38     group by b.product_id, b.project_desc
     39  )
     40  select A.PRODUCT, A.TOTAL, B.FIXED, a.PROD_ID, round((b.FIXED/a.TOTAL) * 100,  2) percent
     41  from
     42  (
     43     select sum(a.total_count) TOTAL, a.product_id PROD_ID, d.project_desc PRODUCT
     44     from total_counts a, product_list c, products d
     45     where a.product_id = c.product_id
     46     and lower(a.project_name) = lower(c.project_name)
     47     and c.product_id = d.product_id
     48     group by a.product_id, d.project_desc
     49  ) A
     50  JOIN final_base_data B
     51  on A.PROD_ID = B.PROD_ID and A.PRODUCT = B.PRODUCT
     52  ;
    
    PRODUCT                                     TOTAL              FIXED            PROD_ID            PERCENT
    ------------------------------ ------------------ ------------------ ------------------ ------------------
    Prod 1                                       2000                  4                  1                 .2
    Prod 2                                       1000                 58                  2                5.8
    Prod 3                                        500                  3                  3                 .6
    
    3 rows selected.
    

    See you soon,.

  • Domain! = Insert then in the other Table

    Hello
    I can't figure out how to create a trigger that inserts data based on cases an old.field! = new.field. If the field has been changed to
    a tbl_test table then insert this file into the other tbl_test_history of the table. It's a little different since I want to insert a record if an update
    has taken place. The update will still take place at tbl_test, but I want an insert will be held at tbl_test_history.
    CREATE OR REPLACE TRIGGER AU_INSERT_TEST_HISTORY 
      AFTER UPDATE
      ON TBL_TEST   FOR EACH ROW
    WHEN (
        OLD.Orange != NEW.Orange
     OR OLD.Apple != NEW.Apple
          )
    BEGIN
    INSERT INTO TBL_TEST_HISTORY
     (ORANGE,
      APPLE
      BANANA,
      GRAPE
    )
      select ORANGE,
             APPLE
             BANANA,
             GRAPE
    FROM TBL_TEST, TBL_TEST_HISTORY
      WHERE  TBL_TEST.PK_TEST_ID = TBL_TEST_HISTORY.PK_TEST_ID;
    END AU_INSERT_TEST_HISTORY;
    /
    I have a separate trigger that will insert records from tbl_test to tbl_test_history. This trigger compiles without error but when I
    create a record in tbl_test I have an error message. I don't know if the syntax is correct, can someone help me with this?

    My bad. I put the colon: in the when clause. They were not there in your code. I usually use an if condition, which is a little different.

    I added a NEW logic to also consider the comparison of NULL values.

    CREATE OR REPLACE TRIGGER AU_INSERT_TEST_HISTORY
      AFTER UPDATE  ON TBL_TEST
      FOR EACH ROW
    BEGIN
      if nvl(:old.ORANGE,'xxx') != nvl(:new.ORANGE,'yyy')
         OR nvl(:old.APPLE,'xxx') != nvl(:new.APPLE,'yyy')
      then
        INSERT INTO TBL_TEST_HISTORY
         (ORANGE, APPLE, BANANA, GRAPE)
        values (:new.ORANGE,
                 :new.APPLE,
                 :new.BANANA,
                 :new.GRAPE);
      end if;
    END AU_INSERT_TEST_HISTORY;
    / 
    

    In addition, you can consider making trigger a trigger AFTER INSERT or UPDATE.

    Then you would also put the values inserted early in your history table.

    Published by: Sven w. August 9, 2012 16:14

  • Add multiple attributes to the element via the conversion table?

    Hello...

    I'm sure I know the answer to this question, but am looking for validation.

    Is it possible to add multiple values of the attribute to an element using a conversion table? Table following conversion creates the < some-elem > element with the attribute @attrname to "attrval"... but what happens if I wanted to put two attributes? I tried this... Some-elem [attrname = "attrval"] [otherattrname = "attrval2"]... but the second definition is ignored. Is it possible to do (with conversion tables)?

    Wrap this object This element of With this qualifier
    P: some-para-tagSome-elem [attrname = "attrval"]



    Thank you!

    .. .Scott

    Scott,

    The structured reference apps said to separate assignments of two attribute with an ampersand, as in

    Some-elem [atttrname = "attrval" & otherattrname = "attrval2"]

    I've never done, so it is not tested.

    Van

  • GET A DATE THE TARGET TABLE MAX

    Hello friends,

    Can someone tell me how to extract the date max of the target table.

    Thank you.

    Azhar

    Sorry why again once you are not able to use the aggregator operator to get a max value. You don't need a group of when taking a max value what from a table, unless otherwise specified

    Try it with a simple table b table card

    table (several itemno)

    table b (number maxitem)

    Use aggregator and don't put anything in the section of owb agg transformation group. Generate the code and take a look

  • Release of updated with the value of the other Table

    Hello
    I need the sum there point TableB and insert/update this value in the X field in TableA. I can do this with select statements regular when I add values in my statement, but I'm getting errors now. Need help on how to code the trigger to do this, thank you.
    ORA-00936: lack of expression
    SELECT a.X, SUM(b.Y), 
    INTO a.X
    FROM TableA a, TableB b
    WHERE a.PK = b.FK;

    Ok. I think I understand now what's going on. Think logically that you create the customer first and only then customer can create orders, right? So when you insert a customer into the table DEMO_CUSTOMERS there is no customer order in the DEMO_ORDERS table. As a result, the CREDIT_LIMIT column remains NULL.

    SY.

  • How can I do a new insert data in the other table extrancting?

    Hello, I'm looking how to do an insertion of two tables save values and apply to other tables like this:

    The insert I'm looking for is something like this:

    Have two tables, the first table is emp1 and contains the column: data 1 and 2 with line of data1: 1234 and line data 2:5555, therefore,.

    I want to create an insert on a new table called (emp2) that contain the data in the column: data 1, data 2 (from the first table demo1), data 3, data 4, etc.

    How insert again I can put / call data from another table insert in this table (emp2).

    I don't know if my example is correct (my English is very bad).

    This is an example: (sorry for the points).

    table EMP2:

    1 data... 2 data... 3 data... data 4... data 5
    (from emp1)... (from emp1)... 8534... 2347... 4544

    Thanks for the help.

    Published by: user10182692 on 24-May-2009 08:39

    Published by: user10182692 on 24-May-2009 08:40

    Published by: user10182692 on 24-May-2009 08:45

    Welcome! on the forum.

    You can include the code and data in the {code} tags

    If I'm good, and I know what is your condition

    insert into emp2 ( data1, data2)
    select data1, data2
    from emp1
    

    SS

  • It does not work when you use the trigger to check the data of the other table.

    Please help me with this, I put a trigger on a table, but it can not work as I expect.

    case study: a class has many students, one of them is going to match.
    The purpose of this trigger is to check when to choose a student going to match, this student has in his class where it belongs to.
    Oracle version is 10.2.0.1.0.
    --table:
    DROP TABLE STU;
    DROP TABLE CLASS;
    
    create table CLASS(
    CID     VARCHAR2(5)   PRIMARY KEY,
    CNAME   VARCHAR2(20)  NOT NULL,
    SCHOSEN VARCHAR2(5));
     
    create table STU(
    SID     VARCHAR2(5)   PRIMARY KEY,
    SNAME   VARCHAR2(20)  NOT NULL,
    CID     VARCHAR2(5)   NOT NULL REFERENCES CLASS(CID) ON DELETE CASCADE);
    
    --data:
    --CLASS
    INSERT INTO CLASS(CID,CNAME) VALUES(1,'SUN');
    INSERT INTO CLASS(CID,CNAME) VALUES(2,'MOON');
    INSERT INTO CLASS(CID,CNAME) VALUES(3,'EARTH');
    --STU
    INSERT INTO STU VALUES(1,'JACK',1);
    INSERT INTO STU VALUES(2,'TOM',1);
    INSERT INTO STU VALUES(3,'LILY',2);
    INSERT INTO STU VALUES(4,'DUSTIN',3);
    
    --TRIGGER
    CREATE OR REPLACE TRIGGER CHECK_SCHOSEN
    BEFORE INSERT OR UPDATE OF SCHOSEN ON CLASS
    FOR EACH ROW WHEN (NEW.SCHOSEN IS NOT NULL)
    
    DECLARE
    DUMMY INTEGER;
    INVALID_STU EXCEPTION;
    VALID_STU EXCEPTION;
    MUTATING_TABLE EXCEPTION;
    PRAGMA EXCEPTION_INIT(MUTATING_TABLE, -4091);
    
    CURSOR DUMMY_CURSOR (ST VARCHAR2, CL VARCHAR2) IS
      SELECT SID FROM STU, CLASS
      WHERE STU.SID=ST AND STU.CID=CLASS.CID AND CLASS.CID=CL
        FOR UPDATE OF CLASS.SCHOSEN;
    
    BEGIN
      OPEN DUMMY_CURSOR(:NEW.SCHOSEN, :NEW.CID);
      FETCH DUMMY_CURSOR INTO DUMMY;
      IF DUMMY_CURSOR%NOTFOUND THEN
        RAISE INVALID_STU;
      ELSE
        RAISE VALID_STU;
      END IF;
      CLOSE DUMMY_CURSOR;
    EXCEPTION
      WHEN INVALID_STU THEN
        CLOSE DUMMY_CURSOR;
        DBMS_OUTPUT.PUT_LINE('PLEASE RE-ENTER CLASS ID AND STUDENT ID AS CLASS OR STUDENT IS NOT VALID.');
      WHEN VALID_STU THEN
        CLOSE DUMMY_CURSOR;
        DBMS_OUTPUT.PUT_LINE('STUDENT CHOOSE SUCCEFULLY!');
      WHEN MUTATING_TABLE THEN
        NULL;
    END;
    /
    Just copy and paste on it and try to run next:
    UPDATE CLASS
    SET SCHOSEN = 3
    WHERE CID = 1;
    Clearly, you can't student who is 3 as to Member of class 1. Please help me. Thank you.

    Published by: 991096 on March 1st, 2013 02:36

    Published by: 991096 on March 1st, 2013 03:03

    Published by: 991096 on March 1st, 2013 03:11

    Hello

    991096 wrote:
    1. the purpose of this trigger is to check when to choose a student going to match, this student has in his class where it belongs to. Then, when I try to choose 3 student-member of correspondence of class 1, should give me "PLEASE RE-ENTER ID AND STUDENT ID AS CLASS or STUDENT not IS NOT VALID."

    Then do something like this:

    CREATE OR REPLACE TRIGGER CHECK_SCHOSEN
    BEFORE INSERT OR UPDATE OF SCHOSEN ON CLASS
    FOR EACH ROW WHEN (NEW.SCHOSEN IS NOT NULL)
    DECLARE
        sid_found     stu.sid%TYPE;
    BEGIN
        dbms_output.put_line (:NEW.schosen || ' = schosen entering check_schosen');             SELECT  sid
             INTO    sid_found
         FROM      stu
         WHERE     sid     = :NEW.schosen
         AND     cid     = :NEW.cid
         AND     ROWNUM     = 1     -- to avoid TOO_MANY_ROWS
         ;
    EXCEPTION
        WHEN  NO_DATA_FOUND
        THEN
         RAISE_APPLICATION_ERROR ( -20000
                        , 'Please re-enter class id and student id as class ('
                          || :NEW.cid
                          || ') or student ('
                          || :NEW.schosen
                          || ') is not valid.'
                        );
    end;
    /
    

    DBMS_OUTPUT creates only a message. The message may not be displayed, and if this is the case, then the user cannot see it. The DML will still take place.
    I used instead, RAISE_APPLICATION_ERROR to keep the DML does not happen. It displays a message like

    ORA-20000: Please re-enter class id and student id as class (1) or student (3) is not valid.
    

    ' 2 ' game ' means ' an official competition in which two several people or teams competing.

    What individuals or teams are competing in this case?
    In any case, the question wasn't 'that 'game' means', but

    Frank Kulash wrote:
    What do you mean when you say "going to match?

    I think that now you're saying that the new values of (class.cid, class.schosen) must be equal to (or "fit") some existing (stu.cid, stu.sid).

    3. thanks for your tip, I learned how to use '{code} '.

    4. it's really goes with the exception of MUTATING_TABLE. So, how do to fix the trigger to show me INVALID_STU EXCEPTION when I try to choose a student does not belong
    a class?

    Don't refer to the table of class in the trigger, and the error table mutation occur. All the information you need are in the stu table, so there is no need to query the table of class, anyway.

  • How to extract the values of the other tables in the process upon request

    Hi all
    In Oracle Apex 4.1.
    The Leave_transaction Table contains the following fields,
    1.Leave_id
    2.Emp_name
    3.From_date
    4.To_date
    5.Remaining_days
    The Emp_Master Table contains the following columns
    1.Emp_id
    2.Emp_Name
    3.Remaining_days
    Holiday_master table contains a list of the dates of the holidays as 'From_Date '.

    I have the form based on the Leave_Transaction Table,
    I created the process,
    "Sur-Soumettre after calculations and validations of."
    and posted the following PLSQL code,
    declare
    days number(3);
    ex_days emp_master.remaining_days%type;
    new_rem_days emp_master.remaining_days%type;
    begin
    select count(*) into days from (select dt
    from(
        select to_date(:p1_from_date, 'DD-Mon-YYYY') + rownum -1 dt 
            from dual
    connect by level <= to_date(:p1_to_date, 'DD-Mon-YYYY') - to_date(:p1_from_date, 'DD-Mon-YYYY') + 1)
    where to_char(dt,'fmday') not in ('sunday','saturday') minus (select holiday_start from holiday_master)) dual ;
    
     select remaining_days into ex_days from emp_master where upper(emp_name) = upper(:APP_USER);
    new_rem_days := ex_days - days;
    
      update emp_master set
        remaining_days = new_rem_days
        where upper(emp_name) = upper(:APP_USER);
    update leave_transaction set
        remaining_days = new_rem_days
        where upper(emp_name) = upper(:APP_USER) and
         leave_id=(select max(leave_id) from leave_transaction);
    
    end;
    If the date is between from_date and To_date comes Saturday and Sunday or if any Date exists in the table of Hpliday_master he will exclude and return the count (*) rest of dates.
    For example,.

    If the From_date is 04-may-2012'
    and To_date is 08-may-2012,

    Here the dates 5 May and 6 may are "Saturday" and "Sunday".

    and if any date between From_date and To_date is exist in the Table Holiday_Master
    That is to say that here it is 07-may-2012,

    Then the remaining dates are (excluding sat, Sunday and dates in holiday_table).

    04-may-2012,
    08-may-2012.

    the count (*) is 2.

    I use the code above but it return 5.
    I think that this
     
    ...where to_char(dt,'fmday') not in ('sunday','saturday') minus (select holiday_start from holiday_master))
    code does not work.
    Can someone help me solve my problem.

    Edited by: Gurujothi may 3, 2012 23:59
    set serveroutput on;
    declare
    v_sql varchar2(100);
    begin
            v_sql := 'ALTER SESSION SET NLS_LANGUAGE= ''GERMAN''';
            execute immediate  v_sql;
            dbms_output.put_line(v_sql);
            for c in
                        (
                        select to_char(sysdate + level ,'fmday') day_
                        from dual
                        where to_char(sysdate + level,'fmday') not in ('sunday','saturday')  connect by level < 8
                        ) loop
                        v_sql := c.day_;
                         dbms_output.put_line(v_sql);
                        end loop;
    
            v_sql := 'ALTER SESSION SET NLS_LANGUAGE= ''AMERICAN''';
            execute immediate  v_sql;
            dbms_output.put_line(v_sql);
            for c in
                        (
                        select to_char(sysdate + level ,'fmday') day_
                        from dual
                        where to_char(sysdate + level,'fmday') not in ('sunday','saturday')  connect by level < 8
                        ) loop
                        v_sql := c.day_;
                         dbms_output.put_line(v_sql);
                        end loop;
    end;
    /
    
    ALTER SESSION SET NLS_LANGUAGE= 'GERMAN'
    samstag
    sonntag
    montag
    dienstag
    mittwoch
    donnerstag
    freitag
    ALTER SESSION SET NLS_LANGUAGE= 'AMERICAN'
    monday
    tuesday
    wednesday
    thursday
    friday
    PL/SQL procedure successfully completed.
    

Maybe you are looking for

  • Why not deleted msgs is more go in the TRASH, they disappear?

    I have a trash folder and all Deleted messages used to go. Just noticed that the file basket account (read and unread) were not change, because Deleted messages disappear. Search does not find them, a newly loaded Extension "Recover Deleted Messages

  • Satellite P20-771 with Windows 7: no noise and the screen turns white

    Hi all.. I installed Windows 7 Ultimate on this machine. I tried the latest Realtek AC97 drivers, install the driver and everything seems fine but no sound is produced at all. Regarding the graphics card, I used a few modded Nvidia Drivers 97.tel xx

  • Auto sign WiFi appear after startup mac

    Hello I click on network/forward, then I check all the boxes under "require administered or permission of": creation of computer to computer network; change network; activate wi - if on or off.  Until I stop Mac, I turned off wifi. This means that, i

  • change the ssid on the wireless router

    looking to change the ssid and cant seem to understand how someone can help me on how I can do this. Thanks Dan.

  • Why libraries windows 7 duplicate files?

    I have a 500 Gig hard drive.  Half of my available space is taken by Windows 7 libraries which copy all my images and documents.  If I delete a copy, the original disappears as well.  How can I get rid of the 250 GB of duplicate files?