sql - 该过程引发错误“无法在“CUSTOMER”中插入空值。“CUST_ID”虽然值不为空
问题描述
似乎我的程序不接受我试图插入到客户表中的值。但为什么?列有什么问题cust_id
?
BEGIN
do_new_customer('650707-1111', 'Tito', 'Ortiz', 'qwerTY');
do_new_customer('560126-1148', 'Margreth', 'Andersson', 'olle85');
do_new_customer('840317-1457', 'Mary', 'Smith', 'asdfgh');
do_new_customer('861124-4478', 'Vincent', 'Ortiz', 'qwe123');
COMMIT;
END;
这是我的程序:
create or REPLACE procedure do_new_customer
(p_cust_id in varchar2,
p_first_name in varchar2,
P_last_name in varchar2,
P_passwd in varchar2)
as
v_cust_id number(6);
begin
insert into Customer (cust_id, first_name, last_name, passwd)
values (v_cust_id, P_First_name, P_Last_name, P_passwd);
Commit;
end;
解决方案
该值为空:我想你忘记了将 p_cust_id 转换为数字并将其存储在 v_cust_id 中的步骤
create or REPLACE procedure do_new_customer
(p_cust_id in varchar2, p_first_name in varchar2, P_last_name in varchar2, P_passwd in varchar2)
as
--YOU DIDN'T SET THIS TO A VALUE SO IT'S NULL
v_cust_id number(6);
begin
insert into Customer( cust_id, first_name, last_name, passwd)
--STILL NULL WHEN YOU CAME TO USE IT
values(v_cust_id, P_First_name,P_Last_name,P_passwd);
Commit;
end;
尝试 putSET v_cust_id = p_cust_id::int;
或类似操作将 varchar 转换为大数字,并给 v_cust_num 一个值?
或者如 Tim 所说,直接将其作为 p_cust_id 传递,让 Postgres 算出转换。
或者使 p_cust_id 匹配表中列的类型,并一起摆脱 v_cust_id
推荐阅读
- mongodb - mongodb 聚合 addFields 查询(在 kotlin + 缝合中) - 多个文档一起不起作用
- arrays - 如何在 F# 中均匀分布范围内的数字
- wordpress - 创建变体不会将数据添加到 wp_term_relationships
- c# - 将 IList 对象转换为 List
- vb.net - 比较富文本框时如何提取整个 XML 标记?
- c# - 如何检查所有文本框是否已填充?
- r - R:在函数中使用聚合,不起作用
- sql-server - 如何获得日期和时间的差异以及日期的总和?
- c# - c# - 添加附件到 Discord Webhook 消息
- sql - 在 biq 查询中将字符串转换为表列