1. Create a function
function float float floatbegin # This function is in the body range, so-called "programming Environment" # "define" session variables and assign values return @result; End;
function float float floatbegin # This function is in the body range, so-called "programming Environment" # This range can be used with ordinary variables, already various flow control structures declarefloatdefault 0; # define common variables and set initial values Set result = X*x + y*y; return result; End;
2, the creation process:
This stored procedure is intended for passing two data and inserting the two data into table enum_test.
CREATE PROCEDURE pro1 (n int, Xuanxiang varchar)begin INSERT INTO enum_test (ID, Xuanxiang) VALUES ( N, Xuanxiang); End;
3. Stored procedure with out function
float float float ) begin = Getpingfanghe (z1, Z2); # Call the function to calculate the sum of squares POW (@pingfanghe, 0.5); End ; // when the stored procedure is called, the 3rd argument must be a variable
4. Using the Select stored procedure
CREATE PROCEDURE gettables () begin * from enum_test; * from set_test; * from tab5; End
5, define a trigger, so that the trigger can be inserted in the TAB5 data,
Automatically inserts a piece of data into another table for use by a "foreign partner".
①TAB5 fields: ID, F1, F2, F4, Id2;
② field of another table to be inserted: ID, F1, f2
Create trigger Getsubdata after insert on TAB5 for each row begin #set @id = new.id; #new在触发器中是特定关键字, #代表 "data row just inserted", which represents the ID value of the row data #set @v1 = new.f1; #新插入数据的f1字段的值 #set @v2 = new.f2; #新插入数据的f1字段的值 INSERT INTO tab5_sub (F1, F2) values (NEW.F1,NEW.F2); end;
Database---Create functions, store functions, trigger instances