Oracle's Stored Procedure Programming Lecture 1: Introduction

What is a stored procedure?

 

Is a collection of SQL that can be manipulated programmatically.

 

Advantages of stored procedures?

  • The execution efficiency is very high, because the stored procedure is precompiled, that is, compiled when it is created, while the SQL statement is executed once and compiled once. Calling stored procedures can greatly reduce the number of interactions with the database.
  • Reduce network traffic, because when the stored procedure is executed, only the name of the stored procedure needs to be called, and there is no need to pass a large number of SQL statements. 
  • conducive to reuse.

Disadvantages of stored procedures?

  • The portability is very poor. If the stored procedure written on Oracle needs to be modified when ported to MySQL.
  • The code readability is poor, to implement a simple logic, the code will be very long.

What is the purpose of the stored procedure?

  • Create test data: You can use stored procedures to create millions of data in the table.
  • Data synchronization: Data synchronization between two tables is performed according to certain business logic.
  • data mining.

Stored procedure considerations?

  • When the amount of data is large (100,000+), stress testing must be done, and some stored procedures will have problems only when the amount of data is large.
  • If the number of inserts or updates is relatively large, in order to improve efficiency, it can be executed 10,000 times and then committed once.
  • If you insert a record first, without commit, and then update this record, it will cause deadlock. If the same record is updated successively without commit, it will also cause deadlock. Because the latter statement will wait for the previous statement to commit. If this happens, you need to commit one by one.
  • Don't forget to write commit in the stored procedure.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326570677&siteId=291194637