Execute SQL files for Oracle bat batch processing files

Source: Internet
Author: User

In real projects, you may need to use batch files to execute SQL files. The following describes how to use bat batch processing files to call independent SQL files and stored procedures in databases.

I. the BAT file calls the SQL File

First, create a simple SQL file (log. SQL ).

create table log(  PROBLEMID    VARCHAR2(40),  PROBLEMNAME  VARCHAR2(260),  PROBLEMLEVEL VARCHAR2(40),  PROBLEMORDER VARCHAR2(260),  PARENTID     VARCHAR2(40),  ROOTTYPEDESC VARCHAR2(260),  IFLEAF       VARCHAR2(40),  MEMO         VARCHAR2(1000),  IFVALID      VARCHAR2(40),  ROOTTYPE     VARCHAR2(20));exit;

In this SQL file, we create a table.

Next, we will create a bat batch processing file (log. BAT ).

@echo off sqlplus cssp/cssp@gxcssp @H:\bat_sql\log.sql > log.txtexit

In this batchfile, we use an absolute SQL file and output the execution process and result to the log.txt file.

At the end, run the batchfile to view the recorded content of the log.txt file.

SQL * Plus: Release 10.1.0.2.0-production on Thursday April 7 18:26:03 2011 copyright (c) 1982,200 4, Oracle. all rights reserved. connect to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-productionwith the partitioning, OLAP and Data Mining options table has been created. Disconnection from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-productionwith the partitioning, OLAP and Data Mining options
 

Through this log, we can see that the log table is successfully created. Go to the database and check whether the log table is created.

2. BAT files call stored procedures in Databases

This call process has the same principle as the above call process. Here is a simple description.

Assume that a stored procedure in the database is named produce_log.

You only need to modify the independent SQL file as follows:

Execute produce_log;
Exit;

Please try the specific execution result yourself.

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.