Select Record Between Date Gap-Oracle 11g, Windows 2008 server

hello everyone,
I have a sql query where I need to select only records with an 18 month gap between max(date) and previous date( no dates between max(date)
and 18 month gap date), when I run the below query it should only select supid 130, not 120 (even though 120 does contain an 18 month gap date it also has a date that is less then the 18 month gap( '25-NOV-2012','DD-MON-YYYY').
how would get the query to look back 18 months for the next date and evaluate the month_between.
any help is greatly appreciated.
example:
create table supply(supID number(8), supply varchar2(20), supdate Date,supamount number(13,2));
insert into supply values(100,'Tapes',to_date('01-AUG-2013','DD-MON-YYYY'),50.00);
insert into supply values(100,'TV',to_date('01-APR-2013','DD-MON-YYYY'),250.00);
insert into supply values(100,'Discs',to_date('25-DEC-2012','DD-MON-YYYY'),25.00);
insert into supply values(120,'Tablets',to_date('25-AUG-2013','DD-MON-YYYY'),15.00);
insert into supply values(120,'Paper',to_date('25-NOV-2012','DD-MON-YYYY'),35.00);
insert into supply values(120,'Clips',to_date('20-NOV-2010','DD-MON-YYYY'),45.00);
insert into supply values(120,'Binders',to_date('28-FEB-2012','DD-MON-YYYY'),25.00);
insert into supply values(130,'Discs',to_date('25-JUL-2013','DD-MON-YYYY'),75.00);
insert into supply values(130,'Calc',to_date('25-JAN-2012','DD-MON-YYYY'),15.00);
insert into supply values(130,'Pens',to_date('15-DEC-2011','DD-MON-YYYY'),55.00);
   select * from supply p where to_char(p.supdate,'yyyy')='2013'
   and p.supid in(select s.supid from supply s where months_between(s.supdate,p.supdate)<-18)
     SUPID SUPPLY               SUPDATE    SUPAMOUNT
       120 Tablets              25-AUG-13         15
       130 Discs                25-JUL-13         75

Something like this?
select
from (
select
  supid
, supply
, supdate
, supamount
, lead(supdate) over (partition by supid order by supdate desc) ldate
from supply
where
months_between(supdate,ldate) >= 18
SUPID
SUPPLY
SUPDATE
SUPAMOUNT
LDATE
130
Discs
07/25/2013
75
01/25/2012
Ok. i see you want only he diff to max date.
select
from (
select
  supid
, supply
, supdate
, supamount
, lead(supdate) over (partition by supid order by supdate desc) ldate
, row_number() over (partition by supid order by supdate desc) rn
from supply
where
months_between(supdate,ldate) >= 18
and
rn = 1
Message was edited by: chris227
extended

Similar Messages

  • Send encrypted data from oracle 11g to Ms SQL Server 12

    Hi every body,
    we want to send encrypted data from oracle 11g to Ms SQL Server 12:
    - data are encrypted to oracle
    - data should be sent encrypted to Ms SQL server
    - data will be decrypted in Ms SQL server by sensitive users.
    How can we do this senario, any one has contact simlare senario?
    can we use asymetric encription to do this senario?
    Please Help!!
    Thanks in advance.

    Hi,
      What you want to do about copying data from Oracle to SQL*Server using insert will work with the 12c gateway.  There was a problem trying to do this using the 11.2 gateway but it should be fixed with the 12c gateway.
    If 'insert' doesn't work then you can use the SQLPLUS 'copy' command, for example -
    SQL> COPY FROM SCOTT/TIGER@ORACLEDB -
    INSERT SCOTT.EMP@MSQL -
    USING SELECT * FROM EMP
    There is further information in this note available on My Oracle Support -
    Copying Data Between an Oracle Database and Non-Oracle Foreign Data Stores or Databases Using Gateways (Doc ID 171790.1)
    However, if the data is encrypted already in the Oracle database then it will be sent in the encrypted format. The gateway cannot decrypt the data before it is sent to SQL*Server.
    There is no specific documentation about the gateways and TDE.  TDE encrypts the data as it is in the Oracle database but I doubt that SQL*Server will be able to de-encrypt the Oracle data if it is passed in encrypted format and as far as I know it is not designed to be used for non-Oracle databases.
    The Gateway encrypts data as it is sent across the network for security but doesn't encrypt the data at source in the same way as TDE does.
    Regards,
    Mike

  • Connect to DB2 from oracle 11g on windows 2008 server

    Hi Folks,
    I want to conenct to DB2 from oracle 11g using DB link.
    DB2 :
    user : db2user
    pwd : db2pwd
    database : db2database (OSBLDEV)
    able to connect to db2 server (installed on machine M1) using db2 client with above details from machine M2 (where oracle is installed).
    Oracle :
    user : orauser
    pwd : orapwd
    host : orahost
    port : 1521
    service : oraservice
    able to connect to oracle server using oracle sql developer with above details on Machine M2 (windows 2008 server)
    when i execute the query with database link
    select row_id from siebel.s_org_ext@OSBLDEV;
    I get the message : ORA-12154: TNS:could not resolve the connect identifier specified.
    could you pls check and let me know whether the below enteries are correct or not.
    Pls share if you have step by step connectivity from DB2 to oracle using DB link.
    1. I have created the Data source for DB2 - test successful
    create database link OSBLDEV
    connect to "db2user"
    identified by "ldb2pwd"
    using 'OSBLDEV';
    1. I have made the following entry in E:\oracle\product\11.1.0\db_1\hs\admin\initosbldev.ora
    HS_FDS_CONNECT_INFO = OSBLDEV
    HS_FDS_TRACE_LEVEL = 0
    2. I have made the following entry in E:\oracle\product\11.1.0\db_1\NETWORK\ADMIN\tnsnames.ora
    OSBLDEV =
    (DESCRIPTION=
    (ADDRESS=(PROTOCOL=tcp)(HOST=orahost)(PORT=1521))
    (CONNECT_DATA=(SID=OSBLDEV))
    (HS=OK)
    3. I have made the following entry in E:\oracle\product\11.1.0\db_1\NETWORK\ADMIN\listener.ora and releoaded the listner (lsnrctl reload)
    LISTENER =
    (ADDRESS_LIST=
    (ADDRESS=(PROTOCOL=tcp)(HOST=orahost)(PORT=1521))
    (ADDRESS=(PROTOCOL=ipc)(KEY=PNPKEY)))
    SID_LIST_LISTENER=
    (SID_LIST=
         (SID_DESC = # this is the entry for HSODBC
         (SID_NAME = OSBLDEV)
         (ORACLE_HOME = e:\oracle\product\11.1.0\db_1)
         (PROGRAM = hsodbc)
    Thanks in advance.

    1. My listener.ora is placed at the below location:
    E:\oracle\product\11.1.0\db_1\NETWORK\ADMIN
    2. I have modifed the listener and removed the entry - hsodbc
    3. stop and start the listener.
    still can't see the service entry in listener status.
    C:\>lsnrctl status
    LSNRCTL for 64-bit Windows: Version 11.1.0.7.0 - Production on 19-JUL-2010 02:27
    :08
    Copyright (c) 1991, 2008, Oracle. All rights reserved.
    Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
    STATUS of the LISTENER
    Alias LISTENER
    Version TNSLSNR for 64-bit Windows: Version 11.1.0.7.0 - Produ
    ction
    Start Date 19-JUL-2010 02:21:17
    Uptime 0 days 0 hr. 5 min. 52 sec
    Trace Level off
    Security ON: Local OS Authentication
    SNMP OFF
    Listener Log File e:\oracle\diag\tnslsnr\DALDEVDBCRM1\listener\alert\log
    .xml
    Listening Endpoints Summary...
    (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=daldevdbcrm1.corp.nai.org)(PORT=1521
    Services Summary...
    Service "+ASM" has 1 instance(s).
    Instance "+asm1", status READY, has 1 handler(s) for this service...
    Service "+ASM_XPT" has 1 instance(s).
    Instance "+asm1", status READY, has 1 handler(s) for this service...
    Service "ARIBADEV" has 1 instance(s).
    Instance "ariba", status READY, has 1 handler(s) for this service...
    Service "ARIBADEV_XPT" has 1 instance(s).
    Instance "ariba", status READY, has 1 handler(s) for this service...
    Service "ARIBAXDB" has 1 instance(s).
    Instance "ariba", status READY, has 1 handler(s) for this service...
    Service "aiad.corp.nai.org" has 2 instance(s).
    Instance "aiad1", status READY, has 2 handler(s) for this service...
    Instance "aiad2", status READY, has 1 handler(s) for this service...
    Service "aiadXDB.corp.nai.org" has 2 instance(s).
    Instance "aiad1", status READY, has 1 handler(s) for this service...
    Instance "aiad2", status READY, has 1 handler(s) for this service...
    Service "aiad_XPT.corp.nai.org" has 2 instance(s).
    Instance "aiad1", status READY, has 2 handler(s) for this service...
    Instance "aiad2", status READY, has 1 handler(s) for this service...
    Service "aianew" has 1 instance(s).
    Instance "aianew", status READY, has 1 handler(s) for this service...
    Service "aianewXDB" has 1 instance(s).
    Instance "aianew", status READY, has 1 handler(s) for this service...
    Service "aianew_XPT" has 1 instance(s).
    Instance "aianew", status READY, has 1 handler(s) for this service...
    The command completed successfully
    C:\>

  • Select DBASE IV data from Oracle on Linux

    Can I select DBASE IV data from Oracle on Linux

    You can connect to DBase IV from Oracle by configuring Oracle Heterogenous Services. That will let you create a database link from Oracle to a non-Oracle database. Since there isn't a specific DBASE IV gateway, though, I believe you'll have to use the ODBC gateway, which would probably imply the necessity of a Windows box hosting Heterogenous Services.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Install and uninstall of Oracle 11g R2 on Windows 2008 Server

    Hi,
    I installed Oracle 11g R2 and set up a database on Windows 2008 Server following the steps in the Installation Guide and it was successful. After uninstalling the product and doing a re-install, the step to configure the Net Configuration Assistant fails with the following msg.
    Failed to allocate port(s) in the specified range(s) for the following process(es): JMS
    [5540-5559], RMI [5520-5539], Database Control [5500-5519], EM Agent [3938] | [1830-1849]
    Also, when I ran "netca.bat" and tried to reconfigure the Listener, it indicated the default port 1521 is being used. I ran "netstat -an" and do not see the port listed.
    Questions:
    What is the best way to check if something was leftover from my previous install of Oracle that is using the default ports?
    What do I need to do to ensure a re-install is successful?
    Uninstalling Oracle -
    1.     Log in as the Administrator.
    2.     Stop all Oracle Services.
    3.     From a cmd window, run C:\app\oracle\product\11.2.0\dbhome_1\deinstall\deinstall.bat.
    4.     Delete the C:\app\oracle directory.
    5.     Remove the following registry entries as per http://download.oracle.com/docs/cd/E11882_01/relnotes.112/e16777/toc.htm:
    HKLM\System\CurrentControlSet\Services\EventLog\Application\Oracle Services for MTS
    HKLM\System\CurrentControlSet\Services\EventLog\Application\OracleDBConsole<SID>
    HKLM\System\CurrentControlSet\Services\EventLog\Application\Oracle.<SID>
    HKLM\System\CurrentControlSet\Services\EventLog\Application\Oracle.VSSWriter.<SID>
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Oracle11

    Johan, after I uninstalled Oracle, I checked to ensure there were no remaining Oracle services remaining.
    Srini, below are the steps I followed to uninstall Oracle. In step 3, I just ran deinstall.bat without any parameters and provided required information as prompted. Note, I uninstalled using the Administrator user and not the "oracle" account that I used to install Oracle.
    Uninstalling Oracle -
    1. Log in as the Administrator.
    2. Stop all Oracle Services.
    3. From a cmd window, run C:\app\oracle\product\11.2.0\dbhome_1\deinstall\deinstall.bat.
    4. Delete the C:\app\oracle directory.
    5. Remove the following registry entries as per http://download.oracle.com/docs/cd/E11882_01/relnotes.112/e16777/toc.htm:
    HKLM\System\CurrentControlSet\Services\EventLog\Application\Oracle Services for MTS
    HKLM\System\CurrentControlSet\Services\EventLog\Application\OracleDBConsole<SID>
    HKLM\System\CurrentControlSet\Services\EventLog\Application\Oracle.<SID>
    HKLM\System\CurrentControlSet\Services\EventLog\Application\Oracle.VSSWriter.<SID>
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Oracle11

  • How to monitor oracle 11g database sessions on Windows 2008 server?

    Hi Experts
    How to monitor the Oracle 11g database sessions on Windows 2008 server (other than SQL Developer tool), which procedure or query is taking more time with Java application.

    Recently i found this tool- myorasql on the net to monitor the performence of database, easy to setup and check the performence.  i never tested it but seems impresive.  It is free and i think it would be use ful to you.
    http://myorasql.com/
    You can also use Quest - Toad or sqlplus if you are very good at sql commands and all dictionary tables or OEM/EM grid if it is configured .

  • Select DBase (.dbf) data from Oracle on Linux

    How to select DBase (.dbf) data from Oracle on Linux ?
    dbf files connected to Linux form NetWare server as 'ncpmount'.
    Oracle has access as oracle 'Directory' object.

    If you have an ODBC driver for it and are using Oracle 10g you can use Generic Connectivity. For more information on Generic Connectivity refer to the Chap 7 of the Heterogeneous Connectivity Administrator's Guide.
    http://download-west.oracle.com/docs/cd/B13789_01/server.101/b10764/gencon.htm#1005900

  • How to mask data in oracle 11g database release 1

    how to mask data in oracle 11g database release 1
    my environment is
    Database: 11g release 1
    os: AIX 6 (64 bit)
    GC:10g release 1

    DBA-009 wrote:
    thx but how i can mask data with above give environment?What does "mask data" mean to you and what is the environment you are referring to?
    Telling us that you are using 11.1 helps. But it is far from a complete description of the environment. What edition of the database are you using? What options are installed? What Enterprise Manager packs are licensed? Is any of this changable? Could you license another option for the database or another pack for Enterprise Manager if that was necessary?
    What does it mean to you to "mask data"? Do you want to store the data on disk and then mask the data in the presentation layer when certain people query it (i.e. store the patient's social security number in the database but only present ***-**- and the last 4 digits to certain sets of employees)? Do you want to hide entire fields from certain people? Do you want to change the data stored in the database when you are refreshing a lower environment with production data? If so, do you need and/or want this process to be either determinisitic or reversable or both?
    Justin

  • Best practice for installation oracle 11g rac on windows 2008 server x64

    hello!
    can somebody tell me a good book or an other kind of literature regarding "best practice for installation oracle 11g rac on windows 2008 server x64"? thx in advance!
    best regards,
    christian

    Hi Christian,
    Check this on MOS
    *RAC Assurance Support Team: RAC Starter Kit and Best Practices (Windows) [ID 811271.1]*
    https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&doctype=BULLETIN&id=811271.1
    DOC Modified: 14-DEC-2010
    Regards,
    Levi Pereira

  • Configuring oracle 11g and Appl.server

    hello
    we are beginners and need some step by step guide
    to step our database envirnonment.
    Since we have been working in an obsolete database(8i & dev6)
    we are switching to the new version and hence unable to proceed .
    1. Installed oracle 11g on a server with OS windows2003.we are able to
    open the admin pages in a browser and created users and control files.
    we have also imported one users data using dmp files.
    2. Next we have sample application developed using Developer suite 10g .
    In another PC we have installed OS windows xp and also installed only
    application server 10g services for forms and reports.We have placed our sample fmx files
    in this pc.
    3. we are able able to open the file fmx from the browser on this pc and locally
    (Lan) on other pcs by giving the url completely.
    4. Next we want our remote office to open this file through the internet.
    when we tried this we failed in our attempt.Hence please let us know
    how to open the file from the internet.
    5. Next we require one active server page to authenticate the user (from the Table
    created in the database) and if ok open the sample fmx file .
    Here we are struck and do not know how to proceed .
    Please guide as how we have to go about with a sample script and
    other details.
    Thanks in advance

    I do not intend to be insulting but your question reads something like: "my car doesn't start please tell me why?"
    Did you see any error message displayed?
    Did you look in the log files for error messages?
    Can you ping the server?
    Is there a firewall?
    In other words you need to provide a lot more information before we can help you. Right now it could be anything from the battery is dead to it is out of petrol to some thief took the engine. <g>

  • Dataguard installation oracle 11gr2 on windows 2008 server

    Hi,
    I have oracle 11gr2 database on windows 2008 server. I have been given a primary and secondary server with the same setup.
    Now i want to install dataguard. AFter installing i need to test it for disaster recovery.
    Can anyone please suggest me a document for this? I searched in this forum but i couldnt get any.
    Please help.

    An obvious place to look at is our Online Documentation about Data Guard Installation:
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17022/toc.htm
    See
    3 Creating a Physical Standby Database
    there.
    There is not much special-Windows for Data Guard - of course you need to create Windows Services for both Databases etc. as described here:
    http://www.oracle.com/pls/db112/portal.portal_db?selected=11&frame=#microsoft_windows_installation_guides
    Kind regards
    Uwe Hesse
    http://uhesse.wordpress.com

  • How to create listener in 11g RAC on windows 2008 server

    Dear All,
    i worked on win 2003 and linux 4, 5 too. i have installed oracle RAC on both windows and linux.
    now i have installed oracle RAC11gR1 on windows 2008 server.than installed oracle software . now i want to create listener from db_home which i am facing problem.
    i m starting netca from db_home. following the insturction when i finishing it , the proces get started but in the middle is showing the listener on node1 and node2 can't be created.
    please guid me how i willl be able to creat it.
    2nd poing how to create asm instance on RAC11gR1. is it need to install saparate home like 10g for that or i can create from 11g software home.
    thanks,
    sher khan

    thanks for the update ,
    dear oracle 11g rac recomends to create ocr and voting disk on asm.
    i followed the documents they are saying you have to install grid control infrastructure and than need to create asmcfs.(automatic storage management cluster file system.).
    how to create asmcfs to avoid the gridcontrol, if its must is it need to install on one node or both nodes.
    can you plz guide me how to do this .
    thanks,

  • Is owb 11g r2,supported by 64 bit windows 2008 server

    is owb 11g ,r2 supported on 64 bit windows 2008 server.
    is it true that : OWB 11g,r2 is supported only for 32 bit windows 2008.

    There is no 64b client for windows at this time. You can check on Oracle for available downloads.
    http://www.oracle.com/technetwork/developer-tools/warehouse/downloads/software/index.html

  • Oracle 11g r2 report server on vmware esxi 5.1

    dear gurus
    assist me we are facing issue with oracle 11g r2 report server on vmware esxi 5.1
    see all of sudden report function, however we restart server then it work fine,
    where it is on windows 2008 r2 sp1
    our vendor say not certify by oracle this product, we have no rac just standalone env
    1db 1 form 1 report server  all on VMs guest working
    we could not find os vm oracle logs root causes
    kindly assist or advise

    user6029797 wrote:
    Now - I wanted to create 2 such VM Guest Linux O/S instances and make those 2 Linux/Oracle into Oracle 11g R2 RAC
    Is this possible to do - so I can learn about Oracle 11g R2 RAC operation, tuning, setup and maintenance?Yes, possible to setup.
    No, you are unlikely to learn anything of value ito tuning and maintenance as the environment does not run on actual cluster h/w that are used in real world RAC clusters. For example, huge pages, jumbo frames - pretty meaningless in a VM for tuning Oracle RAC. Bonding of Interconnect Interfaces and pulling the plug - pretty much useless. What about running multiple I/O paths to the cluster's storage server? Using RDS for Interconnect instead of UDP? Etc. Etc.
    RAC is only as performant, scalable and robust as the h/w components it is build on. I cannot see any value in virtualising this and expecting to gain real insight to RAC performance management and tuning. Best one can expect is familiarisation with installation prerequisites, the installation steps and setting up the database. I question if any more value than that can be obtained from a single PC virtualised RAC environment.

  • What is the easiest way to export all tables data from Oracle to MS SQL Server?

    Hello MS,
    I would like to export all tables from Oracle 11.2 to MS SQL Server 2012 R1.
    Using the tool "Microsoft SQL Server Migration Assistant v6.0 for Oracle" did not work for me because there are too many warnings and errors regarding the schema creation (MS cannot know it because they are not the schema designer). My idea is
    to leave/skip the schema creation to the application designer/supplier and instead concentrate on the Oracle data export and MS SQL data import.
    What is the easiest way to export all tables data from Oracle to MS SQL Server quickly?
    Is it:
    - the „MS SQL Import and Export Data“ Tool
    - the “MS SQL Integration Services” Tool
    - not Oracle dump *.dmp format because it is a propritery binary format
    - flat file *.csv (delimited format)
    Thanks!

    Hi lingodingo,
    If you want to directly export all tables from Oracle database to SQL Server, I suggest you use SQL Server Import and Export Wizard. Because you just need to follow the wizard with GUI, this is the easiest way.
    If you want to make some modification for the tables‘ data before loading to SQL Server, I suggest you use SQL Server Integration Services package. For more details, please refer to the following similar thread:
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/38b2bed2-9d4e-48d4-a33f-1d9eed1c062d/flat-file-to-sql-server?forum=sqldatamining
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

Maybe you are looking for

  • Why are my fonts in different groups in Illustrator CS5?

    I am running Illustrator CS5 on a Laptop PC. I am constantly installing new fonts to work on customer projects... I have noticed that sometimes the fonts appear in the font list in alphabetical order, and sometimes they appear either towards the top

  • CUSTOM PAGE SIZES

    iWork > Pages > Document > Page Size : In the most recent update... The Inspector shows / has various pre-set templates.  Is there any way of creating custom sizes - for example 8.5" x 2"?

  • Multiple data sources for one datagrid?

    Hello Everyone, I have a page that has a datagrid called dgMainGrid. I have it bound to an HTTPService and it updates fine. But I need to dynamically bind it to another HTTPService when the user clicks a button. How can I do that? Thanks, Anthony

  • How can i delete a passcode form my iphone?

    i have a find my phone passscode on my iphone but i creates it to much trouble so i want to delete the passcode,how can i do that?

  • How do you make an image appear by clicking on a link?

    I have a div set up as a box for my  images. Underneath I have put a several divs, each of which have numbers in them...01.....02....03....04 I would like to know how to make it so that when you click on 01, an image appears in the box, when you clic