Introduction to SQL Programming

Source: Internet
Author: User

One: SQL is also a programming language that you can use to program

Second: basic general programming elements

variables, operators, expressions, process controls, functions


Variable:

Typically, a field name is a variable name, and a field is a variable!

Special variables, such as system built-in variables (character_set_xxx, autocommit)


Typical operation of a variable: Assign value, get value!


User-defined variables:

User-defined variables need to be prefixed with @ as the variable name to differentiate whether the system built-in variable

Set statement; Can complete the setting of the variable

Set Variable name = variable Value

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M01/77/B4/wKiom1ZsJsHBNzqnAAAwV-67ZyA910.jpg "title=" 01.jpg "alt=" Wkiom1zsjshbnzqnaaawv-67zya910.jpg "/>


How to get it?

You can use the SELECT statement!

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M01/77/B4/wKiom1ZsJymjzQzpAAAZlKcft4w953.jpg "title=" 01.jpg "alt=" Wkiom1zsjymjzqzpaaazlkcft4w953.jpg "/>


Implementation of Programming:

There are three ways of programming: triggers, stored functions, stored procedures


Function:

For MySQL, there are built-in functions

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/77/B3/wKioL1ZsKGfynZFKAAAYo_JmoQU487.jpg "title=" 01.jpg "alt=" Wkiol1zskgfynzfkaaayo_jmoqu487.jpg "/>


Rand (), generate random number function, get random number between 0-1

Need to be used in conjunction with rounding

Floor (), rounding down


substring (string, position, length), intercept string function

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M01/77/B3/wKioL1ZsKcThBAZ2AAAkOfLkMNA274.jpg "title=" 01.jpg "alt=" Wkiol1zskcthbaz2aaakoflkmna274.jpg "/>

Note: Subscript starting at 1, and in number of characters:

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M01/77/B4/wKiom1ZsKi_SSFwxAAAlyCWMBzk373.jpg "title=" 01.jpg "alt=" Wkiom1zski_ssfwxaaalycwmbzk373.jpg "/>


Char_length () Number of characters

Length () bytes

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M00/77/B3/wKioL1ZsKtfiLZZoAABO9tCBLck586.jpg "title=" 01.jpg "alt=" Wkiol1zsktfilzzoaabo9tcblck586.jpg "/>


Convert (string using character set) character to the corresponding target character set

Introduction to SQL Programming

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.