Für SQL Select * where max (date) < bestimmtes Datum

Hello

I need help to create a SQL statement for the following scenario:

History of the table

Process of Date_updated
Process 125.03.2014
Process 120.03.2014
Process 110.03.2014
Process 210.03.2014
Process 201.03.2014
Process 305.03.2014

I want to get all processes what update is earlier than 15.03.2014.

So, the result would be:

-Process 2-> last update = 10.03.2014

-Process 3-> last update = 05.03.2014

How can I achieve this? with something like where max (date_updated) < = to_date('15.03.2014','dd.mm.yyyy') group by process, it does not work

Try HAVING to place WHERE.

SEPARATE is redundant.

Tags: Database

Similar Questions

  • Select Max (date) between multiple tables

    I need to retrieve a record from a Table in a set of similar tables with a common "date field". You can select the record where this "date field" value is greater between multiple tables.

    Here, any help is appreciated.  Thank you in advance.

    FOR EXAMPLE

    No. EMP is the primary key.

    Again, each table can have multiple records for EMP n ° 1

    TABLE1:

    FIRST NAME

    FAMILY NAME
    THE EMP NO.

    BASE SALARY

    DATE_FROM

    TABLE 2

    FIRST NAME

    FAMILY NAME
    THE EMP NO.

    SALARY GRADE

    DATE_FROM

    TABLE 3

    FIRST NAME

    FAMILY NAME
    THE EMP NO.

    COMPENSATION

    DATE_FROM

    Hello

    Said Knani, if you use the current design of the table, then here is a way to do what you want:

    WITH union_data AS

    (

    SELECT MAX (base_salary) AS sal FROM table1 UNION ALL

    SELECT MAX (grade_salary) table2 UNION ALL

    SELECT MAX (compensation) FROM table3

    )

    SELECT MAX (sal) AS max_sal

    Of union_data

    ;

  • ORA-28500 + 'String data, right truncation' when selecting nvarchar (max)

    Hello

    I was able to put in place a db Oracle 11.2.0.1 link to SQL Server 2005 using DG4ODBC.

    When you try to select a column with the data type of nvarchar (max) in the db link I get the following error:
    ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
    [Microsoft][SQL Native Client]String data, right truncation {01004}[Microsoft][SQL Native Client]String data, right truncation {01004}[Microsoft][SQL Native Client]String data, right truncation {01004}[Microsoft][SQL Native Client]String data, right truncation {01004}[Microsoft][SQL Native Client]String data, right truncation {01004}
    ORA-02063: preceding 2 lines from SQLSERVER_DBLINK
    The actual data in the column do not exceed 31 characters, but the application still does not work.

    Any suggestions?
    Thank you.

    checked with DataDirect ODBC driver that returns for col2 = nvarchar (max) and col3 = varchar (max)

    Entry hgopcda at 2010/12/23-11: 55:17
    Column:2 (col2): dtype:-10 (WLONGVARCHAR), prc / scl:1073741823 / 0, nullbl:1, radix: 0 byte: 2147483647, sign: 1
    Out of hgopcda, rc = 0 to 2010/12/23-11: 55:17
    SQLFetch ENTER [1 args]
    I [0] StatementHandle: h0x0816ff40
    ---> RC = 0 (TRC = 0)
    OUTPUT SQLFetch [1 args]
    I [0] StatementHandle: h0x0816ff40
    Entry hgopcda at 2010/12/23-11: 55:17
    Column:3 (col3): dtype:-1 (LONGVARCHAR), prc / scl:2147483647 / 0, nullbl:0, radix: 0 byte: 2147483647, sign: 1
    Out of hgopcda, rc = 0 to 2010/12/23-11: 55:17

    This driver correctly fills the buffer (0 no equal) and function of the buffer the gateway decided to map it to:
    DTY NULL-OK LEN MAXBUFLEN PR/SC CSE IND MOD NAME
    12 Y VARCHAR 20 20 0 / 0 0 0 200 col1
    -1 LONGVARCHAR Y 0 0 0 / 0 0 0 220 col2
    -1 LONGVARCHAR Y 0 0 0 / 0 0 0 220 col3

    and in Oracle when performing a describe statement I see the column as LONG.

    This type of mapping from nvarchar to LONGVARCHAR works in Dg4ODBC if the Oracle DB character set = Unicode. => and you meet this requirement.

    ==>> If it looks like a driver problem, and it might be useful to use a different driver.

    Published by: kgronau on December 23, 2010 12:02

  • Select with the DATE WHERE the...

    Hi all!

    I need to select with where condition on cirtain cust_date date (date) specifying columns say date01 = 25 August 10 'and time range somewhere between time01 = 7:15:00 ' and time2 = 9:30:00 ' ('HH24:MI:SS).
    I have some test data and I saw still some trouble with my select particular regarinding of time slot.

    Can someone tell me what will be the easiest way to do this, especially for the begiinner;

    SELECT * FROM TABLE1 WHERE cust_date > to_date (August 25, 2010 7:15:00 ',' DD-MON-YY HH24:MI:SS')...

    I just do to_date after >?


    TX
    Trent

    Trento wrote:
    Hi all!

    I need to select with where condition on cirtain cust_date date (date) specifying columns say date01 = 25 August 10 'and time range somewhere between time01 = 7:15:00 ' and time2 = 9:30:00 ' ('HH24:MI:SS).
    I have some test data and I saw still some trouble with my select particular regarinding of time slot.

    Can someone tell me what will be the easiest way to do this, especially for the begiinner;

    SELECT * FROM TABLE1 WHERE cust_date > to_date (August 25, 2010 7:15:00 ',' DD-MON-YY HH24:MI:SS')...

    I just do to_date after >?

    TX
    Trent

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/functions183.htm#SQLRF06132

    Connected to Oracle Database 11g Enterprise Edition Release 11.1.0.7.0
    Connected as SYS
    
    SQL> desc SH.SALES
    Name          Type         Nullable Default Comments
    ------------- ------------ -------- ------- -------------------------------------------------------------------------------------------
    PROD_ID       NUMBER                        FK to the products dimension table
    CUST_ID       NUMBER                        FK to the customers dimension table
    TIME_ID       DATE                          FK to the times dimension table
    CHANNEL_ID    NUMBER                        FK to the channels dimension table
    PROMO_ID      NUMBER                        promotion identifier, without FK constraint (intentionally) to show outer join optimization
    QUANTITY_SOLD NUMBER(10,2)                  product quantity sold with the transaction
    AMOUNT_SOLD   NUMBER(10,2)                  invoiced amount to the customer                                                             
    
    SQL>
    SQL> SELECT *
      2  FROM SH.SALES S
      3  WHERE S.TIME_ID >= to_date('19970102','YYYYMMDD')
      4  AND ROWNUM < 4
      5  ;
    
       PROD_ID    CUST_ID TIME_ID     CHANNEL_ID   PROMO_ID QUANTITY_SOLD  AMOUNT_SOLD
    ---------- ---------- ----------- ---------- ---------- ------------- ------------
            37        368 01/01/1998           2        999          1.00        63.57
            37       4687 01/01/1998           2        999          1.00        63.57
            37       8302 01/01/1998           2        999          1.00        63.57
    SQL>  SELECT *
      2  FROM SH.SALES S
      3  WHERE S.TIME_ID >= to_date('19970102 10:12:00','YYYYMMDD HH24:MI:SS')
      4  AND S.TIME_ID < to_date('20000102 10:12:00','YYYYMMDD HH24:MI:SS')
      5  AND ROWNUM < 4
      6  ;
    
       PROD_ID    CUST_ID TIME_ID     CHANNEL_ID   PROMO_ID QUANTITY_SOLD  AMOUNT_SOLD
    ---------- ---------- ----------- ---------- ---------- ------------- ------------
            37        368 01/01/1998           2        999          1.00        63.57
            37       4687 01/01/1998           2        999          1.00        63.57
            37       8302 01/01/1998           2        999          1.00        63.57
    
    SQL> 
    
    SQL>
    SQL>  SELECT *
      2  FROM SH.SALES S
      3  WHERE S.TIME_ID >= to_date('January 15, 1989, 11:00:00','Month dd, YYYY, HH:MI:SS',
      4       'NLS_DATE_LANGUAGE = American')
      5  AND S.TIME_ID < to_date('January 15, 2000, 11:00:00','Month dd, YYYY, HH:MI:SS',
      6       'NLS_DATE_LANGUAGE = American')
      7  AND ROWNUM < 4
      8  ;
    
       PROD_ID    CUST_ID TIME_ID     CHANNEL_ID   PROMO_ID QUANTITY_SOLD  AMOUNT_SOLD
    ---------- ---------- ----------- ---------- ---------- ------------- ------------
            37        368 01/01/1998           2        999          1.00        63.57
            37       4687 01/01/1998           2        999          1.00        63.57
            37       8302 01/01/1998           2        999          1.00        63.57
    
    SQL>
    SQL> SELECT *
      2  FROM SH.SALES S
      3  WHERE S.TIME_ID >= to_date('14-Feb-1998 11:00:00','DD-Mon-YYYY HH24:MI:SS',
      4       'NLS_DATE_LANGUAGE = American')
      5  AND S.TIME_ID < to_date('17-Mar-2000 11:00:00','DD-Mon-YYYY HH24:MI:SS',
      6       'NLS_DATE_LANGUAGE = American')
      7  AND ROWNUM < 4
      8  ;
    
       PROD_ID    CUST_ID TIME_ID     CHANNEL_ID   PROMO_ID QUANTITY_SOLD  AMOUNT_SOLD
    ---------- ---------- ----------- ---------- ---------- ------------- ------------
            36       2168 15/02/1998           3        999          1.00        51.29
            36       7237 15/02/1998           3        999          1.00        51.29
            36       7678 15/02/1998           3        999          1.00        51.29
    
    SQL>  
    
  • Select the year max and max date for a code

    Hello

    I need to extract max year and month max for one code particulare.

    My table contains:

    YEAR MONTH CODE

    ====   =====    ====

    2014 6 X

    2014 7 X

    2013 5 Y

    2013 6 Y


    I need to extract:


    2014 7 X

    2013 6 Y


    I don't like max(YEAR|| le mois), I want the column separated.


    Thank you

    Try this:

    WITH test_data AS (
      SELECT 2014 AS yr, 6 AS mth, 'X' AS code FROM DUAL
      UNION ALL
      SELECT 2014 AS yr, 7 AS mth, 'X' AS code FROM DUAL
      UNION ALL
      SELECT 2013 AS yr, 5 AS mth, 'Y' AS code FROM DUAL
      UNION ALL
      SELECT 2013 AS yr, 6 AS mth, 'Y' AS code FROM DUAL
    )
    SELECT yr
         , MAX(mth) KEEP (DENSE_RANK FIRST ORDER BY 100*yr+mth DESC) AS mth
         , MAX(code) KEEP (DENSE_RANK FIRST ORDER BY 100*yr+mth DESC) AS code
    FROM   test_data
    GROUP BY yr
    ORDER BY 1;
    

    Obviously by storing your dates as the DATE, then ranked by who would be more elegant!

  • Select Max (Date) in two different tables...

    Dear all,

    I need the date of last update of two different tables, I mean max (date). We will update one table at a time. Updated once I need to take the last update.

    It can be either in table A table B.

    for example.

    Table A

    Date of the ID

    100 16/05/2014

    101 20/05/2014

    102, 22/05/2014

    Table B

    Date of the ID

    100 04/06/2014

    101, 26/05/2014

    102 21/05/2014

    I need the date of table B (101 26/05/2014) last updated date...

    Hello

    Another way, using much more GRAND:

    SELECT LARGER (max1, max2) x

    FROM (SELECT MAX (mydate) max1

    OF mytable_a

    )

    (SELECT MAX (myotherdate) max2

    OF mytable_b

    )

    ;

    Best regards

    Bruno Vroman.

  • Cannot find the MAX Date value in the USER_TAB_PARTITIONS HIGH_VALUE

    Hi all

    I'll try to find the Max value of the date of the HIGH_VALUE from the USER_TAB_PARTITIONS, but my request has failed because the HIGH_VALUE is a LONG column.

    Appreciate your valuable contributions here.

    Thank you
    MK.

    Maldini says:
    I'll try to find the Max value of the date of the HIGH_VALUE

    You use the PL/SQL:

    SQL> select  high_value
      2    from  user_tab_partitions
      3    where table_name = 'RANGE_SALES'
      4  /
    
    HIGH_VALUE
    ----------------------------------------------------------------------------------------------
    TO_DATE(' 1998-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 1998-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 1998-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 1999-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 1999-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 1999-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 1999-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 2000-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 2000-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 2000-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TO_DATE(' 2000-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    
    HIGH_VALUE
    ----------------------------------------------------------------------------------------------
    MAXVALUE
    
    12 rows selected.
    

    Now:

    create or replace
      type DateList
        as
          table of date
    /
    declare
        v_DateList DateList := DateList();
        v_max_high_value date;
    begin
        for v_rec in (select high_value from user_tab_partitions where table_name = 'RANGE_SALES') loop
          if v_rec.high_value != 'MAXVALUE'
            then
              v_DateList.extend;
              execute immediate 'begin :1 := ' || v_rec.high_value || '; end;'
                using out v_DateList(v_DateList.count);
          end if;
        end loop;
        select  max(column_value)
          into  v_max_high_value
          from  table(v_DateList);
        dbms_output.put_line('Table RANGE_SALES max high value is ' || to_char(v_max_high_value,'MM/DD/YYYY HH24:MI:SS'));
    end;
    /
    Table RANGE_SALES max high value is 10/01/2000 00:00:00
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

  • Need help with SQL selection ID when the sequence does not match...

    I have the following dilemma:
    Database identifiers as follows:
    Incident #, case #, & sequence manufacturer
    example of
    Record 1
    Incident_Number = 123456
    Case_Number = 1
    Part_sequence = 1

    Worksheet 2
    Incident_Number = 123456
    Case_Number = 1
    Part_sequence = 2

    Sometimes the user will delete (say) 2 Record after creating a new Record 3
    The sequencing will therefore now as follows:

    Record 1
    Incident_Number = 123456
    Case_Number = 1
    Part_sequence = 1

    Worksheet 2
    Incident_Number = 123456
    Case_Number = 1
    Part_sequence = 3

    Now it is no longer a Part_Sequence 2

    Need a SQL to select all records where the sequence of the maximum part > than Incident_number County | » -'|| Case_number

    I tried the following:
    select a.incident_number||'-'||a.case_number||'-'||a.part_sequence
    from chsuser.a_compl_summary a
    where a.entry_date >= '01-may-2011'
    and max(a.part_sequence) > count(distinct a.incident_number||'-'||a.case_number)
    I end up getting an ORA-00934: Group feature is not allowed here (emphasis on the portion (a.part_sequence) Max.

    Advice/suggestions

    Thank you
    select  incident_number || '-' || case_number || '-' || part_sequence
      from  (
             select  incident_number,
                     case_number,
                     part_sequence,
                     max(part_sequence) over(partition by incident_number,case_number) max_seq,
                     count(*) over(partition by incident_number,case_number) cnt
               from  chsuser.a_compl_summary
               where entry_date >= DATE '2011-05-01'
            )
      where cnt != max_seq
    /
    

    SY.

  • nth Max date table...

    Hi all

    I want 4th date max to a table.

    Example:
    I have some report_date in the picture.
    I can get date max using max (report_date), but how to get the next date of max like this... I want the date 4 th max.

    Thank you
    Angelique

    something like?

    SQL> select *
      2    from (
      3  select ename
      4       , hiredate
      5       , rank() over (order by hiredate desc) rn
      6    from emp
      7  )
      8   where rn = 4
      9  /
    
    ENAME      HIREDATE          RN
    ---------- --------- ----------
    JAMES      03-DEC-81          4
    FORD       03-DEC-81          4
    
  • Select the last date

    Hello

    I have a table that looks like this:

    no date of activity
    1 sport 2008-11-23
    2 bike 12/15/2008
    3-Dy free 01/05/2009


    How to choose the last day in the table above? I tried this:

    Select the activity of tbl_above
    where < < date is the last > >

    I want back the 'activity' only, so I got to put the 'check' the ' where clause'

    Any idea?

    Please see this...

    SQL > select * from emp;

    EMPNO, ENAME, JOB HIREDATE DEPTNO COMM SAL MGR
    ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
    7369 SMITH COMMITTED 7902 17 DECEMBER 20 800 80
    7499 ALLEN 7698 1600 20 FEBRUARY SALESMAN 81 300 30
    7521 WARD 7698 1250 22 FEBRUARY SALESMAN 81 500 30
    7566 JONES MANAGER 7839 2975 2 APRIL 81 20
    7654 MARTIN 7698 28 - SEP - 81 1250 1400 30 SALESMAN
    7698 BLAKE MANAGER 7839 2850 MAY 1, 81 30
    7782 CLARK MANAGER 7839 2450 JUNE 9 81 10
    7788 SCOTT ANALYST 7566 3000 APRIL 19, 87 20
    PRESIDENT OF 7839 17 NOVEMBER KING 81 5000 10
    7844 TURNER 7698 08 - SEP - 81 1500 0 30 SALESMAN
    7876 ADAMS 7788 1100 23 MAY CLERK 87 20

    EMPNO, ENAME, JOB HIREDATE DEPTNO COMM SAL MGR
    ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
    7900 7698 DECEMBER 3, CLERK JAMES 81 950 30
    7902 7566 3000 3 DECEMBER ANALYST FORD 81 20
    7934 MILLER COMMITTED JANUARY 7782 1300 23 82 10
    1-1-10

    15 selected lines.

    SQL > select empno from emp where hiredate = (select max (hiredate) from emp);

    EMPNO
    ----------
    7876

    SQL >

    Concerning

  • How to select the csv data stored in a BLOB column as if it were an external table?

    Hi all

    (Happy to be back after a while! )

    Currently I am working on a site where users should be able to load the data of csv (comma is the separator) of their client machines (APEX 3.2 application) in the Oracle 11.2.0.4.0 EE database.

    My problem is:

    I can't use an external table (for the first time in my life ) so I'm a little clueless what to do as the csv data is stored by the application of the APEX in a BLOB column, and I'm looking for an elegant way (at least SQL PL/SQL/maximization) to insert the data into the destination table (run validations by a MERGER would be the most effective way to do the job).

    I found a few examples, but I think they are too heavy and there could be a more elegant way in Oracle DB 11.2.

    Simple unit test:

    drop table CBC purge;

    drop table dst serving;

    create table src

    (myblob blob

    );

    create table dst

    (num number

    , varchar2 (6) str

    );

    Insert in src

    Select utl_raw.cast_to_raw (1; AAAAAA ;'|| Chr (10) |

    2; BATH; »

    )

    Double;

    Desired (of course) output based on the data in table SRC:

    SQL > select * DST;

    NUM STR

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

    1 ABDELKRIM

    2 BATH

    Does anybody know a solution for this?

    Any ideas/pointers/links/examples are welcome!

    / * WARNING: I was 'off' for about 3 months, then the Oracle - the part of my brain has become a bit "rusty and I feel it should not be so complicated as the examples I've found sofar ' * /"

    Haha, wonder about regexp is like the blind leading the blind!

    However, it's my mistake: I forgot to put the starting position setting (so 1, 2, 3,... was in fact the starting position, not the nth occurrence. duh!)

    So, it should actually be:

    select x.*
    ,      regexp_substr(x.col1, '[^;]+', 1, 1)
    ,      regexp_substr(x.col1, '[^;]+', 1, 2)
    ,      regexp_substr(x.col1, '[^;]+', 1, 3)
    ,      regexp_substr(x.col1, '[^;]+', 1, 4)
    ,      regexp_substr(x.col1, '[^;]+', 1, 5)
    ,      regexp_substr(x.col1, '[^;]+', 1, 6)
    from  src
    ,      xmltable('/a/b'
                  passing xmltype(''||replace(conv_to_clob(src.myblob), chr(10), '')||'')
                  columns
                    col1 varchar2(100) path '.') x;
    

    Note: that's assuming that all the "columns" passed in the string won't be lame.

    If one of them might be null, then:

    select x.*
    ,      regexp_substr(ltrim(x.col1, ';'), '[^;]+', 1, 1)
    ,      regexp_substr(ltrim(x.col1, ';'), '[^;]+', 1, 2)
    ,      regexp_substr(ltrim(x.col1, ';'), '[^;]+', 1, 3)
    ,      regexp_substr(ltrim(x.col1, ';'), '[^;]+', 1, 4)
    ,      regexp_substr(ltrim(x.col1, ';'), '[^;]+', 1, 5)
    ,      regexp_substr(ltrim(x.col1, ';'), '[^;]+', 1, 6)
    from   src
    ,      xmltable('/a/b'
                  passing xmltype(replace(';'||replace(conv_to_clob(src.myblob), chr(10), ';')||'', ';;', '; ;'))
                  columns
                    col1 varchar2(100) path '.') x;
    
  • ODI - SQL for Hyperion Essbase data loading

    Hello

    We have created a 'vision' in SQL Server that contains our data.  The view currently has every year and periods of Jan 2011 to present.  Each period is about 300 000 records.  I want to only load one period at a time.  For example may 2013.  Currently we use ODBC through a rule of data loading, but the customer wants to use ODI to be compatible with the versions of dimension metadata.  Here's the SQL on the view that works very well.   Is there a way I can run this SQL in the ODI Interface so it pulls only what I declare in the Where clause?  If yes where can I do it?

    Select

    CATEGORY, YEAR, LOCATION, SCRIPT, DEPT, PROJECT, EXPCODE, TIME, ACCOUNT, AMOUNT

    Of

    PS_LHI_HYP_PRJ_ACT

    Where

    YEAR > = "2013" AND PERIOD = 'MAY '.

    ORDER BY CATEGORY ASC ASC FISCAL_YEAR, LOCATION ASC, ASC, ASC, ASC, ASC, PERIOD EXPCODE PROJECT DEPT SCENARIO CSA ACCOUNT CSA;

    Hello

    Simply use the following KM to load data - IKM SQL for Hyperion Essbase (DATA) - in an ODI interface that has the view that you created the Source model. You can add filters to the source which are dynamically by ODI variables to create the Where clause based on the month and year. Make sure you only specify a rule of load method to load the data into the KM

  • selection of the dates not used for the list

    OK, the last one for today...

    I'm trying to fill a list with values of the month years between the first entry in the table and the month previous (sysdate - 1 month).

    At the moment I have this, which will select every month between the last entry in the table and sysdate-1.
    select to_char( add_months( start_date, level-1 ), 'MON-YY' ) d, to_char( add_months( start_date, level-1 ), 'MON-YY' ) r
    from (select add_months(max(date_received),1) start_date, add_months(sysdate, -1) end_date from localdata) where start_date < end_date
    connect by level <= months_between(trunc(end_date,'MM'), trunc(start_date,'MM') ) + 1
    But I want it uses the first entry and select all the months between then and sysdate-1 where there is no entry in the table.

    I tried something like that, but it returned no data:
    select to_char( add_months( start_date, level-1 ), 'MON-YY' ) d, to_char( add_months( start_date, level-1 ), 'MON-YY' ) r
    from (select min(date_received) start_date, add_months(sysdate, -1) end_date from localdata) where start_date < end_date and to_char(start_date, 'MON-YY') not in (select to_char(date_received, 'MON-YY') from localdata)
    connect by level <= months_between(trunc(end_date,'MM'), trunc(start_date,'MM') ) + 1

    Hello

    pearlyred wrote:
    Thanks for the comment tip, it works great now. I just need how to sort date wise.

    If missing_month is a string, such as "JAN-2013", then it's not good for sorting, since the string "JAN-2013" come after "FEB-2013"(et aussi après «FEB-2014"et «FEB-2015") because 'J' comes after 'F'. "»»» If you want to sort, and then keep the month as a DATE, like this:

    WITH     got_missing_month_s     AS
    (
         SELECT     ADD_MONTH first_month, LEVEL - 1)     AS missing_month_s
         FROM     (
                   SELECT TRUNC ( MIN (date_received)
                                           , 'MONTH'
                                  )          AS first_month
                   FROM   localdata
              )
         CONNECT BY     LEVEL     <= MONTHS_BETWEEN ( SYSDATE
                                                 , first_month
                                          )
        MINUS
            SELECT  TRUNC (date_received, 'MONTH')
         FROM     localdata
    )
    SELECT       TO_CHAR (missing_month_s, 'MON-YYYY')     AS missing_month_d
    ,       missing_month_s
    FROM       got_missing_month_s
    ORDER BY  missing_month_s
    ;
    

    The main request has 2 columns:
    missing_month_d is for display: it's a string such as "JAN-2013".
    missing_month_s is for sorting: it's a DATE.

  • Select table Max

    Dear all,

    I have table userstat

    CREATE_DATE USERNAME REPLY_MESG
    27/10/2012 10:10:10 ABC FAILED
    27/10/2012 10:20:10 ABC FAILED
    27/10/2012 10:30:10 ABC SUCCESS
    27/10/2012 09:08:23 SUCCESS XYZ
    27/10/2012 10:08:23 XYZ has NOT-> SELECT THIS LINE
    27/10/2012 09:08:23 DEF FAILED
    27/10/2012 10:08:23 DEF FAILED
    27/10/2012 12:08:23 DEF FAILED-> SELECT THIS LINE


    OUTPUT MUST BE
    27/10/2012 10:08:23 XYZ FAILED
    27/10/2012 12:08:23 DEF FAILED

    Thanks in advance.

    Test data:

    create table USERSTAT (CREATE_DATE, USERNAME, REPLY_MESG) as select
    TO_DATE('27-10-2012 10:10:10', 'dd-mm-yyyy hh24:mi:ss'), 'ABC', 'FAILED' from DUAL union all select
    TO_DATE('27-10-2012 10:20:10', 'dd-mm-yyyy hh24:mi:ss'), 'ABC', 'FAILED' from DUAL union all select
    TO_DATE('27-10-2012 10:30:10', 'dd-mm-yyyy hh24:mi:ss'), 'ABC', 'SUCCESS' from DUAL union all select
    TO_DATE('27-10-2012 09:08:23', 'dd-mm-yyyy hh24:mi:ss'), 'XYZ', 'SUCCESS' from DUAL union all select
    TO_DATE('27-10-2012 10:08:23', 'dd-mm-yyyy hh24:mi:ss'), 'XYZ', 'FAILED' from DUAL union all select
    TO_DATE('27-10-2012 09:08:23', 'dd-mm-yyyy hh24:mi:ss'), 'DEF', 'FAILED' from DUAL union all select
    TO_DATE('27-10-2012 10:08:23', 'dd-mm-yyyy hh24:mi:ss'), 'DEF', 'FAILED' from DUAL union all select
    to_date('27-10-2012 12:08:23', 'dd-mm-yyyy hh24:mi:ss'), 'DEF', 'FAILED' from dual;
    

    Solution:

    select * from (
      select USERNAME, max(CREATE_DATE) CREATED_DATE,
      max(REPLY_MESG) keep (dense_rank last order by CREATE_DATE) reply_mesg
      from USERSTAT
      group by USERNAME
    )
    where reply_mesg = 'FAILED';
    
    USERNAME CREATED_DATE REPLY_MESG
    -------- ------------ ----------
    DEF      10/27/2012   FAILED
    XYZ      10/27/2012   FAILED
    

    Explanation: you seem to be the most recent record for each user name. If you want just the most recent date, max (create_date) would be enough, but you also need the response message. The DUNGEON (DENSE_RANK LAST function basically said 'Give me the response message which corresponds to the last CREATE_DATE', which is what you want.

    Note Please I am simplifying here: there may be multiple records with the last CREATE_DATE, that's why it is a function of aggregation , with max() around REPLY_MESG.

    The final WHERE clause keeps records where the last response message was 'IMPOSSIBLE '.

    Documentation: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions065.htm#SQLRF00641

  • filling of datetime column SQL Server with the data in the date column oracle

    After a lot of "finangling", I think I have my link dg4msql works well between Oracle and MSSQL.

    Now, what I'm trying to do, is fill a table in MSSQL with an Oracle table column values, whenever a new row is inserted in the Oracle table. I use a very simple trigger on the oracle table that goes basically like this:

    mware is dblink to MSSQL database, oracle col worth DATE and mssql col is of type DATETIME

    This is the relaxation: (edited to show only the column in question)
    ==================================================================================
    CREATE or replace TRIGGER < oracleowner >. INSERT_INTO_NVDB
    AFTER INSERT ON < oracleowner >. < oracletable > for each row
    BEGIN
    insert into '< mssqlowner > '. «< mssqltable > @mware «»
    (
    "load_date_time,"
    )
    VALUES)
    : new.loading_date,.
    );

    END;
    ==================================================================================

    Now, when you enter a record in the Oracle trigger triggers ok table but does not insert a date in the MSSQL table, the 'load_date_time' in the mssql table can have NULL values so I guess there just inserts a null value.

    When I activate the triggers on the table MSSQL, which then takes these values and inserts them into another table with values from other tables, inserting in the Oracle table fails because the relaxation on the MSSQL database tries to pass the date (which is empty) table MSSQL in another table where the datetime field is not null.

    I guess it's because Oracle date format is not compatible with MSSQL, which I think is "yyyy-mm-dd hh: mm:"- so I have to either convert the date format by default Oracle to match a MSSQL, or convert a char of the trigger value. (The developer of the side MSSQL says if I can convert it to a char value that should be ok too)

    I think that it is probably better to leave it in the date format, the best way to do this would be to put an "alter session set nls_date_format ="at the beginning of the trigger?

    Can I convert the date to char the trigger easily? If there is a better way to proceed in the way I approach it I'm all for it.

    Thank you!

    Hello
    Your best option is to explicitly convert dates Oracle in a format recognized by SQL * Server. It's more coding, but then you know exactly what is being inserted and you give more control, if anything changes. You can also code to handle null data.
    I'm not sure than to try to change the format of date to 'alter session... ". "do what you want.
    You can use "to_char" on a date into character data-

    To_char (, "HH24:MI:SSxFF of MON-DD-YYYY")

    and use any mask format supported.
    You also use 'to_date' to transform the character data in a date format, as well as 'to_char' and 'to_date' in combination.
    For example -.

    SELECT TO_CHAR (TO_DATE (October 27, 98 ',' DD-MON-RR'), 'YYYY') 'Year' FROM DUAL;

    This is all discussed in the documentation-

    Oracle® database
    SQL language reference
    11g Release 2 (11.2)

    where it also describes the different format masks.
    If you need further assistance on the use of to_date, to_char formats then ask in the forum SQL/PLSQL.

    SQL and PL/SQL

    where they have more experience.

    Kind regards
    Mike

Maybe you are looking for