I haven't written an article for a long time. I can't find it, but I am too lazy to write it. But today this article must be written, because I know it will definitely be used in the future.
Well, I have always known only the addition, deletion, modification, and query of databases. Other transactions and stored procedures are rarely used. Today, I started to write the project code, and I didn't even have a record in the database, how can I query records that do not exist? I want to add 20 records to a user table. How can I manually add one record ?????
Okay, write a stored procedure! The Code is as follows:
Create procedure alert () specify username varchar (50); declare userpwd varchar (50); declare userturename varchar (50); declare specify varchar (50); declare usermobilephone varchar (50 ); declare userqq varchar (50); declare useraddress varchar (50); declare useremail varchar (50); declare destination int; declare userremark varchar (50); declare userspid int; declare I int; Set userpwd = "123456789"; Set userturename = "testuser"; Set usertelephone = "123456789"; Set usermobilephone = "123456789"; Set userqq = "123456798 "; set useraddress = "24 Xuefu road section"; Set useremail = "asd@qq.com"; Set userisfrezee = 0; Set userparentid = 1; Set userremark = "test_user"; Set userspid = 1; set I = 1; loop1: While (I <21) doset username = Concat ('danger ', I); insert into t_user (user_name, user_pwd, user_true_name, user_telephone, user_mobilephone, login, user_address, user_email, login, login, user_remark, user_sp_id) values (username, userpwd, userturename, usertelephone, usermobilephone, userqq, useraddress, useremail, login, userparentid, userremark, userspid); set I = I + 1; end while loop1; End
After writing the stored procedure, call isertusers;
Question 1: After setting the value of a variable, the declare statement cannot be written after the set statement?
For example:
CREATE PROCEDURE test()BEGINDECLARE a VARCHAR(20);set a = "ddd";DECLARE b VARCHAR(20);END;
The above code returns an error. Change the location:
CREATE PROCEDURE test()BEGINDECLARE a VARCHAR(20);DECLARE b VARCHAR(20);set a = "ddd";END;
Correct! Is there something wrong with me? I feel helpless about this design!
Question 2: MySQL uses "+" to connect two characters ",
Fortunately
concat
How nice the function is, but also solves the type conversion.