The difference of to_char

Hi.
I do two selects on table emp. The first select is:
select ename
from emp
where hiredate<sysdate;
The second select is:
select ename
from emp
where to_char(hiredate,'DD.MM.YYYY')<to_char(hiredate,'DD.MM.YYYY');
The first select is right and it show me all employees.
But the second select show me only four employees. And I don't understand the result of the second select.

You can use TRUNC and ROUND functions.
SQL> alter session set NLS_DATE_FORMAT = 'dd-mm-yyyy:hh24:mi:ss';
Session altered.
SQL> select sysdate,
2 trunc(sysdate, 'DAY') trunc_date,
3 round(sysdate, 'day') round_date
4 from dual;
SYSDATE TRUNC_DATE ROUND_DATE
04-02-2004:17:08:29 02-02-2004:00:00:00 02-02-2004:00:00:00

Similar Messages

  • What is the difference between TO_CHAR and TO_DATE()?

    Hi everybody,
    i am facing a problem in my system.It is quite urgent, can you explain me "What is the difference between TO_CHAR and TO_DATE()?".
    According to user's requirement, they need to generate a code with format "YYMRRR".
    YY = year of current year
    M = month of current month (IF M >=10 'A' ,M >=11 'B' , M >=10 'C')
    RRR = sequence number
    Example: we have table USER(USER_ID , USER_NAME , USER_CODE)
    EX: SYSDATE = "05-29-2012" MM-DD-YYYY
    IF 10
    ROW USER_ID , USER_NAME , USER_CODE
    1- UID01 , AAAAA , 125001
    2- UID02 , AAAAA , 125002
    10- UID010 , AAAAA , 12A010
    This is the original Script code. But This script runs very well at my Local. Right format. But it just happens wrong format on production.
    12A010 (Right) => 11C010 (Wrong).
    SELECT TO_CHAR(SYSDATE, 'YY') || DECODE( TO_CHAR(SYSDATE, 'MM'),'01','1', '02','2', '03','3', '04','4', '05','5', '06','6', '07','7', '08','8','09','9', '10','A', '11','B', '12','C') ||     NVL(SUBSTR(MAX(USER_CODE), 4, 3), '000') USER_CODE FROM TVC_VSL_SCH                                                       
         WHERE TO_CHAR(SYSDATE,'YY') = SUBSTR(USER_CODE,0,2)                         
         AND TO_CHAR(SYSDATE,'MM') = DECODE(SUBSTR(USER_CODE,3,1),'1','01',          
              '2','02', '3','03', '4','04', '5','05',          
              '6','06', '7','07', '8','08', '9','09',          
              'A','10', 'B','11', 'C','12')                    
    I want to know "What is the difference between TO_CHAR and TO_DATE()?".

    try to use following select
    with t as
    (select TO_CHAR(SYSDATE, 'YY') ||
             DECODE(TO_CHAR(SYSDATE, 'MM'),
                    '01', '1',
                    '02', '2',
                    '03', '3',
                    '04', '4',
                    '05', '5',
                    '06', '6',
                    '07', '7',
                    '08', '8',
                    '09', '9',
                    '10', 'A',
                    '11', 'B',
                    '12', 'C') as code
        from dual)
    SELECT t.code || NVL(SUBSTR(MAX(USER_CODE), 4, 3), '000') USER_CODE
      FROM TVC_VSL_SCH
    WHERE SUBSTR(USER_CODE, 1, 3) = t.codeand yes you need check time on your prodaction server
    good luck
    Edited by: Galbarad on May 29, 2012 3:56 AM

  • As to the data type of the data type of the difference between two date type of datas

    Hi,
    I have a question about the data type of the difference between two date type of datas.
    There are two date type of datas as:
    SSHIPMENTS.RECEIVEDATETIME
    SSHIPMENTS.PROMISEDATETIME
    I try to use the following SQL Script in Oracle SQL*Plus as:
    SELECT CASE
    WHEN (SSHIPMENTS.RECEIVEDATETIME - SSHIPMENTS.PROMISEDATETIME) < '000 01:00:00.000' THEN 'OnTime'
    WHEN (SSHIPMENTS.RECEIVEDATETIME - SSHIPMENTS.PROMISEDATETIME) < '000 01:30:00.000' THEN '60-89 Minutes'
    ELSE '3+ Hours'
    END
    FROM SSHIPMENTS;
    The error message of "Invalid Number" for the '000 01:30:00.000' happens.
    I don't know if the data type of the interval is wrong.
    Many Thanks,
    Cathy

    SELECT CASE
    WHEN (to_char(SSHIPMENTS.RECEIVEDATETIME,'hhmiss') - to_char(SSHIPMENTS.PROMISEDATETIME,'hh24miss')) < '010000' THEN 'OnTime'
    WHEN (to_char(SSHIPMENTS.RECEIVEDATETIME,'hhmiss') - to_char(SSHIPMENTS.PROMISEDATETIME,'hh24miss'))< '000 01:30:00.000' THEN '60-89 Minutes'
    ELSE '3+ Hours'
    END
    FROM SSHIPMENTS;
    just try it out..

  • I want to know the difference between Days column and Day1 Column

    Hi All,
    I used this query:
    SELECT to_char(return_date_time,'dd/mon/yyyy hh24:mi:ss') Test,
    DECODE ('I', 'I', DECODE (1, NULL, NULL, 0, NULL, SYSDATE + 1)) Days,
    DECODE ('I', 'I', SYSDATE + 1) Day1
    FROM fm_curr_locn
    WHERE patient_id = 'DU00002765'
    output: 
    Test
    Days
    Day1
    26/oct/2013 00:00:00
    26-OCT-13
    10/26/2013 3:06:59 PM
    I want to know the difference between Days column and Day1 column and why the days column didnt show the time
    Please anyone help.....
    Regards
    Shagar M

    Pleiadian wrote:
    It is the decode statement that is doing this.
    The format of decode is:
    decode(expression, search1, result1, search2, result2, searchn, resultn, default)
    All result fields must be of the same datatype and will be of the datatype of the first result (result1 in this example)
    In your example (the decode for the field Days) the first result is a NULL. I suspect (gurus? anyone?) that Oracle will use the varchar2 overload of the decode statement, and the date field will be converted to varchar2 using your NLS_DATE_FORMAT settings.
    In the second decode statment (Day1) the first result is of datatype date, so the result of the decode statement will be a date field (and will be parsed as such by your sql development tool)
    I agree, as NULL is the first result returned the datatype is undetermined, so Oracle is picking VARCHAR2 over others, and causing an implicit datatype conversion on the resultant date value, whereas the other which is returned as a date will use the local settings of the client tool being used.
    I can replicate the 'issue' in Toad, and it's rectified if we cast the first returned value of the decode statement...
    SELECT DECODE ('I', 'I', DECODE (1, NULL, CAST(NULL AS DATE), 0, NULL, SYSDATE + 1)) Days,
           DECODE ('I', 'I', SYSDATE + 1) Day1
    FROM dual

  • How to Get the difference between date

    Hi
    I try this query to find the difference between 2 date given in the below query.
    But the query can't be execute..
    Please try this query and give the correct one...
    select to_date(to_char(LAST_DAY('2005/03/15')+1,'yyyy/mm/dd'),'yyyy/mm/dd') - to_date('2003/06/15','yyyy/mm/dd') No_days from dual
    Thanks

    try this
    SELECT last_day(to_date('2005/03/15', 'yyyy/mm/dd') + 1) -
    to_date('2003/06/15', 'yyyy/mm/dd') no_days
    FROM dual
    LAST_DAY return a date not a varchar

  • How to get the difference between these two dates

    Hello Friends,
    I need to get the difference between these two fields which store dates but with varchar2 data types
    SELECT pac.segment1, pac.segment2 emp_no, pac.segment3 NAME,
    pac.segment4 POSITION, pac.segment5 start_date, pac.segment6,
    pac.segment7
    FROM per_analysis_criteria pac, fnd_id_flex_structures_vl ffs
    WHERE ffs.id_flex_structure_code = 'Employee Rejoin'
    AND ffs.id_flex_num = pac.id_flex_num
    AND TO_CHAR (TO_DATE (pac.segment7, 'YYYY/MM/DD HH24:MI:SS'))
    - TO_CHAR (TO_DATE (pac.segment6, 'YYYY/MM/DD HH24:MI:SS')) > 1;
    my query is something like this...
    am trying to find the difference between the last two columns but with not much luck..
    can some one suggest me a solution please

    SELECT pac.segment1, pac.segment2 person_id, pac.segment3 NAME,
    papf.employee_number, paaf.supervisor_id, pac.segment4 POSITION,
    pac.segment5 start_date, pac.segment6, pac.segment7,
    papf2.email_address,
    ( TO_DATE (TO_CHAR (pac.segment7), 'DD-MON-YYYY HH:MI:SS AM')
    - TO_DATE (pac.segment6, 'DD-MON-YYYY HH:MI:SS AM')
    + 1
    ) difference,
    POST.email_address
    FROM per_analysis_criteria pac,
    apps.fnd_id_flex_structures_vl ffs,
    per_all_people_f papf,
    per_all_assignments_f paaf,
    per_all_people_f papf2,
    (SELECT email_address, person_id
    FROM per_all_people_f
    WHERE person_id IN (
    SELECT person_id
    FROM per_all_assignments_f
    WHERE position_id IN (SELECT position_id
    FROM per_positions
    WHERE NAME LIKE 'HR Manager.704.')
    AND TRUNC (SYSDATE) BETWEEN effective_start_date
    AND effective_end_date)
    AND TRUNC (SYSDATE) BETWEEN effective_start_date AND effective_end_date
    AND business_group_id = fnd_profile.VALUE ('PER_BUSINESS_GROUP_ID')) POST
    WHERE ffs.id_flex_structure_code = 'Employee Rejoin'
    AND TO_CHAR (papf.person_id) = pac.segment2
    AND ffs.id_flex_num = pac.id_flex_num
    AND TRUNC (SYSDATE) BETWEEN papf.effective_start_date
    AND papf.effective_end_date
    AND papf.current_employee_flag = 'Y'
    AND papf.person_id = paaf.person_id
    AND TRUNC (SYSDATE) BETWEEN paaf.effective_start_date
    AND paaf.effective_end_date
    AND papf.person_id = paaf.person_id
    AND papf2.person_id = paaf.supervisor_id
    AND paaf.primary_flag = 'Y'
    AND TRUNC (SYSDATE) BETWEEN papf2.effective_start_date
    AND papf2.effective_end_date
    AND papf2.current_employee_flag = 'Y'
    and ( TO_DATE(to_char(pac.segment7), 'DD-MON-YYYY HH:MI:SS AM')-TO_DATE (pac.segment6, 'DD-MON-YYYY HH:MI:SS AM')+1) >1
    last line is giving me the error pls suggest a solution

  • The Difference Between?

    Ok so I believe I know the answer here but asking anyway.
    What is the difference between the adobe creative cloud team license vs the adobe creative cloud enterprise license?
    is the team licence basically individually licences products per account users?
    and is the enterprise one license that covers multiple users at once?
    Thanks and sorry for the question but had to verify.

    Hi tbirdbrent ,
    Thank you for posting on the forums, the answer to your question is as follows.
    1) Creative Cloud for teams brings together the very latest Creative Cloud desktop apps, updates and upgrades the moment they’re released, and all of the services and business features your team needs to create their best work and collaborate with their peers. Adobe offers two Creative Cloud for teams plans — you can opt for a complete plan (all apps and services) or a single-app plan such as Photoshop CC (access to one app and select services). With each option, you’ll receive access to the same easy-to-use web-based admin console that allows the administrator to centrally purchase, deploy, and manage all seats across your organization — whether single app or complete — under one membership agreement.
    2) Creative Cloud for enterprise is for organizations with large deployments that require centralized provisioning and customized deployment of apps and services. Enterprises also receive enterprise customer support and expert services. Creative Cloud for enterprise also works with Digital Publishing Suite; Adobe Anywhere for video; and Adobe Marketing Cloud, which includes Adobe Experience Manager — all sold separately.
    Also, the team licences is not individually licences products per account users and the same goes with the enterprise license.
    Thanks,
    Vikrantt Singh

  • When would I use an if, for or while statement in Small Basic and what is the difference between the three?

    I have a Y9 Computer Science Exam next week and I know that this will probably be one of the questions on it so I need to know the answer. What is the difference?

    An If statement executes once IF the statement is true:
    If 1 = 2/2 Then
    Textwindow.writeline("True")
    EndIf
    A While statement executes WHILE the statement is true:
    While 4 = 2+2
    'Will keep looping while it is true
    EndWhile
    A For statement loops a number in increment:
    For i = 1 to 10
    'Every time through, i gets bigger by one until it equals 10
    EndFor
    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

  • BODS 3.1 : SAP R/3 data extraction -What is the difference in 2 dataflows?

    Hi.
    Can anyone advise as to what is the difference  in using the data extraction flow for extracting Data from SAP R/3 ?
    1)DF1 >> SAPR/3 (R3/Table -query transformation-dat file) >>query transformation >> target
    This ABAP flow generates a ABAP program and a dat file.
    We can also upload this program and run jobs as execute preloaded option on datastore.
    This works fine.
    2) We also can pull the SAP R/3 table directly.
    DF2>>SAPR/3 table (this has a red arrow like in OHD) >> Query transformation >> target
    THIS ALSO Works fine. And we are able to see the data directly into oracle.
    Which can also be scheduled on a job.
    BUT am unable to understand the purpose of using the different types of data extraction flows.
    When to use which type of flow for data extraction.
    Advantage / disadvantage - over the 2 data flows.
    What we are not understanding is that :
    if we can directly pull data from R/3 table directly thro a query transformation into the target table,
    why use the Flow of creating a R/3 data flow,
    and then do a query transformation again
    and then populate the target database?
    There might be some practical reasons for using these 2 different types of flows in doing the data extraction. Which I would like to understand.  Can anyone advise please.
    Many thanks
    indu
    Edited by: Indumathy Narayanan on Aug 22, 2011 3:25 PM

    Hi Jeff.
    Greetings. And many thanks for your response.
    Generally we pull the entire SAP R/3 table thro query transformation into oracle.
    For which we use R/3 data flow and the ABAP program, which we upload on the R/3 system
    so as to be able to use the option of Execute preloaded - and run the jobs.
    Since we do not have any control on our R/3 servers nor we have anyone on ABAP programming,
    we do not do anything at the SAP R/3 level
    I was doing this trial and error testing on our Worflows for our new requirement
    WF 1 : which has some 15 R/3 TABLES.
    For each table we have created a separate Dataflow.
    And finally in between in some dataflows, wherein, the SAP tables which had lot of rows, i decided to pull it directly,
    by-passing the ABAP flow.
    And still the entire work flow and data extraction happens ok.
    In fact i tried creating a new sample data flow and tested.
    Using direct download and - and also execute preloaded.
    I did not see any major difference in time taken for data extraction;
    Because anyhow we pull the entire Table, then choose whatever we want to bring into oracle thro a view for our BO reporting or aggregate and then bring data as a table for Universe consumption.
    Actually, I was looking at other options to avoid this ABAP generation - and the R/3 data flow because we are having problems on our dev and qa environments - giving delimiter errors.  Whereas in production it works fine. Production environment is a old set up of BODS 3.1. QA and Dev are relatively new enviornments of BODS. Which is having this delimiter error.
    I did not understand how to resolve it as per this post : https://cw.sdn.sap.com/cw/ideas/2596
    And trying to resolve this problem, I ended up with the option of trying to pull directly the R/3 table. Without using ABAP workflow.  Just by trial and error of each and every drag and drop option. Because we had to urgently do a POC and deliver the data for the entire e recruiting module of SAP. 
    I dont know whether i could do this direct pulling of data - for the new job which i have created,
    which has 2 workflows with 15 Dataflows in each worflow.
    And and push this job into production.
    And also whether i could by-pass this ABAP flow and do a direct pulling of R/3 data, in all the Dataflows in the future for ANY of our SAP R/3 data extraction requirement.  And this technical understanding is not clear to us as regards the difference between the 2 flows.  And being new to this whole of ETL - I just wanted to know the pros and cons of this particular data extraction. 
    As advised I shall check the schedules for a week, and then we shall move it probably into production.
    Thanks again.
    Kind Regards
    Indu
    Edited by: Indumathy Narayanan on Aug 22, 2011 7:02 PM

  • Hello, we have both Creative Cloud and Creative Cloud for teams. Can you help me with the difference and if i need to have both?

    Hello, we have both Creative Cloud membership and Creative Cloud for team. Can you help me with the difference and if i need to have both? We have 9 employees that are using it. Just not sure if i'm paying for something i don't need.
    Thank you

    Please refer to Creative Cloud Help | Creative Cloud / Common Questions
    CC is for retail use with 20 GB of storage space, CCT is where number of seats are purchased & assigned by one program admin where each seat gets 100GB of storage space.
    You can not have both the CC & team in one account as it will only provide you added storage space of 120 GB but you can activate the CC any of them or either of them twice as CC is based on Adobe ID.
    Regards
    Rajshree

  • Difference between char and varchar, also the difference between varchar2

    Hi,
    Can anyone explain me the difference between char and varchar, and also the difference between varchar and varchar2...

    Varchar2 is variable width character data type, so if you define column with width 20 and insert only one character to tis column only, one character will be stored in database. Char is not variable width so when you define column with width 20 and insert one character to this column it will be right padded with 19 spaces to desired length, so you will store 20 characters in the dattabase (follow the example 1). Varchar data type from Oracle 9i is automaticlly promoted to varchar2 (follow example 2)
    Example 1:
    SQL> create table tchar(text1 char(10), text2 varchar2(10))
    2 /
    Table created.
    SQL> insert into tchar values('krystian','krystian')
    2 /
    1 row created.
    SQL> select text1, length(text1), text2, length(text2)
    2 from tchar
    3 /
    TEXT1 LENGTH(TEXT1) TEXT2 LENGTH(TEXT2)
    krystian 10 krystian 8
    Example 2:
    create table tvarchar(text varchar(10))
    SQL> select table_name,column_name,data_type
    2 from user_tab_columns
    3 where table_name = 'TVARCHAR'
    4 /
    TABLE_NAME COLUMN_NAME DATA_TYPE
    TVARCHAR TEXT VARCHAR2
    Best Regards
    Krystian Zieja / mob

  • The difference between Lion and Mountain Lion

    Can some one explain to me the difference between Lion and Mtn Lion? I'm currently 10.6.8 Is it beneficiall for me to upgrade?

    Mountain Lion is an enhanced version of previous OS X and so that is Mavericks.
    About upgrading it all depends on what your needs are and if your hardware supports it.
    System requirements for OS X Lion
    System requirements for OS X Mountain Lion
    OS X Mavericks: System Requirements
    Please check also applications compatibility. From Lion onward, you cannot run PPC application.

  • The Difference between iphone Unlock T-Mobile and iphone Unlock Free-Sim

    As mentiond in the title my questions are:-
    - What is the Difference between iphone Unlock T-Mobile and iphone Unlock Free-Sim?!
    - Did they both work Internationally?!
    - For the Unlock T-Mobile should i use their sim or i can use any sim directly?!
    Thanks

    Unlocked means unlocked and you can use any sim card and keep changing them and the phone will never lock if it is unlocked.
    Sim free, means that the phone is sold at full price without a sim card, but the phone will lock to the first sim card that you put in it.  A sim free phone will work internationally, but you will have to use a roaming plan with your phone company because the phone will be locked, so you CANNOT change it to a local sim card.
    If you have an unlocked phone, you can use it internationally by inserting a local sim card and the phone should then work and you won't have to pay increased roaming charges as you would with a locked phone.
    If you buy a T-Mobile phone that is unlocked, DO NOT activate it with their sim card or the phone will lock to T-Mobile and you will have to approach them to get it unlocked.  Use it with another sim card straight away and it will remain unlocked.

  • The difference between Intel core I7 and dual core

    I have a 2.7 ghz Intel Core I7 macbook, early 2011.  Can someone tell me the difference between this machine and the new macbooks, 2.4 or 2.6 ghz, dual core?
    Thanks!

    Benchmarks:
    http://www.macworld.com/article/2057932/lab-tested-iris-graphics-provide-a-boost -to-new-13-inch-retina-macbook-pro.html

  • The difference between iPhone and iPod earphones with mic ?

    What is the difference between the Apple iPhone Headset with Microphone and the Apple Earphones with Remote and Mic ?

    mamarro wrote:
    The iOS just WORKS as it should and is not glitchy at all like my experience has been with Android.
    I had 6 Droid X's since laundh day on July 15th, and my wife has had 4 Droid Increidble's since she got her phone around that same time - and that one had been out for a few months before she got it even, so the "initial bugs" should have been worked out by then as there were a couple software updates to the phone (not even the 2.2 update I am talking about - just 2.1 updates to fix bugs) before she even got it.
    And, that's another difference.....whenever there is a software update for the iPhone you get it IMMEDIATELY as there is no "hold" by carriers to tailor it to their own needs, etc., like there is with Android. 
    Good point about the updates, I believe the Fascinate just got the update that's been out for months already.

Maybe you are looking for