Call sql file from plsql

Hello,
I am stuck for many days in this issue. Hope someone helps me out.
I am using Oracle 11.
I am writing an utility of Purging the data from the database base on certain criteria.
We don't have physical(actual) partitions present on our system(since we are not using enterprise edition).
We have 57 tables representing 57 partitions. Then we are creating a view of all these 57 tables -
CREATE or REPLACE VIEW MY_VIEW AS
select [column_names] from table1
UNION ALL
select [column_names] from table2
UNION ALL
select [column_names] from table3
UNION ALL
select [column_names] from table57
This upper query is saved in the 'body' of user_views.
Now when a user wants to delete a partition--
-I am reading this query body in .sql file.
-Editing the .sql file ie removing the unwanted 'select * from tablen'
-Dropping the View.
-Recreating the view from the edited .sql file.
The issue is in creating the view on the fly from the procedure--
- I cant do EXECUTE IMMEDIATE 'CREATE VIEW...' and 'DBMS_SQL.PARSE' as the query body is longer than 32767 characters.
So i chose the option to do file write. In the file I write the VIEW query and then I want to create the View from this file.
Now i am not able to call the .sql which contains
CREATE OR REPLACE VIEW MYVIEW AS
select...
UNION ALL
select...
select...
The character length of this file is around 90000.
Please guide me in this issue.
Any new idea to manage the very large View in runtime is also welcome...
Thank You in advance
Vaib
arge View in runtime is also welcome...
Thank You in advance
Vaib

As it's 11g, even better would be to use EXECUTE IMMEDIATE as Solomon suggested. It can handle CLOBs.
If it were 10g, then fair enough use the DBMS_SQL package with something like...
SQL> ed
Wrote file afiedt.buf
  1  declare
  2    v_large_sql  CLOB;
  3    v_num        NUMBER := 0;
  4    v_upperbound NUMBER;
  5    v_sql        DBMS_SQL.VARCHAR2S;
  6    v_cur        INTEGER;
  7    v_ret        NUMBER;
  8  begin
  9    -- Build a very large SQL statement in the CLOB
10    LOOP
11      IF v_num = 0 THEN
12        v_large_sql := 'CREATE VIEW vw_tmp AS SELECT ''The number of this row is : '||to_char(v_num,'fm0999999')||''' as col1 FROM DUAL';
13      ELSE
14        v_large_sql := v_large_sql || ' UNION ALL SELECT ''The number of this row is : '||to_char(v_num,'fm0999999')||''' as col1 FROM DUAL';
15      END IF;
16      v_num := v_num + 1;
17      EXIT WHEN DBMS_LOB.GETLENGTH(v_large_sql) > 40000 OR v_num > 800;
18    END LOOP;
19    DBMS_OUTPUT.PUT_LINE('Length:'||DBMS_LOB.GETLENGTH(v_large_sql));
20    DBMS_OUTPUT.PUT_LINE('Num:'||v_num);
21    --
22    -- Now split that large SQL statement into chunks of 256 characters and put in VARCHAR2S array
23    v_upperbound := CEIL(DBMS_LOB.GETLENGTH(v_large_sql)/256);
24    FOR i IN 1..v_upperbound
25    LOOP
26      v_sql(i) := DBMS_LOB.SUBSTR(v_large_sql
27                                 ,256 -- amount
28                                 ,((i-1)*256)+1 -- offset
29                                 );
30    END LOOP;
31    --
32    -- Now parse and execute the SQL statement
33    v_cur := DBMS_SQL.OPEN_CURSOR;
34    DBMS_SQL.PARSE(v_cur, v_sql, 1, v_upperbound, FALSE, DBMS_SQL.NATIVE);
35    v_ret := DBMS_SQL.EXECUTE(v_cur);
36    DBMS_OUTPUT.PUT_LINE('View Created');
37* end;
SQL> /
Length:40015
Num:548
View Created
PL/SQL procedure successfully completed.
SQL> select count(*) from vw_tmp;
  COUNT(*)
       548
SQL> select * from vw_tmp where rownum <= 10;
COL1
The number of this row is : 0000000
The number of this row is : 0000001
The number of this row is : 0000002
The number of this row is : 0000003
The number of this row is : 0000004
The number of this row is : 0000005
The number of this row is : 0000006
The number of this row is : 0000007
The number of this row is : 0000008
The number of this row is : 0000009
10 rows selected.
SQL>

Similar Messages

  • Invoking .SQL file from JAVA

    Hi All,
    Anyway of calling .SQL files from JAVA ??
    thanks in advance..

    What do you mean by calling?
    Are you talking about a stored procedure? Then yes.typo !!
    i meant invoking .SQL script only...
    No not stored procedure..i mean running or invoking a sql file containing sql statements(inserts etc)

  • Is there any way to call a sql file from a pl/sql block

    Hi,
    I want to call a sql file from a pl/sql block.
    the pl/sql block has an exception handler. The pl/sql block will execute the sql file and in case it throws error then the exception handler will take care of it.
    The sql file will be a master file and it will itself call other sql files.
    is it possible to call any sql file from pl/sql block ?

    When you say "sql file", what precisely do you mean? Do you have a file that has just SQL statements? Or do you have SQL*Plus scripts?
    Where are the files stored? Are they on your client machine? Or the database server?"which in turn calls other sql files" seems to imply that the answer to the first question is that you have SQL*Plus scripts. If you have SQL*Plus scripts, you need SQL*Plus to execute them. PL/SQL is running in the Oracle database, SQL*Plus is a client application. It is not practical to have PL/SQL call SQL*Plus. Since you've already ruled out the best of the bad options, it appears that the answer is no, you can't have your PL/SQL run these files.
    As Alex points out, that's probably a good thing. It sounds like your application has been designed incorrectly. If you need PL/SQL, you should be creating stored procedures and functions and calling those from PL/SQL. Having PL/SQL depend on code in flat files outside the database is not a good idea.
    Justin

  • How to call one .sql file from other .sql

    I am trying to call no of .sql files from one .sql file.
    But it gives me error in SQL*PLUS that unable to open file.
    Suggest me solution.
    Thanks
    Chanda

    Are the sql files in the current directories where sqlplus has been started ?
    If not, did you give the full path name for the called sql files when calling them from sqlplus ?
    Could you give us the complete sqlplus command that you use to call your files and the physical location of the called files with the exact error message ?

  • How to execute a  .sql file from a batch file

    Hi all
    I've to take backup of a database weekly twice on every wednesday & Friday @ 5pm IST. I've written a hot backup script, which works every well.
    now i want to automate the script. ie i want this script to run on wednesday & friday @ 5pm without any human interfearance ie with out actually any1 executing this script.
    i created a batch file prod.bak with the following lines
    @echo off
    set oracle_sid=testdb
    set oracle_home=d:\oracle\ora92
    sqlplus /nolog
    connect sys as sysdba/oracletest@testdb
    this batch file when eexecuted connects me to sql prompt.
    Now i want to execute my backup script bkp.sql automatically when it is connected to sql prompt.
    (i tried with these lines in the above batch file...
    call bkp.sql---it just opens the bkp.sql file in notepad & displays the script
    start bkp.sql---same as call
    connect / as sysdba/pwd@[email protected] --- does not work simply remains a the sql prompt.
    At 17:00 /Every:w,f "d:\bkp.sql"---does not work simply remains at the sql promt.)
    Can any1 let me know what should i write in the batch file that will execute the bkp.sql file automatically after it gets connected to sql prompt. M using oracle 9i.
    I'll manage he time through windows utility of scheduling task.. Let me know how to execute the .sql file from a batch file.
    Thanks
    Tripti

    Try
    sqlplus "sys/oracletest as sysdba" @bpk.sql
    Working locally, and having set the ORACLE_SID, you don't need to specify the SqlNet alias (@testdb).
    Remember to put an exit at the end of the bpk.sql script.

  • Calling SQL*Loader from Forms

    Hi,
    I was wondering if anyone has called SQL*Loader from Forms?
    What I am wanting to do is use Oracle Forms as the interface where you can specify a file that you can import into the database and it will use a set control file. Push the import button and SQL*Loader does the rest.
    Is using Java code to call SQL*Loader from Forms a viable option, or is there an easier way to achieve the desired outcome.
    Any ideas or guidance will be much appreciated.
    Thanks,
    Scott.

    Scott,
    In forms, there's a HOST built-in command which is supposed to execute any o/s commands.
    What you have to do is :
    1. Bult up the string exacltly in the fashion which you will run in o/s
    2. Call the HOST Built-in and pass in the string
    Here's a example :
    Declare
    lOsCmd Varchar2(1000) := Null;
    Begin
    lOsCmd := 'sqlldr user-id=userid/passwd@connectStr '
    || ' control=c:\temp\abc.ctl log=c:\temp\abc.log '
    || ' bad = c:\temp\abc.log';
    Host (lOsCmd, No_Screen);
    End;
    -- Shailender Mehta --

  • Calling Sql*Loader from oracle Form builder

    How do i call sql* loader from my forms to import the external data in different formats into my existing database?
    Specify the flexibility of sql* loader to import external data from .txt files or .xls files.
    Would be thankful if certain examples are given along with the answer.

    Hi,
    1. First you have to create seperate ctl (Control files) which maps to different file formats
    2. Using Oracle Forms,
    2a) You can use the 'HOST' command to execute the command line ie. In this case executing
    SQL*Loader script
    2b) You also have the feature in ORACLE forms to read text files and load the data into
    ORACLE db.
    This can be achieved by using TEXT_IO package which comes with ORACLE Forms.
    Hope this helps
    Ta
    Shailender

  • Oracle BI 11.1.1.7.1: Calling BI webservices from Plsql Procedure: ORA-29532: Java call terminated by uncaught Java exception: java.lang.NoClassDefFoundError

    Hi,
         I have a requirement of calling BI webservices from Plsql stored procedure. I generated all my wsdl java classes and loaded them into the database. However, when I tried to call one of my java class using stored procedure, it is giving me"ORA-29532: Java call terminated by uncaught Java exception: java.lang.NoClassDefFoundError".
    *Cause:    A Java exception or error was signaled and could not be
               resolved by the Java code.
    *Action:   Modify Java code, if this behavior is not intended.
    But all my dependency classes are present in database as java class objects and are valid. Can some one help me out of this?

    Stiphane,
    You can look in USER_ERRORS to see if there's anything more specific reported by the compiler. But, it could also be the case that everything's OK (oddly enough). I loaded the JavaMail API in an 8.1.6 database and also got bytecode verifier errors, but it ran fine. Here are the errors I got when loading Sun's activation.jar, which ended up not being a problem:
    ORA-29552: verification warning: at offset 12 of <init> void (java.lang.String, java.lang.String) cannot access class$java$io$InputStream
    verifier is replacing bytecode at <init> void (java.lang.String, java.lang.String):12 by a throw at offset 18 of <init> void (java.lang.String, java.lang.String) cannot access class$java$io$InputStream
    verifier is replacing bytecode at <init> void (java.lang.String, java.lang.String):18 by a throw at offset 30 of <init> void (java.lang.String, java.lang.String) cannot access class$java$io$InputStream
    verifier is replacing bytecode at <init> void (java.lang.String, java.lang.String):30 by a throw
    Hope this helps,
    -Dan
    http://www.compuware.com/products/devpartner/db/oracle_debug.htm
    Debug PL/SQL and Java in the Oracle Database

  • Execetu script file from plsql

    Is possible execute statements saved in file from plsql block?
    I have file c:\xxx.sql and I want execute it from plsql block. c:\xxx.sql contains DDL and DML statements.
    I need something like
    begin
    execute c:\xxx.sql;
    end;
    thank you for help

    Thank you for reply. Maybe you can help with my problem. I have website and data are in server in mysql database, which I can connect only from localhost. I need get data to oracle database resides on my pc.
    I try create this procedure to get data:
    utl_http.request('http://........../make_ddl_and_dml_script_for_oracle.php'); --run script, which create script ora.sql on server for oracle
    utl_http.request_pieces()--"download" file and save it to my pc
    run ora.sql to create or refresh data in my pc
    I know that I can solve it using java, but exist any solution???
    thank you

  • Calling java classes from plsql procedures

    I'm attempting to call java classes from plsql procedures which will create cmsdk users, folders, groups etc, however when I attempt to load a java class into the oracle schema using the command:
    loadjava -user user/password@database -resolve classname.class
    It generates error messages to the effect that classes (cmsdk classes) required by the class cannot be found. The class is loaded and marked with the status "invalid". Is it therefore necessary for me to load the cmsdk packages into the schema?
    Cheers
    David

    Using CMSDK Java API within the database has never been supported
    (see Problems loading IFS's java class into database
    When we needed to invoke CMSDK code from our PL/SQL code, we used one of two approaches:
    (1) use advanced queues to send requests to an external Java program (the CMSDK code, running outside the database) and receive the results back (asynchronous choice); or
    (2) make an HTTP request to a Java servlet (the CMSDK code, running in some Java web container like iAS) and get the response back in some custom format (XML or something) (synchronous choice).
    It seems to me that the CMSDK Java API was designed to be used only in middle-tier, not in database tier.
    Regards,
    Daniel.

  • Calling jsp page from plsql

    Please help me to the following
    How to Call jsp page from plsql??
    Please its urgent
    Edited by: 883730 on Mar 19, 2012 12:05 AM

    The best approach would be to change the behavior of your site so that it includes index.jsp as one of the default files. Typically that is done using the upper-level control files of the site. Here's a link from Sun that describes their approach.
    http://java.sun.com/j2ee/1.4/docs/tutorial/doc/WebApp4.html
    Actually, you don't say what type of webserver you're using, so it's really hard to guess. But if you were using an Apache webserver, you might want to review the "DirectoryIndex" directive here...
    http://httpd.apache.org/docs/2.2/mod/mod_dir.html
    In fact, if you were using Apache and didn't want to do that, you could do a redirect to another page using the "redirect" directive in the webserver control files as described here:
    http://httpd.apache.org/docs/2.1/en/mod/mod_alias.html#redirect

  • How to execute a script(.sql) file from a PL\SQL procedure

    I would like to know how to execute a .sql file from a stored procedure and the result of it should update a table. My .sql file contains select statements.

    Hi!
    just go through the following piece of code -
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    str varchar2(200);
      3  begin
      4    str := '@C:\RND\Oracle\Misc\b.sql';
      5    execute immediate(str);
      6* end;
    SQL> /
    declare
    ERROR at line 1:
    ORA-00900: invalid SQL statement
    ORA-06512: at line 5ORA-00900: invalid SQL statement
    Cause: The statement is not recognized as a valid SQL statement. This error can occur if the Procedural Option is not installed and a SQL statement is issued that requires this option (for example, a CREATE PROCEDURE statement). You can determine if the Procedural Option is installed by starting SQL*Plus. If the PL/SQL banner is not displayed, then the option is not installed.
    Action: Correct the syntax or install the Procedural Option.
    Regards.
    Satyaki De.

  • Call .bat file from java code

    I need to call an application that uses a .bat file to execute from a java program. Is that possible?
    This is the .bat file:
    importcli.exe ciaf2735 C:\Importcli\files\SAI2735*.txt  
    importcli.exe ciaf2735 C:\Importcli\files\CI2735*.txt  
    importcli.exe ciaf2735 C:\Importcli\files\SC2735*.txt  
    importcli.exe db1800 C:\Importcli\files\*.mdb

    magaupe wrote:
    I need to call an application that uses a .bat file to execute from a java program. Is that possible?
    This is the .bat file:
    importcli.exe ciaf2735 C:\Importcli\files\SAI2735*.txt  
    importcli.exe ciaf2735 C:\Importcli\files\CI2735*.txt  
    importcli.exe ciaf2735 C:\Importcli\files\SC2735*.txt  
    importcli.exe db1800 C:\Importcli\files\*.mdb
    Hmmm, I wonder what would happen if there were a web search engine and you could research like this:
    [http://www.google.com/search?hl=en&q=call+.bat+file+from+java]

  • How to call java files from different directories

    hi, how do i call java files from a different directory??
    let say i got partA.java, and i need to include functions from partB.java which is in a different folder. how can i do that?

    Chicon wrote:
    Hi nuttynibbles,
    Before the class declaration in partA.java, you must have an import statement like :
    import someDirectory.partB;
    public class partA {
    ... and before you ask... you'll probably want to read through this http://java.sun.com/docs/books/tutorial/java/package/index.html

  • Calling Sql-loader from PL/SQL

    What is the command(s) to call Sql-Loader from inside a PL/SQL procedure?
    Regards,
    Ahmad.

    I don't think it is possible ...

Maybe you are looking for

  • Text wrap in text box

    In the book module. I select one of the cover options that has a text box. When I type and get to the end, the text does not wrap to fill the box. Instead it types over the same line. Is there a way to have the text continue to the next line? I am us

  • ITunes has detected an iPod in recovery mode loop

    Hello, I have an Ipod 5 and during update of the OS to the latest, the process got an error. No my Ipod is in recovery mode. Everytime I download the Update (Restore and update) there is this constant pop up that comes up (iTunes has detected an iPod

  • Dreamweaver CS5.5 Android App development question

    I am wondering id it is possible to debug an android app over usb debuging. I have the emulator but it's slow and i'd rather debug on my phone but i didn't know if it's possible to push the build on the the phone vs the emulator

  • Authorization in WEB UI

    Hello, Guru! I want to create company wich generate lead. When i go to create Compaign (in role SAP_CRM_UIU_MKT_PROFESSIONAL) i see next error Cannot display view MKTPRJ_COMMCHNL/OVEFChannels of UI Component MKTPRJ_COMMCHNL An exception has occurred

  • Computer crashes during iPhoto slideshow export

    I've been creating several slideshows in iPhoto and then exporting them as Quicktime movies. Some are 6 or 7 minutes, some 14 or 15. When I started doing this, all went well. Then when I had done a few successfully I started experiencing crashes (ker