Solved

SQL query help

Posted on 2014-03-03
2
325 Views
Last Modified: 2014-03-03
I have one table with two cols

Table1
-----------
col1                                                                  col2
-----                                                                  -----
",,"                  
(null)            
19/05/1975
27/08/1976
MK109 - Sales Training (All Staff)


What I want is to
1. update col2 with date format
2. If there is any data other than dd/mm/yyyy format (regex) make it to null

How do i do that.

I started off but couldnt complete...

update Table1 set col2=(select to_char(mydate,'DD-MON-RR HH:MI') from (
select to_date(col1,'DD-MM-RRRR') mydate from Table1) where (rowid=Table1.rowid and col1 != null));

The above query updates every row to null...

Can you guys help me?
0
Comment
Question by:Perumal_RM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 39902464
update table1 set col2 = to_date(col1,'dd/mm/yyyy')
where regexp_like(col1,'(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/[0-9]{1,4}');


Note, this checks for the correct form and most reasonable ranges; but it's not a completely reliable date checker.


31/06/2014   would be considered a legal date string even though June doesn't have 31 days

29/02/2013 would also be considered legal, even thought 2013 isn't a leap year
0
 

Author Closing Comment

by:Perumal_RM
ID: 39902488
Works like a charm. I have another one there too. that is to append some date and time to a string.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to take different types of Oracle backups using RMAN.

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question