Iván
Iván

Reputation: 1

How to execute a Command Promt on Stored Procedure SQL Developer

I've been trying this:

create or replace PROCEDURE "REPLACE" 
IS                                              
BEGIN

  host @"C:\Replace.bat";
  COMMIT;

END;

The log errors:

Error: ORA-02083: el nombre de la base de datos tiene el carácter no válido ':'

Can someone tell me what's wrong?

Upvotes: 0

Views: 475

Answers (1)

thatjeffsmith
thatjeffsmith

Reputation: 22447

You simply can't do this, not with a PL/SQL stored procedure at least.

First of all, HOST is a SQL*Plus command not a PL/SQL procedure or function you can call.

If you want to stick with a stored procedure - then take the contents of 'replace.bat' and rewrite in native PL/SQL.

If you simply MUST execute that script from inside the database itself (where PL/SQL runs by the way), then consider creating SCHEDULER Job that will call out to SQL*Plus and run that script - assuming that the .bat script itself is some thing that calls out to SQL*Plus.

If you want to really reach out to the operating system from inside the database, you can also write a stored java procedure. That will invoke the JVM, and run your Java code, and you can do pretty much whatever you want provided you know how to code it.

But.

For the best answer and advice, you need to show/tell us just what 'replace.bat' does.

As for the ORA-02083

The compiler is seeing the '@' character and is going into 'oh we must be seeing a DB_LINK coming up. So the next confusing thing it sees after that is the ':' character, which apparently isn't legal for a database name, which it's trying to find in the non-existing DB_LINk.

One last thing:

create or replace PROCEDURE "REPLACE"

REPLACE is a reserved word for a reason. Quoting object names to get around reserved words will create WAY more problems or you than it will solve. Better to

CREATE OR REPLACE PROCEDURE REPLACE_STUFF 

Upvotes: 2

Related Questions