Date Format change During the Insert [message #400869] |
Thu, 30 April 2009 02:21 |
|
hi,
When i try to insert the records in to table. The insert are correctly done, but the date format are changed thus year is changed to 0009. How to solve this problem.
The Following are the code using:
Declare
Cntdt Number(3);
begin
Declare
Cursor emps is SELECT (((TO_DATE('01-Apr-2009', 'DD/mm/YYYY') - 1)) + rownum) Prdate
FROM (SELECT 1 from DUAL
CONNECT BY level <= ((TO_DATE('30-Apr-2009', 'DD/mm/YYYY') + 1) - TO_DATE('01-Apr-2009', 'DD/MM/YYYY')));
Emp Emps%Rowtype;
Begin
Open Emps;
Loop
Fetch Emps into emp;
Exit when Emps%NotFound;
Declare
Cursor empl is select emcode,unmast,departcode from emmast
where unmast = 2;
Empt empl%Rowtype;
WeekD Char(10);
Begin
Open Empl;
Loop
Fetch Empl into empt;
Exit When Empl%NotFound;
Select Upper(to_Char(To_date(Emp.Prdate,'dd/mm/yyyy'),'Day')) into WeekD from dual;
If WeekD not in ('SUNDAY') Then
Insert into attend Values (Empt.emcode,Emp.Prdate,'XX',0,null,Empt.departcode,Empt.unmast);
Else
Insert into attend Values (Empt.emcode,Emp.Prdate,'WW',0,null,Empt.departcode,Empt.unmast);
End if;
End Loop;
Close Empl;
End;
End Loop;
Close Emps;
End;
Commit;
end;
Regards,
C V S
|
|
|
|
|
|
|
Re: Date Format change During the Insert [message #400899 is a reply to message #400869] |
Thu, 30 April 2009 05:39 |
cookiemonster
Messages: 13960 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Then I have no idea what the problem is.
Your cursor will find dates in the year 2009.
emp.prdate should be a date.
If the column you're inserting into is also a date then no conversion should occur.
How are you checking the value after it's been inserted?
|
|
|
Re: Date Format change During the Insert [message #400900 is a reply to message #400897] |
Thu, 30 April 2009 05:43 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
If "emp.prdate" is of a DATE datatype, why do you convert it to DATE again?Quote: | to_Char(To_date(Emp.Prdate,'dd/mm/yyyy'),'Day')
|
Would you mind to post code which contains modified INSERT statement, so that it includes column list; for exampleINSERT INTO your_table (id, name, date_column)
VALUES (emp.id, emp.name, emp.date_col)
Also, it wouldn't hurt if you post tables' description (so that we could track datatypes).
|
|
|
Re: Date Format change During the Insert [message #400915 is a reply to message #400899] |
Thu, 30 April 2009 06:15 |
|
When I select the data after the Insert.
select * from attend where attend_dt between '01-Apr-2009' and '30-APR-2009';
The Output is no rows selected
Re_try to insert the table, they were display the constraints error.
Thus i try the query of
select * from attend where attend_dt between '01-Apr-0009' and '30-APR-0009';
It display the record.
|
|
|
|
|
|
|
Re: Date Format change During the Insert [message #401491 is a reply to message #401221] |
Tue, 05 May 2009 04:01 |
cookiemonster
Messages: 13960 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
sankaresh wrote on Sat, 02 May 2009 20:59 | you can use this coding in pre-form trigger
set_application_property(PLSQL_DATE_FORMAT,'DD-MON-YYYY HH:MI:SS24');
(if u dont need time remove it.)
set_application_property(BUILTIN_DATE_FORMAT,'DD-MON-YYYY HH:MI:SS24');
forms_ddl('alter session set NLS_DATE_FORMAT = ''DD-MON-YYYY HH:MI:SS ''');
regards
Sankar
|
Alternatively the OP could find out where the dodgy conversion is happening and fix it - which'd be far more certain than messing about with system wide settings like that.
sasipalarivattom wrote on Mon, 04 May 2009 06:46 |
Dear friend,
Try using the format mask 'DD/mm/RRRR'.
It works in my system.
And I hope any expert will give us a comment on the difference between these two format masks.
|
It works for you but you're not sure what the difference is?
And you're recommending it anyway?
The RR Datetime Format Element
|
|
|
Re: Date Format change During the Insert [message #401861 is a reply to message #401491] |
Wed, 06 May 2009 13:05 |
sankaresh
Messages: 2 Registered: May 2009 Location: chennai
|
Junior Member |
|
|
hi friends
i used to test with format mask setting in property palette as DD-MM-RRRR
for the particular date field, but i used to get only with 0009
in the backend.
when i used to place the set_application_property ('plsql_date_format, 'DD-MM-YYYY' ) i am able to get as 2009
and am sure it gets the result only with plsql date format.
and we dont need to set the other properties like builtin date format and nls date format.
[Updated on: Wed, 06 May 2009 13:15] Report message to a moderator
|
|
|
|