语句结构(达梦语法):if……then……elseif……then……else……end if;
--if……then……elseif……then……else……end if;
CREATE OR REPLACE PROCEDURE "TEST".proc_GetRole(UserID in varchar(50))
AS
--定义全局变量,作用范围在整个存储过程
userRole varchar(20);
groupId int;
BEGIN
--dmsql语句结构
if (UserID == '1') then
--变量赋值,方式1
set userRole = '1';
set groupId = 1;
elseif (UserID == '2') then
--语句块1,有声明内容
declare
--定义局部变量,作用范围在语句块1内
taskId1, taskId2 int;
begin
--变量赋值,方式2
UserRole := '2';
groupId := 2;
taskId1 := 11;
taskId2 := 22;
groupId := taskId1 + taskId2;
end;
--语句块2,无声明内容
begin
--null语句,什么都不做
null;
end;
else
--null语句,什么都不做
null;
end if;
select userRole as userRole, groupId as groupId;
END;
语句结构(类似mssql):if……begin……end elseif……begin……end else begin……end;
--if……begin……end elseif……begin……end else begin……end;
CREATE OR REPLACE PROCEDURE "TEST".proc_GetRole(UserID in varchar(50))
AS
--定义全局变量,作用范围在整个存储过程
userRole varchar(20);
groupId int;
BEGIN
--与mssql类似的语句结构,区别在于mssql是else if(中间有空格),dm8是elseif(中间无空格)
if (UserID == '1')
begin
--变量赋值,方式1
set userRole = '1';
set groupId = 1;
end
elseif (UserID == '2')
declare
--定义局部变量,作用范围在 elseif 这个语句块内
taskId1, taskId2 int;
begin
--变量赋值,方式2
UserRole := '2';
groupId := 2;
taskId1 := 11;
taskId2 := 22;
groupId := taskId1 + taskId2;
end
else
begin
--null语句,什么都不做
null;
end;
select userRole as userRole, groupId as groupId;
END;