问题描述
嗨
我必须在我的架构的所有表中添加3列 (例如-: updated_time,inserted_time,updated_by),但是有些表只有所有3列中的1列,有些表有所有3列中的2列,有些表有所有3列,有些表没有所有3列。
现在的任务是如何获取具有所有3列的表名 (所有3列应存在于表中)
2) 如何获得没有全部3列或给定3列中有1或2列的表。
提前谢谢。
我必须在我的架构的所有表中添加3列 (例如-: updated_time,inserted_time,updated_by),但是有些表只有所有3列中的1列,有些表有所有3列中的2列,有些表有所有3列,有些表没有所有3列。
现在的任务是如何获取具有所有3列的表名 (所有3列应存在于表中)
2) 如何获得没有全部3列或给定3列中有1或2列的表。
提前谢谢。
专家解答
也许是这样的?
SQL> create table t1 ( x int );
Table created.
SQL> create table t2 ( x int );
Table created.
SQL> create table t3 ( x int );
Table created.
SQL> create table t4 ( x int );
Table created.
SQL>
SQL> alter table t2 add created date;
Table altered.
SQL>
SQL> alter table t3 add created date;
Table altered.
SQL> alter table t3 add modified date;
Table altered.
SQL>
SQL> alter table t4 add created date;
Table altered.
SQL> alter table t4 add modified date;
Table altered.
SQL> alter table t4 add whom varchar2(10);
Table altered.
SQL>
SQL>
SQL> select t.table_name, tc.cnt
2 from user_tables t,
3 ( select table_name, count(*) cnt
4 from user_tab_columns
5 where column_name in ('CREATED','MODIFIED','WHOM')
6 group by table_name
7 ) tc
8 where t.table_name = tc.table_name(+)
9 /
TABLE_NAME CNT
------------------------------ ----------
T1
T2 1
T3 2
T4 3
4 rows selected.
SQL>
SQL>
SQL>
文章转载自ASKTOM,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




