17,132
社区成员
发帖
与我相关
我的任务
分享
SQL> desc t1
Name Type Nullable Default Comments
------ ----------- -------- ------- --------
ID NUMBER Y 中文ID
PID NUMBER Y 父级ID
STATUS VARCHAR2(2) Y 状态
SQL> select * from user_col_comments where table_name='T1';
TABLE_NAME COLUMN_NAME COMMENTS
------------------------------ ------------------------------ --------------------------------------------------------------------------------
T1 ID 中文ID
T1 PID 父级ID
T1 STATUS 状态
SQL>
SQL> create or replace function f_colcom(tname in varchar2) return varchar2 is
2 Result varchar2(400);
3 tsql varchar2(400);
4 begin
5 declare
6 cursor c_job is
7 select column_name, comments
8 from user_col_comments
9 where upper(table_name) = upper(tname);
10 c_row c_job%rowtype;
11 begin
12 for c_row in c_job loop
13 tsql := tsql || c_row.column_name||' "'||c_row.comments||'",';
14 end loop;
15 tsql := substr(tsql,1,length(tsql)-1);
16 tsql := 'select '||tsql||' from '||tname||';';
17 end;
18 result := tsql;
19 return(Result);
20
21 end f_colcom;
22 /
Function created
SQL> select f_colcom('T1') from dual;
F_COLCOM('T1')
--------------------------------------------------------------------------------
select ID "中文ID",PID "父级ID",STATUS "状态" from T1;
SQL> select ID "中文ID",PID "父级ID",STATUS "状态" from T1;
中文ID 父级ID 状态
---------- ---------- ----
1 0 2
2 0 4
3 0 3
4 1 2
5 4 3
6 2 4
7 2 2
8 7 3
9 6 4
10 3 0
11 0 4
12 11 4
13 11 5
14 11 3
15 3 0
16 3 2
17 16 2
18 3 3
19 18 0
20 18 3
中文ID 父级ID 状态
---------- ---------- ----
21 17 0
21 rows selected
SQL>