我正在尝试从 sqlplus 获取一个值,如下所示。然而,它并没有回应我想要的。这是我的脚本:
#!/bin/ksh
OLDEST_PARTITION='sqlplus / as sysdba << EOF
select PARTITION_NAME
from dba_tab_partitions
where table_name='AUD$' and PARTITION_NAME not like '%FIRST%' and rownum<2
order by PARTITION_NAME asc;
EOF'
echo $OLDEST_PARTITION
结果是这样的:
sqlplus / as sysdba << EOF select PARTITION_NAME from dba_tab_partitions where table_name=AUD and PARTITION_NAME not like %FIRST% and rownum<2 order by PARTITION_NAME asc; EOF
答案1
作为嗯指出,除非您错误地复制/粘贴了脚本,否则您需要在需要反引号的地方使用单引号。更改它们使脚本变成:
#!/bin/ksh
OLDEST_PARTITION=`sqlplus / as sysdba << EOF
select PARTITION_NAME
from dba_tab_partitions
where table_name='AUD$' and PARTITION_NAME not like '%FIRST%' and rownum<2
order by PARTITION_NAME asc;
EOF
`
echo "$OLDEST_PARTITION"
我小心地将 保留EOF
在自己的行上,并引用了 OLDEST_PARTITION 变量。