将Oracle code改成PB Code

追风_GaoWu 2012-06-26 11:12:37
CREATE OR REPLACE Function DCMIS.to_TwoEight(p_dec in number,p_base in number )
Return varchar2
Is
l_str varchar2(255) Default NULL;
l_num number Default p_dec;
l_hex varchar2(28) Default '0123456789BCDFGHKLMNPRTVWXYZ';

Begin
If (trunc(p_dec)<>p_dec OR p_dec<0) Then
Raise PROGRAM_ERROR;
End If;
Loop
l_str := substr(l_hex,mod(l_num,p_base)+1,1)||l_str;
l_num := trunc(l_num/p_base);
Exit When (l_num=0);
End Loop;
Return l_str;
End to_TwoEight;

...全文
110 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
DYFDWX 2012-06-27
  • 打赏
  • 举报
回复
顶一下
xuam 2012-06-26
  • 打赏
  • 举报
回复
OK了就行.
[Quote=引用 5 楼 的回复:]
结果不正确,返回空值,

把while写在后面 就返回正确的值
String l_str,l_hex
Long l_num

l_num = p_dec
l_hex = '0123456789BCDFGHKLMNPRTVWXYZ'
If (truncate(p_dec,0)<>p_dec OR p_dec<0) Then
messagebox('提示','出错')
En……
[/Quote]
追风_GaoWu 2012-06-26
  • 打赏
  • 举报
回复
结果不正确,返回空值,

把while写在后面 就返回正确的值
String l_str,l_hex
Long l_num

l_num = p_dec
l_hex = '0123456789BCDFGHKLMNPRTVWXYZ'
If (truncate(p_dec,0)<>p_dec OR p_dec<0) Then
messagebox('提示','出错')
End If


Do
l_str = mid(l_hex,mod(l_num,p_base)+1,1)+ l_str
l_num = truncate(l_num /p_base,0)
Loop While (l_num=0)

Return l_str
xuam 2012-06-26
  • 打赏
  • 举报
回复
看二楼的,通过了的,只没有检验函数效果了.
[Quote=引用 3 楼 的回复:]
PB中的truncate的Function 与Oracle中的不一样,编译不通过
[/Quote]
追风_GaoWu 2012-06-26
  • 打赏
  • 举报
回复
PB中的truncate的Function 与Oracle中的不一样,编译不通过
xuam 2012-06-26
  • 打赏
  • 举报
回复
更正一下:
$PBExportHeader$uf_to_twoeight.srf
global type uf_to_TwoEight from function_object
end type

forward prototypes
global function string uf_to_TwoEight (long p_dec,long p_base)
end prototypes

global function string uf_to_TwoEight (long p_dec,long p_base);
String l_str,l_hex
Long l_num

l_num = p_dec
l_hex = '0123456789BCDFGHKLMNPRTVWXYZ'
If (truncate(p_dec,0)<>p_dec OR p_dec<0) Then
messagebox('提示','出错')
End If


Do While (l_num=0)
l_str = mid(l_hex,mod(l_num,p_base)+1,1)+ l_str
l_num = truncate(l_num /p_base,0)
Loop

Return l_str

end function

xuam 2012-06-26
  • 打赏
  • 举报
回复
$PBExportHeader$uf_to_TwoEight.srf
global type uf_to_TwoEight from function_object
end type

forward prototypes
global function string uf_to_TwoEight (long p_dec,long p_base)
end prototypes

global function string uf_to_TwoEight (long p_dec,long p_base);
String l_str,l_hex
Long l_num
Long ll_i,ll_length

l_num = p_dec
p_base = '0123456789BCDFGHKLMNPRTVWXYZ'
If (truncate(p_dec)<>p_dec OR p_dec<0) Then
messagebox('提示','出错')
End If


Do While (l_num=0)
l_str = mid(l_hex,mod(l_num,p_base)+1,1)+ l_str
l_num = truncate(l_num /p_base)
Loop

Return ls_str

end function

没有测试,自己测试一下.

754

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧