To_char function help

Hi All,
I have run this query in my oracle database
SELECT
J.NAME,
(CASE J.STATUS WHEN 'Completed' THEN COUNT(J.STATUS) ELSE 0 END) CURRENT_MONTH_COMPLETE,
(CASE J.STATUS WHEN 'Pending for Process Engine' THEN COUNT(J.STATUS) ELSE 0 END) CURRENT_MONTH_IN_PROGRESS
FROM
CMN_SCH_JOBS_V J
WHERE
J.STATUS IN ('Completed','Pending for Process Engine') AND J.LANGUAGE_CODE='en'
and to_char(J.START_DATE,MM')=12
GROUP BY J.NAME,J.STATUS;I have a doubt regarding this
to_char(J.START_DATE,MM')=12Basically to_char() function returns a string value, but when it is equated against a numeric value oracle should raise an error right, this query is running fine. Please tell why this is happening.
Regards
Praveen Vuppalapati

What a strange query. I'd expect it to be either:
SELECT
J.NAME,
J.STATUS
COUNT(*)
FROM
CMN_SCH_JOBS_V J
WHERE
J.STATUS IN ('Completed','Pending for Process Engine') AND J.LANGUAGE_CODE='en'
and to_char(J.START_DATE,MM')=12
GROUP BY J.NAME,J.STATUS;... or ...
SELECT
J.NAME,
SUM(CASE J.STATUS WHEN 'Completed' THEN 1 ELSE 0 END) CURRENT_MONTH_COMPLETE,
SUM(CASE J.STATUS WHEN 'Pending for Process Engine' THEN 1 ELSE 0 END) CURRENT_MONTH_IN_PROGRESS
FROM
CMN_SCH_JOBS_V J
WHERE
J.STATUS IN ('Completed','Pending for Process Engine') AND J.LANGUAGE_CODE='en'
and to_char(J.START_DATE,'MM')=12
GROUP BY J.NAME;Ought to wrap the to_char() in a to_number as well, really.

Similar Messages

  • Need help in to_char function

    Hi All,
    I'm using below sql query to get sysdate with time stamp.
    select to_char(sysdate,'YYYYMMDD HH24:MM:SS') from dual
    This gives me below result:  20130816 05:08:49
    Strangely, when I keep on running the same query, I notice after 60 seconds are complete, time stamp starts with  20130816 05:08:01 again.
    Am i missing something here..
    Thanks in advance

    Karthick_Arp wrote:
    Keep a simple thing in mind. Date stored in the DB does not have any format. Format need to be applied while you display. The default date format is specified by the NLS_DATE_FORMAT parameter. You have used TO_CHAR to display date in a specific format. But the problem is that you have converted DATE into string. So if its just for display purpose then set the NLS_DATE_FORMAT, do not use TO_CHAR.
    With respect to your issue You need to represent Minute as MI. You have represented it as MM (Month) That's why you see 08 always.
    " the problem is that you have converted DATE into string"
    No, the problem was that he was explicitly using an incorrect format mask, specifying months where he should have specified minutes.
    The problem inherently cannot be the result of converting a DATE into a string.  Dates are always converted to strings for presentation, either implicitly by using the controlling setting of NLS_DATE_FORMAT (which can be set at several levels) or explicitly by using the to_char function.  Oracle will always convert.  It has to.  Internally, a date is binary gibberish.  But computer screens and printers can only show strings of characters, so the DATE will be converted to a character string, by hook or by crook.  And the method of oracle making that conversion is exactly the same.  The only thing that varies is how the user chooses to make that specification.  And "not choosing" (by not using the to_char function) is still choosing ... choosing to rely on nls_date_format.

  • Reg: error while converting a date datatype to the char using TO_CHAR function.

    Hello all,
    I'm trying to convert a date datatype to the specified format (i.e., by using vaariable using the to_char function in my sql,
    SQL:
    select 0 dummy,'select' from dual
    union all
    select a.COLUMN_ID dummy,
    (case a.DATA_TYPE when 'NUMBER' then '''''' || '||' || a.COLUMN_NAME || '||'',''||'
                      when 'DATE' then '''"''' || '||' || TO_CHAR(a.COLUMN_NAME,'&dateformat') || '||' || '''",''' || '||'
                      else '''"''' || '||' || a.COLUMN_NAME || '||' || '''",''' || '||'
                end)
    from DBA_TAB_COLUMNS a
    where a.OWNER = upper('&owner_name')
    and a.TABLE_NAME = upper('&table_name')
    union all
    select 998 dummy,''' ''' from dual
    union all
    select 999 dummy,'from &owner_name..&table_name;' from dual
    order by dummy
    error:
                      when 'DATE' then '''"''' || '||' || TO_CHAR(a.COLUMN_NAME,'DD-MM-YYYY') || '||' || '''",''' || '||'
    ERROR at line 5:
    ORA-01722: invalid number
    Please help me in resolving this, Thanks in advance.
    Regards,
    Konda.

    > ISA Server is not configured to allow SSL requests from this port. Most Web browsers use port 443 for SSL requests. (12204)
    This seems to be your specific network configuration.  It seems that your corporate network is blocking HTTPS requests which don't use port 443. Your ABAP system is configured to use a port other than 443. Either talk to your basis admins about changing your ABAP system configuration to use port 443 or talk to your network administrators to allow whichever port the ABAP system is running on.

  • ERROR  when called TO_CHAR function from XMLQuery

    when I tried to execute the followingin XMLQuery by calling TO_CHAR() whithin this query I am getting this error"ORA-19237: XP0017 - unable to resolve call to function - fn:TO_CHAR
    any help/ideas on the follwing would be much appreciated.
    Thanks
    Abdul
    select XMLQuery('<marketfeed id="f1" action="CREATE" source="marketfeed1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
    <competitions>
    {for $f in ora:view("fixture")
                        for $c in ora:view("competition")
                         for $homes in ora:view("squad")
                          for $aways in ora:view("squad")
                           for $homet in ora:view("team")
                            for $awayt in ora:view("team")
                       where $f/ROW/GID = "g321667"
                          and $f/ROW/COMPETITIONID = $c/ROW/ID
                          and $f/ROW/HOMESQUADID = $homes/ROW/ID
                          and $f/ROW/AWAYSQUADID = $aways/ROW/ID
                          and $homes/ROW/TEAMID = $homet/ROW/ID
                          and $aways/ROW/TEAMID = $awayt/ROW/ID
                       return              
                       <competition id="{$c/ROW/ID/text()}"
    shortname="{$c/ROW/NAME/text()}"
    name="{$c/ROW/NAME/text()}">
    <teamlists>
    <teamitam name="{$homet/ROW/NAME/text()}"
    id = "{$homes/ROW/TID/text()}" />
    <teamitem name="{$awayt/ROW/NAME/text()}"
    id = "{$aways/ROW/TID/text()}" />
    </teamlists>
    <matches>
    <match id="{$f/ROW/GID/text()}"
    venue="{$f/ROW/VENUE/text()}"
    matchdate="{TO_CHAR($f/ROW/STARTDATE/text(), "YY-MM-DD")}"
    name="{concat($homet/ROW/NAME/text(), " v ", $awayt/ROW/NAME/text())}"
    >
    <teams>
    <team home="H" id = "{$homes/ROW/TID/text()}" />
    <team home="A" id = "{$aways/ROW/TID/text()}" />
    </teams>
    </match>
    </matches>
    </competition>
    </competitions>
    </marketfeed>'
    returning content
    from dual
    Edited by: QAbdul on 26-Oct-2010 06:44

    Hi,
    QAbdul wrote:
    when I tried to execute the followingin XMLQuery by calling TO_CHAR() whithin this query I am getting this error"ORA-19237: XP0017 - unable to resolve call to function - fn:TO_CHARTO_CHAR is a SQL function, XQuery is unaware of it.
    XPath 2.0 specifications define a fn:format-date function but Oracle has not included yet in its XQuery implementation.
    Easiest way to go is A_Non's solution, but if you need to format at multiple places in the query, you can declare a local XQuery function.
    For example, to format to "DD/MM/YYYY" from the canonical xs:date format "YYYY-MM-DD" :
    {code}
    declare function local:format-date($d as xs:date) as xs:string
    let $s := xs:string($d)
    return concat(
    substring($s, 10, 2), "/",
    substring($s, 7, 2), "/",
    substring($s, 2, 4)
    {code}
    and an example of use :
    {code}
    SQL> CREATE TABLE test_xqdate AS SELECT sysdate dt FROM dual;
    Table created
    SQL> SELECT *
    2 FROM XMLTable(
    3 'declare function local:format-date($d as xs:date) as xs:string
    4 {
    5 let $s := xs:string($d)
    6 return concat(
    7 substring($s, 10, 2), "/",
    8 substring($s, 7, 2), "/",
    9 substring($s, 2, 4)
    10 )
    11 }; (: :)
    12 for $i in ora:view("TEST_XQDATE")/ROW/DT
    13 return element e {
    14 attribute xs_date_format { $i/text() },
    15 attribute local_format { local:format-date($i) }
    16 }'
    17 COLUMNS
    18 xs_date_format VARCHAR2(10) PATH '@xs_date_format',
    19 local_format VARCHAR2(10) PATH '@local_format'
    20 )
    21 ;
    XS_DATE_FORMAT LOCAL_FORMAT
    2010-10-28 28/10/2010
    {code}

  • Behaviour of to_char function in sqlplus versions 8.1.6.0.0 and 9.0.1.3.0 .

    Behavior of to_char function in sqlplus versions 8.1.6.0.0 and 9.0.1.3.0:
    Hello,
    We are migrating our apps between different environments and we observed the following behaviour:
    When using the command select to_char(sysdate,'D') from dual, this gives out a value of 4 in sqlplus version 8.1.6.0.0 (win NT). The same command gives out a value of 3 in sqlplus version 9.0.1.3.0 (win XP).
    The underlying software is Oracle Enterprise Edition Release 8.1.7.4.0 in both the cases. Why this difference in behaviour? Can anyone please advise me.
    regards,
    Srikanth

    The first day of week depends on the globalization parameter NLS_TERRITORY. Set it for the instance or for the session to AMERICA to get the week start on sunday. You can also set this in the NLS_LANG os variable (export NLS_LANG=american_germany.we8iso8859p1)
    SQL> alter session set nls_territory='germany'
    SQL> select to_char(sysdate, 'Day D') from dual;
    TO_CHAR(SYS
    Wednesday 3
    SQL> alter session set nls_territory='america';
    SQL> select to_char(sysdate, 'Day D') from dual;
    TO_CHAR(SYS
    Wednesday 4Kind regards
    Laurent Schneider
    OCM-DBA

  • TO_CHAR FUNCTION IN ORACLE FORM

    HI,
    Table called A has column name col1
    col1
    12563.563
    52685.563
    05263.540
    I would like to use SUBSTR(col1,2,6) for insert values from A table to B table by Oracle form and following values are inserted in B table
    2563.5
    2685.5
    263.4
    If I use SQLPLUS it is inserting as my requirement like
    2563.5
    2685.5
    5263.4
    Third row should be 5263.5 instead of 263.4. In Oracle form may have internal coversion function to convert character value to number values, I do not want to convert the value to number. Both table columns are varchar2 column.
    What is the equal to_char function in Oracle form. If it is NLS_NUMERIC_CHARACTERS, please what are the parameters to be passed along with column.
    Thanks in advance
    Saravanan.

    Hello,
    If you don't want to take account any calculation on the decimal part, you could consider the Trunc() function instead of the To_Char():
    Connected to:
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    SQL> select to_char(52685.563,'00000000.0'), trunc(52685.563,1) from dual
      2  /
    TO_CHAR(526 TRUNC(52685.563,1)
    00052685.6            52685.5
    SQL> Francois

  • Replace function help

    Hi all, sry for post sql problens in APEX forum, but i realy need help for this...
    I´m trying to replace : for , to make a select where in () with more then one value... but the replace function its not work with more then 1 value...
    like this
    select name from vw_requerente where id_cliente in REPLACE(:P5000_CLIENTE,':',',')in that item has this value: 71:72:73 , but all i get is a ORA: INVALID NUMBER, how can i make a replace function to work with this?
    tnks alot and sry my english.

    He also posted this in the pl/sql forum and received some good advice there:
    replace function help
    Especially the tom kyte blog portion:
    [http://tkyte.blogspot.com/2006/06/varying-in-lists.html]
    Thank you,
    Tony Miller
    Webster, TX

  • What is the use of To_date, to_char functions?

    what is the use of To_date, to_char functions?
    while i am using these in my day to day activities but never able to know the exact working of tehse.
    Message was edited by:
    437022

    Dates are stored and manipulated as coded (binary) values that always contain "century, year, month, date, hour, minute second"
    We don't want to see the date as stored. We want to see the characters (digits) that make up the date. So we use to_char(the-date-value)
    We want to tell the system a date, but have a heck of a time entering the binary. So we input the characters (digits) that make up the date and tell the system to convert that to a binary 'date' using to_date(our-string-that-respresents-dates)
    The magic Oracle has added is the format codes (see chapter 2 of the SQL Reference manual for the complete list). We can get the system to print out dates and times, including day of week (and so on) using format codes.
    The default format is to show us the date but not the time. Which leads a lot of people to believe that the time is not stored.

  • How Queues functionality helps in Service Module

    Hi,
    How Queues functionality helps in Service Module.
    how to get the queue details assign to the service call(Technician)
    Please Suggest
    Regards
    Vikram

    Sridharan,
    How to add technician to a queue.
    Employee should be user of SAP?
    Please Suggest.
    Vikram

  • Error in result of To_Char function.

    Hi,
    My name is Ramanujulu, I was practicing Date functions and found one error in one of the To_Char functions.
    Please assume the sysdate as 19th Decmber 2006. (I used this date in example)
    SQL> select to_char(sysdate-7, 'ddspth-month-syear') from dual;
    TO_CHAR(SYSDATE-7,'DDSPTH-MONTH-SYEAR')
    twelfth-december - two thousand six
    It returns the 12th as twelfth. (Additional letter F). Who will correct this and how do i make this change in my Database.
    Please let me know how to correct this.
    Thanks,
    Ramanujulu B.

    http://dictionary.reference.com/browse/twelfth

  • Trouble getting a timestamp formatted by a 'to_char' function

    We have trouble getting a timestamp formatted by a 'to_char' function and a 'group by'
    for a count. By assigning the result of the to_char function to an attribute and
    grouping on that attribute, we try to get the frequency of an event.
    What happens is a non predictable 'IllegalArgumentException' on
    'Timestamp.class' while getting the timestampvalue.
    We make use of a scrollablecursor as you can see in the stacktrace.
    java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff
    at java.sql.Timestamp.valueOf(Timestamp.java:160)
    at oracle.sql.CHAR.timestampValue(CHAR.java:567)
    at oracle.jdbc.driver.ScrollableResultSet.getTimestamp(ScrollableResultSet.java:658)
    at oracle.toplink.oraclespecific.Oracle9Platform.getObjectFromResultSet(Unknown Source)
    at oracle.toplink.internal.databaseaccess.DatabaseAccessor.getObject(Unknown Source)
    at oracle.toplink.internal.databaseaccess.DatabaseAccessor.fetchRow(Unknown Source)
    at oracle.toplink.internal.databaseaccess.DatabaseAccessor.cursorRetrieveNextRow(Unknown Source)
    at oracle.toplink.queryframework.ScrollableCursor.retrieveNextObject(ScrollableCursor.java:512)
    at oracle.toplink.queryframework.ScrollableCursor.loadNext(ScrollableCursor.java:357)
    at oracle.toplink.queryframework.ScrollableCursor.hasNext(ScrollableCursor.java:233)
    After restarting the application server there is a chance that the query returns
    with the expected results. But most of the times it just returns the above
    mentioned exception.
    I don't see the logic in the apparently random parsing of the value.
    The column in the database is a timestamp, but that the reason why i'm using the
    to_char method.

    This is a bug in TopLink with ReportQuery. Please report this is Oracle technical support. Basically TopLink is converting to the attribute type, but should not be if a function was applied to the expression.
    To workaround the issue you can use getField(/) in the expression instead of get(/) (using the database field name instead of the class attribute name).

  • Unusual result with TO_CHAR function on a date

    Can anybody explain to me why I see two different results if I use the following SQL in PL/SQL Developer (Oracle Database 10g Enterprise Edition Release 10.2.0.1.0)? I'm not sure if I have a wrong setting in Oracle or PL/SQL Developer, or if I'm just misunderstanding how the TO_CHAR function works. Many thanks.
    select sysdate, to_char(sysdate, 'dd/mm/yyyy hh:mm:ss') as FORMATTED_DATE from dual
    Results:
    SYSDATE
    10/02/2009 16:52:32
    FORMATTED_DATE
    10/02/2009 04:02:32

    select sysdate, to_char(sysdate, 'dd/mm/yyyy hh:mm:ss') as FORMATTED_DATE from dual
    Results:
    SYSDATE
    10/02/2009 16:52:32
    FORMATTED_DATE
    10/02/2009 04:02:32It should not be -> mm it should be mi .
    Got me?
    Regards.
    Satyaki De.

  • TO_CHAR Function Format Argument Limit

    I was curious if there is a limitation to the length of the string used as the Format argument in the TO_CHAR Function? If so, how long is it?

    I couldn't find it in the documentation, but it appears at first glance to be 63 for numbers with a simple format mask. You could experiment with the others:-
    SQL>
    SQL> DECLARE
      2     v1 VARCHAR2(32767);
      3     v2 VARCHAR2(32767);
      4  BEGIN
      5     FOR i IN 1 .. 32767 LOOP
      6        BEGIN
      7           v1 := v1 || '9';
      8           SELECT TO_CHAR(1,v1) INTO v2 FROM dual;
      9        EXCEPTION
    10           WHEN OTHERS THEN
    11              DBMS_OUTPUT.PUT_LINE(
    12                 'Maximum length of format mask for ' ||
    13                 'numbers is [' || TO_CHAR(i-1) || ']'
    14                 );
    15              RETURN;
    16        END;
    17     END LOOP;
    18  END;
    19  /
    Maximum length of format mask for numbers is [63]
    PL/SQL procedure successfully completed.
    SQL> SELECT TO_CHAR(1, '99999999999999999999999999999999999999999999999999999999999999') as sixty_two
      2  FROM   dual;
    SIXTY_TWO
                                                                  1
    SQL> SELECT TO_CHAR(1, '999999999999999999999999999999999999999999999999999999999999999') as sixty_three FROM dual
      2  /
    SIXTY_THREE
                                                                   1
    SQL> SELECT TO_CHAR(1, '9999999999999999999999999999999999999999999999999999999999999999') as sixty_four FROM dual
      2  /
    SELECT TO_CHAR(1, '9999999999999999999999999999999999999999999999999999999999999999') as sixty_four FROM dual
    ERROR at line 1:
    ORA-01481: invalid number format modelRegards
    Adrian

  • TS1702 I just updated numbers to newest version and found that numbers quits to home screen when I tap the information icon on "function  help", it starts to load the "help" then quits  this happens on both my ipad3 & iphone5

    2/3/14: I just updated numbers to newest version and found that numbers quits to home screen when I tap the information icon on "function  help", it starts to load the "help" then quits. It happens on both my ipad3 &amp; iphone5. I tried restarting the devices but it didn't help.

    Try this  - Reset the iPad by holding down on the Sleep and Home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons. (This is equivalent to rebooting your computer.) No data/files will be erased. http://support.apple.com/kb/ht1430
    iOS 7: Help with how to fix a crashing app on iPhone, iPad (Mini), and iPod Touch
    http://teachmeios.com/help-with-how-to-fix-a-crashing-app-on-iphone-ipad-mini-an d-ipod-touch/
    Troubleshooting apps purchased from the App Store
    http://support.apple.com/kb/TS1702
    Delete the app and redownload.
    Downloading Past Purchases from the iTunes Store, App Store and iBooks Store
    http://support.apple.com/kb/ht2519
     Cheers, Tom 

  • Need PP Functional help for some legacy fields

    Hi all,
    I am a BW consultant. I need to replicate in SAP-BW some reports that are currently in a legacy system (non SAP). I have identified the functional area for those reports as PP. I need a little functional help from you guys to find out what some fields in the legacy system mean in SAP. Once I know the R/3 fields (and source tables if someone can tell me), I can move forward with mapping those fields into BW objects and the rest of the process.
    The reason why I am seeking help from here is, unfortunately our functional team is not available right now and their availability is indefinite. So I just want to keep myself busy till they are back.
    Well, here are the fields that I need help for (for now)
    The report is for Daily summary of activities at a plant
    Work order process
    Work order type
    Daily Created Bags
    Daily Capacity Bags (Bags per Hour Rate* Available Hours)
    Daily Count of Work Order Number
    Goods issued for work order completion
    Goods finished
    Please help me identify what R/3 fields (and their tables) correspond to the above legacy fields
    Points WILL be assigned for helpful answers
    Thank you

    Hi,
    Work order process - I assume this is the set of operations for the order - AFVC (table)
    Work order type      - AUFK - (Field) AUART data needs to be fetched for AUFNR(Work order number)
    Daily Created Bags - MSEG - data needs to be fetched for BWART = 101 or 102 and AUFNR(Work order number)
    Goods issued for work order completion - MSEG- data needs to be fetched for  BWART = 261 and AUFNR(Work order number)
    Goods finished - MSEG - data needs to be fetched for BWART = 101 or 102 and AUFNR(Work order number)
    Regards,
    Prasobh

Maybe you are looking for

  • Itunes will not detect my new nano. HELP! I have a dell with vista. my old shuffles work fine with itunes, but it will no longer detect my nano. Apple says my nano is fine.

    I've worked with Apple 2 times. The first time we spent 2 hours on the phone uninstalling and reinstalling itunes, quicktime and other software and it worked for a while. Now, once again, itunes will not recognize my 6th generation nano. My old shuff

  • InDesign CS6 crashing constantly - why?

    Since updating to Mavericks, my daily crashes whilst using InDesign CS6 (on an iMac) have escalated to a ridiculous degree and it doesn't seem to matter what I'm doing at the time. Have Googled this issue again and again, tried a plethora of suggeste

  • Running WebLogic as Web Server

              Hi,           Please help!           I am using WebLogic as a Web Server.           For some reason, I cannot access HMTL files in myserver/public_html folder.           What should be added/modified in order for this to work?           Tha

  • Sync external MP3 with SWF

    We're developing a movie that will upon the users input select the sound source as well as input a dynamic text. When creating the FLA we placed a sample MP3 in the timeline and sync "stream" with the movie. It plays fine on both Mac and Win machines

  • My iPhone 4s won't turn my wifi on. Help!

    I go to settings to switch over the little button and it won't move. I tell siri to turn it on, and she says she does but it still won't work. I was told to reset my phone and did, and that didn't work. I don't know what else to do! I can't take it i