The most recent query

How t to check the query the most recent of which was held on the database?

Select * from v$version;
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
"CORE     10.2.0.5.0     Production"
TNS for HPUX: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production

In 10g and more, you can check the views dba_hist. visit dba_hist_active_sess_history to get the sql_id (based on when the user runs the job) and then map it with sql_id in dba_hist_sqtext to get the sql_text.

For example, the following query receives the details sql_text and session for all sessions between 01:00 and 02:00.
SELECT a.sample_time, a.session_id, b.username, a.program, a.module, a.action,
a.client_id, a.machine, c.sql_text
OF dba_hist_active_sess_history a, b dba_users, dba_hist_sqltext c
WHERE a.sql_id = c.sql_id
AND a.user_id = b.user_id
AND a.sample_time BETWEEN TO_DATE ('20111013 01:00 ', 'HH24 YYYYMMDD')
AND TO_DATE ('20111013 02:00 ', 'HH24 YYYYMMDD');

Tags: Database

Similar Questions

  • Performance of the queries in order to get the most recent price

    Happy new year everyone.

    I have a table of price in my system that has several awards for each product with the date, the price is entered into force.

    I have queries throughout the system to retrieve the most recent actual price for the date of the transaction.

    I can find to implement the easiest way is to have a user-defined function to collect the prize.

    My problem is that many of my questions have access to large amounts of data (for example, transactions) and my table of prices is also big enough - both have millions of records. Using a Pl/SQL function defined by the user in my query, I get a lot of switching context between SQL and PL/SQL and my questions are not well

    Here is an example of code, which simplifies my scenario:

    drop table xo_stock_trans;
    create table xo_stock_trans (item varchar2(25), trans_date date, quantity number(20,4));
    insert into xo_stock_trans values('A',TO_DATE('25-DEC-2014','DD-MON-YYYY'), 4);
    insert into xo_stock_trans values('A',TO_DATE('27-DEC-2014','DD-MON-YYYY'), -2);
    insert into xo_stock_trans values('A',TO_DATE('28-DEC-2014','DD-MON-YYYY'), 5);
    insert into xo_stock_trans values('B',TO_DATE('23-DEC-2014','DD-MON-YYYY'), 20);
    insert into xo_stock_trans values('B',TO_DATE('26-DEC-2014','DD-MON-YYYY'), -6);
    insert into xo_stock_trans values('B',TO_DATE('29-DEC-2014','DD-MON-YYYY'), 15);
    /
    -- Generate lots more data
    BEGIN
        -- Generate more trans dates
        for r in 1..1000
        LOOP
            insert into xo_stock_trans
            select item, trans_date - r - 7 as  trans_date, ROUND(dbms_random.value(1,50),2) as quantity
            from xo_stock_trans
            where trans_date between TO_DATE('23-DEC-2014','DD-MON-YYYY') AND TO_DATE('29-DEC-2014','DD-MON-YYYY')
              and item in ('A','B');
        END LOOP;
        COMMIT;
        -- generate more items
        for lt in 1..12 
        LOOP
            -- generate C,D, E, items
            INSERT into xo_stock_trans
            SELECT chr(ascii(item)+(lt*2)) as item, trans_date, quantity
            from xo_stock_trans
            where item in ('A','B');
            -- generate A1, A2, B1, B2, etc
            for nm in 1..10
            LOOP
                INSERT INTO xo_stock_trans
                select item || to_char(nm), trans_date, quantity
                from xo_stock_trans
                where length(item) = 1;
            END LOOP;
            COMMIT;
        END LOOP;
        COMMIT;
    END;
    /
    create index xo_stock_trans_ix1 on xo_stock_trans (item);
    create index xo_stock_trans_ix2 on xo_stock_trans (trans_date);
    exec dbms_stats.gather_table_stats(ownname =>user, tabname => 'XO_STOCK_TRANS' , estimate_percent => 100, degree => dbms_stats.auto_degree, cascade=>true);
    /
    
    
    drop table xo_prices;
    create table xo_prices (item varchar2(25), price_date date, gross_price number(20,4), net_price number(20,4), special_price number(20,4) );
    insert into xo_prices values ('A', to_date('01-DEC-2014','DD-MON-YYYY'), 10, 8, 6);
    insert into xo_prices values ('A', to_date('25-DEC-2014','DD-MON-YYYY'), 9, 8, 6);
    insert into xo_prices values ('A', to_date('26-DEC-2014','DD-MON-YYYY'), 7, 6, 4);
    insert into xo_prices values ('B', to_date('01-DEC-2014','DD-MON-YYYY'), 5.50, 4.50, 3);
    insert into xo_prices values ('B', to_date('25-DEC-2014','DD-MON-YYYY'), 5.00, 4.00, 3);
    insert into xo_prices values ('B', to_date('26-DEC-2014','DD-MON-YYYY'), 3.50, 2.50, 2);
    /
    -- Generate lots more data
    BEGIN
        -- Generate more price dates
        for r in 1..1000
        LOOP
            insert into xo_prices
            select item, price_date - r - 7 as  price_date,gross_price, net_price, special_price
            from xo_prices
            where price_date between TO_DATE('23-DEC-2014','DD-MON-YYYY') AND TO_DATE('29-DEC-2014','DD-MON-YYYY')
              and item in ('A','B');
        END LOOP;
        COMMIT;
        -- generate more items
        for lt in 1..12 
        LOOP
            -- generate C,D, E, items
            INSERT into xo_prices
            SELECT chr(ascii(item)+(lt*2)) as item, price_date, gross_price + (lt*2), net_price + (lt*2), special_price + (lt*2)
            from xo_prices
            where item in ('A','B');
            -- generate A1, A2, B1, B2, etc
            for nm in 1..10
            LOOP
                INSERT INTO xo_prices
                select item || to_char(nm), price_date, gross_price, net_price, special_price
                from xo_prices
                where length(item) = 1;
            END LOOP;
            COMMIT;
        END LOOP;
    END;
    /
    
    create index xo_prices_ix1 on xo_prices (item, price_date);
    exec dbms_stats.gather_table_stats(ownname =>user, tabname => 'XO_PRICES' , estimate_percent => 100, degree => dbms_stats.auto_degree, cascade=>true);
    /
    
    create or replace function xo_get_price(I_Item in VARCHAR2, I_Date in DATE, i_Price_type IN VARCHAR2) RETURN NUMBER
    IS
        -- Function to get most recent effective price prior to the date
        CURSOR c_get_prices(P_Item VARCHAR2, P_Date VARCHAR2)
        IS
        SELECT gross_price, net_price, special_price
        FROM XO_PRICES
        WHERE item = P_Item
         AND price_date <= P_Date
        ORDER BY price_date desc; -- most recent price
        
        l_gross_price NUMBER(20,4);
        l_net_price NUMBER(20,4);
        l_special_price NUMBER(20,4);
    BEGIN
        OPEN c_get_prices(I_Item, I_Date);
        FETCH c_get_prices INTO l_gross_price, l_net_price, l_special_price;
        CLOSe c_get_prices;
        
        IF I_Price_Type='GROSS' then return l_gross_price;
        ELSIF I_Price_Type= 'NET' then return l_net_price;
        ELSIF I_Price_Type= 'SPECIAL' then return l_special_price;
        END IF;
    END xo_get_price;
    /
    
    -- Here is a typical query I am trying to perform
    select tr.item, tr.trans_date, tr.quantity
        , xo_get_price(tr.item, tr.trans_date, 'GROSS') as gross_price
        , xo_get_price(tr.item, tr.trans_date, 'NET') as net_price
        , xo_get_price(tr.item, tr.trans_date, 'SPECIAL') as special_price
    from xo_stock_trans tr
    where tr.trans_date between '01-AUG-2014' and '31-AUG-2014';
    

    I would like to refactor my request so that I do not use the user Pl/SQL functions, but so far I can't get something that works better than the SQL above. For example, the following query is MUCH longer:

    select tr.item, tr.trans_date, tr.quantity
        , pr.gross_price
        , pr.net_price
        , pr.special_price
    from xo_stock_trans tr
    join xo_prices pr on pr.item = tr.item
                    and pr.price_date = (select max(pr2.price_date)
                                         from xo_prices pr2
                                         where pr2.item = pr.item
                                           and pr2.price_date <= tr.trans_date
                                         )
    where tr.trans_date between '01-AUG-2014' and '31-AUG-2014';
    

    I'm interested to know if anyone has addressed a similar scenario and have managed to write more efficient code.

    I looked at the determinism/manual caching of the function, but the article/date combinations are quite unique and therefore he does not benefit from him.

    Any suggestion under review - parallelism, analytical, pipeline functions, etc.

    Alan

    Hi, Alan.

    Alan Lawlor wrote:

    ...

    My problem is that many of my questions have access to large amounts of data (for example, transactions) and my table of prices is also big enough - both have millions of records. Using a Pl/SQL function defined by the user in my query, I get a lot of switching context between SQL and PL/SQL and my questions are not well...

    You got that right!  User-defined functions can be very practical, but this practice comes with a price.

    What version of Oracle are you using?  The Oracle 12, there is a new feature of 'temporal validity' which may help you.

    In any version, it will be much faster if you add a new column to the xo_prices table.  You can call this end_date, although it would in fact be the date when some other prices took effect.  You might put DATE' 9999-12-31 in the column end_date for current prices.  You can calculate end_date using the analytical function of LEAD.  Be sure to re-calcluate end_date when you insert new rows into xo_prices, or when you update the dates on existing lines.

    Once you have PRICE_DATE and end_date in the XO_PRICES table, you can join this table to get the real price from d by including

    AND d > = xo_prices.price_date

    AND d< >

    in the join condition.

    In some situations, especially when you don't have much different (item, dates) combinations, scalar-sub-queries could be faster than joins.

    Whatever it is, it participates without PL/SQL, so there is no context switching.

  • How to read only the most recent records in PL/SQL

    Oracle version: 11.2

    I have a table in ORACLE called RATES and it is EFFECTIVE_DATE, RATE_NAME, RATE_AMOUNT


    RATE
    ------------
    1 RATE_ONE 01/01/2000 0.10
    2 RATE_ONE 01/05/2005 0.15
    RATE_ONE 12/01/2010 3, 0.20
    RATE_TWO 4 10/15/2009 0.33
    5 RATE_THREE 07/09/2011 0.05
    6 RATE_THREE 31/12/2011 0.06

    A rate can be there several times, but the most recent rate is the rate of the asset. I need to query this table and want only to bring the currently active lines:
    DOCUMENTS 3, 4 and 6

    How can I do this in the most elegant way?

    I can say:

    SELECT RATE WHERE trunc (sysdate) between EFFECTIVE_DATE and trunc (sysdate);

    (it will not work. I don't know how to do this without a date column exp and then I could tell
    SELECT RATE WHERE trunc (sysdate) between EFFECTIVE_DATE and end_date

    The problem is that I can't add this column at this time, so need to find a way to do it by programming

    Published by: userLynx on February 1, 2012 08:56

    Hello

    Here's one way:

    WITH     got_r_num     AS
    (
         SELECT     rate.*          -- or list columns you want
         ,     RANK () OVER ( PARTITION BY  rate_name
                          ORDER BY          effective_date     DESC
                        )           AS r_num
         FROM    rate
    --     WHERE     ...          -- If you need any filtering, put it here
    )
    SELECT     *          -- Or list all columns except r_num
    FROM     got_r_num
    WHERE     r_num     = 1
    ;
    

    If you would care to post CREATE TABLE and INSERT statements for your sample data, and then I could test this.

    If the combination (rate_name, effective_date) is not unique, this includes all rows that have the last effective_date for this rate_name. If you want exactly one line per rate_name when there is a tie, then add the columns of tiebreaker to analytical or use ROW_NUMBER instead of RANK ORDER BY clause.

  • How to get the values based on the most recent date

    Oracle Version 8i



    How to get the new_value based on the most recent date

    SELECT max (MODIFIED_ON), the Group LOG_ITEM_CHARACTERISTICS by MODIFIED_ON new_value - does not

    Please, someone help me
    CREATE TABLE LOG_ITEM_CHARACTERISTICS
    (
      CHAR_LOG_ID          NUMBER(10)               NOT NULL,
      PIRM_ID              VARCHAR2(8)              NOT NULL,
      CONSTANT_FLAG        VARCHAR2(1),
      CHARACTERISTIC_NAME  VARCHAR2(25)             NOT NULL,
      TYPE_NAME            VARCHAR2(10)             NOT NULL,
      NEW_VALUE            VARCHAR2(3000),
      UOM                  VARCHAR2(10),
      MODIFIED_BY          VARCHAR2(30),
      MODIFIED_ON          DATE
    )
    
    SET DEFINE OFF;
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (187376, '0307490N', 'N', 'OUTPUT CURRENT', 'PS2030/WVL', '1', 'AMPS', 'EMPXD88', TO_DATE('10/25/1999 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (187377, '0307490N', 'N', 'OUTPUT VOLTAGE', 'PS2030/WVL', '54.9', 'VOLTS', 'EMPXD88', TO_DATE('09/22/1998 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (187378, '0307490N', 'N', 'OUTPUT CURRENT', 'PS2030/WVL', '0', 'AMPS', 'EMDXB88', TO_DATE('09/22/1998 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (187384, '0307490N', 'N', 'OUTPUT CURRENT', 'PS2030/WVL', '2', 'AMPS', 'EMAXC29', TO_DATE('11/10/2000 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (187385, '0307490N', 'N', 'OUTPUT VOLTAGE', 'PS2030/WVL', '55.1', 'VOLTS', 'EMAXC29', TO_DATE('10/19/2001 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_ON)
     Values
       (2400742, '0307490N', 'N', 'MEASURED LOAD ON PER', 'PS2030/WVL', '2', 'AMPS', TO_DATE('10/19/2001 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (574093, '0307490N', 'N', 'MEASURED LOAD ON PER', 'PS2030/WVL', '2', 'AMPS', 'EMCTH88', TO_DATE('12/13/2002 11:55:16', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (574094, '0307490N', 'N', 'OUTPUT VOLTAGE', 'PS2030/WVL', '54.9', 'VOLTS', 'EMCTH88', TO_DATE('12/13/2002 11:55:16', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (3131486, '0307490N', 'N', 'MEASURED LOAD ON PER', 'PS2030/WVL', '6', 'AMPS', 'EMCTH88', TO_DATE('12/16/2004 14:31:14', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (3131487, '0307490N', 'N', 'LAST MEASURED DATE', 'PS2030/WVL', '16-12-04', 'DD/MM/YY', 'EMCTH88', TO_DATE('12/16/2004 14:31:14', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, MODIFIED_BY, MODIFIED_ON)
     Values
       (3131488, '0307490N', 'Y', 'POWER SUPPLY', 'PS2030/WVL', 'ESSENTIAL', 'EMCTH88', TO_DATE('12/16/2004 14:31:14', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (3131489, '0307490N', 'N', 'OUTPUT VOLTAGE', 'PS2030/WVL', '54.9', 'VOLTS', 'EMCTH88', TO_DATE('12/16/2004 14:31:14', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (4759086, '0307490N', 'N', 'MEASURED LOAD ON PER', 'PS2030/WVL', '6', 'AMPS', 'EMRCT88', TO_DATE('11/15/2007 14:33:03', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (4759087, '0307490N', 'N', 'OUTPUT VOLTAGE', 'PS2030/WVL', '54.9', 'VOLTS', 'EMRCT88', TO_DATE('11/15/2007 14:33:03', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (4759088, '0307490N', 'N', 'LAST MEASURED DATE', 'PS2030/WVL', '14/11/07', 'DD/MM/YY', 'EMRCT88', TO_DATE('11/15/2007 14:33:03', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (6646012, '0307490N', 'N', 'MEASURED LOAD ON PER', 'PS2030/WVL', '5', 'AMPS', 'PAUL DEVERILL', TO_DATE('01/06/2011 12:56:17', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, MODIFIED_BY, MODIFIED_ON)
     Values
       (6646013, '0307490N', 'Y', 'BATT TEST SET AT 3M', 'PS2030/WVL', 'null', 'PAUL DEVERILL', TO_DATE('01/06/2011 12:56:17', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, MODIFIED_BY, MODIFIED_ON)
     Values
       (6646014, '0307490N', 'Y', 'CAP ALARM INHIBITED', 'PS2030/WVL', 'null', 'PAUL DEVERILL', TO_DATE('01/06/2011 12:56:17', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (6646015, '0307490N', 'N', 'OUTPUT VOLTAGE', 'PS2030/WVL', '55', 'VOLTS', 'PAUL DEVERILL', TO_DATE('01/06/2011 12:56:17', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, MODIFIED_BY, MODIFIED_ON)
     Values
       (6646016, '0307490N', 'Y', 'YR ROUTINES REQUIRED', 'PS2030/WVL', 'null', 'PAUL DEVERILL', TO_DATE('01/06/2011 12:56:17', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, MODIFIED_BY, MODIFIED_ON)
     Values
       (6646057, '0307490N', 'Y', 'BATT TEST SET AT 3M', 'PS2030/WVL', 'null', 'PAUL DEVERILL', TO_DATE('01/06/2011 13:03:18', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, MODIFIED_BY, MODIFIED_ON)
     Values
       (6646058, '0307490N', 'Y', 'CAP ALARM INHIBITED', 'PS2030/WVL', 'null', 'PAUL DEVERILL', TO_DATE('01/06/2011 13:03:18', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, MODIFIED_BY, MODIFIED_ON)
     Values
       (6646059, '0307490N', 'Y', 'YR ROUTINES REQUIRED', 'PS2030/WVL', 'null', 'PAUL DEVERILL', TO_DATE('01/06/2011 13:03:18', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (6648577, '0307490N', 'N', 'MEASURED LOAD ON PER', 'PS2030/WVL', '6', 'AMPS', 'EMPXD88', TO_DATE('01/07/2011 13:35:45', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (6648578, '0307490N', 'N', 'OUTPUT VOLTAGE', 'PS2030/WVL', '55', 'VOLTS', 'EMPXD88', TO_DATE('01/07/2011 13:35:45', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, MODIFIED_BY, MODIFIED_ON)
     Values
       (6648579, '0307490N', 'Y', 'YR ROUTINES REQUIRED', 'PS2030/WVL', 'NULL', 'EMPXD88', TO_DATE('01/07/2011 13:35:45', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, MODIFIED_BY, MODIFIED_ON)
     Values
       (6648580, '0307490N', 'Y', 'BATT TEST SET AT 3M', 'PS2030/WVL', 'NULL', 'EMPXD88', TO_DATE('01/07/2011 13:36:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, MODIFIED_BY, MODIFIED_ON)
     Values
       (6648581, '0307490N', 'Y', 'CAP ALARM INHIBITED', 'PS2030/WVL', 'NULL', 'EMPXD88', TO_DATE('01/07/2011 13:36:10', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (6648634, '0307490N', 'N', 'MEASURED LOAD ON PER', 'PS2030/WVL', '5', 'AMPS', 'EMPXD88', TO_DATE('01/07/2011 13:51:06', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into LOG_ITEM_CHARACTERISTICS
       (CHAR_LOG_ID, PIRM_ID, CONSTANT_FLAG, CHARACTERISTIC_NAME, TYPE_NAME, NEW_VALUE, UOM, MODIFIED_BY, MODIFIED_ON)
     Values
       (6648635, '0307490N', 'N', 'OUTPUT VOLTAGE', 'PS2030/WVL', '55', 'VOLTS', 'EMPXD88', TO_DATE('01/07/2011 13:51:06', 'MM/DD/YYYY HH24:MI:SS'));
    COMMIT;

    user4587979 wrote:
    Hi Frank

    Yes, but I had more than 2 tables with item_characteristics, type_characteristics

    If there are other tables involved, then CREATE TABLE and INSERT statements for them (for the relevant columns only). You must not post a lot of examples of data; usually just a couple of lines per table is enough to show the problem.
    Also post the results desired from these data.

    What I try to do is, I'm comparing new_value in log_item_characteristics (whichever is most recent) with CHR_VALUE in the item_characteristics and the needs of different output values

    I am trying to query is not giving desired out put

    Point out some places where the output is wrong and explain how you get good results in these places, using specific examples from the data sample.

    select  lic.PIRM_ID, ic.CHR_ID, lic.CHARACTERISTIC_NAME,
    lic.TYPE_NAME, ic.CHR_VALUE, lic.NEW_VALUE,  lic.MODIFIED_BY,  lic.MODIFIED_ON,
    ic.CREATED_BY, ic.CREATED_ON,ic.MODIFIED_BY, ic.MODIFIED_ON
    from log_item_characteristics lic, item_characteristics ic,type_characteristics tc  where
    lic.TYPE_NAME=tc.TYPE_NAME
    and lic.CHARACTERISTIC_NAME=tc.CHR_NAME
    and lic.PIRM_ID=ic.PIRM_ID
    and tc.CHR_ID=ic.CHR_ID and ic.CHR_VALUE <> lic.NEW_VALUE
    and lic.pirm_id in ('0307490N','0307521C')
    order by lic.pirm_id
    

    Thank you; It is useful to see the existing query. Really, you have to format your code.

    Please can you help me

    What you've posted so far is like saying "I'm going 200 meters to the North, and then 500 meters East, but I'm not getting where I want to go." I would have a better chance to help you if you said, 'I'm out of my house, at 100, Elm Street and try to get to the supermarket at Broadway 279. I'm going 200 meters to the North... ', or, even better. "I want to buy a newspaper and some orange juice, so I thought I'd go to a convenience store. I start at my house, at 100, Elm Street... »
    Always post some examples of data (CREATE TABLE and INSERT statements, as you did in your first post) and the desired results from these data. Explain how you get these results from these data.

  • identify the most recent candidate

    First I'm sorry for the creation of a long term position, just trying to understand.
    Please help me make my efficient query.

    Example followed with a logic behind the scenes.

    create table finalcand (ptsequence number,version number,candidate varchar2(10),date_submitted date,
    file_valid varchar(2))
    insert into finalcand values(101,1,'VJ',TRUNC(SYSDATE),'Y');
    insert into finalcand values(102,1,'RD',TRUNC(SYSDATE),'Y');
    insert into finalcand values(103,1,'GD,TRUNC(SYSDATE),'Y');
    insert into finalcand values(104,1,'GD',TRUNC(SYSDATE),'N');
    insert into finalcand values(105,2,'GD,TRUNC(SYSDATE),'Y');
    insert into finalcand values(107,2,'GVR',TRUNC(SYSDATE),'N');
    insert into finalcand values(106,1,'GD',TRUNC(SYSDATE+1),'Y');
    insert into finalcand values(108,1,'GD',TRUNC(SYSDATE),'Y');
    insert into finalcand values(109,2,'GVR',TRUNC(SYSDATE+1),'Y');
    o/p required
       PTSEQUENCE    VERSION    PATIENT DATE_SUBMITTED FILE_VALID   RNK
         105     2     GD     7/23/2009           Y             2
         108     1     GD     7/23/2009           Y             3
         103     1     GD     7/23/2009           Y             4
         104     1     GD     7/23/2009           N             4
         107     2     GVR     7/23/2009           N             2
    IM using this query that works perfectly, but I'm still trying to see if I can do it effectively.
    SELECT z.*
      FROM (SELECT r.*,
                   RANK() OVER(
                   PARTITION BY r.candidate 
                   ORDER BY R.DATE_SUBMITTED DESC,
                            R.VERSION DESC, 
                            R.PTSEQUENCE desc) rnk
              FROM finalcand r
              where file_valid='Y') z
     WHERE RNK >1
    union all
    SELECT z.*
      FROM (SELECT r.*,
                   RANK() OVER(
                   PARTITION BY r.candidate  
                   ORDER BY R.DATE_SUBMITTED DESC,
                            R.VERSION DESC, 
                            R.PTSEQUENCE desc) rnk
              FROM finalcand r
              ) z
     WHERE RNK >1
     and z.file_valid='N'
    Logic behind it all

    This is to identify all records that are no more final candidate

    -> candidate is identified by the name of the candidate.
    -> version and date_submitted is used to identify the most recent entry of this candidate.
    -> if same candidate has several entries with the same version and also date_submitted even then use max (ptsequence) to identify the most recent.

    Problem here is
    -> if we see a candidate with File_valid input = ' don't this means that the earlier version of this candidate should be the most recent.
    An other problem is
    -> if we see a candidate with File_valid input = ' don't and no not all old records, then the current should be the last.


    Thanks for reading this post.

    Published by: user5495111 on July 23, 2009 13:37

    OK then, this query matches your output (with the exception of the rank column)

    select * from (
    select r.*
         , row_number() over (partition by r.candidate
                                  order by r.file_valid desc
                                      , r.date_submitted desc
                                      , r.version desc
                                      , r.ptsequence desc) rn
      from finalcand r)
      where rn!=1
      order by candidate, rn
    
    PTSEQUENCE  VERSION  CANDIDATE  DATE_SUBMITTED    FILE_VALID RN
    ----------- -------- ---------- ----------------- ---------- ----
    105         2        GD         23-JUL-2009       Y          2
    108         1        GD         23-JUL-2009       Y          3
    103         1        GD         23-JUL-2009       Y          4
    104         1        GD         23-JUL-2009       N          5
    107         2        GVR        23-JUL-2009       N          2   
    
    5 rows selected
    
  • Need help get data with the most recent date of entry into

    Hey guys;

    I need help with fine tuning a query to get the one with the most recent implementation.

    Here's my current query:

    /**********************************************
    Select sge.seal_group_id,
    SGE.equipment_id,
    SGE.effective_date
    of seal_group_equipment EMS.
    seal_group sg
    where equipment_id = 48801
    AND EMS. SEAL_GROUP_ID = SG. SEAL_GROUP_ID
    and sge.end_date is null
    Group of sge.equipment_id, sge.seal_group_id, sge.effective_date
    After having sge.effective_date = max (sge.effective_date)

    ******************************************************/

    Which produces the following results:
    SEAL_GROUP_ID - EQUIPMENT_ID - EFFECTIVE_DATE
    25-48801 - 01/01/1993-00: 00:00
    11730-48801 - 22/08/2003 08:42:11


    What I really need, is to show only the line with the most recent date of entry into
    I hope someone can help
    Thank you

    MAX will not work because the SEAL_GROUP_ID could depart. I would say analytical:

    select seal_group_id,
    equipment_id,
    effective_date
    from (
    select sge.seal_group_id,
    sge.equipment_id,
    sge.effective_date,
    RANK() over (partition by equipment_id order by effective_date desc) r
    from seal_group_equipment sge,
    seal_group sg
    where equipment_id = 48801
    AND SGE.SEAL_GROUP_ID = SG.SEAL_GROUP_ID
    and sge.end_date is null)
    where r = 1;
    

    Keep in mind if two records have the same effective_date, they would both appear.

    Note: query above has not been tested, since there is no script provided.

  • selecting a field value, which is the most recent CREATE_DATE

    I have two fields in the table CREATE_DATE (Date) and QUEBEC (varchar). How the value of the field for record with the most recent CREATE_DATE? So, if the table contains the following records

    AS CREATE_DATE
    ABCD ON 20/12/2008
    2008-12-21 DEFH
    2009-01-10 ALINE

    I want to request to return ALINE. I now have a query "select table where rownum = 1 order by desc CREATE_DATE. Is there a better way to do it?

    Thank you
    Ravi

    Select from the table where CREATE_DATE = (SELECT MAX (CREATE_DATE) FROM table)

  • How to find the most recent record?

    How to find the most recent record?

    Hello

    It is part of our Bill the elements table, retrieved by the following query:

    SELECT movimento, dt_movimento, cd_material,
    cd_tp_operacao, nf, series,
    sole, pr_unitario
    Of itemfat
    WHERE cd_material IN ('722136', '759177', ' 810725', 818848')
    AND cd_tp_operacao ("' 1102 c ' ', ' 2102 C")
    ORDER BY cd_material,
    dt_movimento


    MOVIMENTO DT_MOVIMENTO CD_MATERIAL CD_TP_OPERACAO NF SERIES AS PR_UNITARIO
    2008-03-11 2137625, 722136 2102 1084738 3 120 2 915
    2588890 08/05/2008 722136-2102 1090987 3 120 2,5615
    755522 09/10/2007 759177-2102 101449 1 200 0.6
    701055 03/10/2007 810725-2102 1013865 1 36 10.9
    1588804 20/12/2007 810725 2102 1014182 1 96 10.9
    1305653 03/12/2007 818848-2102 108555 1 240 6.5
    3102134 07/18/2008 818848 2102 109784 1 360 6.5


    Seems that I whant to retrieve only the most recent records for each item, as:

    MOVIMENTO DT_MOVIMENTO CD_MATERIAL CD_TP_OPERACAO NF SERIES AS PR_UNITARIO
    2588890 08/05/2008 722136-2102 1090987 3 120 2,5615
    755522 09/10/2007 759177-2102 101449 1 200 0.6
    1588804 20/12/2007 810725 2102 1014182 1 96 10.9
    3102134 07/18/2008 818848 2102 109784 1 360 6.5


    Can someone help me with a sentece SQL to do?

    Thanks in advance.

    You can certainly do it:

    SELECT   movimento, dt_movimento, cd_material, cd_tp_operacao, nf, serie,
             quantidade, pr_unitario
        FROM itemfat i
       WHERE cd_material IN ('722136', '759177', '810725', '818848')
         AND cd_tp_operacao IN ('1102C', '2102C')
         AND dt_movimento =
                (SELECT MAX (dt_movimento)
                   FROM itemfat d
                  WHERE d.cd_material = i.cd_material
                    AND d.cd_material IN ('722136', '759177', '810725', '818848')
                    AND d.cd_tp_operacao IN ('1102C', '2102C'))
    ORDER BY cd_material, dt_movimento
    

    : p

  • I did the most recent iOS 10 updated, just heard on the news that Yahoo has been hacked.  I changed my Yahoo email but can't find the field to change on my devices.  It is simply not there, what is happening?

    I did the most recent iOS 10 updated, just heard on the news that Yahoo has been hacked.  I changed my password to Yahoo mail but can't find the field to change the password on my devices.  It is simply not there, what is happening?

    For some reason any change automatically if change you it online. Today, I changed my password through my office and I went to change the mail and she had already changed.

    You can try to delete your account your unit off and add it again.

  • Try to add a page to a pages document. It worked until now but just finished page 13 with text and photos and cannot add another page, using macbook pro with El Capitan and the most recent version of the Pages.

    Try to add a page to a pages document. It worked until now but just finished page 13 with text and photos and cannot add another page, using macbook pro with El Capitan and the most recent version of the Pages.

    You have placed your beam to insert at the end of your text on page 13 and then apply Insert menu: Page Break? In the v5.6.2, Pages I just add a new page to a section of four pages to this approach.

  • I have Firefox 38.2.0 and it tells me that it is the most recent version but online there is version 40 + and it won't let me install it.

    My OS is Windows 10. I have Firefox 38.2.0 and it tells me that it is the most recent version. However, I got emails telling me to upgrade to the latest version which seems to be in the 40s. When I go to the https://www.mozilla.org/en-US/firefox/new/ website, it tells me
    "Looks like you are using an older version of Firefox."

    So I click on upgrade and it loads a file "stub". I close in Firefox, go to the folder where the file is located and run it. At the end of the process, he told me that Firefox still works and I have to close it for the new version to load. Then I go to the Task Manager, and he told me that no request to don't run! I went through this process three times without any positive result.

    What to do?

    I'll answer your question, but I suggest not changing your version of Firefox until find us out if having to do any with your plant, discussed here: https://support.mozilla.org/questions/1078897

    At some point, there are two different versions of Firefox:

    • Public release of the standard/large: currently Firefox 40.0.2
    • Extended support release (ESR): currently Firefox 38.2.0

    The version of ESR is intended for companies who need maximum stability for their users. New features usually are not added for at least six months, although security patches are issued approximately every six weeks.

    You want to switch to the standard version? If so, this is how I suggest to do:

    Clean reinstall it

    We use this name, but it isn't about deleting your settings, this is to ensure that the program, files are clean (not incompatible, corrupt or exotic code files). As described below, this process does not disrupt your existing settings. Don't uninstall NOT Firefox, that does not need.

    (A) download a fresh Installer for Firefox 40.0.2 of https://www.mozilla.org/firefox/all/ in an ideal location. (Scroll down your preferred language).

    (B) the release of Firefox (if any).

    (C) to rename the program folder, either:

    (Windows 64-bit folder names)

    C:\Program Files (x86)\Mozilla Firefox
    

    TO

    C:\Program Files (x86)\FxESR
    

    (Windows 32-bit folder names)

    C:\Program Files\Mozilla Firefox
    

    TO

    C:\Program Files\FxESR
    

    (D) run the installer downloaded to (A). It should automatically connect to your existing settings.

    Note: Some plugins can only exist in the old folder. If it is missing something essential, present in these files:

    • \FxESR\Plugins
    • \FxESR\browser\plugins
  • Can you is more middle - click on the buttons back and forward to open the most recent last/next page as a new tab?

    I use Firefox 26, and I remember at some point in the past you could middle - click on the buttons back and forward to open the most recent last/next page as a new tab. Now, it does not work. I have not changed anything else on Firefox I know works, so was it gradually as keyword.url or is this something else?

    ... OK, this is weird. I restarted Firefox in safe mode and the reworked for/back Middle-click, so I thought it was one of my modules. Yet once, I opened Firefox in normal mode... and Middle-click works.

    I have no idea.

  • Firefox continues to show that I need high-grade firefox but I have the most recent, how to stop it

    Popup message that I need to high-grade, fire fox, already have the most recent in a (No 26). Have uninstalled and reinstalled and still get the message that I need to up grade, have windows 7.

    Whenever you get a message / popup that software / files must be updated.

    DO NOT USE ONE OF THE LINKS PROVIDED.

    If this can be a legitimate message, could also be a Virus or Malware.
    No matter when you want or need to check updates.
    Go to the website of the real owner of the program in question.
    For example, for Firefox, go to Mozilla.org
    or Firefox in any language.

  • Sometimes, I get a notice from a site that Firefox needs an update. When I go into FIrefox, it says that I use the most recent version. What is happening?

    I wonder if these sites are trying to make me download malware or virus. If I go to the Firefox site and it says that I use the most recent version, I think Mozilla tells me and wonder "why a site told me that I have to update? I hope only that Mozilla and not blindly download something without studying. Am I paranoid?

    No, it's a scam which is the link to the site, mozilla does not use a site to ask you to update, it uses an automatic update.

    You can report it here

  • The most recent episode is to Download Stitcher but NOT iTunes?

    So my last episode does not appear on the iTunes store that my 32 other episodes are fine no problem but the most recent is not. I downloaded it almost a week ago so I know this isn't a thing of timing because they are usually no more than a few hours of posting. Stitcher has also the most recent episode so I'm pretty confident that my feed is working.

    Perhaps you have not allowed enough time for the Bank to update. You have perhaps fallen on an intermittent bug in the store. Perhaps there is a mistake in your stream. If you post the URL of your store page and feed there is no way of knowing.

Maybe you are looking for