Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get data type of field in select statement in ORACLE

Can I get data types of each column I selected instead of the values, using a select statement?

FOR EXAMPLE:

SELECT a.name, a.surname, b.ordernum  FROM customer a JOIN orders b ON a.id = b.id 

and result should be like this

name    | NVARCHAR(100) surname | NVARCHAR(100) ordernum| INTEGER 

or it can be in row like this, it isn't important:

name           |   surname     |  ordernum NVARCHAR(100)  | NVARCHAR(100) |   INTEGER 

Thanks

like image 602
Bushwacka Avatar asked Apr 09 '14 12:04

Bushwacka


People also ask

How do I find the data type of a field in SQL?

You can get the MySQL table columns data type with the help of “information_schema. columns”. SELECT DATA_TYPE from INFORMATION_SCHEMA. COLUMNS where table_schema = 'yourDatabaseName' and table_name = 'yourTableName'.

How do I get column details in SQL Developer?

You can find details about the columns in your user's tables by querying user_tab_columns.

How do I find the data type of a variable in PL SQL?

If the variable doesn't exist you'll get a NO_DATA_FOUND , and if there are two variables with the same name in the object you'll get ORA-01422: exact fetch returns more than requested number of rows .


1 Answers

I found a not-very-intuitive way to do this by using DUMP()

SELECT DUMP(A.NAME),         DUMP(A.surname),         DUMP(B.ordernum)  FROM   customer A         JOIN orders B           ON A.id = B.id 

It will return something like:

'Typ=1 Len=2: 0,48' for each column.

Type=1 means VARCHAR2/NVARCHAR2
Type=2 means NUMBER/FLOAT
Type=12 means DATE, etc.

You can refer to this oracle doc for information Datatype Code
or this for a simple mapping Oracle Type Code Mappings

like image 168
Maxwell Cheng Avatar answered Sep 28 '22 03:09

Maxwell Cheng