需要使用表和comlumns注释列表生成XML。
SELECT * FROM USER_TAB_COMMENTS; -- my tables
| TABLE_NAME | TABLE_TYPE | COMMENT |
-----------------------------------------
| table_a | TABLE | t.A comment |
| table_b | TABLE | t.B comment |
SELECT * FROM USER_TAB_COMMENTS; -- my comments
| TABLE_NAME | COLUMN_NAME | COMMENT |
-------------------------------------------
| table_a | col_1 | c.A1 comment |
| table_a | col_2 | c.A2 comment |
| table_b | col_1 | c.B1 comment |
| table_b | col_2 | c.B2 comment |
表格的XML描述,我需要:
SELECT DBMS_METADATA.GET_XML(REPLACE(OBJECT_TYPE, ' ', '_'), OBJECT_NAME) xml
FROM USER_OBJECTS
WHERE OBJECT_TYPE IN ('TABLE');
问题是:如何为我的评论获得等效的XML?
SELECT DBMS_METADATA.GET_XML('COMMENT', TABLE_NAME) xml
FROM USER_TAB_COMMENTS; -- doesn't work
致以最诚挚的问候和感谢帮助。
答案 0 :(得分:0)
每个项目获得一行:
SELECT XMLELEMENT(
"TABLE",
XMLFOREST(
table_name,
table_type,
comments
)
).getClobVal() As xml
FROM user_tab_comments;
使用嵌套在其中的所有XML获取一行:
SELECT XMLELEMENT(
"TABLES",
XMLAGG(
XMLELEMENT(
"TABLE",
XMLFOREST(
table_name,
table_type,
comments
)
)
)
).getClobVal() As xml
FROM user_tab_comments;