EDP_EDP_EXTERNAL_PLANT_REPORT_U_$RUN_DATE.dat与 SELECT BYTES FROM USER_SEGMENTS WHERE SEGMENT_NAME = 'table_name_bad'; SELECT NUM_ROWS FROM USER_TABLES WHERE TABLE_NAME = 'table_name_bad'; 及$RUN_DATE 如何将上面查询语句结果集拼接为复合的SELECT语句并将结果用空格隔开?
时间: 2023-08-03 20:05:31 浏览: 78
nouveau_connector.rar_LVDS EDP_LVDS to EDP_The Power_edp
以下是将查询语句结果集拼接为复合的SELECT语句并将结果用空格隔开的SQL语句:
```
SELECT LISTAGG(result, ' ') WITHIN GROUP (ORDER BY result_order) AS combined_results
FROM (
SELECT 'SELECT ' || bytes || ' FROM ' || segment_name || ';' AS result, 1 AS result_order
FROM USER_SEGMENTS
WHERE SEGMENT_NAME = 'table_name_bad'
UNION ALL
SELECT 'SELECT ' || num_rows || ' FROM ' || table_name || ';' AS result, 2 AS result_order
FROM USER_TABLES
WHERE TABLE_NAME = 'table_name_bad'
UNION ALL
SELECT '$RUN_DATE' AS result, 3 AS result_order
FROM dual
)
ORDER BY result_order;
```
其中,`USER_SEGMENTS`和`USER_TABLES`是Oracle系统表,用于查询表的信息,`dual`是Oracle系统表,用于查询常量。这个查询语句将三个查询结果拼接在一起,并用空格隔开,结果集中每一行都是一个完整的SELECT语句。其中,`$RUN_DATE`是作为一个常量插入到结果集中的,可以根据需要自行修改。
阅读全文