From 981c05c082cc34acd096863b61fedcca17505583 Mon Sep 17 00:00:00 2001 From: lzlk <1930069369@qq.com> Date: Mon, 10 Oct 2022 11:44:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E5=8D=81=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022-10-7\344\275\234\344\270\232.sql" | 75 +++++++++++++++++++ ...4\350\256\260 \345\202\250\345\255\230.md" | 54 +++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 "07 \345\273\226\346\262\273\345\205\210/\344\275\234\344\270\232/2022-10-7\344\275\234\344\270\232.sql" create mode 100644 "07 \345\273\226\346\262\273\345\205\210/\347\254\224\350\256\260/2022-10-7 \347\254\224\350\256\260 \345\202\250\345\255\230.md" diff --git "a/07 \345\273\226\346\262\273\345\205\210/\344\275\234\344\270\232/2022-10-7\344\275\234\344\270\232.sql" "b/07 \345\273\226\346\262\273\345\205\210/\344\275\234\344\270\232/2022-10-7\344\275\234\344\270\232.sql" new file mode 100644 index 0000000..d28855b --- /dev/null +++ "b/07 \345\273\226\346\262\273\345\205\210/\344\275\234\344\270\232/2022-10-7\344\275\234\344\270\232.sql" @@ -0,0 +1,75 @@ +--1. 定义存储过程实现查询出账户余额最低的银行卡账户信息,显示银行卡号,姓名,账户余额 + create proc minmoney + @cardno varchar(50) output, + @name varchar(50) output, + @money money output + as + begin + select @cardno=CardNo,@name=RealName,@money=CardMoney from BankCard b join AccountInfo a on b.AccountId=a.AccountId + where CardMoney in (select min(cardmoney) from BankCard) + end + declare @cardno varchar(50) ,@name varchar(50) ,@money money + exec minmoney @cardno output,@name output,@money output + select @cardno,@name,@money +--2. 模拟银行卡存钱操作,传入银行卡号,存钱金额,实现存钱操作 + create proc inmoney + @incardno varchar(50), + @inmoney money + as + begin + insert into CardExchange + values (@incardno,@inmoney,0,GETDATE()) + update BankCard set CardMoney+=@inmoney where CardNo=@incardno + end + exec inmoney '6225125478544587',100000 +--3. 模拟银行卡取钱操作,传入银行卡号,取钱金额,实现取钱操作,取钱成功,返回1,取钱失败返回-1 + alter table bankcard add constraint money check(cardmoney>=0) + create proc outmoney + @outcardno varchar(50), + @outmoney money + as + begin + declare @false int=0 + update BankCard set CardMoney-=@outmoney where CardNo=@outcardno + set @false+=@@ERROR + if(@false=0) + begin + insert into CardExchange + values (@outcardno,0,@outmoney,GETDATE()) + print 1 + end + else + begin + print -1 + end + end + exec outmoney '6225125478544587',1000 +--4. **查询出某时间段的银行存取款信息以及存款总金额**,取款总金额,传入开始时间,结束时间,显示存取款交易信息的同时,返回存款总金额,取款总金额。 + create proc iomoney + @btime smalldatetime, + @etime smalldatetime + as + begin + select sum(MoneyInBank)存款总金额,sum(MoneyOutBank)取款总金额 from cardexchange where ExchangeTime>@btime and ExchangeTime<@etime + end + exec iomoney '2022-9-1','2022-10-8' +--5. **密码升级**,传入用户名和密码,如果用户名密码正确,并且密码长度<8,自动升级成8位密码 + +--(提示:随机生成 0-9 的整数: float(rand()*10)) rand():随机生成0.0-1.0的小数 float:向下取整) + create proc mima + @username varchar(50), + @password varchar(50) + as + begin + declare @password1 varchar(50), + @uname varchar(50), + @accountid int + select @accountid=AccountInfo.AccountId,@password1=CardPwd,@uname=RealName from AccountInfo join BankCard on BankCard.AccountId=AccountInfo.AccountId + where RealName=@username + if len(@password1)<8 + begin + update BankCard set CardPwd=concat(right(rand(),4),right(rand(),4)) where AccountId=@accountid + end + end + exec mima '刘备','123456' + \ No newline at end of file diff --git "a/07 \345\273\226\346\262\273\345\205\210/\347\254\224\350\256\260/2022-10-7 \347\254\224\350\256\260 \345\202\250\345\255\230.md" "b/07 \345\273\226\346\262\273\345\205\210/\347\254\224\350\256\260/2022-10-7 \347\254\224\350\256\260 \345\202\250\345\255\230.md" new file mode 100644 index 0000000..4a5d975 --- /dev/null +++ "b/07 \345\273\226\346\262\273\345\205\210/\347\254\224\350\256\260/2022-10-7 \347\254\224\350\256\260 \345\202\250\345\255\230.md" @@ -0,0 +1,54 @@ +鍒涘缓瀛樺偍: +1.娌℃湁杈撳叆鍙傛暟锛屾病鏈夎緭鍑哄弬鏁扮殑瀛樺偍杩囩▼銆 +sql +create proc <瀛樺偍杩囩▼鍚嶇О> +as +begin + +end +鎵ц: +exec <瀛樺偍杩囩▼鍚嶇О> + +2.鏈夎緭鍏ュ弬鏁帮紝娌℃湁杈撳嚭鍙傛暟鐨勫瓨鍌ㄨ繃绋 + +sql +create proc <瀛樺偍杩囩▼鍚嶇О> +<鍙橀噺1> <鏁版嵁绫诲瀷> +<鍙橀噺2> <鏁版嵁绫诲瀷> +... +as + +鎵ц: +exec <瀛樺偍杩囩▼鍚嶇О> <褰㈠弬1>,<褰㈠弬2>,... + +3.鏈夎緭鍏ュ弬鏁帮紝娌℃湁杈撳嚭鍙傛暟锛屼絾鏄湁杩斿洖鍊肩殑瀛樺偍杩囩▼锛堣繑鍥炲煎繀椤绘暣鏁帮級銆 + +sql +create proc <瀛樺偍杩囩▼鍚嶇О> +<鍙橀噺1> <鏁版嵁绫诲瀷> +<鍙橀噺2> <鏁版嵁绫诲瀷> +... +as + +return 鏁存暟 +鎵ц: +declare @鍙橀噺 +exec @鍙橀噺 = <瀛樺偍杩囩▼鍚嶇О> <褰㈠弬1>,<褰㈠弬2>,... + +4.鏈夎緭鍏ュ弬鏁帮紝鏈夎緭鍑哄弬鏁扮殑瀛樺偍杩囩▼ & 涓涓彉閲忓叿澶囧悓鏃惰緭鍏ヨ緭鍑哄弬鏁扮殑瀛樺偍杩囩▼ + +sql +create proc <瀛樺偍杩囩▼鍚嶇О> +<鍙橀噺1> <鏁版嵁绫诲瀷> output +<鍙橀噺2> <鏁版嵁绫诲瀷> output +... +as + +return 鏁存暟 +鎵ц: +declare @鍙橀噺 +exec <瀛樺偍杩囩▼鍚嶇О> <褰㈠弬1>,<褰㈠弬2>,@鍙橀噺 output +select @鍙橀噺(output 鍙橀噺) + +鍒犻櫎瀛樺偍锛 +drop procedure <瀛樺偍杩囩▼鍚嶇О> \ No newline at end of file -- Gitee