Storage structure of MySQL database

Source: Internet
Author: User
Tags case statement

--Encapsulate several SQL statements, a name called a procedure, and a function that has no return value--storing the process in a database--stored procedure

--the creation process of the stored procedure create PROCEDURE Proceducename () Beginsql statement end$--View Show procedure status \g--Invoke Call ProcedureName () $--  Declaring variable declare age int default 18;--operation set age:=age+10;--changing bounds delimiter $--example CREATE PROCEDURE P1 () Begindeclare age int Default 18;set age:=age+10;select age;end$--with Call P1 () $ Called when age    28 occurs

--CREATE TABLE test (ID int,name varchar () NOT NULL default ", age int,content varchar ()) Engine MyISAM CharSet utf8$ Inserting data insert into test values (1, ' Zhangsan ', 13, ' learning Good '), (2, ' Lisi ', 15, ' incarnation of Wisdom '), (2, ' Wangwu ', 14, ' humble ') $

--Stored Procedure Store SQL statements CREATE PROCEDURE P2 () Beginselect content from test where age=15;end$--stored procedures can be programmed-meaning you can use variables, expressions, Control structure complete complex function--if/else statement using if condition then statement; else if condition then statement; Else statement; end If;create Procedure P3 () Begindeclare age int Default 1 8;if age>=18 thenselect ' You have grown up '; Elseselect ' underage '; end If;end$--while Loop while conditional do statement; End while;--parentheses can declare parameters--parameter types [in/  Out/inout] Parameter Name argument type CREATE PROCEDURE P4 (Agee int) Beginselect name from test where age=agee;end$in indicates input parameter argument out indicates output parameter pass variable name Outgoing value to set the initialization value inout the input parameter is executed and the output passes in a declared variable name, create procedure P5 (in age int) Beginselect as ' You are a few years old '; End$--out parameter, to initialize parameters inside procedure CREATE PROCEDURE P6 (out result int) begindeclare i int default 1;set result:=0;while i<= Doset Result:=result+i;set i:=i+1;end while;end$--calls call P6 (@num) $select @num $--inout Parameters CREATE PROCEDURE P7 (inout Age int) Beginset Age:=age+10;select ages as ' 10 years later you're a few years old '; End$set @age =10$call P7 (@age) $select @age $--case statement case variable name when value 1 t Hen operation 1;when Value 2 then operation 2;...else Operation N;end Case;--repeat loop repeat operatorSentence until condition end repeat; 

Storage structure of MySQL database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.