Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8139655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:54:01+00:00 2026-06-06T11:54:01+00:00

I previously ask about converting strings to dates and formatting them.. split string based

  • 0

I previously ask about converting strings to dates and formatting them..
split string based on character position in ORACLE 11g SQL

Here is the solution I have come up with where WKENDING is VARCHAR2 and RYEAR is date
The WKENDING has data that looks like ‘523’(mmdd) and RYEAR is ‘2012’..

UPDATE OB_SEL_LST84_AGG_WKEND  SET WKENDYEAR =  (TO_DATE((TO_DATE(substr(WKENDING,3,2)),'dd')||(TO_DATE(substr(WKENDING,0,1)),'mon')||(TO_DATE(TO_CHAR(RYEAR)),'yyyy')),'dd-mon-yyyy');

I am now getting an error ‘ORA-00907: missing right parenthesis’, I’ve double checked the parenthesis a couple of times and they look right to me.. any help would be great.. thanks!

UPDATE
– After looking at the syntax of what I have above I thought that maybe there are too many TO_DATE attempted conversions going on. So, I shortened it to this..

UPDATE OB_SEL_LST84_AGG_WKEND  SET WKENDYEAR =  (TO_DATE((substr(WKENDING,3,2))||(substr(WKENDING,0,1))||TO_CHAR(RYEAR)),'dd-mon-yyyy');

I’m still getting the missing parenthesis error though.. ARGH!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:54:03+00:00Added an answer on June 6, 2026 at 11:54 am

    Since the data type of the wkendyear column is DATE, you should just need to

    UPDATE OB_SEL_LST84_AGG_WKEND  
       SET wkendyear = to_date( lpad(WKENDING,4,'0') || RYEAR, 'mmddyyyy' )
    

    This assumes, of course, that all your string data can be converted into a valid date. As soon as you have a wkending of 0229 and a ryear of 2013 (or some other combination of strings that are not a valid date), the TO_DATE function is going to throw an exception. That’s one of the reasons that storing dates in VARCHAR2 columns is generally problematic.

    If not all of your data can be converted correctly to a DATE, you can create a function that attempts to do the conversion and returns a NULL if there is an exception. For example

    CREATE OR REPLACE FUNCTION my_to_date( p_str IN VARCHAR2, p_format IN VARCHAR2 )
      RETURN DATE
    IS
      l_dt DATE;
    BEGIN
      l_dt := to_date( p_str, p_format );
      RETURN l_dt;
    EXCEPTION
      WHEN others THEN
        RETURN NULL;
    END;
    

    Your UPDATE statement would then become

    UPDATE OB_SEL_LST84_AGG_WKEND  
       SET wkendyear = my_to_date( lpad(WKENDING,4,'0') || RYEAR, 'mmddyyyy' )
    

    You can also look for rows where the string cannot be converted to a date

    SELECT *
      FROM OB_SEL_LST84_AGG_WKEND  
     WHERE my_to_date( lpad(WKENDING,4,'0') || RYEAR, 'mmddyyyy' ) IS NULL
       AND (wkending IS NOT NULL or ryear IS NOT NULL)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem that I tried to ask about previously, but didn't get
Previously I'm a C programmer(wanna know more about system programming but don't wanna go
I'd already ask about this, but still don't have an answer. I think the
Ok so maybe I didn't ask my previous question correctly - it was about
I would like to ask a theoritical question about how some web sites work.
May I ask a question about the CC compiler in Solaris environment. I try
I've looked around, and I do see previous questions where people ask about Date/Time
Did ask a question about the same problem here: Silly problem with UTF8 but
Previously I asked you about ways to test sending multiple emails at once. Now
I’d like to ask you a question again. It is basically about data frames,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.