似乎我的过程不接受我要插入到客户表中的值。但为什么? 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;
答案 0 :(得分:2)
该值为null:我认为您忘记了将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;
尝试进行SET v_cust_id = p_cust_id::int;
或类似操作将varchar转换为大数值,并为v_cust_num赋予一个值?
或者如蒂姆所说,直接将其作为p_cust_id传递,让Postgres找出转换。
或者使p_cust_id与表中列的类型匹配并一起摆脱v_cust_id
答案 1 :(得分:0)
我认为这里的问题是您要传递from c in northwindEntities.Categories
join p in northwindEntities.Products on c.CategoryID equals p.CategoryID
group c by c.CategoryName into Category
select new { CategoryName = Category.Key, Products = Category.ToList() };
作为v_cust_id
列值,但是此值在任何地方都没有定义。我看不出您为什么不仅仅使用cust_id
子句中的所有输入的任何原因:
VALUES
答案 2 :(得分:0)
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 values (p_cust_id, P_First_name, P_Last_name, P_passwd);
Commit;
end;
答案 3 :(得分:0)
未为“插入操作”设置变量v_cust_id,但定义了为什么获得空值的原因。 您确定要执行的操作是将p_cust_id插入客户表,以便 相反:
insert into Customer (cust_id, first_name, last_name, passwd)
values (v_cust_id, P_First_name, P_Last_name, P_passwd);
重写插入内容:
insert into Customer (cust_id, first_name, last_name, passwd)
values (P_cust_id, P_First_name, P_Last_name, P_passwd);
功能将是:
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 (P_cust_id, P_First_name, P_Last_name, P_passwd);
Commit;
end;
答案 4 :(得分:-1)
-没有使用此变量-'v_cust_id number(6)'; -创建过程为-
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
BEGIN
INSERT INTO Customer (cust_id, first_name, last_name, passwd)
VALUES (p_cust_id, p_first_name, P_last_name, P_passwd);
COMMIT;
END;