Calling a sql script file from a function.

Hi,
I need to call a sql script file from a user defined function. Currently i am trying to do this in Oracle SQL Developer. i tried calling with
@ {filename}, EXECUTE IMMEDIATE etc, but nothing worked. I get the Compiler error.
Basically my need is to call catldap.sql file so that DBMS_LDAP package gets loaded and then I can call the API functions from this.
Please let me know if this is possible doing in a PL/SQL function.
thanks,
Naresh

user784520 wrote:
I need to call a sql script file from a user defined function. Not possible.. and it seems that you do not fully understand the client-server within the Oracle context.
All SQL and PL/SQL are parsed and executed by an Oracle server process. The SQL and PL/SQL engines each expects a single command block at a time. Neither of these can accept a series of separate commands as a single call and then execute each in turn. The SQL engine expects a single SQL statement at a time. The PL engine expects a single PL/SQL anonymous block at a time.
This server process also cannot break into the local file system to access script files. Nor can it hack across the network to access script files on the client.
In order for the server process to access local files, a directory object needs to be created and the current Oracle schema needs read and/or write access on that directory object. As sound security principles apply.
There's no PL/SQL command to execute a script. You must not mistake SQL*Plus commands (this client has a very limited vocabulary) with PL/SQL commands. SQL*Plus executes its own commands.. and send SQL and PL/SQL commands (a statement block a time) to the Oracle server process to be serviced and executed.
It is also a very bad idea to execute external script contents from inside an Oracle server process - as that script resides externally and thus outside Oracle's security mechanisms. This means that is is pretty easy for someone to access that script, compromise it, and then have you inject and execute the contents of that script into the database.
It is not sound security.
Last issue - it is even worse to have application PL/SQL code dynamically creating (or trying to create) portions of the Oracle data dictionary and PL/SQL call interface.
The database needs to be installed correctly - and this includes loading and executing the required rdbms/admin scripts during database installation. It does not make sense at all for application code to try and execute such scripts. It raises numerous issues, including having to allow that application code full and unrestricted SYS access to the database instance. A very serious security violation.
I do not agree at all with the approach you want to use.

Similar Messages

  • Executing .sql scripts file from command prompt

    I had created the .sql scripts for
    --Create Database
    --Create tables
    --Create Stored procedure
    I am using SQL server 2008.
    Now i want to deploy it into the target server using the command prompt.
    How can I call to execute that script on the target server?

    with few errors as "Incorrect Syntax near "GO"".
    Hello,
    GO is a command, which is only known & interpretted by SSMS + SqlCmd.exe; SQL Server engine / data access components don't know this command, therefore you get an error.
    See
    Query Options Execution (General Page); for SSMS you can change it from GO to any other term.
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • How can I run a SQL script file...

    How can I run a SQL script file from a location on my computer without providing the whole path?
    Is there some way I can set a "Working folder" in SQL Plus??
    Thanks!
    Tom

    You can create an environment variable called "SQLPATH" which is a list of directories that SQL*Plus will search for your .SQL
    scripts.
    I would like to use another directory than the oracle/bin...
    How can I do this ??
    Hello,
    U can do this by this way:
    Save odm_script.sql file to the default Oracle
    directory i.e. Oracle-Home/bin and Run following command
    through SQL Plus.
    SQL>@Script_Name
    I hope this will resolve ur problem.
    Regards,
    Omer Saeed Khan.

  • Is it possible to call a windows batch file from PL/SQL block ??

    Hi gurus,
    Would require your help.Is it possible to call a windows batch file from PL/SQL block ??If yes can you give an example for the same or any workaround for the same.
    Regards
    Vijay

    You didn't specify a database version, but if you are 10g or higher, it's quite straightforward using an external job type in DBMS_SCHEDULER. Funnily enough i'm looking at something similar myself at the moment.
    Useful guide to some of the issues here Guide to External Jobs on 10g with dbms_scheduler e.g. scripts,batch files

  • Calling a SQL script from the PL/SQL block.

    Hello All,
    I am using oracle 11g database.
    My requirment is as follows. I have a SQL script to alter the table. But before alter the table I need to test some condition , if the condition satisfy then I have to alter the table through the SQL script. For the checking the condition I have to use the plsql block and inside I need to call the SQL script.
    Can I call a SQL script from PL/SQL block, if yes then how?
    I am tring to use START, RUN and @ command but it is throughing error.
    Thanks
    SUN

    [PL/SQL manual|http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/functions55a.htm#77600] Ctrl-F start, finds nothing. [SQLPlus manual|http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/toc.htm] Ctrl-F start finds this. Isn't it wonderful that Oracle documents this stuff so we don't have to guess.
    Can I call a SQL script from PL/SQL block, if yes then how? No.
    You could call the stored procedure in a SQL*Plus script before the alter table and have it raise an exception if the condition is not met and have the script quit when there is an error.

  • Is it possible to call a windows batch file from PL/SQL

    Hi gurus,
    Would require your help.Is it possible to call a windows batch file from PL/SQL??If yes can you give an example for the same or any workaround for the same.
    Regards
    Vijay

    Hi!
    Youn need some extproc related entries in you listener.ora and tnsnames.ora file.
    *1. In the listener.ora:*
    Defining the listener process is done in two parts.
    The information contained in each listener differs!!!
    The first part is as follows:
    LISTENER =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = IPC)(KEY = extproc))  <---  *ADD THIS LINE
          (ADDRESS = (PROTOCOL = TCP)(HOST = yourhostname)(PORT = 1521))
      )The seoncd part is as follows:
    SID_LIST_LISTENER =
      (SID_LIST = 
        (SID_DESC =
          (GLOBAL_DBNAME = YOUR_GLOBAL_DBNAME)
          (ORACLE_HOME = c:\oracle\product\10.2.0)  <-- THIS IS YOUR ORACLE_HOME
          (SID_NAME = YOUR_SID)                            <-- SID
        (SID_DESC =                                              <--- ADD THIS LINE
          (SID_NAME = PLSExtProc)                          <--- ADD THIS LINE
          (ORACLE_HOME = c:\oracle\product\10.2.0) <--- ADD THIS LINE AND EDIT TO YOUR ORACLE_HOME
          (PROGRAM = extproc)                                <--- ADD THIS LINE
          (ENV = "EXTPROC_DLLS=ANY")                  <--- ADD THIS LINE
        )                                                                <--- ADD THIS LINE
      )*2. In the tnsnames.ora you need to add the following entry:*
    *(The KEY value entered must be match to the KEY value entered int the listener.ora file!)*
    EXTPROC_CONNECTION_DATA =
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = IPC)(KEY = extproc))
        (CONNECT_DATA =
          (SID = PLSExtProc)
          (PRESENTATION = RO)
      )Finally you need to restart your listiner. After restarting there will be a service called "PLSExtProc" in your listener.
    This are only examples for extproc configuration, your tnsnames.ora and listener.ora can be differs.
    FIRST MAKE MAKE A BACKUP OF YOUR ORIGINAL tnsnames.ora AND listener.ora FILES
    For more information please check metalink note 68061.1 "EXTPROC: Creating External Procedures on Windows NT"
    Bestr Regards
    Norbert

  • SQL script with a prompt functionality.

    Hello experts,
    I tried searching this on the net but was unsucessful...
    Bascially I need to update an sql script with a prompt functionality..Basically I would like a user prompt that would enter 'Yes or No' to compile invalid objects using utlrp.
    If Yes, it should compile it
    If No it should exit out...
    Can anyone please help.. Need to do this today.
    Edited by: user568296 on Oct 2, 2009 8:18 AM

    Hi,
    As someone suggested, you're probably better off doing this at the OS level.
    SQL*Plus does not have any good mechanism for conditional branching. One trick you can do in SQL*Plus is to run one script from another by saying <tt>@@filename</tt>. By using a substitution variable (which can be defined based on the results of a query) in place of a literal filename, you can make this dynamic.
    For example, the following script runs either
    recompile.sql or
    goodbye.sql
    based on the answer to a prompt:
    ACCEPT     recompile_now      PROMPT        'Do you want to recompile objects now?  '
    COLUMN     next_script_col        NEW_VAL next_script
    SELECT     CASE     
              WHEN  UPPER ('&recompile_now') LIKE 'Y%'
              THEN  'recompile'
              ELSE  'goodbye'
         END     AS next_script_col
    FROM     dual;
    @@&next_script<tt>@@filename</tt> assumes filename.sql is on the same directory as the calling script. You could also give a full path name using only one @-sign:
    <tt>@pathname</tt>

  • Running script file from VB

    Hi,
    Is there any shell command or exe to run oracle script file from VB?
    thanx

    You should be able to call WinExec() (Windows API) there are bound to be MS KB articles that cover this. Create a small CMD file that you pass a parameter to with the SQL Script name and then exec that.

  • Help! Need to generate SQL script file in every build of every changes in database project on TFS

    Hi everyone,
                I want to accomplish a task in TFS that I need to auto generate the database changes as SQL script file in drop folder for every build.
    For ex.: If I add a table in a database and then check in the changes, I need to get that create table script in the drop folder as .sql file extension
    I want to automate the build too for every check in. Help me out and guide me a step by step procedure because since I am new to TFS build in visual studio.
    Thanks

    Check out SSDT:
    https://msdn.microsoft.com/en-us/data/tools.aspx
    It can generate a DACPAC which can be used to update a SQL Database through the commandline. To ensure that the .sql file executed is compatible with the target database schema it contains a compiled version of teh schema and will generate the change script
    on-the-fly.
    If you want, you call SqlPackage,exe to generate a SQL script if you want to inspect it before executing.
    https://msdn.microsoft.com/en-us/library/hh550080%28v=vs.103%29.aspx
    My blog: blog.jessehouwing.nl

  • Running sql script files to re create database

    We have having around 10 sql script file that has sql statments inside it (example insert .... delete...update.... etc).Right now what we do is that in jdbc we open each script file, and read each line ,and then make jdbc call run jdbc for each sql statement inside the file.
    Wondering if there is a better way to do this.
    Right now the challenges are
    1)The process goes wrong if there is an extra semi colon ...or extra space after a statments...etc...Basically I find this way of creating data odd...
    2)it is slow because of the network traffic between application server and database server for every sql statements that gets executed.The solution for this issue is to do a batch update....But still I dont like this solution.
    Can someone give me any better idea.
    I am thinking to have all this sql script moved to a store procedure (rather than inside the sql script file) .JDBC then can pick this store procedure sql file ,and create this store procedure via jdbc, and then execute this store procedure.
    This will be faster because all the sql will be running in the databsase.Only one trip to database to call this store procedure.
    Is this a good idea ?
    thx
    m

    Manjit wrote:
    We have having around 10 sql script file that has sql statments inside it (example insert .... delete...update.... etc).Right now what we do is that in jdbc we open each script file, and read each line ,and then make jdbc call run jdbc for each sql statement inside the file.
    Wondering if there is a better way to do this.
    Right now the challenges are
    1)The process goes wrong if there is an extra semi colon ...or extra space after a statments...etc...Basically I find this way of creating data odd...
    2)it is slow because of the network traffic between application server and database server for every sql statements that gets executed.The solution for this issue is to do a batch update....But still I dont like this solution.
    Can someone give me any better idea.
    I am thinking to have all this sql script moved to a store procedure (rather than inside the sql script file) .JDBC then can pick this store procedure sql file ,and create this store procedure via jdbc, and then execute this store procedure.
    This will be faster because all the sql will be running in the databsase.Only one trip to database to call this store procedure.
    Is this a good idea ?
    thx
    mI'm not 100% sure i follow (it's Friday and i have a mild case of ADD).
    Are you suggesting having the Java application create procedures in the database on the fly? If so i would say that's not a good idea.
    Create the stored procedures in the database, have Java call them as needed to process data.
    If you need to load copious amounts of data, look in to external tables, it's possible they could come in handy for what you are doing .... or not ... again, it's hard to say given i find your description of what's currently happening somewhat confusing.

  • How to generate .SQL format file from oracle database?

    How to generate .SQL format file from oracle database?
    I have a database of Oracle 8.1.6,now want to generate script file (including table structure,index,etc.) from it,What should I do?
    Thanks.

    Your question pertains to the Database Export/Import. This forum exclusively focusses on the export/import utilities that come along with "Oracle Portal" which is a web-based tool. Could you please post your question under the RDBMS export/import or migration forum.

  • I want to transfer files from a functioning hard drive in a nonfunctioning MacBook Pro to an external drive. I have an IDE/SATA drive adapter. The files won't fit on the drive for a working computer I have. Can I use it to transfer files to the external?

    I want to transfer files from a functioning hard drive in a nonfunctioning MacBook Pro to an external drive. I have an IDE/SATA drive adapter. The files won't fit on the drive for a working computer I have. Can I use it to transfer files to the external drive?

    Good luck and you are welcome.
    Like I said, I bought one of their inexpensive enclosures and now can use the hard drive just as a source for the files that are on it...my external drives are much larger and faster so I just plug that drive in when I need something from it.
    This one is on sale for $16 http://eshop.macsales.com/item/OWC/ES2.5BPU2S/

  • How can I rip a 10" x 10" post script file from InDesign 6, it keeps telling me "the active document

    How can I rip a 10" x 10" post script file from InDesign 6, it keeps telling me "the active document uses multiple pages sizes and won't print.  My page sizes are all 10" x 10"

    Please post in the InDesign forums here http://forums.adobe.com/community/indesign/indesign_general. They will be able to help you.

  • Calling PL/SQL stored procedure from JSP tag

    Hello,
    I need to call a PL/SQL procedure from a JSP tag , I donot want to use any Bean to call the PL/SQL procedure. How would I call PL/SQL stored procedure from within JSP using JSP tag library, need some code.
    Thank you
    Syed

    need to call a PL/SQL procedure from a JSP tag , I donot want to use any Bean to call the PL/SQL procedure. How would I call PL/SQL stored procedure from within JSP using JSP tag library, need some code.
    regards
    Indira Rani Bandi

  • APEX: How to execute Script file from APEX

    Hello All,
    Can anyone tell me how to execute script file from APEX?(Step by Step process)
    Thanks & Regards,
    Jiten Pansara

    http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21677/sql_rep.htm#AEUTL193
    Regards,

Maybe you are looking for

  • Issue in populating Limits Value of PO in its Line item

    Hi All,     There is an issue while creating a PO from PR.     When we change the Item Category of the line item to 'B'. it is asking to enter the Limit value in the LIMIT Tab of the item detail.     In our example we enter expected value field say 2

  • Best Way to Remove Duplicate Movies

    I'm a professor and use Keynote for my lectures. I noticed that my lecture files are HUGE (my summary lecture was over 650mb). When I looked at the package I found several duplicates of movies and images that I use in my slides. Is there any efficien

  • Photos won't import

    Connected my iphone to sycnronize with itunes. itunes/iphone did not recongnize device Opened up image capture. Unplugged phone and re-plugged it and then device showed up in image capture.  Attemped to go through the process to pull photos off phone

  • SQL query  to sorting top 20 customers

    I want to query my Oracle 9i DB to get a listing of the TOP 20 customers based on invoiceamount. I further want to group by cutomertype and region Is the following query correct ? select distinct branch, region , partyname, customertype , qnty , invo

  • Find first occurence of an integer in a string

    Hi all, I have a number of strings which go something like "MBNA Flow 12a" and I want to separate the integer from the rest of the string so I can parse it, sort the strings into some sort of order according to their integer, and then put it all back