pratik kanawade Wrote:
-------------------------------------------------------
>
> ORG_ID NUMBER default TO_NUMBER ( DECODE (
> SUBSTRB ( USERENV ( 'CLIENT_INFO') ,1,1 ) , '
> ',NULL,SUBSTRB ( USERENV ( 'CLIENT_INFO') ,1,10 )
> ) ),
>
Hmmm, you cannot do this in that way.
MySql allows only constants in the DEFAULT clause in the create table statement.
http://dev.mysql.com/doc/refman/5.5/en/create-table.html
Quote
The DEFAULT clause specifies a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such as NOW() or CURRENT_DATE. The exception is that you can specify CURRENT_TIMESTAMP as the default for a TIMESTAMP column. See Section 10.3.4, “Automatic Initialization and Updating for TIMESTAMP”.
Just skip the DEFAULT clause and create the table without it.
You may also create a before insert trigger , check if this column is null, and if yes - select the default value from another table.
Edited 3 time(s). Last edit at 02/28/2012 03:20AM by irek kordirko.