Definition and operation of Oracle transaction, process, and function transactions 1. The characteristics of the transaction acid:2. Atomicity (atomicity): The statement that makes up a transaction forms a logical single
Yuan, you cannot only perform a subset of them.
3. Consistency (consistency): The database is consistent (database data integrity constraints) before and after transaction execution.
4. Isolation (isolcation): The impact of a transaction on another transaction processing.
5. Persistence (Durability): The effect of transaction processing can be permanently preserved.
One of the following conditions is the end of the transaction: 1. Explicit end: Commit or rollback executed;
2. Implicitly commits: Executes the DDL,DCL statement, or exit exits.
3. Implicit rollback: System abnormal shutdown, crash, power off.
SavePoint Save Point (example) SELECT * from emp savepoint A; INSERT INTO EMP e (e.empno,e.ename,e.job,e.mgr) VALUES (9999, ' xiaoming ', ' clerk ', 7902) savepoint B Delete F Rom emp where emp.empno=9999 savepoint c rollback to c rollback to A commit or rollback before
Data status (without locking) 1. The data state before the change is 2 recoverable. A user who performs a DML operation can query the previous correction 3 through a SELECT statement. Other users cannot see the changes made by the current user until the current user finishes the transaction.
Data status after submission 1. Data changes have been saved to the database.
2. The data before the change has been lost.
3. All users can see the results.
4. Locks are released and other users can manipulate the data involved.
5. All save points are released. Stored Procedures
What is a stored procedure.
: Stored procedures are typically used to perform a specified operation, which encapsulates a particular operation that is commonly used as a procedure.
Procedures for not receiving parameters: (example) Create or replace procedure P1 as begin Dbms_output.put_line (' Current date is: ' | |
To_char (sysdate, ' yyyy-mm-dd '));
End
Begin P1 ();
End
Result: The current date is:2018-03-07 receives parameters for the input type: (example) 1.
Create or Replace procedure Addyonghu (stu_id in number, stu_name in Nvarchar2,
class_id in number, sex in Nvarchar2, Email in nvarchar2, address in nvarcha
R2) as begin insert into student values (stu_id, stu_name, class_id, sex, emails, address);
End
Call Addyonghu (1012, ' Shaomeng Jia ', 2, ' female ', ' [email protected] ', ' Henan Gongyi ');
2. Create or Replace procedure Getemailbyid (Stuid in Student.stu_id%type) as V_email Student.email%type;
Begin select S.email into V_email from student s where s.stu_id = Stuid; Dbms_output.put_line (' ID number ' | | | stuid | | ' E-mail is: ' | |
V_email); Exception when No_data_found then Dbms_output.put_line (' According to ID number ' | | stuid | |
' Could not find the student ');
End
Call Getemailbyid (1012);
Parameters that receive the output type: (example) Create or Replace procedure getclassinfor (v_id in Student.stu_id%type,
Class_infor out Class%rowtype) as Class_infor1 Class%rowtype; Begin SELECT * into Class_infor from class where class.class_id = (select s.class_id from student s
where s.stu_id = v_id);
Class_infor1: = class_infor;
End
DECLARE class_information Class%rowtype;
Begin Getclassinfor (1002, class_information);
Dbms_output.put_line (class_information.class_id | |
Class_information.class_name | |
Class_information.class_teacher);
End
In Out parameter: (example) Create or Replace procedure Studentinfo (student_information in Out student%rowtype) as begin SELECT *
Into Student_information from student Stuwhere stu.stu_id = student_information.stu_id;
End
SELECT * FROM student declare student_infor student%rowtype;
Begin student_infor.stu_id: = ' 1003 ';
Studentinfo (student_infor);
Dbms_output.put_line (student_infor.stu_id | | student_infor.stu_name | | student_infor.class_id | |
Student_infor.sex | | Student_infor.email | |
student_infor.address);
End
Passing variables and data for parameters can be transferred by position 1. Passing by position means that the names of the arguments are written sequentially in the order of the arguments, and the form participates in the arguments to pass 2. In this method, the names of the formal participation arguments are independent, unrelated, and the order is important 3. It is simpler to write than by the method of passing names, however, if you update the order of the formal parameters of a procedure, all calls to the procedure must be updated accordingly, which will increase the difficulty of maintaining the application name pass 1. Passing by name refers to writing out the arguments according to the name of the formal participation argument at the time of the call. The formal parameter, associating the formal participation argument to pass 2. In this method, the names of the formal participation arguments are independent, unrelated, and the name correspondence is important, but the order is not important. 3. Name passing specifies the parameter name when calling a subroutine and uses the associated symbol "=>" to provide the corresponding numeric value or Variable combination pass 1. You can mix 2 by location, by name, and in the same call. However, the preceding arguments must be passed by location, and the rest of the arguments can be passed by name by using the method *********************** Functions: Functions are used to return specific data, if it is often necessary to return specific data by executing SQL statements in an application, you can create a specific function function and a structure similar to the procedure based on these actions, but you must have a return clause that returns the function value.
Function description to specify the function name, the type of the result value, and the parameter type, and so on.
Example of a parameterless function: (example) Create or Replace function Fun_getchar return NVARCHAR2 as begin return ' Jun Cheng hello ';
End Select Fun_getchar from dual a parameter function example: (example) Create or Replace function fun (v_stu_id number) return NVARCHAR2 as V_stu_nam
e Student.stu_name%type;
Begin select S.stu_name into V_stu_name from student s where s.stu_id=v_stu_id;
return v_stu_name;
End
declare v_id number;
Begin v_id:= ' &id ';
Dbms_output.put_line (Fun (v_id));
End Process and function comparison processes and functions have many of the same functions and features are used in the parameters of the in mode to pass in data, the parameter return data input parameter of Out mode can receive the default value, both can be used when the argument of the value invocation can use the position notation or the name notation has the declaration part , the operative part, and the exception handling section generally, if you need to return multiple values or do not return a value, use the procedure if you only need to return a value, use the function although the function with out mode parameters can return multiple values, but it is generally considered that this method is a bad programming habit or style process generally
To perform a specified action, the function is generally used to compute and return a value