How to get column type of column in Oracle with PL-SQL with low privileges?

I have read-only access to only a few tables in an Oracle database. I need to get schema information for some columns. I would like to use something similar to MS SQL sp_help .

I see the table that interests me in the following query:

 SELECT * FROM ALL_TABLES 

When I run this query, Oracle tells me that "the table was not found in the schema," and yes, the parameters are correct.

 SELECT DBMS_METADATA.GET_DDL('TABLE', 'ITEM_COMMIT_AGG', 'INTAMPS') AS DDL FROM DUAL; 

After using my Oracle 9000 universal translator, I assumed that this does not work because I do not have sufficient privileges. Given my limitations, how can I get the data type and data length in a column of a table that I have read access to using the PL-SQL statement?

+41
oracle plsql ddl privileges
Feb 26 2018-10-28T00
source share
8 answers

ALL_TAB_COLUMNS must be requested from PL / SQL. DESC is a SQL * Plus command.

 SQL> desc all_tab_columns; Name Null? Type ----------------------------------------- -------- ---------------------------- OWNER NOT NULL VARCHAR2(30) TABLE_NAME NOT NULL VARCHAR2(30) COLUMN_NAME NOT NULL VARCHAR2(30) DATA_TYPE VARCHAR2(106) DATA_TYPE_MOD VARCHAR2(3) DATA_TYPE_OWNER VARCHAR2(30) DATA_LENGTH NOT NULL NUMBER DATA_PRECISION NUMBER DATA_SCALE NUMBER NULLABLE VARCHAR2(1) COLUMN_ID NUMBER DEFAULT_LENGTH NUMBER DATA_DEFAULT LONG NUM_DISTINCT NUMBER LOW_VALUE RAW(32) HIGH_VALUE RAW(32) DENSITY NUMBER NUM_NULLS NUMBER NUM_BUCKETS NUMBER LAST_ANALYZED DATE SAMPLE_SIZE NUMBER CHARACTER_SET_NAME VARCHAR2(44) CHAR_COL_DECL_LENGTH NUMBER GLOBAL_STATS VARCHAR2(3) USER_STATS VARCHAR2(3) AVG_COL_LEN NUMBER CHAR_LENGTH NUMBER CHAR_USED VARCHAR2(1) V80_FMT_IMAGE VARCHAR2(3) DATA_UPGRADED VARCHAR2(3) HISTOGRAM VARCHAR2(15) 
+39
Feb 26 '10 at 3:55
source share

You can use the desc command.

 desc MY_TABLE 

This will give you the column names, whether null is valid, and the data type (and length, if applicable)

+26
Feb 26 '10 at 2:07
source share

Note. If you are trying to get this information for tables that are in another SCHEMA, use the all_tab_columns view, we have this problem, because our Applications use another SCHEMA for security purposes.

use the following:

EG:

 SELECT data_length FROM all_tab_columns WHERE upper(table_name) = 'MY_TABLE_NAME' AND upper(column_name) = 'MY_COL_NAME' 
+14
Nov 07 '12 at 18:59
source share

The best solution I have found for such a case is

 select column_name, data_type|| case when data_precision is not null and nvl(data_scale,0)>0 then '('||data_precision||','||data_scale||')' when data_precision is not null and nvl(data_scale,0)=0 then '('||data_precision||')' when data_precision is null and data_scale is not null then '(*,'||data_scale||')' when char_length>0 then '('||char_length|| case char_used when 'B' then ' Byte' when 'C' then ' Char' else null end||')' end||decode(nullable, 'N', ' NOT NULL') from user_tab_columns where table_name = 'TABLE_NAME' and column_name = 'COLUMN_NAME'; 

@Aaron Stainback, thanks for the fix!

+11
Jun 19 '13 at 14:50
source share
 select t.data_type from user_tab_columns t where t.TABLE_NAME = 'xxx' and t.COLUMN_NAME='aaa' 
+6
Mar 04 '10 at 6:38
source share

Oracle: get a list of the complete data type in your table:

 select data_type || '(' || data_length || ')' from user_tab_columns where TABLE_NAME = 'YourTableName' 
+5
Jul 18 '11 at 20:05
source share
 select column_name, data_type || '(' || data_length || ')' as datatype from all_tab_columns where TABLE_NAME = upper('myTableName') 
+2
Aug 20 '14 at 10:58
source share

A quick and dirty way (e.g. see how the data is stored in oracle)

 SQL> select dump(dummy) dump_dummy, dummy , dump(10) dump_ten from dual DUMP_DUMMY DUMMY DUMP_TEN ---------------- ----- -------------------- Typ=1 Len=1: 88 X Typ=2 Len=2: 193,11 1 row selected. 

will show that the dummy column in the sys.dual table has typ = 1 (varchar2), and 10 has Typ = 2 (number).

+1
Sep 22 '15 at 19:05
source share



All Articles