DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: Changing the date format using a trigger

  1. #1
    Join Date
    Mar 2002
    Posts
    2

    Post

    Hi All,

    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...

  2. #2
    Join Date
    Dec 2001
    Location
    Brazil
    Posts
    282

    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
    BEGIN
    EXECUTE IMMEDIATE 'alter session set nls_date_format = ''DD/MM/YY HH24:MI:SS''';
    END;


    F.

  3. #3
    Join Date
    Mar 2002
    Posts
    2
    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...

  4. #4
    Join Date
    Dec 2001
    Location
    Brazil
    Posts
    282

    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....

    eg.
    to_date(variable, 'dd/mm/yyyy') -- from a pl/sql block.

    ?


    F.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width