Llamar a SQL *Plus desde un script en Bash
Lo que queremos es poder llamar a SQL *Plus desde un script de la siguiente manera:
$root> ./ejecutar_script.sh |
Nuestro script puede ser del siguiente estilo:
[oracle@localhost ~]$ cat script-bash.sh sqlplus hr/password << EOF select count(*) from employees; update employees set salary= salary*1.10; commit; quit EOF |
En este script podemos ejecutar todas las sentencias PL/SQL que deseemos. En nuestro ejemplo hacemos una query y posteriormente una actualización de la tabla de empleados.
El resultado de ejecutar el script es el siguiente:
[oracle@localhost ~]$ bash script-bash.sh SQL*Plus: Release 11.2.0.2.0 Production on Sun Apr 10 10:11:53 2011 Copyright (c) 1982, 2010, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> COUNT(*) ---------- 107 SQL> 107 rows updated. SQL> Commit complete. SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options |