From bdf1f2204ce8f5d60cd2011eb32ac7b147b338a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E7=8E=AE=E5=96=86?= Date: Mon, 10 Oct 2022 13:15:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E5=8D=81=E4=B8=80=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\346\254\241\344\275\234\344\270\232.txt" | 84 +++++++++++++++++++ ...30\345\202\250\350\277\207\347\250\213.md" | 43 ++++++++++ 2 files changed, 127 insertions(+) create mode 100644 "04\351\203\221\347\216\256\345\226\206/\344\275\234\344\270\232/2022.10.07-\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232.txt" create mode 100644 "04\351\203\221\347\216\256\345\226\206/\347\254\224\350\256\260/2022.10.07-\345\255\230\345\202\250\350\277\207\347\250\213.md" diff --git "a/04\351\203\221\347\216\256\345\226\206/\344\275\234\344\270\232/2022.10.07-\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232.txt" "b/04\351\203\221\347\216\256\345\226\206/\344\275\234\344\270\232/2022.10.07-\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232.txt" new file mode 100644 index 0000000..aa3fdf1 --- /dev/null +++ "b/04\351\203\221\347\216\256\345\226\206/\344\275\234\344\270\232/2022.10.07-\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232.txt" @@ -0,0 +1,84 @@ +--定义存储过程实现查询出账户余额最低的银行卡账户信息,显示银行卡号,姓名,账户余额 +create proc proc_GetBankMessage +as +select a.RealName,b.CardNo,b.CardMoney from AccountInfo a inner join BankCard b on a.AccountId = b.AccountId +where b.CardMoney = (select min(CardMoney) from BankCard) +go +exec proc_GetBankMessage +go + +--模拟银行卡存钱操作,传入银行卡号,存钱金额,实现存钱操作 +create proc proc_InMoney +@cardNo varchar(20), +@InMoney money +as +begin + update BankCard set CardMoney += @InMoney where CardNo = @cardNo + insert into CardExchange values(@cardNo,@InMoney,0,getdate()) + +end +go +exec proc_InMoney '6225547854125656',5000 +go + +--模拟银行卡取钱操作,传入银行卡号,取钱金额,实现取钱操作,取钱成功,返回1,取钱失败返回-1 +create proc proc_OutMoney +@cardNo varchar(20), +@OutMoney money +as +begin + declare @code int + declare @CardMoney money = (select CardMoney from BankCard where CardNo = @cardNo) + if(@CardMoney - @OutMoney > 0) + begin + update BankCard set CardMoney -= @CardMoney where CardNo = @cardNo + insert into CardExchange values (@cardNo,0,@OutMoney,getdate()) + return 1 + end + return -1 +end +go +declare @code int + exec @code = proc_OutMoney '6225547858741263',7000 + print @code + go + + --查询出某时间段的银行存取款信息以及存款总金额**,取款总金额,传入开始时间,结束时间, + --显示存取款交易信息的同时,返回存款总金额,取款总金额。 + create proc proc_GetChargeMessage + @Start_time smalldatetime, + @End_time smalldatetime, + @SumInMoney money output, + @SumOutMoney money output + as + begin + select @SumInMoney = sum(MoneyInBank),@SumOutMoney = sum(MoneyOutBank) from CardExchange + where ExchangeTime between @Start_time and @End_time + end + go +declare @Start_time smalldatetime = '2022-09-05 ', @End_time smalldatetime = '2022-09-19' +declare @SumInMoney money , @SumOutMoney money +exec proc_GetChargeMessage @Start_time,@End_time,@SumInMoney output,@SumOutMoney output +select @SumInMoney 存款总金额,@SumOutMoney 取款总金额 +go + +--密码升级,传入用户名和密码,如果用户名密码正确,并且密码长度<8,自动升级成8位密码 +--(提示:随机生成 0-9 的整数: floor(rand()*10)) rand():随机生成0.0-1.0的小数 floor:向下取整) +create proc proc_PassWordUp +@userName varchar(10),@passWord varchar(10) output +as +begin + if(@userName = 'kk' and @passWord = '123456' and len(@passWord)<8) + begin + set @passWord = Convert(decimal(8,0),floor(rand()*100000000)) + end +end +go +drop proc proc_PassWordUp +declare @userName varchar(10) = 'kk' +declare @passWord varchar(10) = '123456' + +exec proc_PassWordUp @userName,@passWord output +select @passWord + + diff --git "a/04\351\203\221\347\216\256\345\226\206/\347\254\224\350\256\260/2022.10.07-\345\255\230\345\202\250\350\277\207\347\250\213.md" "b/04\351\203\221\347\216\256\345\226\206/\347\254\224\350\256\260/2022.10.07-\345\255\230\345\202\250\350\277\207\347\250\213.md" new file mode 100644 index 0000000..c0f6290 --- /dev/null +++ "b/04\351\203\221\347\216\256\345\226\206/\347\254\224\350\256\260/2022.10.07-\345\255\230\345\202\250\350\277\207\347\250\213.md" @@ -0,0 +1,43 @@ + 11、存储过程 + +分类 + +无输入、输出参数 + + create proc proc_name + as + begin + end + +有输入,无输出参数 + + create proc proc_name + @variable datatype + as + begin + end + +有输入参数,无输出参数,有返回值:只返回整型数据 + + create proc proc_name + @variable datatype + as + begin + return @variable int + end + +有输入参数,有输出参数 + + create proc proc_name + @variable1 datatype + @variable2 datatype output -输出参数 + as + begin + return @variable int + end + +执行存储过程 + +exec proc_name @variable1,@variable2 + +exec @variable1 = proc_name @variable2 -- Gitee