NLS_DATE_FORMAT in DB trigger

Hi all,
I have a problem with NLS_date_format, there exists in database such a trigger
CREATE OR REPLACE TRIGGER TR_MZDR1_BRIU
BEFORE INSERT OR UPDATE OF col2 ,col3, col4, col5, col6
on MAN_TAB1 FOR EACH ROW
begin
IF INSERTING THEN
select SEQ_id11.nextval into :new.col1 from dual;
END IF;
:new.col5:=nvl(:new.col6,'01.01.2100');
:new.col6:=nvl(:new.col5,'01.01.1900');
:new.col4:=nvl(:new.col4,'?');
:new.col2:=nvl(:new.col2,'?');
:new.col3:=nvl(:new.col3,'?');
end;
when I try to do following insert INSERT INTO tab1 (col1, col2, col3) values (1, 'aaaa', 'bbb');
i get error
ORA-01843: not a valid month
ORA-06512: at "DWS01.TR_MZDR1_BRIU", line 6
ORA-04088: error during execution of trigger 'DWS01.TR_MZDR1_BRIU'
if I use alter session command
alter session set nls_date_format = 'DD.MM.YYYY';
then insert is successful, but if I'm trying execute next insert again I get error again and I have to issue ALTER SEESION again
generally problem is more complicated beacuse this insert is generated by DBMS_SQL and procedure is called from Oracle Forms, and it always crashes with this error
any idea ?

Hi,
brano7332 wrote:
Hi all,
I have a problem with NLS_date_format, there exists in database such a trigger
CREATE OR REPLACE TRIGGER TR_MZDR1_BRIU
BEFORE INSERT OR UPDATE OF col2 ,col3, col4, col5, col6
on MAN_TAB1 FOR EACH ROW
begin
IF INSERTING THEN
select SEQ_id11.nextval into :new.col1 from dual;
END IF;
:new.col5:=nvl(:new.col6,'01.01.2100');
:new.col6:=nvl(:new.col5,'01.01.1900');Do you really want to use one column on the left of the := operator, and a different column on the right?
:new.col4:=nvl(:new.col4,'?');
:new.col2:=nvl(:new.col2,'?');
:new.col3:=nvl(:new.col3,'?');
end;
when I try to do following insert INSERT INTO tab1 (col1, col2, col3) values (1, 'aaaa', 'bbb');
i get error
ORA-01843: not a valid month
ORA-06512: at "DWS01.TR_MZDR1_BRIU", line 6
ORA-04088: error during execution of trigger 'DWS01.TR_MZDR1_BRIU'
if I use alter session command
alter session set nls_date_format = 'DD.MM.YYYY';
then insert is successful, but if I'm trying execute next insert again I get error again and I have to issue ALTER SEESION again
generally problem is more complicated beacuse this insert is generated by DBMS_SQL and procedure is called from Oracle Forms, and it always crashes with this error
any idea ?Don't use a string (such as '01.01.2100') where a DATE is expected.
NVL expects 2 arguments of the same data type. If col6 is a DATE, the NVL expects the 2nd argument of
nvl(:new.col6,'01.01.2100');to be a DATE also, like this
nvl ( :new.col6
    , TO_DATE ( '01.01.2100'
              , 'DD.MM.YYYY'
    );Use NLS_DATE_FORMAT to control the default appearance of DATEs in SELECT statements. Using NLS_DATE_FORMAT for anything else is almost certainly wrong.

Similar Messages

  • Logon trigger setting nls_date_format over ridden by sql developer?

    Problem: Developers are inserting a Date record into a varchar field. I can't change this process right now. Non-Date info is stored here also. Would require a code change.
    To simplify this, I wanted to get all the developers to insert using the same 'nls_date_format'. I had hoped to be able to centralize this by having Oracle set it in the database. I tried this by setting the database nls_date_format and with a logon trigger.
    See test below. Seems to be over ridden.
    Test case is with SQL Developer. Noticed the same thing when developers use Websphere. I think we reduce the chance for errors, if I can handle this in the database. However, my nls_date_format settings are getting over ridden.
    1. s et database parameter nls_date_format to YYYY-MM-DD HH24:MI:SS , this gets over riden by SQL Developer/Websphere
    2. Created a trigger with an 'alter session', but this seems to get over ridden also.
    Please see test case below:
    Oracle 11.2.0.3
    test logging: SQLPLUS locally on the unix server, then log in using SQL Developer which is installed on my laptop.
    SQL Developer NLS_DATE_FORMAT : YYYY-MON-DD HH24:MI:SS , This is different for test purposes
    I have auditing turned turned on to db,extended with 'audit all by 'user' by access;' for test purposes to get more info.
    create table test (username varchar2(30),sid number,mytest varchar2(300),insert_date date);
    create or replace
    TRIGGER LOGINTRG
    AFTER LOGON ON DATABASE
    BEGIN
    insert into test select user,   sys_context('USERENV','SID') ,value,sysdate from v$parameter where name = 'nls_date_format';
    EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_FORMAT=''YYYY-MM-DD HH24:MI:SS''';
    insert into test select user,   sys_context('USERENV','SID') ,value,sysdate from v$parameter where name = 'nls_date_format';
    commit;
    END LOGINTRG;
    /Results/Questions
    1. When I select from 'test', I confirm that my NLS_DATE_FORMAT is the same both before and after the alter session.
    2. select value from v$parameter where name = 'nls_date_format'
    output: YYYY-MON-DD HH24:MI:SS (so sql developer is over riding this);
    3. select * from dba_audit_trail where username = 'MYUSER' order by timestamp desc;
    The SQLs from the logon trigger are not captured. how do I capture logon trigger sqls? Not a huge deal, just curious
    4. I do not see any alter sessions issued by my user. shouldn't audit all by access capture that? how could my session nls_date_format change without an alter session?
    Edited by: Guess2 on Apr 22, 2013 10:44 AM

    >
    Problem: Developers are inserting a Date record into a varchar field.
    >
    No - they aren't. That is physically impossible. The only thing that can be stored in a 'varchar field' is a string. Oracle considers ANYTHING stored in a character column to be a string.
    Date values are stored in DATE columns. Perhaps you meant that developers are converting DATE values to strings and then storing the string in a 'varchar field'?
    >
    I can't change this process right now. Non-Date info is stored here also.
    >
    WONDERFUL! Why use a column to stored just one type of data? That is extremely wasteful. Hopefully you store strings that represent numbers in that same column also? It makes the data model so much easier to understand if developers only need to learn one datatype.
    >
    Would require a code change.
    >
    The horror!
    You should never, ever, EVER use a code change to fix a problem if there is even the slightest possibility that you can change the ENTIRE DATABASE instead.
    I've got good news though. You are now on version Oracle 11.2.0.3 and Oracle, after months of protests by some of their largest clients, has finally dropped the exhorbitant license fees for using some of the more esoteric datatypes like DATE and NUMBER.
    You should suggest to your manager that they use some of the license fee money saved to hire developers that already know how to design proper data models and use those new-fangled datatypes.
    Trust me - once you've made it up that steep learning curve your code will have fewer of those pesky 'dirty data' issues to deal with.
    Sure - it means less job security for your current developers. But sometimes you just have to 'take one for the team'!

  • Problem with trigger and entity in JHeadsart, JBO-25019

    Hi to all,
    I am using JDeveloper 10.1.2 and developing an application using ADF Business Components and JheadStart 10.1.2.27
    I have a problem with trigger and entity in JHeadsart
    I have 3 entity and 3 views
    DsitTelephoneView based on DsitTelephone entity based on DSIT_TELEPHONE database table.
    TelUoView based on TelUo entity based on TEL_UO database table.
    NewAnnuaireView based on NewAnnuaire entity based on NEW_ANNUAIRE database view.
    I am using JHS to create :
    A JHS table-form based on DsitTelephoneView
    A JHS table based on TelUoView
    A JHS table based on NewAnnuaireView
    LIB_POSTE is a :
    DSIT_TELEPHONE column
    TEL_UO column
    NEW_ANNUAIRE column
    NEW_ANNUAIRE database view is built from DSIT_TELEPHONE database table.
    Lib_poste is an updatable attribut in TelUo entity, DsitTelephone entity, NewAnnuaire entity.
    Lib_poste is upadated in JHS table based on TelUoView
    I added a trigger on my database shema « IAN » to upadate LIB_POSTE in DSIT_TELEPHONE database table :
    CREATE OR REPLACES TRIGGER “IAN”.TEL_UO_UPDATE_LIB_POSTE
    AFTER INSERT OR UPDATE OFF lib_poste ONE IAN.TEL_UO
    FOR EACH ROW
    BEGIN
    UPDATE DSIT_TELEPHONE T
    SET t.lib_poste = :new.lib_poste
    WHERE t.id_tel = :new.id_tel;
    END;
    When I change the lib_poste with the application :
    - the lib_poste in DSIT_TELEPHONE database table is correctly updated by trigger.
    - but in JHS table-form based on DsitTelephoneView the lib_poste is not updated. If I do a quicksearch it is updated.
    - in JHS table based on NewAnnuaireView the lib_poste is not updated. if I do a quicksearch, I have an error:
    oracle.jbo.RowAlreadyDeletedException: JBO-25019: The row of entity of the key oracle.jbo. Key [null 25588] is not found in NewAnnuaire.
    25588 is the primary key off row in NEW_ANNUAIRE whose lib_poste was updated by the trigger.
    It is as if it had lost the bond with the row in the entity.
    Could you help me please ?
    Regards
    Laurent

    The following example should help.
    SQL> create sequence workorders_seq
      2  start with 1
      3  increment by 1
      4  nocycle
      5  nocache;
    Sequence created.
    SQL> create table workorders(workorder_id number,
      2  description varchar2(30),
      3   created_date date default sysdate);
    Table created.
    SQL> CREATE OR REPLACE TRIGGER TIMESTAMP_CREATED
      2  BEFORE INSERT ON workorders
      3  FOR EACH ROW
      4  BEGIN
      5  SELECT workorders_seq.nextval
      6    INTO :new.workorder_id
      7    FROM dual;
      8  END;
      9  /
    Trigger created.
    SQL> ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';
    Session altered.
    SQL> insert into workorders(description) values('test1');
    1 row created.
    SQL> insert into workorders(description) values('test2');
    1 row created.
    SQL> select * from workorders;
    WORKORDER_ID DESCRIPTION                    CREATED_DATE
               1 test1                          30-NOV-2004 15:30:34
               2 test2                          30-NOV-2004 15:30:42
    2 rows selected.

  • Can't get NLS_DATE_FORMAT from windows regedit

    My windows version is xp, and I do set NLS_DATE_FORMAT = 'YYYY/MM/DD HH24:MI:SS' in register table, and I use oracle SQL*worksheet, when I query
    select sysdate from dual,
    it will get the date which format exactly like 'YYYY/MM/DD HH24:MI:SS' ;
    But When I query in SQL*Developer:
    select sysdate from dual
    it will get the date which format exactly like 'DD-MMM-YY'
    I just wonder why SQL*Developer doesn't use NLS_DATE_FORMAT in register table but use the default date format?
    Thanks

    I don't know the why, just that it doesn't pull that setting from windows. It is probably related to it being written in java.
    Anyways, in 1.0, you need to setup a login trigger to set the date format at login. There are examples of how to do this if you search the forum.
    In the 1.1 eval version, there is a setting in tools -> preferences -> Database -> nls parameters.
    Eric

  • NLS_date_format in triggers

    Hi everyone
    Please tell what NLS settings are for trigger sessions, for example i make update on table where there are trigger
    which make some inserts and update on other tables on string column but with date datatype, so how this date will be formatted in this string column,(there is no to_char setting) , does trigger get NLS setting from session which fire that trigger or are taken from instance level?
    Best regards
    thx

    913813 wrote:
    Hi everyone
    Please tell what NLS settings are for trigger sessions, for example i make update on table where there are trigger
    which make some inserts and update on other tables on string column but with date datatype, so how this date will be formatted in this string column,(there is no to_char setting) , does trigger get NLS setting from session which fire that trigger or are taken from instance level?
    Best regards
    thxI second Sybrands comments on not storing dates as strings. It is a really bad idea.
    As to your question, what stops you from running a quick test to see what happens. This took me all of 5 minutes:
    SQL> create table t (real_date date,
      2                  string_date varchar2(25),
      3                  nls_mask varchar2(25));
    Table created.
    SQL> create trigger t_bi
      2     before insert on t
      3     for each row
      4  begin
      5     :new.string_date := :new.real_date;
      6  end;
      7  /
    Trigger created.
    SQL> select parameter, value from v$nls_parameters
      2  where parameter = 'NLS_DATE_FORMAT';
    PARAMETER        VALUE
    NLS_DATE_FORMAT  DD-MON-FXYYYY
    SQL> insert into t (real_date, nls_mask)
      2  values (sysdate, 'Default');
    1 row created.
    SQL> alter session set nls_date_format = 'dd/mm/yyyy hh24:mi:ss';
    Session altered.
    SQL> insert into t (real_date, nls_mask)
      2  values (sysdate, 'dd/mm/yyyy hh24:mi:ss');
    1 row created.
    SQL> alter session set nls_date_format = 'yyyy-Mon-dd hh24:mi:ss';
    Session altered.
    SQL> insert into t (real_date, nls_mask)
      2  values (sysdate, 'yyyy-Mon-dd hh24:mi:ss');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select * from t;
    REAL_DATE            STRING_DATE               NLS_MASK
    2012-Mar-12 10:50:55 12-MAR-2012               Default
    2012-Mar-12 10:52:20 12/03/2012 10:52:20       dd/mm/yyyy hh24:mi:ss
    2012-Mar-12 10:53:13 2012-Mar-12 10:53:13      yyyy-Mon-dd hh24:mi:ss
    SQL> alter session set nls_date_format = 'dd-mon-yyyy';
    Session altered.
    SQL> select * from t;
    REAL_DATE   STRING_DATE               NLS_MASK
    12-mar-2012 12-MAR-2012               Default
    12-mar-2012 12/03/2012 10:52:20       dd/mm/yyyy hh24:mi:ss
    12-mar-2012 2012-Mar-12 10:53:13      yyyy-Mon-dd hh24:mi:ssJohn

  • Date Format Issue with Pre-Insert trigger

    I have created a form wherein creation_date and last_update_date are columns in a table that needs to be populated with sysdate (in format mm/dd/yyyy hh:mi:ss am) at time of saving.
    In pre-insert triiger, if I assign date as follows , it works:
    :creation_date=sysdate;
    However this creates date in format yyyy/mm/dd.
    I would like to set it in format mm/dd/yyyy hh:mi:ss am.
    How can this be done-I tried using to_date and to_char but wont work.
    Any ideas?

    hi
    u may try this too.
    when-new-form-instance trigger:
    set_application_property(PLSQL_date_FORMAT,'DDMMYYYY HH12:MI:SS');
    set_application_property(BUILTIN_date_FORMAT,'DDMMYYYY HH12:MI:SS');
    forms_ddl('ALTER SESSION SET NLS_date_FORMAT=''DDMMYYYY HH12:MI:SS'''); sarah

  • Trigger to Update in the same table.

    Hi,
    I would like to create a trigger that when we insert into table ALL_CAPACITY_SNS_CELL1 it updates column Action on teh same table,if teher is an update, it will update the same table , column ACTION.
    This is what I have attempted but seems to be technically wrong.
    <pre>
    create table ALL_CAPACITY_SNS_CELL1
    ( A varchar2,
    action char(2),
    date_executed date);
    create or replace
    TRIGGER ALL_CAPACITY_HISTORY_TRACKING
    AFTER INSERT OR DELETE OR UPDATE ON ALL_CAPACITY_SNS_CELL1 FOR EACH ROW
    DECLARE
    v_operation VARCHAR2(10) := NULL;
    BEGIN
    IF INSERTING THEN
    v_operation := 'I';
    ELSIF UPDATING THEN
    v_operation := 'U';
    ELSE
    v_operation := 'D';
    END IF;
    IF INSERTING
    UPDATE ALL_CAPACITY_SNS_CELL1
    SET ACTION =v_operation,
    DATE_EXECUTED =sysdate ;
    ELSIF UPDATING THEN
    UPDATE ALL_CAPACITY_SNS_CELL1
    SET ACTION =v_operation,
    DATE_EXECUTED =sysdate ;
    END IF;
    END;
    </pre>

    CrackerJack wrote:
    But above query made all ACTION nul...so we shoudl after insert or update trigger right?Obviously it is not working. You modified my code the way it does not make sense.
    IF INSERTING
    THEN
    :NEW.ACTION := 'I';
    IF UPDATING
    THEN
    :NEW.ACTION := 'U';
    ELSE
    :NEW.ACTION := 'X';
    END IF;The code above checks if trigger fired on INSERT (IF INSERTING). In THEN branch of that IF you check if trigger fired on UPDATE. It makes no sense. Now, if you would use my trigger:
    SQL> create table ALL_CAPACITY_SNS_CELL1
      2  ( A varchar2(1),
      3  action char(2),
      4  date_executed date);
    Table created.
    SQL> create or replace
      2    TRIGGER ALL_CAPACITY_HISTORY_TRACKING
      3      BEFORE INSERT
      4         OR UPDATE
      5      ON ALL_CAPACITY_SNS_CELL1
      6      FOR EACH ROW
      7      BEGIN
      8          IF INSERTING
      9            THEN
    10              :NEW.ACTION := 'I';
    11            ELSE
    12              :NEW.ACTION := 'U';
    13          END IF;
    14          :NEW.DATE_EXECUTED := sysdate ;
    15  END;
    16  /
    Trigger created.
    SQL> insert into ALL_CAPACITY_SNS_CELL1(a) values('A')
      2  /
    1 row created.
    SQL> insert into ALL_CAPACITY_SNS_CELL1(a) values('B')
      2  /
    1 row created.
    SQL> alter session set nls_date_format='mm/dd/yyyy hh24:mi:ss'
      2  /
    Session altered.
    SQL> select * from ALL_CAPACITY_SNS_CELL1
      2  /
    A AC DATE_EXECUTED
    A I  05/13/2009 08:56:02
    B I  05/13/2009 08:56:09
    SQL> update ALL_CAPACITY_SNS_CELL1
      2  set a = 'X'
      3  where a = 'B'
      4  /
    1 row updated.
    SQL> select * from ALL_CAPACITY_SNS_CELL1
      2  /
    A AC DATE_EXECUTED
    A I  05/13/2009 08:56:02
    X U  05/13/2009 08:57:05
    SQL> update ALL_CAPACITY_SNS_CELL1
      2  set a = 'Y'
      3  /
    2 rows updated.
    SQL> select * from ALL_CAPACITY_SNS_CELL1
      2  /
    A AC DATE_EXECUTED
    Y U  05/13/2009 08:57:21
    Y U  05/13/2009 08:57:21
    SQL> insert into ALL_CAPACITY_SNS_CELL1(a) values('C')
      2  /
    1 row created.
    SQL> select * from ALL_CAPACITY_SNS_CELL1
      2  /
    A AC DATE_EXECUTED
    Y U  05/13/2009 08:57:21
    Y U  05/13/2009 08:57:21
    C I  05/13/2009 08:57:53
    SQL> SY.

  • Nls_date_format in oracle 10g XE

    Hi guys,
    I've been trying to change the default date format in my instance of 10g XE. I could do it in Standard version just modifying the init script but I couldn't find a way to do it in XE.
    I don't want to use "ALTER SESSION" since I really need to change the default date format and not just in the sesion.
    Could you help me?
    Cheers.

    You could create an after logon trigger as in following example :
    SQL> sho user
    USER is "SYS"
    SQL> select sysdate from dual;
    SYSDATE
    24-MAY-07
    SQL> create or replace trigger after_logon
      2  after logon on database
      3  begin
      4     if user='TEST' then
      5             execute immediate
      6             'alter session set nls_date_format=''YYYY-mm-dd hh24:mi:ss''';
      7     end if;
      8  end;
      9  /
    Trigger created.
    SQL> conn test/test
    Connected.
    SQL> select sysdate from dual;
    SYSDATE
    2007-05-24 15:56:55
    SQL> conn system/manager
    Connected.
    SQL> /
    SYSDATE
    24-MAY-07
    SQL>

  • Setting  nls_date_format....in oracle 9i v 9.2

    Setting nls_date_formate is working in session level fine.
    But i need to set the format in an application level.For that i tried the following,but date format is not changed.
    i created the Pfile from SPfile,made an entry nls_date_format='DD/MM/YYYY'. and then i created SPfile from Pfile.but date format is not changed.

    Hi,
    If the client environment sets any of the NLS_* parameters, they override the server in all cases. So if the client sets, for example, the NLS_LANG parameter, that will cause all NLS_* settings on the server to be ignored. The server will use the client's specified values and default values for all other NLS settings instead, ignoring anything in init.ora.
    Where that typically comes into play is if the client is Windows. The client install on Windows sets the NLS_LANG parameter in the registry by default. The fact that the client sets the NLS_LANG parameter causes the NLS settings you put in the init.ora not to be used by that client. To solve this, you can
    * Set the NLS_DATE_FORMAT in the registry on the client
    * Put an ALTER SESSION SET nls_date_format=your_format statement in your application right after the connect
    * Use an AFTER LOGON trigger similar to the one supplied below:
    create or replace trigger
    data_logon_trigger
    after logon
    on database
    begin
    execute immediate 'alter session set nls_date_format = ''your format here'' ';
    end;
    /Cheers

  • Fractions of seconds in NLS_DATE_FORMAT

    Hi all,
    Does anyone know what the date mask is to have hundredths of seconds? I've been trolling around the
    net but I can't seem to find a list of valid masks.
    I need to compare date/time values in Oracle with those in another database where the fractions are stored as .nnn
    At present I've got NLS_DATE_FORMAT set as 'ALTER SESSION SET NLS_DATE_FORMAT=''YYYY-MM-DD HH24:MI:SS''';
    What I really need is something the lines of
    'ALTER SESSION SET NLS_DATE_FORMAT=''YYYY-MM-DD HH24:MI:SS.FFF''' ;
    where FFF is the fractions.
    I would even be happy to have the fractions all come out as .000
    Is this possible?
    Thanks
    Dave

    hi,
    that all works fine using your example but... I'm extracting from v$logmnr_contents which is created by the logminer application.
    This view contains a field called SQL_REDO which may or may not contain any date/time columns. e.g.
    "delete from ARCH_RCPT_MAST where RCPT_NO = '45510' and CREATE_DT = TO_DATE('2008-01-10 09:25:13', 'YYYY-MM-DD HH24:MI:SS') and USER_NAME = 'MARKL' and STATUS = 'POST' and STATUS_DT = TO_DATE('2008-01-10 11:17:41', 'YYYY-MM-DD HH24:MI:SS') and INV_STATUS IS NULL and RECV_LOC = 'IN' and RECV_DOCK = '1' and PTWY_RULE = 'DEFAULT' and INSP IS NULL and LOCATION IS NULL and TRAILER_NO IS NULL and BOL_NO IS NULL and AUX_1 = ' 45510' and AUX_2 = '193455' and AUX_3 IS NULL and AUX_4 IS NULL and AUX_5 IS NULL and AUX_6 IS NULL and AUX_7 IS NULL and AUX_8 IS NULL and AUX_9 IS NULL and AUX_10 IS NULL and UPLD = 'Y' and UPLD_DT IS NULL and UPLD_CNT IS NULL and CARRIER IS NULL and CHKIN_RULE IS NULL and CLOSE_DT = TO_DATE('2008-01-10 11:17:41', 'YYYY-MM-DD HH24:MI:SS') and WHO_CLOSE = 'GG' and POST_DT = TO_DATE('2008-01-10 11:17:41', 'YYYY-MM-DD HH24:MI:SS') and WHO_POST = 'GG' and FIRST_TRANS = '8659969' and LAST_TRANS = '8659969' and WHO_CREATE = 'MARKL' ";
    This string needs converting to ANSI SQL so it can put pushed into a SQL server database so all I can really do is parse out the Oracle functions such as TO_DATE etc
    I have a trigger on the login which forces the date data in the coulmn SQL_REDO to come out as YYYY-MM-DD HH24:MI:SS
    Unless I'm missing something I don't see how I can use to_timestsamp functions on a large char column such as this.
    Regards
    Dave

  • Logon Trigger setting NLS_SESSION_PARAMETERS not working

    Hello,
    I have a problem with a logon trigger setting session parameters:
    create or replace
    TRIGGER standard.after_logon_trg
    AFTER LOGON ON STANDARD.SCHEMA
    BEGIN
      DBMS_APPLICATION_INFO.set_module(USER, 'Initialized');
      EXECUTE IMMEDIATE ('ALTER SESSION SET current_schema=standard');
      EXECUTE IMMEDIATE ('ALTER SESSION SET NLS_DATE_LANGUAGE=''AMERICAN''');
      EXECUTE IMMEDIATE ('ALTER SESSION SET NLS_TERRITORY=''AMERICA''');
      EXECUTE IMMEDIATE ('ALTER SESSION SET NLS_TIMESTAMP_FORMAT=''HH24:mi:ss''');
      EXECUTE IMMEDIATE ('ALTER SESSION SET NLS_DATE_FORMAT=''YYYY-MM-DD''');
      EXECUTE IMMEDIATE ('ALTER SESSION SET NLS_COMP=LINGUISTIC');
      EXECUTE IMMEDIATE ('ALTER SESSION SET NLS_SORT=BINARY_CI');
      insert into standard.testcc (bezeichnung, datum) values ('logontrigger', SYSDATE);
    END;After I log in, the new row is added to the table, but the session parameters are completely untouched.
    select * from NLS_SESSION_PARAMETERS says:
    NLS_LANGUAGE     GERMAN
    NLS_TERRITORY     GERMANY
    NLS_CURRENCY     €
    NLS_ISO_CURRENCY     GERMANY
    NLS_NUMERIC_CHARACTERS     ,.
    NLS_CALENDAR     GREGORIAN
    NLS_DATE_FORMAT     DD.MM.RR
    NLS_DATE_LANGUAGE     GERMAN
    NLS_SORT     GERMAN
    NLS_TIME_FORMAT     HH24:MI:SSXFF
    NLS_TIMESTAMP_FORMAT     DD.MM.RR HH24:MI:SSXFF
    NLS_TIME_TZ_FORMAT     HH24:MI:SSXFF TZR
    NLS_TIMESTAMP_TZ_FORMAT     DD.MM.RR HH24:MI:SSXFF TZR
    NLS_DUAL_CURRENCY     €
    NLS_COMP     BINARY
    NLS_LENGTH_SEMANTICS     BYTE
    NLS_NCHAR_CONV_EXCP     FALSEIf I execute the ALTER SESSION statements in the sql console (as user standard) they work perfectly, so this seems to be no permission issue.
    Whats wrong with the trigger?
    Thanks and regards
    Christian
    Edited by: 853536 on 20.04.2011 00:31
    OK, I've traced the entire database, and found out that my parameters are overwritten. So after my trigger has been executed, the NLS Session parameters are altered, for example:
    =====================
    PARSING IN CURSOR #4 len=386 dep=0 uid=40 oct=3 lid=40 tim=4721509708 hv=302297662 ad='ab275c28'
    select parameter,value from nls_session_parameters
    union all SELECT 'DB_TIMEZONE' name, DBTIMEZONE  value FROM DUAL
    union all SELECT 'SESSION_TIMEZONE' name, SESSIONTIMEZONE value FROM DUAL
    union all SELECT 'SESSION_TIMEZONE_OFFSET' name, TZ_OFFSET(SESSIONTIMEZONE) value from DUAL
    union all SELECT parameter, value FROM nls_database_parameters WHERE parameter='NLS_CHARACTERSET'
    END OF STMT
    PARSE #4:c=0,e=3962,p=0,cr=4,cu=0,mis=1,r=0,dep=0,og=1,tim=4721509705
    EXEC #4:c=0,e=21,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=4721509816
    FETCH #4:c=0,e=111,p=0,cr=0,cu=0,mis=0,r=10,dep=0,og=1,tim=4721509976
    FETCH #4:c=0,e=132,p=0,cr=0,cu=0,mis=0,r=10,dep=0,og=1,tim=4721510598
    FETCH #4:c=0,e=204,p=0,cr=3,cu=0,mis=0,r=1,dep=0,og=1,tim=4721511118
    STAT #4 id=1 cnt=21 pid=0 pos=1 obj=0 op='UNION-ALL  (cr=3 pr=0 pw=0 time=264 us)'
    STAT #4 id=2 cnt=17 pid=1 pos=1 obj=0 op='FIXED TABLE FULL X$NLS_PARAMETERS (cr=0 pr=0 pw=0 time=128 us)'
    STAT #4 id=3 cnt=1 pid=1 pos=2 obj=0 op='FAST DUAL  (cr=0 pr=0 pw=0 time=1 us)'
    STAT #4 id=4 cnt=1 pid=1 pos=3 obj=0 op='FAST DUAL  (cr=0 pr=0 pw=0 time=0 us)'
    STAT #4 id=5 cnt=1 pid=1 pos=4 obj=0 op='FAST DUAL  (cr=0 pr=0 pw=0 time=1 us)'
    STAT #4 id=6 cnt=1 pid=1 pos=5 obj=96 op='TABLE ACCESS FULL PROPS$ (cr=3 pr=0 pw=0 time=194 us)'
    =====================
    PARSING IN CURSOR #3 len=41 dep=0 uid=40 oct=42 lid=40 tim=4721512239 hv=2321140216 ad='ab275184'
    alter session set NLS_TERRITORY='GERMANY'
    END OF STMT
    PARSE #3:c=0,e=329,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=1,tim=4721512236
    EXEC #3:c=0,e=48,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=4721512424
    =====================
    PARSING IN CURSOR #2 len=35 dep=0 uid=40 oct=42 lid=40 tim=4721513208 hv=2785092162 ad='ab274e88'
    alter session set NLS_SORT='GERMAN'
    END OF STMT
    PARSE #2:c=0,e=283,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=1,tim=4721513205
    EXEC #2:c=0,e=20,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=4721513370
    =====================
    ...This explains why they are overwritten, but I still don't know why the session parameters are altered after my trigger at all. Any idea?
    Edited by: 853536 on 20.04.2011 01:24
    Problem solved: I was using Oracle SQL Developer to edit my trigger and to try it - and SQL Developer seems to ovewrite the NLS_Session parameters. Duh.
    Edited by: 853536 on 20.04.2011 02:04

    Yes, SQL Developer will usually override the settings. It should not do this if you go to Tools->Preferences->Database->NLS and check "Skip NLS Settings".
    But, any program using JDBC OCI will also override most of the settings. Therefore, you should not rely on the database to fix the NLS settings. It is applications' job to prepare the NLS environment correctly (if the standard initialization based on the O/S settings and/or NLS_LANG is not satisfactory).
    -- Sergiusz

  • Automatic date converting via-trigger

    Hi all!
    I'd like to know if there's a way to set triggers on tables with date-fields that can:
    1. automatically convert the date from (e.g) 01/10/2005 to 01-oct-2005 00:00:00 AM on every INSERT and UPDATE on that column
    2. automatically convert the date from (e.g) 01-oct-2005 00:00:00 AM to 01/10/2005 on every SELECT on that column
    3. get only the timetable from that field and so on...
    using Oracle 9i.
    Thanx a lot!

    The trigger can't help you here. You should think of changing the settings of your
    session or using to_date() function:
    SQL> create table t (date# date);
    Table created.
    SQL> insert into t values('01/28/2005');
    insert into t values('01/28/2005')
    ERROR at line 1:
    ORA-01843: not a valid month
    SQL> insert into t values(to_date('01/28/2005','MM/DD/YYYY'));
    1 row created.
    SQL> alter session set nls_date_format = 'MM/DD/YYYY';
    Session altered.
    SQL> insert into t values('01/28/2005');
    1 row created.Rgds.

  • Trigger definition & "Show SQL"

    Hi,
    This code compiles & creates the trigger without any errors.
    CREATE OR REPLACE TRIGGER ON_LOGON_LOGMNR
    AFTER LOGON ON DATABASE
    WHEN ( USER = 'LOGMNR' )
    BEGIN
    EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_FORMAT=''YYYYMMDD HH24:MI:SS''';
    END;
    However if I click on the trigger in Enterprise Manager (9i) and select "Show SQL"
    I get this...
    CREATE OR REPLACE TRIGGER "SYS"."ON_LOGON_LOGMNR" AFTER
    LOGON ON DATABASE BEGIN
    EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_FORMAT=''YYYYMMDD HH24:MI:SS''';
    END;
    Which does not include the "WHEN (USER = 'LOGMNR')" part of the code.
    I'm creating the trigger whilstr logged in as SYS.
    What am I missing?
    Thanks
    Dave

    Hi,
    Looks like the trgger definition is ok...
    SQL> SELECT text
    2 FROM dba_source
    3 WHERE name = 'ON_LOGON_LOGMNR';
    TEXT
    TRIGGER ON_LOGON_LOGMNR
    AFTER LOGON ON DATABASE
    WHEN ( USER = 'LOGMNR' )
    BEGIN
    EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_FORMAT=''YYYYMMDD HH24:MI:SS''';
    END;
    6 rows selected.

  • Client NLS_DATE_FORMAT

    Can I override the windows registry NLS_DATE_FORMAT from Reports 6i? I want to be able to do this to run certain reports. Ideally from the BEFORE PARAMETER FORM trigger.
    Thanks

    In the end the only way I found to execute a report with it's own private NLS_DATE_FORMAT was by setting the format at the command line and then executing the report from the command line. I wrapped this up in a batch file and called it (with the NO_SCREEN option) from the Form using a Host command (conditionally on Get_Application_Property(OPERATING_SYSTEM)). Bit tacky - but it gets round the issue until we can get all the reports working correctly in a single environment.
    Other alternatives were:
    Using ALTER SESSION from reports to change the NLS_DATE_FORMAT - that works for Forms but not Reports.
    Using D2kwutil to change the registry, run the report then change it back - not suitable since there are many Oracle applications running on the same client.

  • Getting error message FRM-40700:No such trigger: SPECIAL20

    Hi,
    We have designed a custom report (Quote) and would like to use Special Menu's(Reports Menu) to open this custom Report. When I try to open this Report using
    REPORTS->Quote, The Report is opening seccuessfully but i am getting following error message at the bottom of screen bar.How can I clear this message ?
    FRM-40700:No such trigger: SPECIAL20
    The code which I wrote in the custom.pll is
    IF (form_name = 'OEXOEORD') THEN
    -- Enable View Order Report -- V1.4 --
    if (event_name = 'WHEN-NEW-FORM-INSTANCE') then
    app_special.instantiate('SPECIAL20', 'View Order Report');
    app_special.enable('SPECIAL20',PROPERTY_OFF);
    else
    if (event_name='WHEN-NEW-BLOCK-INSTANCE') THEN
    if block_name='ORDER' then
    app_special.enable('SPECIAL20',PROPERTY_ON);
    else
    app_special.enable('SPECIAL20',PROPERTY_OFF);
    end if;
    end if;
    end if;
    if (event_name='SPECIAL20' and block_name='ORDER') then
    param_to_pass1 := name_in('ORDER.HEADER_ID');
    select order_number into param_to_pass2 from oe_order_headers_all where header_id=param_to_pass1;
    editor_pkg.report(BSI_Quote(param_to_pass2), 'Y');
    null;
    end if;
    end if;
    Please give me valuable inputs on this issue.
    Thanks,
    HTH

    Hi,
    your package " app_special" does a call to "execute_trigger('SPECIAL20');" ,
    but there is no trigger with this name in your form. ( perhaps an Menu-item exists with this name.)
    Lock for "execute_trigger" in:
    app_special.instantiate('SPECIAL20', 'View Order Report');

Maybe you are looking for