Issue date (again)

Hi all

I have a column of strings that contain equivalent dates data.
--DDL & DML Statement
CREATE TABLE TEST_TABLE AS
(
SELECT '29-Jul-2009 NUL:NUL:NUL' col_1 FROM Dual
UNION ALL
SELECT '28-Jul-2009 16:16:16' FROM Dual
UNION ALL
SELECT '28-Jul-2009 04:16:16 PM' FROM Dual
)
/
I have therefore given as
SQL> SELECT * FROM TEST_TABLE
  2  /

COL_1
-----------------------
29-Jul-2009 NUL:NUL:NUL  -- String with no time component
28-Jul-2009 16:16:16        -- String in 24Hr Format
28-Jul-2009 04:16:16 PM   -- String in 12Hr Format

3 rows selected.
I need to convert these strings to dates

I tried the following:
SQL> SELECT col_1, SUBSTR (REPLACE (col_1, 'NUL', '00'), -2, 2),
  2         CASE
  3            WHEN SUBSTR (REPLACE (col_1, 'NUL', '00'), -2, 2) IN
  4                                                         ('PM', 'AM')
  5               THEN TO_DATE (REPLACE (col_1, 'NUL', '00'),
  6                             'DD-Mon-YYYY HH12:MI:SS'
  7                            )
  8            ELSE TO_DATE (REPLACE (col_1, 'NUL', '00'),
  9                          'DD-Mon-YYYY HH24:MI:SS')
 10         END date_col
 11    FROM test_table
 12  /
ERROR:
ORA-01830: date format picture ends before converting entire input string



no rows selected

SQL> 
Can someone help me please understand what I am doing wrong in the above query, or give advice to achieve the desired results.

Thank you
Ann

You forgot the AM/PM indicator in your format mask.

SQL> SELECT col_1, SUBSTR (REPLACE (col_1, 'NUL', '00'), -2, 2),
  2         CASE
  3            WHEN SUBSTR (REPLACE (col_1, 'NUL', '00'), -2, 2) IN
  4                                                         ('PM', 'AM')
  5               THEN TO_DATE (REPLACE (col_1, 'NUL', '00'),
  6                             'DD-Mon-YYYY HH:MI:SS AM'
  7                            )
  8            ELSE TO_DATE (REPLACE (col_1, 'NUL', '00'),
  9                          'DD-Mon-YYYY HH24:MI:SS')
 10         END date_col
 11    FROM (select '29-Jul-2009 NUL:NUL:NUL' col_1 from dual union all
 12          select '28-Jul-2009 16:16:16'    col_1 from dual union all
 13          select '28-Jul-2009 04:16:16 PM' col_1 from dual
 14         )
 15  /

COL_1                   SU DATE_COL
----------------------- -- --------------------
29-Jul-2009 NUL:NUL:NUL 00 29-JUL-2009 00:00:00
28-Jul-2009 16:16:16    16 28-JUL-2009 16:16:16
28-Jul-2009 04:16:16 PM PM 28-JUL-2009 16:16:16

Tags: Database

Similar Questions

  • I had a hard drive crash and had to move all the data again. Now, I get an error saying that my Visa is not an authorized version. How can I find the product key to reactivate?

    Vista Product Code question

    I had a hard drive crash and had to move all the data again.  Now, I get an error saying that my Visa is not an authorized version.  How can I find the product key to reactivate?  I don't have the sticker on the back and the software I have does not have the code?  I bought this laptop DELL at Best Buy a little more than a year.

    Thank you.

    Hello

    This problem may occur if you make a significant hardware change. See the link provided below.

    Error message when you start Windows Vista: "your activation period has expired".

    http://support.Microsoft.com/kb/925616

    If the OS came preinstalled Dell you may need to contact Dell technical support for assistance.
    http://support.Dell.com/support/topics/global.aspx/support/win7_support/win7_portal?c=us&CS=04&l=en&s=BSD

  • the consoles switched. transferred all the data again except xbox live profiles. does not accept my password. reset message receive does not a password.

    I bought a new concole. I transferred all my data, except the pfofiles of xbox live. It does not accept my password or security question answer. I don't get a password reset email.

    Hello

    -What is the new console you bought?
    -What is the exact error that you have found and where are you?

    -Is the XBOX password which is not accepted.

    If there is a problem with the XBOX, I recommend you ask your question on the forums xbox for better assistance.
    http://www.Xbox.com/en-us/forums

    Please provide us with more information about the issue so that we can better help you.

    Suggestions for a question on the help forums
    http://support.Microsoft.com/kb/555375

  • mask for the format issue date

    I was wondering why this first query works, but the second does not work, if someone could help please :

    [quote]

    SELECT course_no, section_id, to_char (start_date_time, 'Day' The "Ddspth" of "fmMonth yyyy") IN the section

    WHERE to_char (start_date_time 'DY') = 'Sun '; [/ quote]

    [quote]

    WHERE to_char (start_date_time, 'Day') = 'Sunday '; [/ quote]

    any ideas? can't see what I'm missing?

    Thanks in advance,

    Nick

    Date format day returns the name of the white day to the length of the longest day name (in the appropriate language):

    SQL > select ' [' | to_char (sysdate + 1, 'day') |] ']' double.

    '['|| TO_CHA
    -----------
    [Sunday]

    SQL > select ' [' | to_char (sysdate + 1, 'FMDay') |] ']' double.

    '['|| TO_CHA
    -----------
    [Sunday]

    SQL >

    Use FM modifier and,'nls_date_language = English "to make independent NLS:"

    WHERE to_char (start_date_time 'FMDay', 'nls_date_language = English') = 'Sunday ';

    SY.

  • Issue DATE

    Hello

    I'm passing a date for a TRIAL, then do an INSERTION of this date in a table...
      PROCEDURE Insert_Current_Data(
       p_create_date                 IN         VARCHAR2
    ) IS
     e_constraint_error               EXCEPTION;
       PRAGMA EXCEPTION_INIT (e_constraint_error, -2291);
    CURSOR ei_claimant_ext_cur
          IS
          SELECT to_number(NOC_CODE) NOC_CODE,
                      to_number(ECONOMIC_REGION_CODE) ECONOMIC_REGION_CODE,
                      CASE EI_PROV_CODE
                        WHEN '00' THEN 1
                        WHEN '01' THEN 4
                        WHEN '02' THEN 2
                        WHEN '03' THEN 3
                        WHEN '04' THEN 5
                        WHEN '05' THEN 6
                        WHEN '06' THEN 7
                        WHEN '07' THEN 8
                        WHEN '08' THEN 9
                        WHEN '09' THEN 10
                        WHEN '10' THEN 11
                        WHEN '11' THEN 12
                        ELSE 13
                      END EI_PROV_CODE,
                      POSTAL_CODE
            FROM ei_claimant_curr_year_external
            WHERE ei_prov_code <> 12
            AND     economic_region_code <> 99
            AND     postal_code is NOT NULL
            AND     ROWNUM < 1000;
            
            ei_claimant_ext_rec ei_claimant_ext_cur%ROWTYPE;
            
            v_create_date       VARCHAR2(20);
            
        BEGIN
               
         dbms_output.put_line('Date passed: '||p_create_date);  
    
            OPEN ei_claimant_ext_cur;
            
            LOOP
      
                FETCH ei_claimant_ext_cur 
                INTO ei_claimant_ext_rec;
                    
                EXIT WHEN ei_claimant_ext_cur%NOTFOUND;      
                
                BEGIN
                              
                   INSERT INTO ei_claimant_curr_year
                    VALUES  (EI_SEQ.nextval,
                                ei_claimant_ext_rec.noc_code,
                                ei_claimant_ext_rec.EI_PROV_CODE,                            
                                ei_claimant_ext_rec.ECONOMIC_REGION_CODE,
                                p_create_date, --- CURRENT Month 
                                ei_claimant_ext_rec.POSTAL_CODE
                                );
                                COMMIT;                              
    
                    EXCEPTION
                        WHEN e_constraint_error THEN dbms_output.put_line('CONSTRAINT Error '); 
                            fwutil_pkg.logerror (SQLERRM||' '||ei_claimant_ext_rec.noc_code||' Prov Code: '||ei_claimant_ext_rec.EI_PROV_CODE||'  Econ Region: '||ei_claimant_ext_rec.ECONOMIC_REGION_CODE||
                            ' Postal Code: '||ei_claimant_ext_rec.POSTAL_CODE||' Date: '||p_create_date,
                                  SQLCODE,
                                  NULL,
                                  'Populate_EI_Claimant_Main -- Insert into EI_Claimant_curr_year '
                                 );   
                        WHEN OTHERS
                        THEN
    
                            fwutil_pkg.logerror (SQLERRM||' '||ei_claimant_ext_rec.noc_code||' Prov Code: '||ei_claimant_ext_rec.EI_PROV_CODE||'  Econ Region: '||ei_claimant_ext_rec.ECONOMIC_REGION_CODE||
                            ' Postal Code: '||ei_claimant_ext_rec.POSTAL_CODE||' Date: '||p_create_date,
                                  SQLCODE,
                                  NULL,
                                  'Populate_EI_Claimant_Main -- Insert into EI_Claimant_curr_year '
                                 );          
                END;
                
            END LOOP;
        
            CLOSE ei_claimant_ext_cur;        
            
        END Insert_Current_Data;
    Get the error:

    ORA-01858: a non-digit character was found here where was waiting for a digital

    Why so complicated dates :-(

    Help, please!

    Thanks in advance!

    Hello

    >
    Why the dates so complicated?
    >

    Dates are not difficult, but you do not use the dates but varchar2 as shown below:

      PROCEDURE Insert_Current_Data(
       p_create_date                 IN         VARCHAR2
    ...
    

    I suggest to change that to:

      PROCEDURE Insert_Current_Data(
       p_create_date                 IN         date
    ...
    

    Then call the procedure with an actual as date:

    begin
    Insert_Current_Data( to_date('10-12-2012', 'dd-mm-yyyy') );
    

    If then you have a problem let us know.

    Kind regards

    Peter

  • Issue Date format as a VARCHAR

    Using Oracle 10 g:
    I have a varchar field that keeps a date like:

    2010-08-28 14:40:21

    I am trying to format the date so I can check if it is greater than the sysdate. I'm doing:

    To_char (end_date, 'YYYYMMDD') > to_char (sysdate, 'YYYYMMDD');

    I get an error message:
    ORA-01722: invalid number
    01722 00000 - "invalid number."

    Which makes sense, but I'm not sure how to properly format the end_date in YYYYMMDD format.

    Hello

    user9179751 wrote:
    Using Oracle 10 g:
    I have a varchar field that keeps a date like:

    2010-08-28 14:40:21

    I am trying to format the date so I can check if it is greater than the sysdate. I'm doing:

    To_char (end_date, 'YYYYMMDD') > to_char (sysdate, 'YYYYMMDD');

    I get an error message:
    ORA-01722: invalid number
    01722 00000 - "invalid number."

    Which makes sense, but I'm not sure how to properly format the end_date in YYYYMMDD format.

    Is the VARCHAR2 column end_date?
    To_char, as its name suggests, converts a DATE to a string of record CHAR. If you already have a string of characters, so there's no need of TO_CHAR.
    You can call TO_DATE, such as

    WHERE   TO_DATE ( end_date
                    , 'YYYY-MM-DD HH24:MI:SS'
                    )  > SYSDATE
    

    but it is more effective and less prone to say

    WHERE   end_date > TO_CHAR (SYSDATE, 'YYYY-MM-DD HH24:MI:SS')
    

    Why is it more effective? The optimizer considers SYSDATE be a constant, even if the query takes a long time. Therefore, it only will convert SYSDATE in a string once, even if you have 1 million rows in the table. If you did the first way, you must call TO_DATE a million times, once for each line. In addition, your column, end_date, being alone on one side of the > operator, the optimizer can use an index on that column.
    Why is it less error-prone? If you still have a line where End_date is incorrect, you will get an error if you call TO_DATE. Not try to convert end_date, you won't make mistakes.

    This works because the format for End_date is suitable for sorting. If the format was, say, 'DD-Mon-YYYY', you would have to be converted to a DATE.

    It would be better if End_date a DATE column. It is never a good idea to use a VARCHAR2 column to store points in time.

  • Issue date and time with the javascript scripts

    Hi all

    I need to maintain a bit of history on my pdf form, so I need to get the date and time when the user submits the form.  Currently, I am able to do this in FormCalc.

    var todayDate = Date()
    var todayTime = Time()
    var today = concat (Num2Date (todayDate, "MMMM DD, YYYY"), "", Num2Time (todayTime, "h: mm A") "");

    today will contain: April 28, 2009 14:23

    I want exactly the features in javascript.  I'm not able to get the same result.

    Please give me some code for the same in javascript snippet

    Deepak.

    Hi Deepak,

    This example should show you how you can recover each "piece" of the date in JavaScript and piece and then that their back together according to your needs.

    You will find several examples of scripts on the date formatting here: http://javascript.internet.com/time-date/

  • Find operations on which items generate much of the data again?

    Hi all
    I use Oracle 10 g on linux than 64.i 2 would like to minimize the generation of redo of my database for only critical tables (another object can be easily replenished (tables, index...). How operation on which objects generate most can restore data?

    Kind regards


    Groxy

    Log Miner to retrieve this type of information.

    For example:

    BEGIN
    sys. DBMS_LOGMNR. ADD_LOGFILE (NOM_FICHIER_JOURNAL => ' / backup/arc/mbdb/arc_204469_1_595785865.arc', OPTIONS-online sys.) DBMS_LOGMNR. ADDFILE);
    END;

    BEGIN
    sys. DBMS_LOGMNR. Start_logmnr (OPTIONS-online sys. DBMS_LOGMNR. DICT_FROM_ONLINE_CATALOG);
    END;

    SELECT seg_owner, seg_name, table_name, operation, COUNT (1) IN V$ LOGMNR_CONTENTS
    GROUP BY seg_owner nom_seg, table_name, operation
    ORDER BY COUNT (1) DESC

    BEGIN
    sys. DBMS_LOGMNR. END_LOGMNR();
    END;

  • Issue date max back in 2009

    Everyone knows about this problem?

    Create the following new table and add the data...
    CREATE TABLE ETL_LASTRUN
    (
    DATE OF CBX_TLEMSANI_2000TJE
    )
    /
    Insert into ETL_LASTRUN
    (CBX_TLEMSANI_2000TJE)
    Values
    (TO_DATE (DECEMBER 31, 2008 23:17:13 ',' DD/MM/YYYY HH24:MI:SS'));))
    Insert into ETL_LASTRUN
    (CBX_TLEMSANI_2000TJE)
    Values
    (TO_DATE (DECEMBER 31, 2008 23:26:31 "," MM/DD/YYYY HH24:MI:SS'));))
    Insert into ETL_LASTRUN
    (CBX_TLEMSANI_2000TJE)
    Values
    (TO_DATE (DECEMBER 31, 2008 23:36:35 ',' DD/MM/YYYY HH24:MI:SS'));))
    Insert into ETL_LASTRUN
    (CBX_TLEMSANI_2000TJE)
    Values
    (TO_DATE (DECEMBER 31, 2008 23:46:23 ',' DD/MM/YYYY HH24:MI:SS'));))
    Insert into ETL_LASTRUN
    (CBX_TLEMSANI_2000TJE)
    Values
    (TO_DATE (DECEMBER 31, 2008 23:56:30 "," MM/DD/YYYY HH24:MI:SS'));))
    Insert into ETL_LASTRUN
    (CBX_TLEMSANI_2000TJE)
    Values
    (TO_DATE (JANUARY 1, 2009 00:06:36 ',' DD/MM/YYYY HH24:MI:SS'));))
    Insert into ETL_LASTRUN
    (CBX_TLEMSANI_2000TJE)
    Values
    (TO_DATE (JANUARY 1, 2009 00:16:39 ',' DD/MM/YYYY HH24:MI:SS'));))
    Insert into ETL_LASTRUN
    (CBX_TLEMSANI_2000TJE)
    Values
    (TO_DATE (JANUARY 1, 2009 00:26:30 "," MM/DD/YYYY HH24:MI:SS'));))
    Insert into ETL_LASTRUN
    (CBX_TLEMSANI_2000TJE)
    Values
    (TO_DATE (JANUARY 1, 2009 00:36:38 ',' DD/MM/YYYY HH24:MI:SS'));))
    COMMIT;


    Now, run the following query
    SELECT MAX (to_char (CBX_tlemsani_2000tje, "MM/DD/YYYY HH24 '")) as CBX_tlemsani_2000tje FROM etl_lastrun

    The results I get (using 10.2.0.1.0)
    CBX_tlemsani_2000tje
    =====
    2008-12-31 23:56

    Hello

    This is because you take to_char max. try this instead:

    select to_char(max(last_run), 'MM/DD/YYYY HH24:MI') as last_run
      from etl_lastrun
    
    LAST_RUN
    ----------------
    01/01/2009 00:36
    1 row selected.
    

    Best regards
    Peter

  • 4.0.22.33382 required ASAP issue date

    I need to present the notes as part of the internal change management upgrade to 4.0.22.33382 ticket. It's on an ix12-300r. Thank you.

    Hello cbotner,

    Here is a link to the documentation/download page to update to this version:
    https://Lenovo-na-en.custhelp.com/app/answers/detail/A_ID/23142

    If you want more details, you can contact support here:
    https://Lenovo-na-en.custhelp.com/app/ask/

  • IDSMC V1.2 issue Date please?

    Hello

    where can I get the release notes V1.2 for IDSMC products

    I would particularly like to know if CSCea55080 bug fix

    in included in this version

    Thanks for the tips

    JYP

    Hello

    You can find the release notes here:

    http://www.Cisco.com/en/us/products/SW/cscowork/ps3990/prod_release_note09186a00801b142b.html

    There are also a few bug fixes for IDS MC 1.2, you might want to look at the software Center.

  • How can I return the data again to Flex my cfc

    I use a cfc by default CRUD built in Flex Builder 3 using activeRecord. I changed my cfc to return the query and access remotely, but I always event.result = null.

    What I am doing wrong? I just want to return the folder after I save it.

    I know I could create a new method in my manager to call a query that will get the record based on my values of form, but I want to return that same value without having to suddenly. Is this possible?

    Flex MXML

    < mx:RemoteObject

    ID = "roMyObject" destination = "ColdFusion" source = "CFCs. MyGateway"showBusyCursor ="true">

    < name mx:method = 'save' result = "MyHandler (event); "/ >

    < / mx:RemoteObject >

    Gateway CFC

    < cffunction = 'save' output name = "false" access = "remote" >

    < name cfargument = "obj" required = "true" / >

    < cfreturn obj.save () / >

    < / cffunction >

    CFC

    < cffunction = 'save' output name = "false" access = "public" returntype = "Cancel" >

    < cfscript >

    If (this.getClassifiedID (eq) 0)

    {

    Create();

    } else {}

    Update();

    }

    < / cfscript >

    < / cffunction >

    < name cffunction "crΘer" output = "false" returntype = access = "remote" = "query" >

    < cfargument name = "obj" required = "true" >

    < cfset var qCreate = "" >

    < cfset var qread read = "" >

    < cftransaction isolation = "read_committed" >

    < cfquery name = "qCreate" >

    Create folder

    < / cfquery >

    < cfquery name = "qGetID" >

    Select last_insert_id() as new_id;

    < / cfquery >

    < / cftransaction >

    < cfreturn qGetID >

    < / cffunction >

    Hello

    You gave the return type of function as zero economy. Try the following code.

    If (this.getClassifiedID (eq) 0)

    {

    result = create();

    } else {}

    result = update();

    }

    Hope this helped you

    concerning

  • Data on passports blackBerry won't turn on again after having turned off Wifi

    Hello

    When I turn off my Wifi, my passport is not connect to the data.  I need to turn off the mobile network and restart to get the data again. It happens 100% of the time.

    Reflections on the patches?

    See also:

    supportforums.BlackBerry.com/T5/BlackBerry-Passport/Calendar-Time-Zone-issue-Again/TD-p/3031616

    It's 2 problems with my passport.  My patience to the test.  Although to be honest, my Z10 in February 2013 was a disastrous wreck of a phone - I can't believe delt with that nonesense for almost 2 years.  The Passport is a bargain compared to this, but still these 2 questions upset me a lot.

    Your help would be great.

    David

    That's what I want to do, live with it, maybe try an OS reinstall on a rainy weekend just to know if it is or not.

  • Issues of data Migration

    Hello

    I'm trying to migrate my SQL Server 7 database to Oracle 10 g R2 using SQL Developer (Version 1.5.1
    During the migration of the data, the process is complete to halfway through due to network problem.
    Is it safe to repeat the migration of data from there?
    SQL Developer migration Workbench "know" when to seek where it terminus? This will create duplicates of records in the target database?
    Any recommendations on the best approach to migrate the data will be much appreciated.

    Thank you
    wilora

    Hi Wilora,

    Developer SQL 'know' the migration of the previous data.
    You must truncate all your tables first. You can write a quick script to do this.

    SELECT 'truncate table ' | table_name | ';' From user_tables; -of course be connected to your migrated user.

    Then proceed to migrating data again. Online data migration is designed only for smaller data sets, say<100 mb.="" if="" you="" have="" a="" network="" issue="" again.="" i="" would="" truncate="" the="" tables="" so="" they="" are="" ready="" to="" receive="" the="" data="" again.="" and="" use="" the="" offline="" data="" move="">

    Heres a quick Viewlet of offline data move
    http://www.Oracle.com/technology/tech/Migration/Workbench/Viewlets/OFDM.html

    Kind regards
    Dermot.

  • I'm running on snow leopard and upgrade to el capitan. If I just upgrade, my data will be safe after finished or need to recover again?

    I'm running on snow leopard and upgrade to el capitan. If I just update without backup (because I have no external HARD disk) data will generally be safe / normal after all as we updated iOS iPhone via OTA or need to recover the data again whenever we have updated to Mac OS?

    If all goes to plan, your data will be safe.  At times things go bad for a backup is indispensable if you value your data.

    Ciao.

Maybe you are looking for

  • any chance to find lost iphones?

    Hi, my daughter and I lost two iPhones in exactly a week - an Iphone5 16 Gb and Iphone 5 s 34 GB - in Vienna. Both phones have been locked by a password but had almost no stack at time of loss / that stolen while. Is there a chance to find them? If t

  • Equium A60-156: energy consumption

    Hi all! Someone at - it an idea of how much energy consume a laptop Equium A60-156 or where I could find this information? I searched inside Toshiba Web site, but haven't found anything. Thank you Iracema

  • Z400 can't see full 4 TB HARD drive

    I have a workstation HP Z400 (KK595ET #ABU). I am using insert a backup internal (do not install the operating system on it) 4 TB HARD drive, but he sees that (offers to initialize) 1.6 to. This seems to indicate only the quantity greater than 2 TB t

  • CASE structure: Can I use a bit word to choose a particular case?

    I know that I can use 'STRUCTURE CASE' in which I can put 2 different situation: TRUE AND FALSE. I know that I can also add other cases, but... How can I change a Boolean value. I know that I can also use integers, but... it is possible to use Boolea

  • Kindle also shows in offline mode on the computer

    Original title: Kindle Device My kindle is reading on the computer offline. Computer is reading device in the Panel and the kindle says it is paired with my computer. I must be missing something, anyone know?  Thank you