Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle Date Formatting Null date as 00/00/0000

How can I format the Null Dates in my Oracle SQL to 00/00/0000. I am using NVL function but it doesn't recognize the 00/00/0000 as the date format.

Is there any Date Formatting available in Oracle SQL which formats null date to 00/00/0000

like image 674
msbyuva Avatar asked Jan 03 '11 16:01

msbyuva


People also ask

Can we insert NULL in date column in Oracle?

The simplest way to put NULL into any column, regardless of the datatype, is: INSERT INTO emp (hiredate) VALUES (NULL); Don't use single-quotes around NULL. Putting it in single-quotes makes it a 4-character string value.

What is Rrrr in date format?

Hi, YYYY gives the current year as 4 digits. RRRR format means 2-digit years in the range 00 to 49 are assumed to be in the current century (ie have the same first two digits as the current year), and years given as 50 through 99 are assumed to be in the previous century. 0 · Share on TwitterShare on Facebook.

How do I display a date in YYYY MM DD format in Oracle?

Use TO_CHAR to display it in any format you like. For example: SELECT TO_CHAR ( TO_DATE (date_value, 'yyyy-mm-dd') , 'mm/dd/yyyy' ) FROM table_x; Things are much easier if you store dates in DATE columns.

Can we use NVL for date in Oracle?

So, we can use the NVL function. We first need to work out what value we want to display. This could be a static date (i.e., 31-DEC-9999), for example. As you can see, the NVL function can be used to translate a NULL date value to something else.


2 Answers

Do the to_char first and wrap it in the NVL. For example,

select nvl(to_char(null, 'DD-MM-YYYY'), '00-00-0000') from dual
like image 50
DwB Avatar answered Oct 24 '22 05:10

DwB


Use this function to assign default values of null values of date:

SELECT id, NVL(start_date, to_date('20020101','YYYYMMDD')) FROM employee;
like image 1
Majid Hasan Avatar answered Oct 24 '22 06:10

Majid Hasan