当前位置:网站首页>Databases - create databases, tables, functions, etc.
Databases - create databases, tables, functions, etc.
2022-07-30 15:41:00 【temperamenttalkj】
数据库 - 创建数据库、表、函数等
1、创建自定义函数
- 自定义函数分为:Scalar-valued functions or table-valued functions.
- 标量值函数:如果 RETURNS 子句指定一种标量数据类型,则函数为标量值函数.
- 表值函数:如果 RETURNS 子句指定 TABLE,Then the function is a table-valued function.
- There are two types of table-valued functions:内嵌表值函数(行内函数)or multi-statement functions
- 如果 RETURNS 子句指定的 TABLE List without columns,Then the function is an inline table-valued function.
- 如果 RETURNS 子句指定的 TABLE Types have columns and their data types,Then the function is a multi-statement table-valued function
1.1 函数语法:
Create function 函数名(参数)
Returns 返回值数据类型
[with {Encryption | Schemabinding }]
[as]
begin
SQL语句(必须有return 变量或值)
End
1.2 Scalar-valued function instance:
CREATE FUNCTION Foo(@ret int ) --传入了一个int类型的参数
RETURNS int --Note that what is returned here is a data type
AS
BEGIN
declare @n int
set @n = 3
return @n* @ret
END
1.3 Inline table-valued function syntax:
create function 函数名(参数)
returns table
[with {Encryption | Schemabinding }]
as
return(一条SQL语句)
eg
create function GetUser(@name varchar(10))
returns table
as
return select * from userInfo where userName=@name
调用:
select * from getuser('admin')
1.4 Multi-statement table-valued function syntax:
--Multi-sentence table-valued functions
create function 函数名(参数)
returns table variable nametable (Table variable definitions)
[with {Encryption | Schemabinding }]
as
begin
SQL语句
end
--A multi-sentence table-valued function contains multiple entriesSQL语句,At least one of the table variables is filled with data values
eg
create function GetInfo(@name varchar(20))
returns @cTable table(UserName varchar(10),UserPwd varchar(10))
as
begin
insert into @cTable
select userName,userPass from userinfo where username=@name
return --The last statement in a function must be a return statement.
end
--调用
select * from GetInfo('admin')
------------
UserName UserPwd
admin amin
边栏推荐
- tiup install
- MySql error: SqlError(Unable to execute query", "Can't create/write to file OS errno 2 - No such file...
- RISC-V调用惯例
- Flask introductory learning tutorial
- JHM:芳环羟化双加氧酶数据库DARHD建立及相关引物评价
- TensorFlow自定义训练函数
- (Crypto必备干货)详细分析目前NFT的几大交易市场
- yarn安装详细教程说明、升级教程、修改yarn的全局和缓存目录、yarn基本命令
- tiup env
- 视频切换播放的例子(视频切换范例)代码
猜你喜欢
随机推荐
InputStream和OutputStream流的使用
如何做好技术选型
Shell脚本的概念
TiUP 命令概览
Store Limit 使用文档
Go to Tencent for an interview and let people turn left directly: I don't know idempotency!
(Popular Science) What is Fractional NFT (Fractional NFT)
Local Transactions vs Distributed Transactions
vite 多页面应用刷新页面时,不会在当前路由中,会返回到根路由
Distributed pre-course: MySQL implements distributed locks
嵌入式开发:嵌入式基础知识——正确启动固件项目的 10 条建议
TiDB tool download
HUAWEI CLOUD Releases Open Source Software Governance Service - Software Component Analysis
组态 - 笔记
Introduction to TiUP
[Cloud Native] Service Industry Case - Solutions for Unpredictable Concurrency Scenarios
Kubernetes应用管理深度剖析
TiDB 工具下载
CMake库搜索函数居然不搜索LD_LIBRARY_PATH
【云原生】灰度发布、蓝绿发布、滚动发布、灰度发布解释









