我正在尝试为那些违反给定阈值的表空间获取表空间总空间。当我在输出中获得多个表空间时,我将它们拆分,然后在数组上运行 for 循环。现在我需要为每个 i 获取字节,但它是第一次出现的唯一打印值。我应该如何附加所有值?请检查以下代码:
output1=`sqlplus -s username/password as sysbackup <<END1
set linesize 200
set head off
select tablespace_name||',' from dba_tablespace_usage_metrics where used_percent > 50;
exit;
END1`
IFS=', ' read -r -a array <<< $output1
for val in "${array[@]}"
do
output2=`sqlplus -s username/password as sysbackup <<END2
set serveroutput on;
set linesize 200
set head off
spool test.txt
SELECT TABLESPACE_NAME, ROUND (SUM (BYTES) / 1048576) FROM DBA_DATA_FILES WHERE TABLESPACE_NAME = '${array[val]}' GROUP BY TABLESPACE_NAME;
spool off;
@test.txt
exit;
END2`
done
@test.sql 应该打印:
SYSAUX 2048
SYSTEM 4027
但它唯一的印刷品:
SYSAUX 2048