I'm trying to create a trigger that when someone attempts to insert a new record, the trigger changes the date using to_date to allow a date/time combination to be entered.
The problem is that my users are connecting to the database using a JDBC connection so the trigger can only be at the database layer.
I'm sure this is possible but after looking at pl/sql error messages for the last 12 hours, perhaps I'm wrong...
I'm not sure if my script is what you are looking for. It changes the date format using a trigger through execute immediate. Set the format you want ...
CREATE OR REPLACE TRIGGER date_format
BEFORE INSERT ON table
EXECUTE IMMEDIATE 'alter session set nls_date_format = ''DD/MM/YY HH24:MI:SS''';
Well, it compiled! :-)
But when I connect via ODBC (not tried JDBC yet but I guess it would be the same), I get ORA-01380.
I need to_date but haven't anywhere I can put it unless it's in this trigger. Or I suppose we can completely re-write the application changing all the selects... That however would be ALOT of work...
And if you return the thing you want to_date into a pl/sql variable .... use java in pl/sql .. (create or replace procedure .. .as language java) and then you apply the to_date function to the pl/sql variable....
to_date(variable, 'dd/mm/yyyy') -- from a pl/sql block.