日期:2014-05-17  浏览次数:20918 次

怎么把select出的参数 传入到下一个sql语句中?

BEGIN
newId INTEGER
select Base_ID.nextval INTO newId from dual;

insert into Base(ID) values(newId);

END


但是报错

[Err] 
PLS-00103: Encountered the symbol "INTEGER" when expecting one of the following:

   := . ( @ % ;
The symbol "; was inserted before "INTEGER" to continue.

PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:

   ; <an identifier> <a double-quoted delimited-identifier>
The symbol ";" was substituted for "end-of-file" to continue.

------解决方案--------------------
declare
  newId number(18);
BEGIN

select Base_ID.nextval INTO newId from dual;
 
insert into Base(ID) values(newId);
 
END;

PL/SQL所有变量必须声明在declare和begin之间,和T-SQL不一样。
------解决方案--------------------
引用:
Quote: 引用:

declare
  newId number(18);
BEGIN

select Base_ID.nextval INTO newId from dual;
 
insert into Base(ID) values(newId);
 
END;

PL/SQL所有变量必须声明在declare和begin之间,和T-SQL不一样。



可以了!  再问一下,number(18),18是什么意思,oracle里声明number要限制长度?


18表示变量长度,PL/SQL中变量是需要有类型和长度的。
------解决方案--------------------
写的数据块就有问日,变量的声明是放在declare里面的,在begin之前的