gaurav
gaurav

Reputation: 345

Date format error

declare
   v_date date;

   CURSOR abc 
   is
      select a_date
        from abc
       where part_id ='E00000001';
begin
   open abc; 
   fetch abc into v_date;
   close abc;

   dbms_output.put_line('date is '||v_date);
end;
/

Here my date that is been fetched is '31/12/2099 23:59:59',Now the issue is that when i fetch this into v_date using cursor its coming ....date is 31/DEC/99

What may be the issue

I am using oracle as RDBMS

Upvotes: 0

Views: 216

Answers (1)

Yahia
Yahia

Reputation: 70379

I see one thing that bothers me with your code - abc is the name of the table and of the cursor... that's bad practice IMHO.

As for the date format problem try

dbms_output.put_line('date is '||TO_CHAR ( v_date, 'DD/MM/YYYY HH24:MI:SS') );

The output you see is most probably the result of some db/session-level NLS setting regarding the date format which is used when converting a DATE to a VARCHAR2 . My code uses an explicit date format to work independently of that setting (which is NOT ideal since it might make it problematic in situations where localization/globalization is needed!).

Upvotes: 1

Related Questions