Wrong characters in default value

MarcielDeg

Member²
I got a problem running DDL query to set a default value to a column:

Test case: Running in a SQL Window:

Code:
CREATE TABLE TEST1 (ID NUMBER(10), STATUS NUMBER(2))

Code:
ALTER TABLE TEST1 MODIFY STATUS DEFAULT 0

Code:
SELECT USER_TAB_COLS.DATA_DEFAULT
  FROM USER_TAB_COLS
 WHERE USER_TAB_COLS.TABLE_NAME = 'TEST1'
   AND USER_TAB_COLS.COLUMN_NAME = 'STATUS'

In this case, default value has an extra enter (0D0A):
image01.png


But, if I run alter table query in this way:

Code:
BEGIN
  EXECUTE IMMEDIATE 'ALTER TABLE TEST1 MODIFY STATUS DEFAULT 0';
END;

it works correctly:
image02.png


I tried oracle client versions 11, 19 and 21, with the same result. I believe that PL/SQL is manipulating SQL improperly before executing.

I'm using PL/SQL Developer v15.0.4
 
Last edited:
Perhaps the statement from the SQL Window is sent to the server with an extra linefeed. I'm not sure why this linefeed would affect the outcome, but we'll investigate.
 
Oracle has some questionable features. The command below generates the default value "0 " (with an extra space), not "0":

Code:
ALTER TABLE TEST1 MODIFY STATUS DEFAULT 0 NOT NULL

To generate without the extra space, it is necessary to join the value with the NOT NULL command:

Code:
ALTER TABLE TEST1 MODIFY STATUS DEFAULT 0NOT NULL

Ugly, and it feels wrong.
 
Last edited:
The same thing happens in SQL*Plus, so I don't think it's a PL/SQL Dev issue.

The default value is stored as a string so a conversion to numeric is required at insert time anyway, but maybe the stray CRLF requires an extra processing step that could show up at high volumes. Maybe someone less lazy than me could test it and see if it makes any measurable difference for a 10 million row insert.
 
Back
Top