sqlserver和mysql存储过程的转化

下面是sqlserver存储过程和mysql存储过程的转化:

SQL SERVER MYSQL
GO 去掉GO
create procedure之后的AS 去掉AS
SET QUOTED_IDENTIFIER ON、SET ANSI_NULLS ON 去掉这两句
使用参数带@符号 使用参数前去掉@
create procedure()中的传入符号@参数 @参数换成IN 参数
sqlserver参数直接赋值 参数赋值写到BEGIN下面的set语句
if begin......end else bgin......end if then......else......end if
update a set ... from a,b update a,b set...
update p set ... from 
product p LEFT JOIN product_price pp
where p.productid= pp.productid
UPDATE product p LEFT JOIN product_price pp 
ON p.productid= pp.productid SET ...
convert cast()
return语句

label:BEGIN

LEAVE label; # 退出存储过程

调用存储过程,可以直接EXEC CALL pro(a, b)
[dbo]. 可以直接去除
select a=b赋值 select a into b
ISNULL(expr1,expr2) IFNULL(expr1,expr2)
 select * from test(nolock)  去掉(nolock)
 DATEDIFF(day,date1,date2)  DATEDIFF(date1,date2)
 --注释  #注释
 exec('select * from '+@tablename)

declare msql varchar(2000);

set @MyQuery='select * from '+tablename;

prepare msql from @MyQuery;

execute msql;

#定义游标
declare std_cur cursor for ......
--打开游标
open std_cur;
--读取第一条记录
fetch first from std_cur into......
while (@@fetch_status = 0)

 #遍历数据结束标志

declare done boolean default false;

#定义游标

declare std_cur cursor for ......

#将结束标志绑定到游标

declare continue handler for not found set done=true;

#打开游标

open std_cur;

#当done为false时,会一直遍历,直到结束。

while !done do

 

 

 

               

 

posted @ 2022-04-21 11:22  最萌小胡胡  阅读(437)  评论(0编辑  收藏  举报