我真的只想要 SQL 查詢中表中的列數,但不知何故我無法得到正確的結果。有誰知道我做錯了什么?
select count(*) from user_tab_columns where table_name='tablename' //works and gives me the number of columns
select
TABLE_NAME,
NUM_ROWS,
(select count(*) from user_tab_columns where table_name=TABLE_NAME) as Test
from user_tables
uj5u.com熱心網友回復:
哈哈,看看這個:
where table_name=TABLE_NAME
這將始終為真,因為表名就是表名。
這是具有限定列名的查詢:
select
table_name,
num_rows,
(select count(*) from user_tab_columns tc where tc.table_name = t.table_name) as test
from user_tables t;
uj5u.com熱心網友回復:
作為替代方案,您可以聚合整個查詢:
select t.table_name
, num_rows
, count(*) as num_columns
from user_tables t
join user_tab_columns c on c.table_name = t.table_name
group by t.table_name, t.num_rows
order by 1;
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/346919.html
標籤:sql 甲骨文 sql-subselect
