How to execute a sql file inside a plsql file?
It's easy to exec a plsql inside a sql. Simply
start my_proc.plsql
exec my_proc;
But how to execute a sql file inside a plsql file?
declare ...
begin
start my_sql.sql?
end;
Thanks.
- Zac
Doesn't work. Even though @ is different from start in this case but it just doesn't like the way sql and plsql are mixed. For example:
DECLARE n NUMBER := 0;
BEGIN
select COUNT(*) INTO n from user_tab_partitions;
DBMS_OUTPUT.put_line('Number of partitioned tables = ' || to_char(n));
if n = 0 then
DBMS_OUTPUT.put_line('createViewsProcs.sql');
@createViewsProcs.sql
else
DBMS_OUTPUT.put_line('createPartitionViewsProcs.sql');
@createPartitionViewsProcs.sql
end of;
END;
SQL> @postimp.sql
SQL> DECLARE n NUMBER := 0;
2 BEGIN
3 select COUNT(*) INTO n from user_tab_partitions;
4
5 DBMS_OUTPUT.put_line('Number of partitioned tables = ' || to_char(n));
6
7 if n = 0 then
8 DBMS_OUTPUT.put_line('createViewsProcs.sql');
9 @createViewsProcs.sql
9 SET SERVEROUTPUT ON SIZE UNLIMITED;
10 SET TERM ON;
11 SET ECHO ON;
12 EXEC DBMS_OUTPUT.put_line('STARTING VIEWS, PROCS, ETC, THIS MAY TAKE A FEW MINUTES');
13 EXEC DBMS_OUTPUT.put_line(SYSTIMESTAMP());
14
15
16 CREATE OR REPLACE PACKAGE db_convert AS
17 FUNCTION ......
32 END;
33 /
SET SERVEROUTPUT ON SIZE UNLIMITED;
ERROR at line 9:
ORA-06550: line 9, column 5:
PL/SQL: ORA-00922: missing or invalid option
...
Similar Messages
-
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
TriptiTry
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. -
Any ideas how to execute a .sql file on database server from java?
Any ideas how to execute a xyz.sql file (which is fisically on
database server) from java?
thanksTry
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. -
How to execute PL/SQL file (*.sql) ?
In SQL*plus, I use edit command to input a sample PL/SQL program into a foo.sql, but now I don't know how to execute this PL/SQL file in SQL*plus. Who can help me ?
In sql plus, issue the following command (for purposes of this example, I am assuming that foo.sql is in the c:\temp directory.
@c:\temp\foo.sql
The "@" can also be written as
start c:\temp\foo.sql -
How to execute one sql file in unix
Hi,
I need to run the follwing script in a file in unix , then run the corresponding spooled file again
SET echo OFF;
SET sqlblanklines ON;
SET feedback OFF;
SET linesize 1500;
SET trimspool ON;
SET termout OFF;
SET pagesize 0;
spool updatedfix.sql;
SELECT ' <update stmt>
spool OFF;
SET termout ON;
SET echo ON;
SET feedback ON;
How can the above script in a file be executed in unix
like
ed script
@ script
then
@ updatedfix.sql;
plz help
thanksI haven't got unix to hand but the principle is the same in windows batch files..
c:\temp>type gen_update.sql
set echo off
set sqlblanklines on
set feedback off
set linesize 1500
set trimspool on
set termout off
set pagesize 0
spool updatedfix.sql
select 'update emp set comm = -1 where comm is null;' from dual;
select 'exit' from dual;
spool off;
set termout on
set echo on
set feedback on
exit
c:\temp>sqlplus user/pass@db @gen_update.sql
SQL*Plus: Release 10.2.0.3.0 - Production on Wed May 6 12:25:10 2009
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> set feedback on
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
c:\temp>sqlplus user/pass@db @updatedfix.sql
SQL*Plus: Release 10.2.0.3.0 - Production on Wed May 6 12:25:37 2009
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
10 rows updated.
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
c:\temp>Just run one after the other in the script file. -
How to Run a .sql file from simple java class
How to execute a .sql file consisting of Complex Queries,procedures through simple java class.
The queries may have different delimiters,queries independant of each other.
I am able to do with Specific De-limiter.But I need in such a way that there should not be any
Constraints. Since My .sql may Contain different De-limiters.
If any one can Suggest Some Solution.
It will be Great Help.
regards
AnilCheck out ibatis script runner, it' a third party library but quite handy for running sql files...
m -
How to execute an SQL query present in a string inside an ABAP program?
hello,
How to execute an SQL query present in a string inside an ABAP programRaut,
You can execute Native SQl statements.
Ex: To use a Native SQL statement, you must precede it with the EXEC SQL statement, and follow it with the ENDEXEC statement as follows:
EXEC SQL [PERFORMING <form>].
<Native SQL statement>
ENDEXEC.
There is no period after Native SQL statements. Furthermore, using inverted commas (") or an asterisk (*) at the beginning of a line in a native SQL statement does not introduce a comment as it would in normal ABAP syntax. You need to know whether table and field names are case-sensitive in your chosen database.
In Native SQL statements, the data is transported between the database table and the ABAP program using host variables. These are declared in the ABAP program, and preceded in the Native SQL statement by a colon (:). You can use elementary structures as host variables. Exceptionally, structures in an INTO clause are treated as though all of their fields were listed individually.
If the selection in a Native SQL SELECT statement is a table, you can pass it to ABAP line by line using the PERFORMING addition. The program calls a subroutine <form> for each line read. You can process the data further within the subroutine.
As in Open SQL, after the ENDEXEC statement, SY-DBCNT contains the number of lines processed. In nearly all cases, SY-SUBRC contains the value 0 after the ENDEXEC statement. Cursor operations form an exception: After FETCH, SY-SUBRC is 4 if no more records could be read. This also applies when you read a result set using EXEC SQL PERFORMING.
EXEC SQL PERFORMING loop_output.
SELECT connid, cityfrom, cityto
INTO :wa
FROM spfli
WHERE carrid = :c1
ENDEXEC.
Pls. Mark If useful -
How to execute a sql script in dbms_job?
how to execute a sql script in dbms_job?
See my response to Re: how to execute a sql script file in procedure or trigger.
Cheers, APC -
Importing and executing a .sql file into Oracle 10g
Hi
I am looking to import and execute a .sql file(create scripts created of a databse designed in MS SQL Server 2005). The file was imported into Oracle APEX 3.10 but we are unable to execute the script. Please suggest alternatives as to how we can import these files.
Thanks in advance.You likely need to migrate the database (objects and data). This is not so easy and you should have a look to migration tools: http://www.oracle.com/technology/oramag/oracle/07-sep/o57sql.html.
-
Bat file execute all *.sql files in a folder
Hi all,
How to write a *.bat file to execute all *.sql files in a folder?
Because have about 20 *.sql file in a folder. There are used to fix data in my database. The number of *.sql file increases day by day. So I want to write a *.bat file to execute all *.sql file in the folder. Since I just run this *.bat file.
Mai Thanh Hải.user545846 wrote:
Hi
I have done this many times. can guide you. :)And did it fail to work all the times you tried it?
c:\>type test1.sql
select 1 from dual;
exit
c:\>type test2.sql
select 2 from dual;
exit
c:\>sqlplus scott/tiger@testdb @c:\test*.sql
SQL*Plus: Release 10.2.0.3.0 - Production on Thu Aug 6 12:37:04 2009
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SP2-0556: Invalid file name.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining optionsWildcards in SQL*Plus filenames don't work. So why do you suggest that?
Better is to use the DOS command FOR...
c:\>for %i in (test*.sql) do sqlplus scott/tiger@testdb @%i
c:\>sqlplus scott/tiger@testdb @test1.sql
SQL*Plus: Release 10.2.0.3.0 - Production on Thu Aug 6 12:38:06 2009
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
1
1
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
c:\>sqlplus scott/tiger@testdb @test2.sql
SQL*Plus: Release 10.2.0.3.0 - Production on Thu Aug 6 12:38:06 2009
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
2
2
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
c:\>... although even better would be to proceduralise the SQL into packages/procedures on the database and have just a single procedure call do all the work. -
Executing multipule .sql files in Sequence
Hi ,
I am new to oracle world . I need to execute 150 .sql files from my local machine . I am trying do something like this ...
but facing many errors ... I am using oracle 10 g
Please advice me .
CREATE OR REPLACE PROCEDURE MYPROC AS
BEGIN
DECLARE
CNT NUMBER :=0;
@c:\sql\1.sql;
CNT:=CNT+1;
@c:\sql\2.sql;
CNT:=CNT+1;
commit;
EXCEPTION
BEGIN
ROLLBACK;
DBMS_OUTPUT.PUT_LINE('TRANSACTION ROLLEDBACK')
DBMS_OUTPUT.PUT_LINE('Failed at Executing' CNT-1)
CNT:=0;
END;
END;
END MYPROCuser11791474 wrote:
i need to create pl sql because if any of these files are errored then i need to terminate my execution . I guess just executing 15o sql files in one wrapper sql will keep executing next sql files.
do you have any idea about how to call sql files in pl sql then ?No you can't call an sql*plus file in Pl/sql.
What you can do in SQl*plus is someting like this:
untested
-- set an exit condition
WHENEVER SQLERROR EXIT ROLLBACK
spool logscripts.log
prompt "running script 1"
@script1.sql
prompt "running script 2"
@script2.sql
prompt "running script 3"
@script3.sql
prompt "running script 5"
@script4.sql
prompt "running script 6"
@script5.sql
spool off -
How to execute PL/SQL from Java?
I want to execute (compile) a PL/SQL file to a database and I don't know how it can be done with Java.
Please note that I am NOT trying to call a stored procedure. I know that can be done with CallableStatement.
Background:
My actual requirement is to execute PL/SQL files with error notifications. I tried Ant SQL task; but it fails to give compilation error information. I also tried another open source task called Incanto - that also not that helpful as if I execute in bulk, very hard to figureout which one throws error. Hence I decided to write my own Ant task.Hi,
do u want to execute PL/SQL files? or just you want to execute the block of code?
in the case of PL/SQL file:
you need to read total file as StringBuffer/String and then execute.
Block of code:
you can directly pass the code to the java file as input and then execute.
Ex:
StringBuffer queryString = new StringBuffer();
queryString = queryString.append("BEGIN execute immediate ' ");
queryString = queryString.append(query);
//queryString = queryString.append("BEGIN dbms_job.run(142);END;");
queryString = queryString.append(" '; END; ");
final_Query = queryString.toString();
try {
System.out.println("final : "+final_Query);
cstmt = con.prepareCall(final_Query);
System.out.println("Job is Running...");
new ThreadCountdownExtThread().start();
System.out.println("bfore execute()...............");
cstmt.execute();Note: if you are running pl/sql file read file and save it in a Stirng , and then do the same as above stated -
Need help, executing a SQL file from Forms
Hi everyone,
I don't know if this can be done. I want to execute a SQL file from a When-Button-Pressed trigger. I checked a couple of place but havent found anything yet on how to do this. If someone know of a way, please help.
Thanks
Ericprocedure p_call_sqlplus is
l_filename varchar2 (1000) := 'C:\abc\def\test.sql' ;
begin
host ('sqlplus /NOLOG @' || l_filename ) ;
end ;
rem ======== test.sql ========
connect scott/tiger
spool 'C:\abc\def\test'
select * from emp ;
spool off
exit
rem ======================working on the machine where forms is running -
How to execute a jar file which has an applet, without using a html file ?
I have a jar file which contains a set of class files. iam able to execute the jar file by using this html code
<html>
<applet code="file.class" archive="file.jar" width="500" height="300">
<param name="name" value="value">
</applet>
</html>
I want to know how to execute this class file without using the html tags.
pls help me out in this.
AnkiHi,
You can make an executable jar file such that when you double click on that it starts running. Just follow the steps.
1. Open a notepad and write the following
Main-Class: XXXXXXXX
XXXXXXX means Your Main Class name. Don't forget to press Enter after you write your class name.
2. Save the file as Mani.mf
3. In the commant prompt ( your directory ) type following lines.
jar cmf Mani.mf Demo.jar *.*
4. This will make a jar file which is executable jar file
Hope this will help you.
Deepak -
Hi All ,
How to execute a .exe file in Jsp without using a process ??? ...
Is it Possiable ????itsdhanasaraa wrote:
But as this a web application ... By using Runtime i'm getting some probs ..
Let me guess, you want your web application to run a program on the client and to your surprise that's not working?
Ain't gonna happen.
its taking more time to execute .... that's y is there any other option to execute .exe file other than Runtime.getRuntime().exec("filename");Write proper English and you may be taken more seriously.
1) it's not "taking more time to execute", whatever that's supposed to mean.
2) there's no other way to execute something. Not that you should every use even that way anyway
3) whenever you start thinking of executing external programs from Java, start thinking of not using Java in the first place.
Maybe you are looking for
-
I have two apple I.D., one with the .me email address I want, how can I delete it so that I can use that .me address on my other account Or is it possible to transfer the purchases (apps) to my new .me account so that I can re-download them in the fu
-
HP Officejet Pro not printing for me, but printing for my coworkers
My office just got an Officejet Pro 8630 and I have been installing them onto our laptops. I have installed the drivers on four computers, and it has worked well for three of them (all but mine). Our office is doing wireless printing, and the printer
-
How do i find out which generation of i pod i have, i have a pink ipod mini bought 2005.?
-
Error message when attempting to email
For the first time I tried to email from the "share" menu in iPhoto 6.0 I get the following error message: "Can't make class document." I used both Mac mail and AOL mail and had the same error message. Hope you can advise what I can do to correct the
-
Deleting source system - background? any program?
Hi! We built our training system from a client copy of an existing system which has references to other source systems which are not relevant in this new system. I have been trying to delete the source system but it takes ages and often failed (drop-