哦,我糊涂了。
这是模式的代码:
CREATE TABLE TABLE_INFO
(
TNAME VARCHAR2 (30)
,CNAME VARCHAR2 (30)
,DTYPE VARCHAR2 (30)
,COLCOMMENT VARCHAR2 (100)
);
INSERT INTO TABLE_INFO VALUES ('Employee','Emp_ID','NUMBER','Employee ID');
INSERT INTO TABLE_INFO VALUES ('Employee','Emp_Nm','VARCHAR','Employee Name');
INSERT INTO TABLE_INFO VALUES ('Employee','Emp_Sal','NUMBER','Employee Salary');
INSERT INTO TABLE_INFO VALUES ('Job','Job_ID','NUMBER','Job ID');
INSERT INTO TABLE_INFO VALUES ('Job','Job_Nm','VARCHAR','Job Name');
INSERT INTO TABLE_INFO VALUES ('Department','Dept_ID','VARCHAR','Department ID');
INSERT INTO TABLE_INFO VALUES ('Department','Dept_Nm','VARCHAR','Department Name');
而且,这是一个执行代码:
-- FOR TABLE CREATION
SELECT
CASE WHEN RNO = 1 THEN 'CREATE TABLE '||T1.TNAME||' ( ' ELSE ' ' END ||
T2.CNAME || ' ' || T2.DTYPE ||
CASE WHEN CNT = RNO THEN ');' ELSE ',' END AS SQLTEXT
FROM ( SELECT TNAME
,COUNT (1) CNT
FROM TABLE_INFO
GROUP BY TNAME) T1
,(SELECT ROW_NUMBER () OVER (PARTITION BY TNAME ORDER BY CNAME) RNO
,X.*
FROM TABLE_INFO X) T2
WHERE T1.TNAME = T2.TNAME
ORDER BY T1.TNAME, T2.RNO;
-- FOR COMMENT CREATION
SELECT 'COMMENT ON TABLE ' || TNAME || '.' || CNAME || ' IS ''' || COLCOMMENT || ''';' AS SQLTEXT
FROM TABLE_INFO;
你可以在这里找到结果
注意:我ROW_NUMBER ()
只在 Oracle 使用过函数。请注意这一点。