Oracle SQL Developer – How to Find Where Length Semantics Gets Changed

oracleoracle-11g-r2oracle-sql-developeroracle-xesqlplus

I've code to create tables that doesn't specify length semantics:

CREATE TABLE CHAR_TEST (
    CHAR_TEST_ID NUMBER(*,0) NOT NULL,
    FOO VARCHAR2(6) NOT NULL,
    BAR VARCHAR2(6) NOT NULL,

    CONSTRAINT CHAR_TEST_PK PRIMARY KEY (CHAR_TEST_ID) ENABLE
);

Actual code is fairly large and contains hundreds of objects. I have two versions of the code that correspond to different source control revisions separated by a couple of years.

I've created 2 users/schemas on the same server with identical settings. I then run each revision in each respective schema. To my surprise, the latest revision gets an unexpected CHAR semantic:

Name         Null     Type        
------------ -------- ----------- 
CHAR_TEST_ID NOT NULL NUMBER(38)  
FOO          NOT NULL VARCHAR2(6) 
BAR          NOT NULL VARCHAR2(6) 
Name         Null     Type        
------------ -------- ---------------- 
CHAR_TEST_ID NOT NULL NUMBER(38)  
FOO          NOT NULL VARCHAR2(6 CHAR) 
BAR          NOT NULL VARCHAR2(6 CHAR) 

I can't figure out where those CHAR come from!

  • I can't reproduce it if I run CREATE TABLE code isolately
  • I've been unable to find ALTER TABLE CHAR_TEST statements in my code base that change anything but keys or indexes
  • SELECT value FROM V$PARAMETER WHERE NAME LIKE '%nls_length_semantics%'; prints BYTE in both schemas

Could you please suggest where to look further?

Best Answer

I forgot the most obvious thing: session parameters can be changed!

I had this on the latest revision:

ALTER SESSION SET NLS_LENGTH_SEMANTICS = 'CHAR';

... but not the older one. I was running the scripts in a different session thus I couldn't spot the value change.