如何从shell脚本调用SQL语句

时间:2015-02-10 21:25:13

标签: oracle bash unix sqlplus

我有一个代码,可以为简单的select * from查询调用SQL语句,但我不知道我做错了什么,总是给我一个错误。

这是shell代码:

#!/bin/sh 
. /usr/local/bin/oracle.profile.prod
. /usr/local/bin/bscs.profile.prod   

hostname=`uname -n`
basedato=PQBSCS

if [[ $basedato = "PQBSCS" && $hostname = "panhp03" ]];then 

   export RUTASHELL=/user/cartera_varios/Shell_Portabilidad/others/shell
   export RUTASQL=/user/cartera_varios/Shell_Portabilidad/others/plsql
   export RUTALOG=/user/cartera_varios/Shell_Portabilidad/others/log
   . /user/cartera_varios/Shell_Portabilidad/others/.MM.txt
   else

   echo " ambiente no valido, se cancela el proceso."
   exit 1

  fi

FECHA=`date +%Y%m%d%H%M%S`
sqlplus -S $USER/$PASS@$basedato @$RUTASQL/consulta.sql $RUTA_UTL $DIAS> $RUTALOG/Consulta$FECHA.log

sleep 5
echo " proceso finalizado, revisar la ruta de log "

这是我试图调用的SQL语句:

SET SERVEROUTPUT ON SIZE 1000000  SET PAGESIZE 1000  SET TIMING OFF  SET VERIFY OFF  SET HEADING OFF 
SPOOL /user/cartera_varios/Shell_Portabilidad/others/log/resultado_select.txt

declare 

/*Variable que almacena el resultado de la función*/  resul varchar2(30); 

begin 

/* LLamada a la funcion*/  resul:=select * from mdsrrtab where REQUEST
= '536897804';

END;  / EXIT;

这就是结果。

result:=select * from mdsrrtab where REQUEST = '536897804';
* ERROR at line 9: ORA-06550: line 9, column 8:  PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:  ( - + case mod new not null <an identifier>  <a double-quoted delimited-identifier> <a bind variable> avg  count current exists max min prior sql stddev sum variance  execute forall merge time timestamp interval date  <a string literal with character set specification>  <a number> <a single-quoted SQL string> pipe  ORA-06550: line 12, column 1:  PLS-00103: Encountered the symbol "DBMS_OUTPUT"   ORA-06550: line 12, column 33:  PLS-00103: Encountered the symbol ";" when expecting one of the following:  . ( , * % & - + / at mod rem <an identifier>  <a double-quoted delimited-identifier> <an exponent (**)> as  from into || bulk

任何帮助都将受到高度赞赏。

0 个答案:

没有答案