Ejecutar comando sistema

Tengo que ejecutar un comando de sistema operativo desde un pl/sql en concreto dentro de un procedimiento almacenado en base de datos. ¿Cómo puedo hacerlo?

1 Respuesta

Respuesta
1
Puedes utilizar el PL/Run, la manera de utilizarlo depende del Sistema operativo que utilices.
Puedes encontrar la sintaxis en metalink.
El sistema operativo es windows 2000, y no se a que te refieres con el metalink.mis conocimientos no llegan atanto. Gracias
Metalink es el serivicio de soporte de oracle para los usuarios que adquieren legalmente la base de datos.
Alli encuentras forums, notas y conentarios.
El siguiente es un extracto de la nota 130799.1:
Overview
--------
This sample illustrates how to use an EXTERNAL PROCEDURE call to execute
cmd.exe and pass Windows NT os commands such as 'del' and 'ren' as arguments.
Program Notes
-------------
o This sample application requires a database schema account which has
privileges to create a library object.
o This sample requires that you have the appropriate entries configured
in the network tnsnames.ora for enabling external procedure calls.
O Steps to build the sample application:
1. Launch SQL*PLUS and login to the database as a user with
the appropriate privileges to create the library object.
2. Create the library and PL/SQL wrapper with the SQL provided
in the code section of this article. You may want to change the
physical location of the library to one that is appropriate for
your environment.
3. Create a new win-32 dynamic link library using MSVC 6.0.
4. Add an empty c source file to the project.
5. Paste the code provided for the DLL source into the .c file.
6. Set the options->directories path for the include and lib files.
7. Choose the build command from the Build pull down menu.
8. Copy the DLL to the exact location specified in the library reference
you created in step 2.
o The sample was tested using the following components:
1. Windows NT 4.0 SP 6
2. Microsoft Visual C 6.0 sp 4.0
3. Oracle RDBMS 8.1.6.0.0
4. Oracle Net 8 8.1.6.0.0
Caution
-------
The sample program in this article is provided for educational purposes only
and is NOT supported by Oracle Support Services. It has been tested
internally, however, and works as documented. We do not guarantee that it
will work for you, so be sure to test it in your environment before relying
on it.
Program
-------
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - - - - - -
create library ora_nt is 'C:\ntshell1.dll'
/
create or replace function ntshell(cmdin varchar2, arg1 varchar2, arg2 varchar2)
return binary_integer is
external library ora_nt
name "exec"
language C
parameters (cmdin string, arg1 string, arg2 string);
/
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include<process.h>
__declspec(dllexport) exec(char *cmdin, char *arg1, char *arg2)
{
if(spawnlp(P_NOWAIT, cmdin, cmdin, arg1, arg2, NULL) == -1) return -1;
return 1;
}
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - - - - - -
Sample Output
-------------
SQL> select ntshell('cmd.exe','/c','del c:\sig.txt') from dual;
NTSHELL('CMD.EXE','/C','DELC:\SIG.TXT')
---------------------------------------
1

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas