0

如何从此 Delphi 函数编写等效的 PL/SQL 函数:

Function TConvert.MGRS(lat : Double; Lon : Double; a : Double; 
         InverseFlattening : Double; Coding:Integer; Digits : Integer) : String ;
var
 UTMs1 : String;
 E1 : Double;
 N1 : Double;
 Zn : Integer;
 Lzn : String;
 Sq : String;
begin
 UTMs1 := UTM(lat, Lon, a, InverseFlattening) ;
 E1 := UTMX(UTMs1);
 N1 := UTMY(UTMs1);
 Zn := UTMZone(lat, Lon);
 Lzn := MGRSLatZone(lat);
 Sq := SquareID(Zn, N1, E1, Coding);
 Result := Format('%.2d', [Zn] )  + Lzn + Sq +
     Copy(Format('%.5d',[Round(E1 - 100000 * Trunc(E1 / 100000))]), 1, Digits) +
     Copy(Format('%.5d',[Round(N1 - 100000 * Trunc(N1 / 100000))]), 1, Digits);
end;

MGRS(0, 0, 6378.137, 298.2572236, 1, 5) = 31NAA6602100000

4

1 回答 1

4

不确定整个代码是否可以转换为本地 Oracle 调用,但关于字符串格式化的初始问题,结果代码可能如下所示:

create or replace function MyFunction(
  Zn     in number,
  Lzn    in varchar2,
  Sq     in varchar2,
  E1     in number,
  N1     in number,
  Digits in number
) 
return varchar2
as
  vRes varchar2(4000);
begin

  vRes := trim(to_char(Zn,'999999999999999999.00')) || LZn || Sq || 
          substr(trim(to_char(round(E1 - 100000 * trunc(E1/100000)),'999999999999999999.00000')), 1, Digits) || 
          substr(trim(to_char(round(N1 - 100000 * trunc(N1/100000)),'999999999999999999.00000')), 1, Digits) 
  ;

  return vRes;

end;

SQLFiddle test

Oracle 格式模型

TO_CHAR()

TRUNC()

修剪()

谷歌;)

于 2013-09-12T11:54:10.803 回答