Batch executes multiple SQL files to Oracle

Source: Internet
Author: User
Tags sqlplus

Recently, because of project needs, I intend to write a batch program to update the table data in the database. Wrote 3 SQL files: A.sql,b.sql,c.sql, in these three files, implements the operation to create the table and insert data into the table.
Currently I can execute a SQL file through Sqlplus, for example:
Sqlplus Test/[email protected] @a.sql

How to execute three SQL files sequentially in a batch file.
I created a new A.bat file to fill in the file
Sqlplus Test/[email protected] @a.sql
@b.sql
@c.sql
Executes the file A.bat, just executes the file A.sql, executes the file A.sql, does not continue to execute the file behind, how to sequentially execute the statements in multiple SQL files in the batch processing.

So to find on the Internet, I can meet the problem, others should also have encountered, so we found the following:

Solution:In the Windown environment:

First, all the SQL files are ready, the content of each file is not listed here.

To prepare a fully executed SQL file, I call it all.sql for the time being, which reads as follows:

--@y:\ Table \a.sql--@y:\ Table \b.sql--@y:\ Table \c.sql@y: \ Table \receive28.sql@y: \ Table \receivetcs.sql@y: \ Table \receiveattachment.sql@y: \ Table \containerlists.sql@y: \ Table \documentattachedinformationlist.sql@y: \ Table \edocrealation.sql@y: \ Table \entrycontainerinformationlist.sql@y: \ Table \entryidentityinformationlist.sql@y: \ Table \eportlocationinformationlist.sql@y: \ Table \goodsinformationlist.sql@y: \ Table \logisticslocationinformationlis.sql@y: \ Table \main.sqlExit

The syntax is the same as the usual SQL syntax, you can use "--" to annotate some unused tables, and the last exit indicates that the SQLPLUS environment is launched after the order execution is complete.

Then write a a.bat file, the content is very simple, as follows:

:: sqlplus system/[email protected] @all. sql>log.txtsqlplus system/[email protected] @all. sql

Two lines are written, the first line can be used to save information in the Log.txt file, and if you do not need to save the log information, you can use the second line of code

In the Linux environment:

You can write the bat file as follows.

Sqlplus-s/nolog <<EOF    conn Test/[email protected]    @a.  SQL    @b. SQL    @c. sqleof

I only test in the Windows environment can be used, Linux temporarily no environment, please test yourself.

Reference Source: http://bbs.csdn.net/topics/390288596

Batch executes multiple SQL files to Oracle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.