2

I am trying to fetch column names form Table in Oracle. But I am not getting Column Names. I used Many query's, And Find may query's in Stack overflow But I didn't get answer.

I used below query's:

1.  SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME='TABLE_NAME';

2.  SELECT COLUMN_NAME from ALL_TAB_COLUMNS where TABLE_NAME='TABLE_NAME';

But Out Put is

 no row selected 

What is the problem here. Thank you very much

3 Answers 3

1

both of the queries are correct, just the thing which can cause this problem is that ,maybe you did n't write your table name with capital letters you must do something like this:

SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS 
where TABLE_NAME = UPPER('TABLE_NAME');

OR

SELECT COLUMN_NAME FROM USER_TAB_COLUMNS 
where TABLE_NAME = UPPER('TABLE_NAME');
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @Hamidreza I have given lower case. that's why it's not worked .Now it's fine Thank you very much
0

Try this:

SELECT column_name
FROM   all_tab_cols
WHERE  upper(table_name) = 'TABLE_NAME'
       AND owner = ' || +_db+ || '
       AND column_name NOT IN ( 'password', 'version', 'id' ) 

or

SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS where TABLE_NAME = UPPER('TABLE_NAME');

4 Comments

yes it's exists. When executed "Select * from TableName;" It showing result. But When I am trying to retrieve column name it's showing No Row Selected
is it possible you created the table with double brackets ? try changing the filter to upper(table_name) = 'TABLE_NAME'
@codegeek:- This is working fine for me. As suggested by haki please try to change the column name to upper letters
@codegeek:- You are welcome. I have updated my answer as well. So that it helps others in future!
0

I hope This query would help yu out

SELECT SCHEMA_NAME  (schema_id) + '.' + t.name AS 'Table Name'    
FROM sys.tables t 
INNER JOIN sys.columns c
ON c.object_id = t.object_id
WHERE c.name like '%hmy%
ORDER BY 'Table Name'

Comments

Your Answer

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