postgresql - plpgsql:没有函数匹配给定的名称和参数类型。您可能需要添加显式类型转换
问题描述
我使用 DBeaver 在 PostgreSQL 中创建了一个存储过程。& 我正在尝试通过从 DBeaver 调用该过程将数据插入表中。但这给了我一个错误
SQL 错误 [42883]: 错误: 函数 public.proc_insert_test(integer, unknown, unknown, unknown, unknown, timestamp with time zone, integer, integer, integer, timestamp with time zone) 不存在 提示:没有函数与给定名称匹配和参数类型。您可能需要添加显式类型转换。职位: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$
;
调用过程:
select public.proc_insert_test(123, 'Test2', 'Test2', 'T', 'T', now(), 1, 9, 1234, now());
可能是什么问题?
我对此完全陌生。
更新:
过程调用:
select public.proc_insert_test(123, 'Test2'::varchar(100), 'Test2'::varchar(100), 'T'::char(1), 'T'::char(1), now(), 1, 9, 1234, now());
错误:
SQL 错误 [42883]:错误:函数 public.proc_insert_test(整数,字符变化,字符变化,字符,字符,带时区的时间戳,整数,整数,整数,带时区的时间戳)不存在提示:没有函数匹配给定名称和参数类型。您可能需要添加显式类型转换。职位:8
解决方案
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)
从timestamp
(now()
函数的结果类型)到date
的转换正在丢失转换。默认情况下是不允许的。所以你应该强制它(通过显式转换),或者你应该使用current_date
返回date
类型的伪常量,并且不需要任何转换。
推荐阅读
- arrays - 作为 System.Object[] 发送的 PowerShell V5 Invoke-RestMethod 数组
- php - 为什么我的模型只传递单行而不是所有行?
- ios - 如何使用 Swift 通过单击完成按钮来关闭以前和当前的视图控制器
- python - 如何将 2D numpy 数组的 2D numpy 数组重组为 4D 浮点数组?
- reactjs - Heroku上传反应应用程序显示无法访问'/app/build/static/js/*.js':没有这样的文件或目录
- postgresql - 在 aws 的 rds 上,您可以为数据库 (postgresql) 安排任务吗?
- jdeveloper - How to integrated Lombok library and JDeveloper IDE
- python-3.x - Error while concatenating keras layers: A `Concatenate` layer requires inputs with matching shapes
- r - 如果满足条件,如何在循环中更新 -lm- 的因变量
- php - How do at make my standalone file woocommerce ready so I can use the functions