请教:在shell脚本执行sql语句为什么会报错
最近,在网上看到有个查看数据库表空间的shell,就修改了部分,在机器上进行了调试,老是报错,代码和报错信息如下:
#####################################################################
## he_oracle.sh ##
#####################################################################
#!/bin/ksh
sqlplus inventory/inventory@mos5100 <<EOF
set feed off
set linesize 100
set pagesize 200
spool hetest.txt
SELECT F.TABLESPACE_NAME,
TO_CHAR ((T.TOTAL_SPACE - F.FREE_SPACE),'999,999') "USED (MB)",
TO_CHAR (F.FREE_SPACE, '999,999') "FREE (MB)",
TO_CHAR (T.TOTAL_SPACE, '999,999') "TOTAL (MB)",
TO_CHAR ((ROUND ((F.FREE_SPACE/T.TOTAL_SPACE)*100)),'999')||' %' PER_FREE
FROM (
SELECT TABLESPACE_NAME,
ROUND (SUM (BLOCKS*(SELECT VALUE/1024
FROM V$PARAMETER
WHERE NAME = 'db_block_size')/1024)
) FREE_SPACE
FROM DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME
) F,
(
SELECT TABLESPACE_NAME,
ROUND (SUM (BYTES/1048576)) TOTAL_SPACE
FROM DBA_DATA_FILES
GROUP BY TABLESPACE_NAME
) T
WHERE F.TABLESPACE_NAME = T.TABLESPACE_NAME
AND (ROUND ((F.FREE_SPACE/T.TOTAL_SPACE)*100)) < 80;
spool off
exit
EOF
登录到oracle用户下,直接执行:ck_tbsp.sh 后就报如下错误信息:
[root@mos5100db /opt/yanpan 0 ]#su oracle
oracle@mos5100db:/opt/yanpan> he_oracle.sh
SQL*Plus: Release 11.1.0.7.0 - Production on Tue Sep 13 12:24:07 2011
Copyright (c) 1982, 2008, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Release 11.1.0.7.0 - 64bit Production
SQL> SQL> SQL> SQL> SQL> 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 FROM V
*
ERROR at line 9:
ORA-04044: procedure, function, package, or type is not allowed here
SQL> SQL> Disconnected from Oracle Database 11g Release 11.1.0.7.0 - 64bit Production
oracle@mos5100db:/opt/yanpan>
请各位大大解答!
[解决办法]
可能是sql文太长了