Solved

SQL query help

Posted on 2014-03-03
2
315 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
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Oracle Insert not working 10 30
2 IIF's in Access query 25 44
query question 12 32
Oracle create type table from existing table%rowtype ? 6 32
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

792 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