SamiBOB
SamiBOB

Reputation: 243

How to execute sql file via PL/SQL (the name of the sql file is know at execution time)

I need to write a PL/SQL bloc that executes an sql file. the thing is that the name of the sql file is determined at the execution time.

This is a snippet of what i'm trying to do here :

begin
  @'OracleV5\'||DBMS_DB_VERSION.VERSION||'g\script.sql';   
end;
/

PL/SQL doesn't seem to accept this kind of code :-(

any help please?

Upvotes: 0

Views: 4338

Answers (2)

Rene
Rene

Reputation: 10541

The PLSQL block is executed in the database. The problem is how to access the SQL file and execute it's contents. The file needs to be in a location where the database has access to it. You can then create a directory object to access the location and read the file content using utl_file or by opening the file as a Blob using Bfile.

(sorry for the very abstract answer but that's all I've got time for now)

Upvotes: 1

Satya
Satya

Reputation: 8881

try execute immediate . this link might be helpgul

Upvotes: 0

Related Questions