使用Oracle SQL Developer。我有以下示例工作:
DECLARE
v_next_TransId INTEGER; -- declare
BEGIN
select (max(Transaction_ID)+1) into v_next_TransId from xxpos.pos_transactions;
dbms_output.Put_line(v_next_TransId); --display
END;
现在,我想在插入和/或选择中使用该变量,我尝试使用和不使用:前缀。以下示例为我提供了ORA-01008:找不到所有变量。
DECLARE
v_next_TransId INTEGER; -- declare
BEGIN
select (max(Transaction_ID)+1) into v_next_TransId from xxpos.pos_transactions;
dbms_output.Put_line(v_next_TransId); --display
-- insert new row will go here
-- commit will go here
-- now verify the insert worked okay
--select * from xxpos.pos_transactions where Transaction_ID = ( select max(Transaction_ID) from xxpos.pos_transactions )
select * from xxpos.pos_transactions where Transaction_ID = :v_next_TransId;
END;
版本:
Oracle数据库11g企业版11.2.0.4.0版-64位生产
PL / SQL版本11.2.0.4.0-生产
答案 0 :(得分:0)
在PLSQL代码块中,必须将select语句的列分配给变量。您必须在plsql代码块中使用select into
子句,如下所示。
DECLARE
v_next_TransId INTEGER; -- declare
l_pos_transactions xxpos.pos_transactions%ROWTYPE;
BEGIN
select (max(Transaction_ID)+1) into v_next_TransId from xxpos.pos_transactions;
dbms_output.Put_line(v_next_TransId); --display
-- insert new row will go here
-- commit will go here
-- now verify the insert worked okay
--select * from xxpos.pos_transactions where Transaction_ID = ( select max(Transaction_ID) from xxpos.pos_transactions )
select * into l_pos_transactions
from xxpos.pos_transactions where Transaction_ID = :v_next_TransId;
DBMS_OUTPUT.PUT_LINE(l_pos_transactions.column1|| ',' || l_pos_transactions.column2);
END;