将 PlSql 函数转换为 Tsql
我想将以下函数从 plsql 转换为 tsql。但是我不擅长 tsql,而且 swisssql 也无法正确转换它。你能看一下吗?谢谢
CREATE OR REPLACE function yonetici_kontrol_musteri (p_ID_MUSTERI_SIRKET in number, p_ID_YONETICI in number)
return number
is
v_unvan number;
v_yonetici number;
v_tmp_unvan number;
v_tmp_yonetici number;
v_result number;
begin
v_result:=-1;
SELECT id_unvan INTO v_unvan FROM lu_yonetici WHERE id_yonetici=p_ID_YONETICI;
for c in ( SELECT NVL (b.id_mufettis, 0) id_mufettis, b.id_sef
FROM cr_rut_musteri c, lu_bayi_temsilci b
WHERE c.id_musteri_sirket = p_id_musteri_sirket
AND c.id_temsilci = b.id_temsilci
AND c.valid = 1
AND b.valid = 1
AND c.aktif = 1
AND b.aktif = 1
)
loop
CASE v_unvan
WHEN 1 THEN
if c.id_mufettis = p_ID_YONETICI then
v_result:=1;
else
v_result:=0;
end if;
WHEN 2 THEN -- satis sefi
if c.id_sef = p_ID_YONETICI then
v_result:=1;
else
v_result:=0;
end if;
ELSE
v_yonetici:=c.id_sef;
loop
SELECT uy.id_unvan, uy.id_yonetici INTO v_tmp_unvan, v_tmp_yonetici
FROM lu_yonetici y, lu_yonetici uy
WHERE y.id_ust_yonetici=uy.id_yonetici
AND y.id_yonetici=v_yonetici;
if v_tmp_unvan=v_unvan then
if v_tmp_yonetici=p_ID_YONETICI then
v_result:=1;
else
v_result:=0;
end if;
else
v_yonetici:=v_tmp_yonetici;
end if;
exit when v_result=1 or v_tmp_unvan>=v_unvan;
end loop;
END CASE;
exit when v_result=1;
end loop;
return v_result;
exception
when others then
return 0;
end;
I want to convert following function from plsql into tsql.But i am not good at in tsql and also swisssql couldnt convert it correctly.Can u look at it?Thanks
CREATE OR REPLACE function yonetici_kontrol_musteri (p_ID_MUSTERI_SIRKET in number, p_ID_YONETICI in number)
return number
is
v_unvan number;
v_yonetici number;
v_tmp_unvan number;
v_tmp_yonetici number;
v_result number;
begin
v_result:=-1;
SELECT id_unvan INTO v_unvan FROM lu_yonetici WHERE id_yonetici=p_ID_YONETICI;
for c in ( SELECT NVL (b.id_mufettis, 0) id_mufettis, b.id_sef
FROM cr_rut_musteri c, lu_bayi_temsilci b
WHERE c.id_musteri_sirket = p_id_musteri_sirket
AND c.id_temsilci = b.id_temsilci
AND c.valid = 1
AND b.valid = 1
AND c.aktif = 1
AND b.aktif = 1
)
loop
CASE v_unvan
WHEN 1 THEN
if c.id_mufettis = p_ID_YONETICI then
v_result:=1;
else
v_result:=0;
end if;
WHEN 2 THEN -- satis sefi
if c.id_sef = p_ID_YONETICI then
v_result:=1;
else
v_result:=0;
end if;
ELSE
v_yonetici:=c.id_sef;
loop
SELECT uy.id_unvan, uy.id_yonetici INTO v_tmp_unvan, v_tmp_yonetici
FROM lu_yonetici y, lu_yonetici uy
WHERE y.id_ust_yonetici=uy.id_yonetici
AND y.id_yonetici=v_yonetici;
if v_tmp_unvan=v_unvan then
if v_tmp_yonetici=p_ID_YONETICI then
v_result:=1;
else
v_result:=0;
end if;
else
v_yonetici:=v_tmp_yonetici;
end if;
exit when v_result=1 or v_tmp_unvan>=v_unvan;
end loop;
END CASE;
exit when v_result=1;
end loop;
return v_result;
exception
when others then
return 0;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想尝试 SwisSQL 在线迁移工具
它给出以下结果:
编辑:有关更多详细信息,请参阅 这个问题
You might want to try the SwisSQL Online migration tool
It gives the following result:
edit:for further details look into this question