Shr*_*kar 8 sql database postgresql plpgsql
我使用 DBeaver 在 PostgreSQL 中创建了一个函数。& 我正在尝试通过调用 DBeaver 中的函数将数据插入表中。但这给了我一个错误:
SQL错误[42883]:错误:函数public.proc_insert_test(整数,未知,未知,未知,未知,带时区的时间戳,整数,整数,整数,带时区的时间戳)不存在提示:没有函数与给定名称匹配和参数类型。您可能需要添加显式类型转换。位置:8
功能:
CREATE OR REPLACE FUNCTION public.proc_insert_test(
p_brndcode integer, p_brndname varchar(100), p_brndsname varchar(100),
p_prdtype char(1), p_discontinue char(1), p_crddate date,
p_status integer, p_recstat integer, p_brndgrpseqno integer,
p_wefrom date)
RETURNS char
LANGUAGE plpgsql
AS $body$
BEGIN
Insert into arc_mmstbrndgroup(brndcode, brndname, brndsname, prdtype, discontinue, crddate, status, recstat, brndgrpseqno, wefrom)
values(p_brndcode, p_brndname, p_brndsname, p_prdtype, p_discontinue, p_crddate, p_status, p_recstat, p_brndgrpseqno, p_wefrom);
END;
$body$
;
Run Code Online (Sandbox Code Playgroud)
调用函数:
select public.proc_insert_test(123, 'Test2', 'Test2', 'T', 'T', now(), 1, 9, 1234, now());
Run Code Online (Sandbox Code Playgroud)
可能是什么问题?
我对此完全陌生。
Postgres 不允许从timestamp到date数据类型的隐式转换。注意 - Postgresdate类型与 Oracle 类型不同date。
CREATE OR REPLACE FUNCTION public.test(v date)
RETURNS void
LANGUAGE plpgsql
AS $function$
BEGIN
RAISE NOTICE '%', v;
END;
$function$
postgres=# SELECT test(now());
ERROR: function test(timestamp with time zone) does not exist
LINE 1: SELECT test(now());
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
postgres=# SELECT test(current_date);
NOTICE: 2019-11-14
+------+
| test |
+------+
| |
+------+
(1 row)
postgres=# SELECT test(now()::date);
NOTICE: 2019-11-14
+------+
| test |
+------+
| |
+------+
(1 row)
Run Code Online (Sandbox Code Playgroud)
timestamp从(函数的结果类型now())到的转换date正在丢失转换。默认情况下是不允许的。因此,您应该强制执行它(通过显式转换),或者您应该使用current_date返回date类型的伪常量,并且不需要任何转换。
| 归档时间: |
|
| 查看次数: |
45657 次 |
| 最近记录: |