Between the two, and dates

Hi all

Given the following data:
  A  |     START_DATE        |         END_DATE
--------------------------------------------------------------
  1  |  01/01/1970  00:00:00 | NULL
  2  |  01/01/1970  00:00:00 | NULL
  3  |  01/01/2004  00:00:00 | NULL
  4  |  01/01/2004  00:00:00 | 01/01/2007 00:00:00
If I run the following query,
SELECT
  *
FROM
  (
    SELECT
      NVL(trim(TO_CHAR(A)),'-') AS "Code",
      NVL(trim(TO_CHAR(start_date)),'-') AS "Start",
      NVL(trim(TO_CHAR(end_date)),'-') AS "End"
    FROM
      my_table
    ORDER BY
       A
  )
WHERE
  (
    '01/01/2004' BETWEEN to_date("Start",'DD/MM/YYYY') AND to_date(
      case "End"
        WHEN '-'
        then '31/12/9999'
        else '01/01/2007'
      END,'DD/MM/YYYY')
  )
I have only the first three rows. Why the fourth line is excluded?

Stephan

----------------------------
10.2.0.1.0 Oracle
Linux 32 bit

Yes, you're right it does not and, after working on it for more than an hour, I'm pretty sure it's a bug in the CASE statement.

Look at this:

Alter session set nls_date_format='YYYYMMDDHH24MISS';

SQL> SELECT
  2  Endd,
  3  case WHEN endd='*' then '-' else endd END,
  4  to_date(case WHEN endd='*' then '-' else endd END,'DD/MM/YYYY'),
  5  to_char(to_date(case WHEN endd='*' then '-' else endd END
  6  ,'DD/MM/YYYY'),'yyyymmddhh24miss')
  7  FROM (SELECT '01/01/2007' endd FROM DUAL);

ENDD       CASEWHENEN TO_DATE(CASEWH TO_CHAR(TO_DAT
---------- ---------- -------------- --------------
01/01/2007 01/01/2007 20070101000000 00000000000000

As you can see the Endd column is set to 01/01/2007 and this is the value of the CASE and the TO_DATE too. But when you convert it to a string using TO_CHAR you get 00000000000000.

This only happens if you use the CASE and compared, in the CASE WHEN clause, ENDD to something.
For example, this works:

SQL> SELECT
  2  Endd,
  3  case WHEN 1=2 then '-' else endd END,
  4  to_date(case WHEN 1=2 then '-' else endd END,'DD/MM/YYYY'),
  5  to_char(to_date(case WHEN 1=2 then '-' else endd END,'DD/MM/YYYY'),'yyyymmddhh24miss')
  6  FROM (SELECT '01/01/2007' endd FROM DUAL);

ENDD       CASEWHEN1= TO_DATE(CASEWH TO_CHAR(TO_DAT
---------- ---------- -------------- --------------
01/01/2007 01/01/2007 20070101000000 20070101000000

It is identical to the previous one except the CASE WHEN clause.
I did more than 20 different tests and whenever I put Endd in the CASE WHEN clause, the CASE seems to work fine, fact the TO_DATE but not the outermost TO_CHAR referring 00000000000000...

As a workaraudo, you can use DECODE place od the CASE:

SQL> SELECT
  2    *
  3  FROM
  4    (
  5      SELECT
  6        NVL(trim(TO_CHAR(A)),'-') AS "Code",
  7        NVL(trim(TO_CHAR(start_date)),'-') AS "Start",
  8        NVL(trim(TO_CHAR(end_date)),'-') AS "End"
  9      FROM
 10        my_table
 11      ORDER BY
 12         A
 13    )
 14  WHERE
 15    (
 16      '01/01/2004' BETWEEN to_date("Start",'DD/MM/YYYY') AND
 17                           to_date(DECODE("End",'-','31/12/9999',"End"),'DD/MM/YYYY')
 18    )
 19  /

Code                                     Start      End
---------------------------------------- ---------- ----------
4                                        01/01/2004 01/01/2007

but I suggest you change the entire query to simplify it, like:

select a code, start_date "Start", end_date "End"
from my_table
where to_date('01/01/2004','dd/mm/yyyy') BETWEEN start_date
      and nvl(end_date,to_date('31/12/4712','DD/MM/YYYY'));

Published by: Massimo Ruocchio, December 19, 2009 15:52
All of the above queries were run on 10.2.0.1 the same version used by the Po.
I tested all applications above on 9.2.0.4, 10.2.0.4 11.1.0.6 and everything works fine.
Now, I'm sure it's a bug of the 10.2.0.1 version.

Max
[My Italian Blog Oracle | http://oracleitalia.wordpress.com/2009/12/19/totali-parziali-con-group-by-rollup/]

Tags: Database

Similar Questions

  • delay between the trigger and data acquisition

    Hi, I use NI SMU-6368 as a tool for data acquisition. In my experience, I use an external digital trigger to start taking measures of a thermistor.

    However, before the experience, I want to know the time that elapses between the detection of the trigger signal and data acquisition start time.

    Is there a way to do this?

    Here's the kind of thing I configure to get an accurate measure of time of t = 0 trigger signal to the

    the actual first A/D conversion.   It may be too much for a measurement of the temperature, but you should get

    the right track.

    -Kevin P

  • Noise reduction and sharpening in lightroom 5.2 problem develop between the two and library module.

    Hi, I have a photo I asked a lot of noise and sharpening to, when I swich develop between module and library, the noise does not disappear? I also tried to export the image without the chance to get rid of the noise.

    Edit

    I tried to update the metadata & preview DNG. No luck...

    I have tried to change the settings of the catalog / handling / Standard size preview of the file. No luck... But the peak seems to make a littlebit better.

    Anyone?

    D800 Nikon,

    Import to DNG,

    2.8 ISO 6400

    Win 8 64-bit

    16 GB OF RAM

    Processor 2.4 Ghz

    Concerning

    Kent

    This is due to the high ISO 6400, long exposure and large amount of sharpening, as I have indicated on the site of Photoshop Lightroom bug reports.

    To prove if this is really the cause see the image in two modules at the sight of 1:1. They now look the same? If so, you have your answer!

    (1) try to lower the detail 25 sharpening slider and the color detail slider to 50.

    (2) look at the image in 1:1 two modules to recreate the cache to develop and the library preview images. In each module wait LR to apply the new settings to the image.

    (3) now, look at the image to display 'Fit' in the two modules.

    (4) it is sometimes necessary to step #2 above twice (i.e. twice) to ensure that the point of view 'Fit' has new LR settings applied.

    How to develop and the library view ' worthy' compare now?

  • The difference between the chroma and Saturation?

    Can someone explain the difference between the chroma and saturation?

    Also, how would I change the saturation of a color in Photoshop?

    Thank you!

    c,

    You can take a look here:

    http://en.Wikipedia.org/wiki/colorfulness

    A search in the Helpfile Photoshop will show if there is a real distinction (in later versions) between the two, and if it is possible to work with chroma rather than saturation.

  • How to count the number of Sundays between the two dates

    Hello

    I want the number of Sundays between the two dates

    example of

    number of number of Sundays between 4 January 2013 ' and April 30, 2013 "in a select query, I have to include this as a sub query in my select statement.

    nordine B wrote:
    Hi Frank,.
    Have 1 doubt...

    In many countries the week could me "Monday". How the application handles it?
    Or did I get something wrong?

    Help, please!

    For ' IW'(ISO week) early in the day is always Monday...

    It's so simple - calculate the weeks between two dates based on Monday... This is the number of Sundays...

    NEXT_DAY is another option...

    SQL> with dd as
      2  (
      3      select TO_DATE('01-04-2013','dd-mm-yyyy') fdt, TO_DATE('30-04-2013','dd-mm-yyyy') ldt from dual
      4  )
      5  SELECT       fdt,ldt,
      6            (next_day(ldt,'sunday')-next_day(fdt-1,'sunday'))/7 sdays
      7  FROM         dd;
    
    FDT       LDT            SDAYS
    --------- --------- ----------
    01-APR-13 30-APR-13          4
    

    Published by: JAC on May 2, 2013 12:20

  • Why my display of the date of the mailbox does not have a / between the year and the month?

    I'm talking here about how the date of different e-mails appear in my Inbox. I have a / between the month and the day, and a / after the day, but I did not / between the year and the month.

    TB uses the date format short, such that defined by your operating system, which, in the case of Windows, is located in the Panel control/region and language.

    http://KB.mozillazine.org/Date_display_format

    There are a few modules that might also be useful:

    https://addons.Mozilla.org/en-us/Thunderbird/addon/ConfigDate/

    https://addons.Mozilla.org/en-us/Thunderbird/addon/Super-date-format/

    http://chrisramsden.vfast.co.UK/3_How_to_install_Add-ons_in_Thunderbird.html

  • The difference between the two copies and Clone?

    I make a copy of an existing symbol. On the Edit menu, they have Dulicate and Clone to achieve this. What is the difference between the two? As far as I can tell, if I select the clone, it puts a copy of the object directly on top of the selected object to copy. If I select duplicate it offered the copy is not directly above the original to copy object. What is the difference?

    Well Yes

    Jim Babbage

  • Trouble with the voice and data Vlan vlan translate between CT3905 and SF300 - 24 p

    Hey actually, we have the solution to monitoring of implementation with CT3905 phone, SF300 - switches 24 p cameras and AIR-AP1041N Access Points

    We have the problem with the vlan tag in SF300 switch ports - 24 p we can´t tag vlan of the voice and data VLANs on the same port on SF300 - 24 p it is Possible or we must dedicate a port for each VLAN or ussing the same data segment of VLANs and vlan voice?

    Someone has an answer or technical documentation that can help us

    Best regards

    First of all,

    Please disable lldp transmit in SF 300 switch.

    The command is "no lldp transmitted."

    After you disable check the following steps.

    https://supportforums.Cisco.com/docs/doc-27005

    facing the same problem with cisco SG 300 and 3905 ip phone switch.

    And nested thing was my 7945 and 6941 phones use to work properly, without above configuration.

    Cisco 3905 became not vlan Ip address votes and even if I put static, it did not work.

    After a long struggle, I was able to solve the problem. Now both phone and system work fine in the same port.

    Samantha

  • find and change between the two

    I want to change in my text frames written in the style of paragraph text "EBT".

    Between 1 to 3 of the text 'ABC '.

    Between the 4 and 7 'BIM' text

    Between 7 and 10 'KLM '.

    must write

    where and how a mistake

    var myDoc = app.activeDocument;
    var myFrame = myDoc.allPageItems;
    for(var i=0;i<myFrame.length;i++){
    //if(myFrame[i].appliedObjectStyle == tmc) {
    //if(i==5){break;}
    app.findGrepPreferences = app.changeGrepPreferences = null; 
    app.findGrepPreferences.appliedParagraphStyle = "myParS";
    app.findGrepPreferences.findWhat = "EBT";
    if ((i > 0) && (i <= 3)) {var changeX = app.changeGrepPreferences.changeTo  = "ABC";}
    if ((i > 3) && (i <= 7)) {var changeX = app.changeGrepPreferences.changeTo  = "BIM";}
    if ((i > 7) && (i <= 10)) {var changeX = app.changeGrepPreferences.changeTo  = "KLM";}
    myFrame[i].texts[0].changeGrep(); 
    app.findGrepPreferences = app.changeGrepPreferences = null; 
    
    

    Dirty solution... ;-)

    var myDoc = app.activeDocument;
    var myFrame = myDoc.allPageItems;
    
    for(var i=0;i 0) && (j <= 3)) {app.changeGrepPreferences.changeTo  = "ABC"; myFrame[i].changeGrep(); }
        if ((j > 3) && (j <= 7)) {app.changeGrepPreferences.changeTo  = "BIM"; myFrame[i].changeGrep(); }
        if ((j > 7) && (j <= 10)) {app.changeGrepPreferences.changeTo  = "KLM"; myFrame[i].changeGrep(); }
        app.findGrepPreferences = app.changeGrepPreferences = null;
    }
    
  • Find the difference of pressure between the two transducers using a NI DAQ 6008

    Hello

    First of all, I'm a relatively inexperienced LabVIEW Developer, so my apologies in advance if this message does not have something, or otherwise lacks clarity.

    I try to develop a VI as follows the pressure difference between the 2 EME 3100 pressure sensors (4-20 my), related to two different pressure lines, using a NO-DAQ 6008. I would like for the acquisition of data to read the two transducers, then have him find VI the differential and write this differential in an Excel file.

    The data sheet for these sensors may be found at: http://www.gemssensors.com/Products/Pressure/Pressure-Tranducers/Sputtered-thin-film/~/media/GemsNA/...  It is a 3-wire system, with a voltage between 8 - 24V. I use an external power supply of generic brand to power sensors, which provides a maximum of 24V @ 4A.

    I drifted my physical connection (for the two transducers) this thread http://forums.ni.com/t5/LabVIEW/I-am-having-trouble-Omega-PX4200-Pressure-Transducers-to-where-I/m-p... and am relatively certain of the accuracy of the information. For purposes of signal conditioning, I use a 500 Ohm resistor between the signal of each transducer and the Earth wire.  On the side of software, I use the latest version of LabVIEW (2011) as well as MAX on a Windows 7 64-bit machine.

    In an ideal world, the sampling rate would be as high as possible, but 4 samples per second would suffice for all purposes useful.

    Given this goal, are there any sample of VI (especially for MAX, which I have not yet used) who would be similar/applicable to this project, specifically, regarding setting a sampling frequency, calibration of the transducers or affecting the pins/channels appropriate? All resources would be greatly appreciated.

    Kind regards

    MG Wilkinson

    Measure the voltage between the two resistance (resistance by probe 4-20 MA) using the differential inputs of the x 600.

    When you configure the task, you can read several entries at once, by entering in "Dev_ / AI0:1" in the physical channels and using the "several channels / {unique |}". multiple} samples"polymorphic instance.

    600 x can read 1kS/sec.

    Do maths/conversions on the table, and then simply subtract the two tables.

    Could also take some samples (10-100) at 1 kHz and their average together, give you a smaller rate effective sampling but with less noise.

    A loop of producer-consumer would be good architecture here, let the daqmx reading live in a loop and sends the data via a queue to a 2nd consumer that performs mathematical operations and write to a file.

  • I can't stop finite samples daqmx read between the two?

    Hi all

    I want to read data from 10 seconds to a trigger is received. for this im using daqmx task finished sample mode and read the data on the trigger getting. It works fine but I can't stop my vi between the two when its reading of the data. I have to wait for it to complete the reading of values, and then stop the vi.

    so I switched to continuous sampling mode that allowed me to stop the vi whenever I want.

    I just want to know is there any means or the property using which I can stop my task over daqmx read when I want?

    I guess you call DAQmx Read with extraordinary value (-1) for samples of #.  It is also the default if left thread continues.  In a finished sample task, it means to wait until the memory full buffer has been filled with samples before returning.  Once you make that call, you cannot directly finish soon.  You're stuck waiting for buffer fill or for the timeout expires (default 10 seconds).

    One way to avoid getting stuck is not to ask for samples that do not exist already.  You can query a DAQmx Read property, known as the "Samples available" or something like that and son of this result in a call to DAQmx Read.  Such a call will return immediately whatever data are currently available.  Subsequent calls will give you samples.

    -Kevin P

  • difference between the view and the procedure

    Hi Master,

    Today I received a request from my senior technical leader... !!

    Q > what is the difference between the view and the procedure?

    I got response like this...

    A view represents the logic of one or more tables/views. It won't take no place in db... It is a virtual table, query will only store in db... useful

    for safety... If the main table has obtained changes... automatically discovers also change... etc.

    Proecudure is a db object will be performs a perticular action... It may or may not return values. ?

    But somehow, he isn't happy... He expects more... .very close view of diff. b & w and procedure.

    Please explain it to me...!

    Concerning

    AR

    874273 wrote:

    Hi Blu,

    Thanks for your replies...! But we think if notice and procedure will be the same no matter what point of view? Both are the same? If Design view... We can create a stored procedure?

    How a view and procedure may do the same thing?  They are two different things with different objectives.  You use the correct one depending on what you want to achieve; they are not interchangeable.

    And another question...!

    (Q) how you will store Japan, characters of China in a database table? will there be a new feature in Oracle 11 g?

    (A) I use dbms_lob package? Japan/China characters are multi byte characters... so we can use the nclob data type?

    is this correct... ?

    No, it not there no novelty in Oracle 11 g for the storage of Japanese or Chinese characters, because there is already a feature for their storage in previous versions as well.  It is determined by the parameters characterset and nationality that you use when you create the database.

    Why would you choose to store them in a LOB using DBMS_LOB?  Yes, they have multibyte characters, but if you have configured your database for the correct character sets, for example using UTF - 8, then you can store the characters in VARCHAR2, like any other language.  The only difference is that the storage of 4000 bytes limit still applies, so you maybe isn't able to store 4000 multibyte characters in a varchar2 column 4000 single-byte, it can be as little as 1000 characters if they are all characters in 4 bytes.  (Note: 12 c limit in SQL can be increased up to 32,767 characters, to harmonize it with variable varchar2 PL)

  • How to get the points of contact between the points and polygons

    Hi ~

    I am
    work based on Oracle 11 g and
    looking for a way to get points of contact between the points and polygons.

    For example, I have two data STORE (point) "and"(polygon) ROAD"and each store must have a contact point or points of contact for the nearest road.

    I know what the closest route is using SDO_NN, but I don't know hot to get the point of contact.

    Please let me know hot to do ~

    Thank you.

    If you have the point and its nearest road, you can find the contact point (ie the store point nearest the road linestring) using SDO_LRS function Project_Pt as follows:

    With route As (
      select SDO_GEOMETRY(3302,NULL,NULL,SDO_ELEM_INFO_ARRAY(1,2,1),SDO_ORDINATE_ARRAY(2.0,2.0,0.0, 2.0,4.0,3.218, 8.0,4.0,12.872, 12.0,4.0,19.308, 12.0,10.0,28.962, 8.0,10.0,35.398, 5.0,14.0,43.443)) as route,
             SDO_GEOMETRY(2001,NULL,sdo_point_type(9,3,NULL),null,null) as store
      from dual
      )
      SELECT SDO_LRS.PROJECT_PT(route, store) as store_on_route
      FROM route ;
    -- Result
    --
    STORE_ON_ROUTE
    --------------------------------------------------------------------------------------------------------
    MDSYS.SDO_GEOMETRY(3301,NULL,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1,1),MDSYS.SDO_ORDINATE_ARRAY(9,4,14.481))
    

    If you don't have a space licence, try using my LRS for users of Locator at: http://www.spatialdbadvisor.com/source_code/214/linear-package-sdo_lrs-replacement

    If this is correct, please give points. (I work for love IE Points not money!)

    concerning
    Simon

  • Persistence, shared between the EJB and WAR projects

    Hello

    I created an Enterprise Application in netbeans which an EJB project and archive web. This can be expanded further at a later date by the presence of a client application as well. I'm still pretty new to this so you don't have to forgive me if it is a simple problem. I have a persistence unit (persistence.xml) that I need to share between the two WAR and EJB, but so far, does not feel very lucky. I have read the various responses and they say I should have the EAR that is constructed in the following way:

    Project.ear
    =======
    META-INF/MANIFEST. MF
    lib/Persistence.jar
    -> META-INF
    -> META-INF/persistence.xml
    project - ejb.jar
    project - war.war

    When I try to compile, if I get the following messages among two EE modules:

    Note: The XML persistence [META-INF/persistence.xml] has not been found. NO GENERATION will occur! Please ensure that a persistence XML is available either from the directory CLASS_OUTPUT [META-INF/persistence.xml] or by using the eclipselink.persistencexml property to specify its location.

    I tried to copy the persistence.xml in the META-INF directory in the EAR file and defining the eclipselink.persistencexml=META-INF/persistence.xml, but it still shows the same thing. Is this a classpath problem or is something else wrong?

    Thank you very much

    The EAR is a good idea, but you put the META-INF/persistence.xml in your ejb module. The EJB is where you do all your (managed container) transactional stuff, so do call in your EJB since the WAR instead of trying to share a persistence between modules unit.

  • Qosmio G50 - 10I - no synchronization on TV between the picture and sound

    My problem is that there is no synchronization between the picture and sound (+ the sound is thin about 5 seconds +)
    When I watch TV on Windows Media Center on the Qosmio G50 - 10I

    I tried to change the settings in Windows Media Center, but some will escape.

    How to connect this TV to the G50?
    You use the HDMI cable that provides audio and video signal together at the same time or you connect the TV with two different cables (for audio & video signal)?

    Also check the settings in Realtek HD audio Manager located in the control panel. Here, you can change some sound effects for different outputs (digital speakers, HDMI) audio

    PS: Last but not least install codecs. I recommend a package called K-Lite Mega codec package

Maybe you are looking for

  • IPhone 6 and desperate death

    It's a new iPhone 6 without scratches and had a case and screen protecter on it. I woke up to my phone acting glitchy two days ago.  Soon he would not allow me to hear phone calls, but I could hear everything. My phone is dead soon so I plugged it in

  • Pogo Java based games will not load with the new update.

    I just got the update last for Firefox 3.6.14. I was always able to use Firefox to play games on Pogo.com. After the update today, I can enter the site, but 90% of the games won't download. Pogo said in their help pages: Mozilla has a documented bug

  • LabWindows and gpib

    HII all! I'm new to labwindows, want to develop an application to automate the instruments (controller and data movement counters) using the gpib interface. I want to know if I have to install the system initially with connections to the gpib control

  • Update Windows problem drivespace

    Notification of update microsoft security essentials 1.117.2744.0 update is 74.5 MB. I have 15% free drivespace.  Is the update transferred to diving?  Please notify

  • impossible to reinstall windows XP pro...

    Hi, I'm hoping there's an Assistant "you have not" reading of this... I got tired of random programs from decide who wanted not run/open/work at all without reason aparant, some viruses of compensation or foolishly setting set somewhere im enough com