1. Introduction to plsql

What is pl/sql?
pl/sql ( procedural language/sql ) is an extension of oracle to the standard sql language. pl/sql not only allows to embed the sql language, but also defines variables and constants, allows the use of conditional statements and loop statements, and allows the use of exceptions to handle various errors, which makes its functions more powerful

. 1. Procedures, functions, and triggers are pl/sql written.
2. Procedures, functions, and triggers are in oracle.
3.pl/sql is a very powerful database procedural language.
4. Procedures and functions can be called in java programs.

Why learn pl/sql
1. Improve the running performance of the application
2. Modular design idea
3. Reduce the amount of network transmission
4. Improve the security

Disadvantages of pl/sql :
poor portability.


What to use to write pl/sql

1.sqlplus development tool
sqlplus is a tool provided by oracle company.

Case: Write a stored procedure that can add records to a table.
1) Create a simple table
create table mytest(name varchar2(30), passwd varchar2(30));

2) Create a stored procedure
SQL> create or replace procedure sun_pro1 is
  2 begin
  -- execute part
  3 insert into mytest values('Li Hua','tiger');
  4 end;
  5 /

The procedure has been created.

replace: Indicates that if there is sun_pro1, replace it.

How to view the error message:
show error;

how to call the procedure?
1) exec process name (parameter 1, parameter 2...)
2) call process name (parameter 1, parameter 2...)
The difference between the two methods:

In the first method, if there is no parameter, you can directly exec the procedure name; in
the second method, even if there is no parameter, it is the call procedure name ();


2.pl/sql developer development tool
pl/sql developer is used to develop pl/sql blocks Integrated Development Environment (IDE), which is a standalone product, not an add-on to Oracle.

Case: Write a stored procedure that deletes a table record.
SQL> create or replace procedure sun_pro2 is
  2 begin
  3 delete from mytest where name='Li Hua';
  4 end;
  5 /
Procedure created

Execution procedure
SQL> exec sun_pro2;
PL/SQL procedure successfully completed


Introduce
developers to use pl/sql to write When applying the module, not only need to master the writing method of sql statement, but also master pl/sql statement and grammar rules. pl/sql programming can use variables and logic control statements, so that very useful function modules can be written. For example: paging stored procedure module, order processing stored procedure module, transfer stored procedure module.. And if we use pl/sql programming, we can easily complete very complex query requirements.


The basic unit of simple classification
pl/sql programming: block

With blocks you can write: procedures (stored procedures), functions, triggers, packages



Guess you like

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