title: How to invoke an SQL statement from a shell script
body: <p>I have a code that invoke a SQL statement for a simple <code>select * from</code> query, but I don't know what I´m doing wrong, always gives me an error.</p>
  
  <p>This is the shell code:</p>
  
  <pre><code>#!/bin/sh 
  . /usr/local/bin/oracle.profile.prod
  . /usr/local/bin/bscs.profile.prod   
  
  hostname=`uname -n`
  basedato=PQBSCS
  
  if [[ $basedato = "PQBSCS" &amp;&amp; $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&gt; $RUTALOG/Consulta$FECHA.log
  
  sleep 5
  echo " proceso finalizado, revisar la ruta de log "
  </code></pre>
  
  <p>And this is the SQL statement that I´m trying to invoke:</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>and this is the result.</p>
  
  <pre><code>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 &lt;an identifier&gt;  &lt;a double-quoted delimited-identifier&gt; &lt;a bind variable&gt; avg  count current exists max min prior sql stddev sum variance  execute forall merge time timestamp interval date  &lt;a string literal with character set specification&gt;  &lt;a number&gt; &lt;a single-quoted SQL string&gt; 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:  . ( , * % &amp; - + / at mod rem &lt;an identifier&gt;  &lt;a double-quoted delimited-identifier&gt; &lt;an exponent (**)&gt; as  from into || bulk
  </code></pre>
  
  <p>Any help will be highly appreciated.</p>