0

Specify the day, month, and year as three INTEGER values with no separators between them, using these rules:

The day and month components must have two digits. When the day or month is less than 10, it must be preceded by a zero.

For any year, the year component can have four digits (for example, 1997). For years in the range 1950 to 2049, the year component can, alternatively, have two digits (50 represents 1950, and so on).

You cannot use any separators between the date components.

Examples: '240497' or '04241997'

1 Answers1

1

I'm not sure what's the question but you can format a date with to_char

select to_char(sysdate,'ddmmyyyy')  as d
  from dual;

OUPUT

D       
--------
07092016

If you want to insert into a table

insert into t1 (field1)
values (to_char(sysdate,'ddmmyyyy'));
vercelli
  • 4,717
  • 2
  • 13
  • 15
  • thanks for the answer... its working within dual table. but its not working when is used it in an insert statement. – Nomi Mehar Sep 07 '16 at 09:40
  • @NomiMehar what insert stament? You should post some more info on your question (destination table, is the data coming from another table...) – vercelli Sep 07 '16 at 09:42
  • i have a table called 'EMP'. it has fields emp_id Numbers(7), first_name varchar2(20), last_name varchar2(20).. now i want that when ever i insert a new record it automatically insert emp_id as current date in given format e.g 240497 that is equal to 24-04-19997 – Nomi Mehar Sep 07 '16 at 09:51
  • i have used this type of coding insert into t1 (field1) values (to_char(sysdate,'ddmmyyyy')); but it gives me error "literal does not match the format string" – Nomi Mehar Sep 07 '16 at 09:55
  • thanks for the answers... its working now i have just change the datatype of emp_id to varchar2\ – Nomi Mehar Sep 07 '16 at 10:02
  • @NomiMehar Ok, good to know. I don't think is a good idea to store a date as emp_id since you probably can have 2 employees hired on the same date. – vercelli Sep 07 '16 at 10:12