1

I am trying to write a query that returns the size of a column in a particular table in my database

I am using SQL Developer environment and I am new to it

I have tried this simple code to which I applied what I found in the Internet :

CREATE TABLE tab1 (
       col1      VARCHAR2(15) PRIMARY KEY,
       col2      Number(4) NOT NULL)

select data_type, data_length 
  from user_tab_columns
 where table_name = 'tab1'
   and column_name = 'col1';

I expect for my second query to get this: VARCHAR2 and 15

But I get this :

no data found

Do you have any idea of what I'm doing wrong?

1
  • 3
    Try 'TAB1' and 'COL1' (using capital letters). Unless table and/or column names are given in double-quotes (which is a bad practice), names are case insensitive. However, when written to the dictionary tables, they are written in upper case letters, and that's how you must use them when you query the dictionary tables. Commented Jun 8, 2019 at 14:30

2 Answers 2

3

You should use uppercase version of identifiers:

select data_type, data_length 
  from user_tab_columns
 where table_name = UPPER('tab1')   -- 'TAB1'
   and column_name = UPPER('col1'); -- 'COL1'

db<>fidde demo

Schema Object Names and Qualifiers

You can use either quoted or nonquoted identifiers to name any database object. However, database names, global database names, and database link names are always case insensitive and are stored as uppercase. If you specify such names as quoted identifiers, then the quotation marks are silently ignored.

Sign up to request clarification or add additional context in comments.

2 Comments

The use of upper() around hard-coded values seems excessive - why not simply write 'TAB1' and 'COL1'? Is that how you query catalog tables?
@mathguy Matter of taste. It could be uppercased string literal as well.
0

Amazing it worked!! Thank you all ! See you soon for the next question :D

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.