Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out the default value for a column (Oracle)

I wonder if there is a way to find out the default value of some column with a simple select statement. Tried several things like:

SELECT * FROM all_tab_columns WHERE table_name = 'tablename'

But I can't see the defaultvalues for the columns there. And no I do not want to use something like SQL Plus, I need a SELECT, guess there is some table providing that info?

like image 598
aLpenbog Avatar asked Jan 23 '13 11:01

aLpenbog


People also ask

What is the default value by default of a column?

Default values can be NULL, or they can be a value that matches the data type of the column (number, text, date, for example).

Is the default value of column?

If a data type specification includes no explicit DEFAULT value, MySQL determines the default value as follows: If the column can take NULL as a value, the column is defined with an explicit DEFAULT NULL clause. If the column cannot take NULL as a value, MySQL defines the column with no explicit DEFAULT clause.

What is the default value for VARCHAR2 in Oracle?

A VARCHAR2 column can store a value that ranges from 1 to 4000 bytes. It means that for a single-byte character set, you can store up to 4000 characters in a VARCHAR2 column. By default, Oracle uses BYTE if you don't explicitly specify BYTE or CHAR after the max_size .

Where is a default value?

A default value is the value that is inserted into a column when an explicit value is not specified in an INSERT statement. A default value can be a literal character string that you define or one of the following SQL constant expressions: USER.


3 Answers

Select TABLE_NAME, COLUMN_NAME, DATA_DEFAULT
from DBA_TAB_COLUMNS
where TABLE_NAME = 'TABLE_NAME';

Replace the Table_Name for which you want to see the default column data.

like image 181
Bhuvan Upadhyay Avatar answered Oct 17 '22 13:10

Bhuvan Upadhyay


try the below query

Select * From USER_TAB_COLUMNS where TABLE_NAME ='Table Name'
like image 7
Pandian Avatar answered Oct 17 '22 11:10

Pandian


Default values are in DATA_DEFAULT column from ALL_TAB_COLUMNS:

SELECT TABLE_NAME, COLUMN_NAME, DATA_DEFAULT 
  FROM ALL_TAB_COLUMNS
 WHERE TABLE_NAME = 'tablename'

[2021-01-26] Edit: Note that the 'tablename' parameter must match the case of real table name, as it appears on ALL_TAB_COLUMNS. More often it will be uppercase, so may be useful use UPPER() function to ensure it.

 WHERE TABLE_NAME = UPPER('tablename')
like image 1
helenov Avatar answered Oct 17 '22 13:10

helenov