Oracle 如何将NEXTVAL纳入我的程序?
我有以下程序Oracle 如何将NEXTVAL纳入我的程序?,oracle,procedures,Oracle,Procedures,我有以下程序 create or replace procedure prod_add_sp (p_idproduct in bb_product.idproduct%type, p_prodname in bb_product.productname%type, p_descrip in bb_product.description%type, p_prodimage in bb_product.productimage%type, p_prodpr
create or replace
procedure prod_add_sp
(p_idproduct in bb_product.idproduct%type,
p_prodname in bb_product.productname%type,
p_descrip in bb_product.description%type,
p_prodimage in bb_product.productimage%type,
p_prodprice in bb_product.price%type,
p_prodactive in bb_product.active%type)
is
begin
insert into bb_product(idproduct,productname,description,productimage,price,active)
values (p_idproduct,p_prodname,p_descrip,p_prodimage,p_prodprice,p_prodactive);
commit;
end;
如何使用
seq.nextval
部分修改上述内容,以便在执行时插入具有唯一主键的新行IDPRODUCT
是一个主键,因此它是必需的。您必须首先创建序列。然后可以在idproduct列中使用sequencename.nextval
create or replace procedure prod_add_sp (p_idproduct in bb_product.idproduct%type, p_prodname in bb_product.productname%type, p_descrip in bb_product.description%type, p_prodimage in bb_product.productimage%type, p_prodprice in bb_product.price%type, p_prodactive in bb_product.active%type) is
begin
insert into bb_product(idproduct,productname,description,
productimage,price,active)
values (nextID.nextVal,p_prodname,p_descrip,
p_prodimage,p_prodprice,p_prodactive);
commit;
end;
您需要先创建一个序列,即:
CREATE SEQUENCE productsID_seq
START WITH 0
INCREMENT BY 1
NOMAXVALUE;
然后在值(…
行中:
insert into bb_product(idproduct,productname,description,productimage,price,active)
values (productsID_seq.nextval,...
这里有一些来自的好信息,我已经有一个存档了。只是必须回去检查我的物品。谢谢山姆,这里还是新的,所以我真的不知道怎么做