date = sysdate-18 max in where clause!

Hi all

Please,

My request is I have a lot of mit_date for a perticular stu_name and I wanted to max (mit_date), but this mit_date should not be in the last 18 months of sysdate.

Here's what I wanted to say as a query

SELECT MAX (MIT_DATE), STU_NAME FROM USA_MIT_TBL WHERE MIT_DATE < = (SYSDATE-18) - it's what I dream.
or
Select mit_date, stu_name from mit_usa_tbl where mit_date =)
Select MAX (MIT_DATE) in the USA_MIT_TBL UD UD WHERE. MIT_DATE < = (SYSDATE-18))-IS ALSO NOT feasible
the current data as follows

I have a stu_name like John Smith, who mit_date as follows
20/01/2001
20/01/2002
20/01/2007
2008-01-20. This perticular stu_name, I'm looking for the date "20/01/2007" is not with 18 months of sysdate and which is max (mit_date)-01/20/2001 and 01/20/2002.

Note:-this table has more than one stu_name

Somone please help me in this.
appreciate any help.
SQL> create table t (stu_name,mit_date)
  2  as
  3  select 'John Smith', date '2001-01-20' from dual union all
  4  select 'John Smith', date '2002-01-20' from dual union all
  5  select 'John Smith', date '2007-01-20' from dual union all
  6  select 'John Smith', date '2008-01-20' from dual union all
  7  select 'Another Name', date '2003-01-01' from dual union all
  8  select 'Another Name', date '2007-01-01' from dual union all
  9  select 'Another Name', date '2007-04-01' from dual union all
 10  select 'Another Name', date '2007-07-01' from dual union all
 11  select 'Another Name', date '2007-10-01' from dual
 12  /

Tabel is aangemaakt.

SQL> select stu_name
  2       , max(mit_date)
  3    from t
  4   where mit_date <= add_months(sysdate,-18)
  5   group by stu_name
  6  /

STU_NAME     MAX(MIT_DATE)
------------ -------------------
John Smith   20-01-2007 00:00:00
Another Name 01-04-2007 00:00:00

2 rijen zijn geselecteerd.

Kind regards
Rob.

Tags: Database

Similar Questions

  • using max in where clause

    Hi all

    I have data that looks like this.

    PLAN_INSTANCE DATE_START, DATE_END TOTALS PLAN

    1007 1 20150101 20151231 10

    1007 2 20140101 20141231 25

    1007 3 20130101 20131231 12

    1008 1 20150101 20151231 22

    1008 2 20140101 20141231 9

    I would like you run a query that displays one line per plan based on max (date_start).

    I tried

    Select the total plan, t.date_start, date_end,

    of t_totals t

    where t.date_start= (select max (date_start)

    of t_totals

    where date_start= t.date_start);

    but this does not seem to work that I get all the 5 rows instead of 2 rows.

    Can you suggest me how can I change my query?

    Here is the information of table

    CREATE TABLE T_TOTALS

    (

    PLAN NUMBER (9) NOT NULL,

    PLAN_INSTANCE NUMBER 4 NOT NULL,.

    DATE_START NUMBER (8) NOT NULL,

    DATE_END NUMBER (8) NOT NULL,

    NUMBER (9) TOTALS NOT NULL,.

    );

    CREATE A UNIQUE I_TOTALS ON T_TOTALS INDEX

    (SAK_PUB_HLTH, SAK_SHORT);

    CREATE INDEX X_TOTALS_1 ON T_TOTALS

    (SAK_PUB_HLTH, DTE_EFFECTIVE);

    Thanks in advance,

    sqlamateur

    Hello

    2886750 wrote:

    Hi Pam,.

    I would like to see the data set that results must be displayed

    PLAN DATE_START, DATE_END TOTALS

    1007 20150101 20151231 10

    1008 20150101 20151231 22

    How to modify the query to get the data above?

    The solution you provided still shows all lines instead of simply max lines (date_start).

    Thank you

    Really?  It seems that the Pam should return only 1 package date_start.  Of course, we can not really test without valid CREATE TABLE and INSERT statements, but here's a query using the table scott.emp (which we all have, or can get easily) that uses the same approach:

    SELECT ename, deptno, hiredate - you could include all the columns you want

    FROM scott.emp m

    WHERE hiredate =)

    SELECT MAX (s.hiredate)

    FROM scott.emp s

    WHERE s.deptno = m.deptno

    )

    ORDER BY deptno

    ;

    This query returns all the 14 rows of table scott.emp; She returned only 3 lines that were later hiredate in each of the 3 deptnos:

    ENAME HIREDATE DEPTNO

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

    MILLER 10 January 23, 1982

    ADAMS 20 23 May 1987

    JAMES 30 December 3, 1981

  • Problem with the creation of date range with PL/SQL WHERE clause

    Hello, everyone:

    I'm unable to develop and the SQL statement to filter records today and seven days back. My condition is as follows:
     from  wsualumni.wsu_online_giving_table
           --where ALM_OG_ACTIVITY_DATE >= ALM_OG_ACTIVITY_DATE - 7
           where ALM_OG_ACTIVITY_DATE >= SYSDATE - 7
           and ALM_OG_CAMPAIGN_CODE = 'MED' 
           OR ALM_OG_CAMPAIGN_CODE = 'MED1';
    I think I'm to mess with the (to_char (ALM_OG_ACTIVITY_DATE, ' mm/dd/yyyy ' ")) statement.

    The actual code is below to:
    set serveroutput ON SIZE 1000000
    set heading off                
    set feedback off                
    set trimspool off               
    set echo off                    
    set pagesize 0                  
    
    DECLARE
        v_data_line_hdr      varchar2(1000);
        v_data_file          varchar2(80);
        v_sch_code            varchar2(10);
        v_instance_name       varchar2(10);
        ws_path            payroll.pybutfl.pybutfl_utl_file_path%TYPE; 
        v_data_line           VARCHAR2 (4000)                              := NULL;
        fhandle_o             UTL_FILE.file_type;
        v_line_count          NUMBER                                       := 0;
        v_selected_count      NUMBER                                       := 0;
        v_error_count         NUMBER                                       := 0;
        v_written_count       NUMBER                                       := 0;
        v_error_text          VARCHAR2 (50)       := ' Unable to write the line. ';
        v_errm                VARCHAR2 (255);
        v_sqlerrm             VARCHAR2 (255);
    
    
    CURSOR C1 IS
    
    select RTRIM
        (
        ALM_OG_ID                                           ||'|'||                                                                 
        NULL                                                ||'|'||   
        (to_char(ALM_OG_AMOUNT, '999,999.99'))              ||'|'||            
        'Cash'                                              ||'|'||             
        'Credit Card'                                       ||'|'||             
        (to_char(ALM_OG_ACTIVITY_DATE, 'mm/dd/yyyy'))       ||'|'||                    
        ALM_OG_ACCI_CODE                                    ||'|'|| 
        'On-Line Giving'                                    ||'|'||       
        'On-Line giving'                                    ||'|'||    
        ALM_OG_HONOR_MEM_NAME                               ||'|'||        
        NULL                                                ||'|'||   
        'Do not post'                                       ||'|'|| 
        'StandardThankYou'                                  ||'|'||  
        'Not Acknowledged'                                  ||'|'||        
        'Do not receipt'                                    ||'|'||      
        NULL                                                ||'|'|| 
        'Banner Gift Number'                                ||'|'|| 
        ALM_OG_BANNER_GIFT_NO ||'.'|| ALM_OG_ACCI_CODE      ||'|'|| 
        (to_char(ALM_OG_ACTIVITY_DATE, 'mm/dd/yyyy'))       ||'|'|| 
        NULL                                                ||'|'|| 
        'Web ID'                                            ||'|'|| 
        ALM_OG_WEBID                                        ||'|'|| 
        NULL                                                ||'|'|| 
        'Source'                                            ||'|'||  
        ALM_OG_CAMPAIGN_CODE                                ||'|'||
        'On-Line Giving'    ) data_line 
        
           
           from  wsualumni.wsu_online_giving_table
           --where ALM_OG_ACTIVITY_DATE >= ALM_OG_ACTIVITY_DATE - 7
           where ALM_OG_ACTIVITY_DATE >= SYSDATE - 7
           and ALM_OG_CAMPAIGN_CODE = 'MED' 
           OR ALM_OG_CAMPAIGN_CODE = 'MED1';
           
           
           
     CURSOR C2 IS
     
     select RTRIM(
                    'ConsID'        ||'|'||
                    'GFImpID'       ||'|'||
                    'GFTAmt'        ||'|'||
                    'GFType'        ||'|'||
                    'GFPayMeth'     ||'|'||
                    'GFDate'        ||'|'||
                    'FundID'        ||'|'||
                    'CAMPID'        ||'|'||
                    'GFAppeal'      ||'|'||
                    'GfRef'         ||'|'||
                    'GfPostDate'    ||'|'||
                    'GfPostStatus'  ||'|'||
                    'GfltrCode'     ||'|'||
                    'GfAck'         ||'|'||
                    'GfRcpt'        ||'|'||
                    'GfAttrlmpID00' ||'|'||
                    'GfAttrCat00'   ||'|'||
                    'GfAttrdesc00'  ||'|'||
                    'GfAttrDate00'  ||'|'||
                    'GfAttrlmpD01'  ||'|'||
                    'GfAttrCat01'   ||'|'||
                    'GfAttrdesc01'  ||'|'||
                    'GfAttrlmpID02' ||'|'||
                    'GfAttrCat02'   ||'|'||
                    'GfAttrdesc02'  ||'|'||
                    'GfSubType'      ) line_header      from DUAL;
                    
                    
    
    /**********************************************************************/
    /*                Main Program Processing                             */
    /**********************************************************************/
    
    BEGIN
    
    
    
    
    DBMS_OUTPUT.put_line ('Program Started in wsualumni.wsu_online_giving_online');
    IF UTL_FILE.is_open (fhandle_o)
        THEN   
       UTL_FILE.fclose (fhandle_o);
    END IF;
    
    /* Name The File Here */
    v_data_file := ('MED_SCH_' || TO_CHAR(sysdate, 'dd-MON-yyyy') || '_OG_DATA.txt');
    
    
    
    SELECT RTRIM (pybutfl_utl_file_path)
          INTO ws_path
          FROM payroll.pybutfl;
    
    
    
          fhandle_o := UTL_FILE.fopen (ws_path, v_data_file, 'w');
          DBMS_OUTPUT.put_line ('UTLFILE file for this run is: ' || ws_path||'/'||v_data_file);
          v_written_count := 0;   
          
          
        
    FOR c2_rec IN C2 LOOP
        BEGIN
            v_selected_count := v_selected_count + 1;
            v_data_line_hdr := rtrim(c2_rec.line_header);
            UTL_FILE.put_line (fhandle_o, v_data_line_hdr);
            v_written_count := v_written_count + 1;
    EXCEPTION
         WHEN OTHERS
          THEN
           DBMS_OUTPUT.put_line (v_error_text);
           v_error_count := v_error_count + 1;
        END;
    END LOOP;
    
    
    FOR c1_rec IN C1 LOOP
        BEGIN
            v_selected_count := v_selected_count + 1;
            v_data_line := rtrim(c1_rec.data_line);
            UTL_FILE.put_line (fhandle_o, v_data_line);
            v_written_count := v_written_count + 1;
        EXCEPTION
         WHEN OTHERS
          THEN
           DBMS_OUTPUT.put_line (v_error_text);
           v_error_count := v_error_count + 1;
        END;
    END LOOP;
    
         DBMS_OUTPUT.put_line ('Number of Records Selected: ' || v_selected_count);
         DBMS_OUTPUT.put_line ('Number of Records Written: ' || v_written_count);
    
          IF UTL_FILE.is_open (fhandle_o)
          THEN
             UTL_FILE.fclose (fhandle_o);
          END IF;
    
    
    
    
    END;
    /
    Results
    ConsID|GFImpID|GFTAmt|GFType|GFPayMeth|GFDate|FundID|CAMPID|GFAppeal|GfRef|GfPostDate|GfPostStatus|GfltrCode|GfAck|GfRcpt|GfAttrlmpID00|GfAttrCat00|GfAttrdesc00|GfAttrDate00|GfAttrlmpD01|GfAttrCat01|GfAttrdesc01|GfAttrlmpID02|GfAttrCat02|GfAttrdesc02|GfSubType
    000013505||      20.00|Cash|Credit Card|06/22/2009|221686|On-Line Giving|On-Line giving|||Do not post|StandardThankYou|Not Acknowledged|Do not receipt||Banner Gift Number|1179534.221686|06/22/2009||Web ID|000013505||Source|MED|On-Line Giving
    000013505||      20.00|Cash|Credit Card|06/22/2009|770830|On-Line Giving|On-Line giving|||Do not post|StandardThankYou|Not Acknowledged|Do not receipt||Banner Gift Number|1179534.770830|06/22/2009||Web ID|000013505||Source|MED|On-Line Giving

    Hello

    The problem is due to the "OR" condition (I did not pay attention to it earlier).

    Because of this condition, your query is given beyond 7 days recovery. You need to rewrite the code as:

    ALM_OG_CAMPAIGN_CODE in ('MED', 'MED1')
    

    Instead of

       and ALM_OG_CAMPAIGN_CODE = 'MED'
         OR ALM_OG_CAMPAIGN_CODE = 'MED1';
    

    This will do the magic for you.

    Concerning

    Asif Momen
    http://momendba.blogspot.com

  • Max value return value despite where clause is not not really looking for the reason

    Hello

    Using oracle 11.2.0.3

    Select 'A '.

    of the double

    where 1 = 2

    No returns no row, as expected

    Select max ('A')

    of the double

    where 1 = 2 - that is to say isn't true

    Returns the line with null

    Why is this?

    Thank you

    Hello

    user5716448 wrote:

    Hello

    Thanks for the reply.

    I guess that's rule ageneral wait even if no line because of the place where the condition.

    where 1 = 2 - that is to say isn't true

    Thank you

    Yes, if there are no rows in the table, or no line meets the conditions in the WHERE clause, it would be logical that the query return lines exactly 0, but it is also logical that the query returns exactly 1 row.  People who have designed SQL apperantly thought return 1 row was most helpful.

    If you want the query to return 0 rows when there is no data, you can GROUP BY a constant.  For example:

    SELECT MAX (hiredate) AS last_hitedate

    FROM scott.emp

    WHERE deptno = & deptno_wanted

    GROUP 0

    ;

    If there are any rows that meet the condition in the WHERE clause, then the query will produce 1 row, but if no rows meet this condition, then the query will return 0 rows.

    Personally, I'm happy that they designed this way SQL.  I find it rather convenient that the aggregates without GROUP BY clause will return 1 row.  I do things like

    SELECT COUNT (*)

    FROM table_x;

    often, when I want to know if a table has been filled or not.  Seeing a 0 for the output is much clearer that does not get any results.

  • Cannot run a «BUSINESS...» WHEN ' with a date in a WHERE CLAUSE condition

    Hello

    I need to check for a condition and date according to the date, he would check a set of host names or the other game... so I thought I could write something like this in the WHERE clause:

    AND HOST_NAME IN

    (

    CASE

    WHEN TO_DATE (: StopDate, 'MON-DD-YYYY') > = TO_DATE ('22 - DEC - 2015 "," DD-MON-YYYY ') THEN

    ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC') ON THE OTHER

    ("SERVERNAME1", "NAMESERVER2", "SERVERNAME3")

    END

    )

    I get the following:

    ORA-00907: lack of right parenthesis

    00907 00000 - "lack the right parenthesis.

    But there is no missing parentheses!

    If I take the case... when... end, and run the host_name in ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC') (separately, they run fine)...

    I also tried:

    AND

    (

    CASE

    WHEN TO_DATE (: StopDate, 'MON-DD-YYYY') > = TO_DATE ('22 - DEC - 2015 "," DD-MON-YYYY ') THEN

    HOST_NAME IN ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC') ELSE

    HOST_NAME IN ('SERVERNAME1","NAMESERVER2","SERVERNAME3")

    END

    )

    the error I get is:

    ORA-00905: lack of keyword

    00905 00000 - 'lack the key word'

    What keyword miss me?

    Post edited by: c75d2e42-06a0-4eb1-a576-5652edcbfbe8

    Hello

    c75d2e42-06a0-4eb1-A576-5652edcbfbe8 wrote:

    It was a typo when transferred to the Oracle forum... the version of Oracle is: PL/SQL version 10.2.0.3.0 (10 G)

    I also used IF the statement and that has not worked (in error "missing parenthesis") which I'm sure is a matter of "syntax"... I did not know that the CASE statement returns the value single only, so it's probably the problem.  Is it possible to re - write this?

    ...

    IF only works in PL/SQL.  It does not in SQL, even if that SQL is embedded in PL/SQL.

    There are many ways to re - write the condition.  And here's one:

    AND ((host_name IN ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC')

    AND TO_DATE (: StopDate, "MON-DD-YYYY") > = TO_DATE ('22-DEC-2015', "MON-DD-YYYY")

    )

    OR (host_name IN ('servername1","Nameserver2","SERVERNAME3")

    AND TO_DATE (: StopDate, "MON-DD-YYYY")<  to_date="" ('dec-22-2015', ="">

    )

    )

    If: StopDate can be NULL, it must be a bit more complicated.

    You can also use nested, such as CASE expressions

    AND THE CASE

    WHEN TO_DATE (: StopDate, "MON-DD-YYYY") > = TO_DATE ('22-DEC-2015', "MON-DD-YYYY")

    WHILE CASE

    WHEN host_name IN ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC')

    AND THEN 'OK '.

    END

    OTHER CASES

    WHEN host_name IN ('servername1","Nameserver2","SERVERNAME3")

    AND THEN 'OK '.

    END

    END = 'OK '.

    I wonder if this in your application is the best way, however.  If SERVERNAMEA was put into service on December 22, maybe that that fact should be recorded in a table.  If you have a table with 1 row per server, you can consider adding 2 columns DATE to show when the server was first and last used.  Then, rather than use a WHERE clause to test servers appropriate, you could do an inner join.

  • Materialized view does not quickly refresh with sysdate in where clause

    Hi all

    I am trying to create a view, materialized with sysdate in where clause. This makes the complex query, and so I can't create a quick refreshment mview.

    I tried to create with rowid too, but it does not create a quick refreshment.

    I was wondering if someone can advise me, how can I accomplish this task, which would be really appreciated.

    The query is:

    create a materialized view PS_MEETING

    build the DEFERRED payment

    Refresh quickly with rowid

    as

    SELECT *.

    MEETING M

    WHERE state_desc = 'VIC '.

    OR Meet_date < TRUNC (SYSDATE);

    the behavior is documented: http://docs.oracle.com/cd/E11882_01/server.112/e25554/basicmv.htm#DWHSG8201

    General restrictions on update quickly

    The definition of the materialized view query is limited as follows:

    • The materialized view must not contain references to non-repetitive phrases such as SYSDATE and ROWNUM .

    So I guess that you would need a more static than sysdate condition - or another strategy update.

  • Cannot export data so WHERE clause AND/OR

    I am able to export the results of a query if the WHERE clause has only one condition. But if there are and AND or a RC, you can right-click and choose export data, but nothing happens.

    For example, the following text exports very well:

    SELECT * FROM DUAL
    WHERE ROWNUM = 1;

    But throw in an 'AND', and it will not be exported:

    SELECT * FROM DUAL
    WHERE ROWNUM = 1 AND ROWNUM < 2;

    I'm running worm 1.5.3 and did not apply the patches.

    Unfortunately, in the framework of trying to solve other problems with the export feature, 1.5.3 presented problems where certain types of SQL statements would not export (nothing happened like you are seeing or reports of the errors like ORA-936). While it is not yet perfect, 1.5.5 manages exporters results much better (it fits your case who fails in 1.5.3), then I would say that you upgrade to 1.5.5.

    theFurryOne

  • long data type in where clause

    Hello

    I need to select in an Oracle table with a column having
    Long data type and Oracle does not use this column in the
    WHERE clause. Doco Oracle suggests that the columns with LARGE data types may
    only be used in the select statement (not in the CASE or any other
    conditional clause).

    Anyone know any work around for this problem?

    What is the way to see the value of long data type?

    How can we use them in where clause?

    We can all utility to display the specified records? There are Lakes of records...


    I ned use it in where clause...

    Thanks and greetings
    VD

    Published by: vikrant dixit on November 23, 2008 22:47

    So can OK we use CLOB/BLOB in where clause?

    Yes, you can query the LOB columns using the package (F.ex.SUBSTR or INSTR) DBMS_LOB functions.

    Why u say that the result is FTS?

    This would result in FTS as you cannot index LARGE data or create a function based on the column index.

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/sql_elements001.htm#sthref149


    LONG columns cannot be indexed.

    No other way to my knowledge.

    You can convert the LOB column with function TO_LOB as described in

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/functions185.htm#i79464

    Published by: Sissi Kandi on November 24, 2008 12:28

  • Execution of statement of UPDATE for the whole table even when the WHERE Clause is presentation

    Hi friends,

    I have a problem in a stored procedure where I wrote an update with a where clause clause statement. At some point only one line should be updated according to the unique identifier in where clause.

    But what is happening is that the Update statement is getting executed for all rows in the table to neglect the WHERE clause. I don't get any idea of why this is happening. Here is the stored procedure and the update statement is BOLD:-

    CREATE OR REPLACE PROCEDURE MDMADM.proc_MDM_InsertCntryDetails
    (
    CntryMasterCode IN VARCHAR2,
    CntryName IN VARCHAR2,
    MDMUser IN VARCHAR2,
    Exists IN ITS ENTIRETY,
    status in VARCHAR2,
    Inserted_By IN VARCHAR2 default NULL,
    Modified_By IN VARCHAR2 default NULL,
    Mdm_Code IN the DEFAULT NUMBER 0.
    Action in VARCHAR2 DEFAULT 'Add ',.
    XGenAttNames IN VARCHAR2 default NULL,
    XGenAttValues IN VARCHAR2 default NULL,
    MirusAttNames IN VARCHAR2 default NULL,
    MirusAttValues IN VARCHAR2 default NULL,
    GenisysAttNames IN VARCHAR2 default NULL,
    GenisysAttValues IN VARCHAR2 default NULL,
    XGenModify IN VARCHAR2 default NULL,
    MirusModify IN VARCHAR2 default NULL,
    GenisysModify IN VARCHAR2 default NULL
    )

    IS

    strSQLXGen VARCHAR (1000);
    strSQLMirus VARCHAR (1000);
    strSQLGenisys VARCHAR (1000);
    nMaxMDMCode INTEGER.
    ifExist INTEGER;

    /******************************************************************************
    NAME: proc_MDM_InsertCntryDetails
    PURPOSE:

    REVISIONS:
    Worm Date Description of the author
    --------- ---------- --------------- ------------------------------------
    1.0 03/07/2009 1. Created this procedure.

    NOTES:

    Keywords to replace automatically available Auto:
    Object name: proc_MDM_InsertCntryDetails
    SYSDATE: 03/07/2009
    Date and time: 03/07/2009, 19:11:20 and 03/07/2009-19:11:20
    User name: (put in TOAD Options, editor of the procedure)
    Name of the table: (defined in the dialog box "New PL/SQL object")

    ******************************************************************************/
    BEGIN

    COUNT (*) of SELECT INTO ifExist OF MDM_COUNTRY_MASTER;

    IfExist IF = 0 THEN
    SELECT 1 INTO nMaxMDMCode FROM DUAL;
    ON THE OTHER
    SELECT MAX (MDM_CODE) + 1 IN MDM_COUNTRY_MASTER nMaxMDMCode;
    END IF;


    IF Action = "add" THEN

    INSERT INTO MDM_COUNTRY_MASTER(MDM_CODE,MDM_MASTER_CODE,MDM_DESCRIPTION,MDM_USER,MDM_EXIST,MDM_STATUS,MDM_ACTION,DAT_INSERT_DATE,DAT_INSERTED_BY)
    VALUES(nMaxMDMCode,CntryMasterCode,CntryName,MDMUser,exist,Status,action,sysdate,Inserted_By);

    strSQLXGen: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) XGenAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
    "VALUES (' |)" nMaxMDMCode | ',' || '''' || "XGen | '''' || ',1,' || XGenAttValues | ',' || '''' || Inserted_By | '''' || SYSDATE)';

    EXECUTE IMMEDIATE strSQLXGen;

    strSQLMirus: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) MirusAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
    "VALUES (' |)" nMaxMDMCode | ',' || '''' || "Mirus | '''' || ',2,' || MirusAttValues | ',' || '''' || Inserted_By | '''' || SYSDATE)';

    EXECUTE IMMEDIATE strSQLMirus;

    strSQLGenisys: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) GenisysAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
    "VALUES (' |)" nMaxMDMCode | ',' || '''' || "Genisys | '''' || ',3,' || GenisysAttValues | ',' || '''' || Inserted_By | '''' || SYSDATE)';

    EXECUTE IMMEDIATE strSQLGenisys;

    ON THE OTHER



    UPDATE MDM_COUNTRY_MASTER
    SET MDM_DESCRIPTION = CntryName, DAT_MODIFIED_BY = Modified_By, DAT_MODIFY_DATE = SYSDATE.
    MDM_USER = MDMUser, MDM_ACTION = Action, MDM_STATUS = status MDM_EXIST = exist WHERE MDM_CODE = Mdm_Code;




    COUNT (*) of SELECT INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE = 1 AND MDM_CODE = Mdm_Code;

    IfExist IF = 0 THEN

    strSQLXGen: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) XGenAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
    ' VALUES(' ||) Mdm_Code | ',' || '''' || "XGen | '''' || ',1,' || XGenAttValues | ',' || '''' || Modified_By | '''' || SYSDATE)';

    EXECUTE IMMEDIATE strSQLXGen;

    ON THE OTHER
    strSQLXGen: = "UPDATE MDM_COUNTRY_MAPPING SET | XGenModify | ', DAT_MODIFY_DATE = SYSDATE, DAT_MODIFIED_BY =' | '''' || Modified_By | '''' || "WHERE MDM_CODE =' | ' Mdm_Code | "and SYSTEM_CODE = 1';

    EXECUTE IMMEDIATE strSQLXGen;

    END IF;


    COUNT (*) of SELECT INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE = 2 AND MDM_CODE = Mdm_Code;

    IfExist IF = 0 THEN

    strSQLMirus: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) MirusAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
    ' VALUES(' ||) Mdm_Code | ',' || '''' || "Mirus | '''' || ',2,' || MirusAttValues | ',' || '''' || Modified_By | '''' || SYSDATE)';

    EXECUTE IMMEDIATE strSQLMirus;

    ON THE OTHER
    strSQLMirus: = "UPDATE MDM_COUNTRY_MAPPING SET | MirusModify | ', DAT_MODIFY_DATE = SYSDATE, DAT_MODIFIED_BY =' | '''' || Modified_By | '''' || "WHERE MDM_CODE =' | ' Mdm_Code | "and SYSTEM_CODE = 2';

    EXECUTE IMMEDIATE strSQLMirus;

    END IF;


    COUNT (*) of SELECT INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE = 3 AND MDM_CODE = Mdm_Code;

    IfExist IF = 0 THEN

    strSQLGenisys: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) GenisysAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
    ' VALUES(' ||) Mdm_Code | ',' || '''' || "Genisys | '''' || ',3,' || GenisysAttValues | ',' || '''' || Modified_By | '''' || SYSDATE)';

    EXECUTE IMMEDIATE strSQLGenisys;

    ON THE OTHER
    strSQLGenisys: = "UPDATE MDM_COUNTRY_MAPPING SET | GenisysModify | ', DAT_MODIFY_DATE = SYSDATE, DAT_MODIFIED_BY =' | '''' || Modified_By | '''' || "WHERE MDM_CODE =' | ' Mdm_Code | "and SYSTEM_CODE = 3';

    EXECUTE IMMEDIATE strSQLGenisys;

    END IF;



    END IF;



    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    NULL;
    WHILE OTHERS THEN
    -Consider recording the error and then re-raise
    LIFT;
    END proc_MDM_InsertCntryDetails;
    /


    Thank you

    >
    WHERE mdm_code = mdm_code
    >

    This will always be value true - similar to WHERE 1 = 1.

    You typed it wrong or is the same as the variable column name? If they are the same test rename one of them.

  • Implementation of subqueries in the WHERE clause

    Hi all

    First of all, here are the technical info:

    Oracle JDeveloper 12 c 12.1.3.0.0

    Studio Edition Version 12.1.3.0.0

    Build JDEVADF_12.1.3.0.0_GENERIC_140521.1008.S

    Version of the component

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

    Oracle IDE 12.1.3.0.41.140521.1008

    Java (TM) Platform 1.7.0_51

    Support versioning 12.1.3.0.41.140521.1008

    Secondly, the issue I'm facing is I'm trying to implement a query with three sous-sélections them in the (see image below) WHERE clause. I don't know what is the best way to implement something like this.

    I have implemented this by creating a display object and add a view criteria. I put the whole SQL fragment in the view as a literal value criteria. Is there a better (or best?) approach to implement something like this?

    This implementation is a problem is because as well as query tests out fine when I click on explain Plan even recognized that there is no bind variables in subqueries and allows me to.

    When I run this test by the tester of AM, that it fails to recognize and define the binding (projCategory) variable that appears only in subqueries. All your comments and/or help is very appreciated.

    Query.JPG

    Thank you

    Vladimir

    Vladimir, there is something wrong in the view Definition of criteria dialog box. The button "explain plan...". "running the whole statement generated (as a string) and returns the result. The entire statement is valid and returns the correct result. However, the view criteria, when it is running in the application work differently. Here the literal that you entered is not passed as a string, but the framework does something internally with her (it is necessary to do things as in the research of memory and other things). If you run the criteria to view in the app Tester I get

    SQL error in the preparation of the statement.  Instruction: SELECT Employees.EMPLOYEE_ID, Employees.FIRST_NAME, Employees.LAST_NAME, Employees.EMAIL, Employees.PHONE_NUMBER, Employees.HIRE_DATE, Employees.JOB_ID, Employees.SALARY, Employees.COMMISSION_PCT, Employees.MANAGER_ID, Employees.DEPARTMENT_ID from employees WHERE (((Employees.SALARY< :vc_temp_1="" )="" )="" )="" ):="" ora-01722:="" invalid="">

    Accordingly, for the display criteria

    employes.salaire< (select="" max(e2.salary)="" from="" employees="" e2="" where="" e2.department_id="">

    As you can see the literal is passed as: vc_temp_1 and my binding variable is not visible at all. You can open an SR and ask for the support of working on it. I guess that they do not see a bug here as help for the dialog box says:

    Literal

    Select when you want to provide a value for the attribute, or when you want to set a default value for a lookup field specified by the user for a search query-by-example form.

    When the criteria of view defines a search query for the user interface form, you can leave the field blank. In this case, the user will provide the value. Alternatively, you can provide a value that will act as a default value to the field search that the user will be able to substitute. This entry can include wildcards * or %.

    When the attribute is of type Date, specify the value of the date in the format YYYY-MM-DD; for example, to December 16, 2010, enter 2010-12-16.

    Here, it tells you that a value is expected. Your sub query is not interpreted, but is simply converted to the appropriate data type. In my example, I get an invalid number as expected.

    So I guess my suggestion to use a custom sql statement stands.

    Timo

  • 8287 error: manual/refresh operations with Where clause

    Hello

    I defined a group of read-only cache

    CREATE CACHE READONLY ABC GROUP

    AUTOREFRESH INTERVAL 60 seconds

    OF ORACLE_TABLE

    I want to only load the 3 months of the underlying table for Oracle data so I don't


    ABC LOADING CACHE GROUP

    WHEN TRUNC (date_column) > TRUNC (add_months (sysdate,-3))

    COMMIT ALL 256 ROWS

    4 PARALLEL;

    However, I get the error message

    8287: manual LOADING/REFRESH with clauses WITHID or WHERE operations are not be allowed on ABC Group cache because it is specified as AUTOREFRESH

    The command failed.

    What should I do to load the data of 3 months only if possible? Can I use autorefresh?

    Thanks in advance

    Cache AUTOREFRESH groups to include the WHERE clause in the definition of Group of cache. For example, if drop you in Oracle's:

    CREATE TABLE MYDATE

    (

    C1 VARCHAR2 (10) NOT NULL PRIMARY KEY,

    C2 DATE NOT NULL

    );

    Then your cache group definition would look like this:

    CREATE CACHE READONLY ABC GROUP

    AUTOREFRESH INTERVAL OF 60 SECONDS

    OF MYDATE

    (

    C1 VARCHAR2 (10) NOT NULL PRIMARY KEY,

    C2 DATE NOT NULL

    )

    WHEN TRUNC (c2) > TRUNC (add_months (sysdate,-3));

    And then you would load by using

    ABC LOADING CACHE GROUP

    COMMIT ALL 256 ROWS

    4 PARALLEL;

    As auto refreshes occur time passes, all the data that falls outside the range will be removed from the cache and new data that now lying in the range will be added to the cache.

    Chris

  • Logical OR (where clause) is not capable of change.

    select * from V$version;
    
    BANNER
    -------------------------------------------------------
    Oracle Database 11g Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0      Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    
    

    ALTER SESSION SET NLS_DATE_FORMAT = 'yyyy-mm-dd hh24:mi:ss';
    
    

    create table TestTable(ID,DateCol) as
    select 1,date '2011-11-11' from dual union all
    select 2,date '2012-07-13' from dual union all
    select 3,date '2030-12-31' from dual;
    
    

    -- FirstSQL
    SELECT *
      FROM TestTable
     WHERE sysdate <= DateCol
        OR DateCol = date '2011-11-11';
    
    ID  DateCol
    --  -------------------
     3  2030-12-31 00:00:00
    
    

    -- SecondSQL
    SELECT *
      FROM TestTable
     WHERE DateCol = date '2011-11-11'
        OR sysdate <= DateCol;
    
    ID  DateCol
    --  -------------------
     1  2011-11-11 00:00:00
     3  2030-12-31 00:00:00
    
    

    Why return record figures are diff

    Logical OR (where clause) must be able to change.

    (Ex "Where A or B", "where B or" can change)

    I found the logical predicate have diff.

    set autot trace
    

    -- FirstSQL
    SELECT *
      FROM TestTable
     WHERE sysdate <= DateCol
        OR DateCol = date '2011-11-11';
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
       1 - filter("DATECOL">=SYSDATE@!)
    
    

    -- SecondSQL
    SELECT *
      FROM TestTable
     WHERE DateCol = date '2011-11-11'
        OR sysdate <= DateCol;
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
       1 - filter("DATECOL"=TO_DATE(' 2011-11-11 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') OR "DATECOL">=SYSDATE@!)
    
    

    And for 11.2.0.3 as well:

    BANNER
    -----------------------------------------------------------------------------
    Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE Production 11.2.0.3.0
    AMT for Linux: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production

    5 selected lines.

    SQL > drop table testtable is serving;

    Deleted table.

    SQL > create table TestTable (ID, DateCol) as
    2 Select 1, date '' 2011-11-11 of all the double union
    3 select 2, '' 2012-07-13 of all the double union
    4 Select 3, date ' 2030-12-31' double.

    Table created.

    SQL >-FirstSQL
    SQL > SELECT *.
    2 from TestTable
    3. WHERE sysdate<=>
    4 GOLD DateCol = date '' 2011-11-11;

    ID DATECOL
    ---------- -------------------
    1 11/11/2011 00:00:00
    3 31/12/2030 00:00:00

    2 selected lines.

    SQL >-SecondSQL
    SQL > SELECT *.
    2 from TestTable
    3 WHERE DateCol = date ' 2011-11-11.
    4 GOLD sysdate<=>

    ID DATECOL
    ---------- -------------------
    1 11/11/2011 00:00:00
    3 31/12/2030 00:00:00

    2 selected lines.

    I believe that I've read about this on Metalink somewhere, have yet to find the document, but I'm sure this is a known bug...

  • No output for report of XML editor using CASE/DECODE in a Where Clause

    Hello

    I have a requirement of the company to modify an existing report that has two input parameters,
    -> p_statcode (closed status) which may have values "Y" or "n".
    -> p_overdue (flag late), which can have values of "Y" or "n".

    The flag late is a column evaluated with O/N values and it is evaluated as follows,
    ONTF_MOD_VAL(NVL (
                                         (TRUNC (SYSDATE)
                                          - (TO_DATE (oe_order_lines.attribute18,
                                                      'DD-MON-RRRR')
                                             + TO_NUMBER (fnd_lookup_values.meaning))),
                                         0
                                      ))
                            overdue_flag
    The requirement of user now is that they must be a third option for setting called p_overdue ALL,
    which by the way the output should include records with
    p_statcode is p_statcode ELSE is N AND Y OR p_overdue p_overdue is N

    In other words records with raising the Y and N for flag late must be returned regardless of the value given to the closed state.

    Original where clause contained in the data definition file is as follows,
    WHERE Closed_Status = nvl(:p_statcode,Closed_Status)
                       AND overdue_flag = nvl(:p_overdue,overdue_flag)
    My modified code is the following,
    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
             AND overdue_flag = (CASE
             WHEN :p_overdue = 'Y' THEN 'Y'
             WHEN :p_overdue = 'N' THEN 'N'
             ELSE overdue_flag
             END)
    OR
    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
             AND overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag)
    Both approaches have the same problem.
    The output is in EXCEL format. The modified query works very well for p_overdue as Y or N but when p_overdue is passed as ALL he returned a blank EXCEL sheet with just exit report column headings.
    Any help regarding, why is this the case? What's not in my approach?

    Kind regards
    Vishal

    unclear on p_overdue = ALL
    P_overdue = ALL on what necessary values?

    try sth like

    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
    AND (
       overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag) and :p_overdue != 'ALL'
       or
      :p_overdue = 'ALL' and (overdue_flag = 'Y' or overdue_flag = 'N')
    )
    

    for overdue_flag, which has more then 'Y' values of "n".
    If overdue_flag that in ('Y', ' don't) then

    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
    AND (
       overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag) and :p_overdue != 'ALL'
       or
      :p_overdue = 'ALL'
    )
    
  • Complex Inner Join and outer subquery where clause to join internal?

    The DDL for this post was too big and I had to put on my site:
    http://www.harbortownsolutions.com/DDLForDORTable.txt

    My goal is to create a report of sales data for 116 stores containing daily sales and count of comments in recent years. My challenge is that I am pulling data from the same table, but with different dates to get data from last year and the week in data from date of last year.


    The dates used for reports are:

    SalesDate = 06/04/2009
    SalesDateForLastYear = 2008-06-05
    SalesDateBeginningOfWeek = 01/06/2009
    SalesDateBginningOFWeekLastYear = 2008-06-02

    PSEUDOQUERYS:
    ---======= DOLLAR VARIANCE = You Said you have $100 worth of meat(inventory) but you only have $50 worth of meat
    SELECT 
        BUSI_DATE as BusinessDate, 
        ORACLE_KEY as StoreID,
        FIELD1  as Sales,
        FIELD2  as GuestCount,
        FIELD3  as DollarVariance,
        FIELD4  as Cars
    FROM MYDAILYTOTALS
    WHERE Busi_date = SalesDate
       AND ORACLE_KEY IN (SELECT StoreID From MyStores); 
    -======= ONLY Guest count and Sales are needed in comparisons against last year    
    ---======    Last YEar dates = corresponding dates for this year ie Tuesday of this 
    week matched to Tuesday of last year (except for leap year)
    SELECT 
        ORACLE_KEY as StoreID
        FIELD1  as SalesLastYear
        FIELD2  as GuestCountLastYear   
    FROM MYDAILYTOTALS
    WHERE Busi_date = SalesDateForLastYear 
       AND ORACLE_KEY IN (SELECT StoreID From MyStores);
           
    
    SELECT 
        ORACLE_KEY as StoreID
        SUM(FIELD1)  as WeekToDateSales
        SUM(FIELD2)  as WeekToDateGuestCount  
    FROM MYDAILYTOTALS
    WHERE Busi_date BETWEEN SalesDateBeginningOfWeek and SalesDate
       AND ORACLE_KEY IN (SELECT StoreID From MyStores) 
    GROUP BY ORACLE_KEY 
       --=======  
    SELECT 
        ORACLE_KEY as StoreID
        SUM(FIELD1)  as WeekToDateSalesLastYear
        SUM(FIELD2)  as WeekToDateGuestCountLastYear  
    FROM MYDAILYTOTALS
    WHERE Busi_date BETWEEN SalesDateBeginningOfWeekLastYear and SalesDateLastYear
       AND ORACLE_KEY IN (SELECT StoreID From MyStores) 
    GROUP BY ORACLE_KEY   
    Question: Since they all use the same store of nbrs, I specify on each request? Can't I just specify only once on outer query Where clause?

    Also, how would fit the following of HOEK script:
    See how I put 1 field based on another field value

    He reads a record for each store of 116 stores in the database. There are 2 situations that have been addressed by Hoeks code:
    For each of the 116 stores in the store table, there must be 1 and only
    registration of 1 stock to match the record of MyStoreTotals. However, sometimes there is no record of inventory.
    and sometimes there will be 2 (in a case where a manager of database updates)
    After daily treatment) files. If so, the record with Is_posted = 1
    is the one that should be included in the query. The following text accomplishes this:
    -chr (39) is the single quote
     Select StoreId, 
             DollarVariance 
      from   (select store.storeid, 
                       case
                              when inv.storeid is null then 'None'
                              when inv.is_posted = 0 then 'NP'
                              else chr(39)||inv.total_dol_var||chr(39)
                        end as DollarVariance, 
                        row_number() over (partition by store.storeid order by inv.is_posted desc) rn  
                   from  myInven inv 
                   right outer join mystores  store
                                  on store.storeid = inv.fk_str_main_id
                                  and inv.busi_date = to_date(SalesDate, 'dd-mon-yyyy'))
          where rn = 1;      
    Can I put this request on the place where clause of the outer to query I put on a JOIN clause?

    So I guess that's why you used the MAX.

    That is right.
    I used CASES to identify and complete the necessary columns since the first set of results (WITH).
    So then I more or less "swivels somehow" lines of this result set to the columns, each store will appear once the most.

  • where clause to query the hierarchy in the tree Apex area does not

    Hi all

    I am building a tree Menu in Apex 5.0.3 (Oracle 11 g XE), when using when the clause, it does show all the data, but without him, showing all the data.

    I'm trying to populate Tree Menu with data specific to a user successfully logged on.

    (A) table created as HR2. TREE_MENU

    menu_name varchar2 (50).

    number of menu_parent

    number of menu_child

    menu_id varchar2 (12),

    menu_path varchar2 (100),

    number of user_no

    (B) SQL statement for the tree in the Apex region

    Select case when connect_by_isleaf = 1 then 0

    When level = 1 then 1

    else                           -1

    end the status,

    level,

    'Menu_name' as the title,

    NULL as an icon,

    "MENU_CHILD" as a value.

    NULL as ToolTip,

    NULL as link

    to HR2. "" TREE_MENU ".

    -WHERE USER_NO =: P_USERNO

    Start with 'MENU_CHILD' is null

    connect prior "MENU_PARENT" = "MENU_CHILD."

    brothers and sisters of order by 'MENU_ID '.

    Note: also used static value where clause but is not workd.

    that the mistake of me or something else? When using the wizard, she asks (possibly) where clause, this means that when the clause can be used in the SQL statement.

    Help, please.

    Kind regards.

    If you want to prune your tree to show only the elements of the No. 7 usermenu, copy the following code helps you

    select case when connect_by_isleaf = 1 then 0
                when level = 1             then 1
                else                           -1
           end as status,
           level,
           "MENU_NAME" as title,
           null as icon,
           "MENU_CHILD" as value,
           null as tooltip,
           null as link
    from HR2."TREE_MENU"
    start with "MENU_CHILD" is null
    connect by
        prior "MENU_PARENT" = "MENU_CHILD"
        and "USER_NO" = 7
    order siblings by "MENU_ID"
    

    Concerning

    Mahmoud

Maybe you are looking for

  • Browser does not open so I can't create a new profile to attempt to repair. What should I do?

    I continue to by clicking on my on the firefox icon and it don't is not loading. After looking through the support pages, it seems that I have to save my current profile and create a new, but you must be able to open Firefox for this.

  • Upgrade SSD on G7-2243us

    Hello I have a HP Pavilion G7-2243us and I want to move to an SSD. My question is if the motherboard has a sata 3 6 Gb/s or a 2 2 Gb/s sata controller? I know that any sata SSD working but I don't want to buy a more expensive sata 3 SSD which will op

  • Satellite C660 is slow - drive 'failure '?

    Hello Forum - I hope someone can help. My children (PC) run a C660-IST (two years). I say "run" - the machine is going at a snail pace. Confession - their father always worked on Apple (I know, I know...) then i@m beating everywhere to try to help th

  • microphone in labview data acquisition

    Hello My name is Michael. I want to get micro data in labview using connection jack 3.5 mm on my laptop. I looked in daqmax and did not see the microphone. Is it possible to enter these data in labview? Any help will be great. Thank you Michael

  • How can I install Windows install to download ITunes

    When I try to install I-tunes, this message appears. [The Windows Installer service could not be accessed This can occur if you are running windows in safe mode or if Windows install is not properly installed Contact your suport assistance service] C