1. The syntax of the stored procedure is various
eg
DELIMITER $$
CREATE PROCEDURE TEST_P_ADD9
(
P_name VARCHAR (100),
P_test VARCHAR (100),
P_age INT,
Out O_newid INT
)
BEGIN
INSERT into Table_test (f_name,f_test,f_age,f_date) VALUES (P_name,p_test,p_age,now ());
SET o_newid=last_insert_id ();
end$$
DELIMITER;
/*
DELIMITER is actually telling the MySQL interpreter if the command is over and MySQL is ready to execute.
By default, delimiter is a semicolon;. In the command-line client, if a single line of commands ends with a semicolon,
then enter, MySQL executes the command. Enter the following statement as
Select * from test_table;
Then enter, then MySQL will execute the statement immediately.
But sometimes, you don't want MySQL to do this. More statements are entered for the possible, and the statement contains a semicolon.
*/
Note:
A. Add a semicolon after each sentence.
B. Stored procedure parameters do not need to add @
C. When calling a stored procedure using call, the parameter needs to be added @
For example:
SET @s=0;
Call test_p_add9 (' xxx ', ' 123xx ', @s);
SELECT @s;
D. Declaring variables can be directly assigned to a set without requiring declare
E. No as
F. Output is behind SQL Server in the front
G. Stored procedure does not have parameters to write ()
H.M Ysqlparams parameters need to be used? Instead of @
2. Paging Statements
SELECT * from Table_test LIMIT 5,3;
3. The corresponding Top statement
SELECT * from Table_test LIMIT 5;
4. String concatenation using CONCAT
SELECT CONCAT (' 1 ', ' 2 ');
If you use ' 1 ' + ' 2 ' as the result is 3
5. Use Now () to get the current time
Select today ();
Select Curdate () Date current_date ()
Select Curtime () Time
6.isnull function
Returns 1 if the parameter is NULL returns 0
The 7.ifnull function is equivalent to SQL IsNull
Ifnull (null,10)
8.uuid () function instead of MSSQL newid ();
9.row_count () function instead of @ @rowcount
Update Delete Insert only
10.scop_identity ()
LAST_INSERT_ID ()
11.mysql Nchar,nvarchar,ntext type not supported
12. Self-increment statement using auto_increment
Direct write value behind default without parentheses
14. Identifiers
SQL Server: [name]
MySQL: ' Name '
15.MYSQL support values This SQL Server 2008 is also supported later
INSERT into Table_test (f_name,f_test,f_age,f_date) VALUES (' 321 ', ' 321 ', 21,now ()), (' 123 ', ' 123 ', 123,now ())
Select @count =count (*) from table
MySQL select COUNT (*) from table to @count
If condition statement
If condition Then
End If
Or
If condition Then
Else
End If
Or
If condition Then
ElseIf condition Then
End If
eg
DELIMITER $$
CREATE PROCEDURE Test_test1
(
P_index INT
)
BEGIN
IF P_index >0 Then
SELECT 1;
ELSE
SELECT 2;
END IF;
END $$;
DELIMITER;
MySQL syntax does not return
18. Time Manipulation functions
SELECT Date_add (Curdate (), INTERVAL 1 day) Current time plus 1 days
SELECT date_sub (Curdate (), INTERVAL 1 day) Current time minus 1 days