2
CREATE OR REPLACE FUNCTION "public"."GetSoilCod" (
"cod1" integer = 0,
"cod2" integer = 0,
"cod3" integer = 0,
"cod4" integer = 0,
"cod5" integer = 0,
"cod6" integer = 0,
"cod7" integer = 0
)
RETURNS varchar AS
$body$
declare result varchar;
BEGIN
result = cast($1 as varchar(2)) || '.' ||
cast($2 as varchar(2)) || '.' ||
cast($3 as varchar(2)) || '.' ||
cast($4 as varchar(2)) || '.' ||
cast($5 as varchar(2)) || '.' ||
cast($6 as varchar(2)) || '.' ||
cast($7 as varchar(2));
return trim('.0' from result);
END;
$body$
LANGUAGE 'plpgsql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100;
當我執行該功能和一個或多個代碼被劃分到10,該函數的結果是錯誤的。
例子:
SELECT * FROM "public"."GetSoilCod"(10, 0, 0, 0, 0, 0, 0);
return: 1
expected: 10
SELECT * FROM "public"."GetSoilCod"(10, 20, 0, 0, 0, 0, 0);
return: 10.2
expected: 10.20
爲什麼最後trimed 0(零)?我想如果我執行這個查詢修剪只有」 .0" (點零)
:
SELECT * FROM "public"."GetSoilCod"(10, 20, 0, 0, 0, 0, 1);
all its OK
return & expected is: 10.20.0.0.0.0.1
或:
SELECT * FROM "public"."GetSoilCod"(10, 20, 0, 0, 0, 1, 0);
一切都OK。返回&預計爲:10.20.0.0.0.1
我的錯誤在哪裏?
TNX很多,馬克! :) – Dumitru 2010-06-27 21:04:30