我试图将数据插入到一个表中,该表可以用作报告,以查看每个数据库上次成功备份的时间。正在插入的表具有name,input_type,status,start_time,end_time和duration列,而我的SQL目前是:
INSERT INTO schema.Backup_Report (input_type, status, start_time, end_time, duration)
SELECT *
FROM (SELECT INPUT_TYPE,
STATUS,
START_TIME,
END_TIME,
elapsed_seconds/60 as duration_in_min
FROM v$RMAN_BACKUP_JOB_DETAILS
ORDER BY end_time desc)
WHERE rownum = 1
AND input_type = 'DB INCR'
AND STATUS = 'COMPLETED';
这很有效,但我在查找如何插入名称列时遇到了麻烦,因为我尝试过使用union:
SELECT *
FROM (SELECT name from v$database union
SELECT INPUT_TYPE,
STATUS,
START_TIME,
END_TIME,
elapsed_seconds/60 as duration_in_min
FROM v$RMAN_BACKUP_JOB_DETAILS
ORDER BY end_time desc)
这给了我一个ora-00904错误,因为我认为它不像order by end_time
部分。
答案 0 :(得分:0)
SELECT *
FROM ( SELECT *
FROM (SELECT INPUT_TYPE,
STATUS,
START_TIME,
END_TIME,
elapsed_seconds/60 as duration_in_min
FROM v$RMAN_BACKUP_JOB_DETAILS
ORDER BY
END_TIME DESC )
WHERE ROWNUM = 1
AND INPUT_TYPE = 'DB INCR'
AND STATUS = 'COMPLETED' )
CROSS JOIN
( SELECT name from v$database );