当前位置:网站首页>SQL:存储过程和触发器~笔记
SQL:存储过程和触发器~笔记
2022-07-06 13:07:00 【念迟鱼学编程】
1.变量的概念分类
概念 :被赋予一定值的语言元素。
分类:全局变量、局部变量
| 全局变量 | 由系统提供并且预先声明的变量,用户一般只能查看不能修改全局变量的值,一般是以@@开始的变量 |
|---|---|
| 局部变量 | 用户声明的用以保存特定类型的单个数据值的对象。它局部于一个语句批,一般是以@开始的变量 |
2.变量的声明与赋值
局部变量必须先声明再使用,声明的基本语句:
declare @ 局部变量 [as] 数据类型 [,......n]
注意:使用declare语句声明的局部变量初始值被初始化为NULL。
变量赋值语句格式:
set @ 局部变量名 = 值 | 表达式
注意:表达式可以是任何SQL表达式
也可以使用select语句对局部变量赋值,格式为:
select @ 局部变量 = 值 | 表达式
例题:声明三个整型变量:@x、@y和@z,并给@x、@y变量分别赋予一个初值,然后将这两个变量的和值赋给@z,并显示变量@z的结果。
declare @x int , @y int , @z int
set @x = 10
set @y = 20
set @z = @x + @y
print @z
print的作用是将用户定义的信息返回给客户端,其语法格式为:
print 'ascll文本字符串' | @ 局部变量名 | 字符串表达式 | @@ 函数名
边栏推荐
- Regular expression collection
- Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
- What is the problem with the SQL group by statement
- 968 edit distance
- 技术分享 | 抓包分析 TCP 协议
- Is this the feeling of being spoiled by bytes?
- R語言可視化兩個以上的分類(類別)變量之間的關系、使用vcd包中的Mosaic函數創建馬賽克圖( Mosaic plots)、分別可視化兩個、三個、四個分類變量的關系的馬賽克圖
- R语言可视化两个以上的分类(类别)变量之间的关系、使用vcd包中的Mosaic函数创建马赛克图( Mosaic plots)、分别可视化两个、三个、四个分类变量的关系的马赛克图
- 14年本科毕业,转行软件测试,薪资13.5K
- This year, Jianzhi Tencent
猜你喜欢

Why do job hopping take more than promotion?

【力扣刷题】一维动态规划记录(53零钱兑换、300最长递增子序列、53最大子数组和)
![[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics](/img/2d/9a7e88fb774984d061538e3ad4a96b.png)
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics

After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers

Manifest of SAP ui5 framework json

The difference between break and continue in the for loop -- break completely end the loop & continue terminate this loop

袁小林:安全不只是标准,更是沃尔沃不变的信仰和追求

Swagger UI教程 API 文档神器

OneNote 深度评测:使用资源、插件、模版

数据湖(八):Iceberg数据存储格式
随机推荐
@PathVariable
OneNote in-depth evaluation: using resources, plug-ins, templates
【论文解读】用于白内障分级/分类的机器学习技术
3D人脸重建:从基础知识到识别/重建方法!
Interviewer: what is the internal implementation of ordered collection in redis?
968 edit distance
Start the embedded room: system startup with limited resources
FZU 1686 龙之谜 重复覆盖
967- letter combination of telephone number
The use method of string is startwith () - start with XX, endswith () - end with XX, trim () - delete spaces at both ends
【mysql】游标的基本使用
El table table - sortable sorting & disordered sorting when decimal and% appear
愛可可AI前沿推介(7.6)
PHP saves session data to MySQL database
【Redis设计与实现】第一部分 :Redis数据结构和对象 总结
2017 8th Blue Bridge Cup group a provincial tournament
The difference between break and continue in the for loop -- break completely end the loop & continue terminate this loop
【力扣刷题】32. 最长有效括号
LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
[Li Kou brush questions] 32 Longest valid bracket