(learn) How to execute multiple SQL statements at once in Oracle

Source: Internet
Author: User

Captain Classmate's original address: https://www.cnblogs.com/teamleader/archive/2007/05/31/765943.html
Captain Classmate's original description:

Sometimes we need to execute multiple SQL statements at once, and the SQL used to update them is spelled out according to the actual code.
The solution is to put SQL into this form:

Begin
Update TB_VG Set seq = 1, vessel_id = ' Jin14 ', Vessel_type = ' track ' where batch_number = ' 20837 ' and train_id = ' 0233086 ' ;
Update TB_VG Set seq = 2, vessel_id = ' Jin14 ', Vessel_type = ' track ' where batch_number = ' 20992 ' and train_id = ' 0233110 ' ;
End

Summarized as follows:
Begins with a begin, ends with an end (the semicolon cannot be saved after end), and each SQL statement in the middle is separated by a semicolon;

In the actual code, it is found that even if there is an error, replace the line break in the SQL statement with a space.
A more secure coding method is:
1, in the normal way to write SQL, according to the needs of reading and writing, there will definitely be a newline character in the middle
2. Replace before execution: strSQL = strsql.replace ("\r\n", ""). Replace (' \ n ', ');

If you do not use this method, the possible exceptions are:

Ora-00933:sql command does not end correctly (if SQL does not end with a semicolon)
ORA-00911: Invalid characters (if no begin and end are added)
ORA-06550: line x, section XXX: PLS-00103: The appearance of the symbol "End-of-file" in the need for one of the following: ... (If End does not follow; semicolon)
ORA-06550: line x, section XXX: PLS-00103: The sign appears "" In the need for one of the following: ... (There are line breaks between statements)

Here's what I added:
(See the Red one in the Replace parameter?) , less this can't, @ captain, you have killed a lot of people ah ^_^!

(learn) How to execute multiple SQL statements at once in 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.