【发布时间】:2021-02-04 21:26:45
【问题描述】:
您好,我正在尝试使用基于一个查询结果的 PL/SQL 进行更新,存储结果并将此结果发送到更新查询但得到
ORA-06550: line 2, column 24: PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: := ( ; not null range default character
表:
create table person(id number(10),stat char(1));
insert into person(id,stat)values(123,'Y');
insert into person(id,stat)values(123,'Y');
insert into person(id,stat)values(345,'Y');
commit;
查询:
DECLARE
deptid person.id%TYPE;
BEGIN
SELECT id INTO deptid
FROM person WHERE id = 345;
IF SQL%FOUND THEN
Update person set stat='N' where id=deptid;
commit;
DBMS_OUTPUT.PUT_LINE('Dept Id: ' || deptid ||);
END IF;
END;
/
我在这里做错了什么?
【问题讨论】:
-
为什么不把整个事情包装成一个查询呢?
-
我需要从选择返回的结果。我必须将其传递给其他插入状态。不能这样更新吗?
-
我不明白
select查询的逻辑。它所能返回的只是一个或几行保存值345,您已经将其作为文字值提供给where子句。然后您使用该信息更新同一张表。为了使问题有意义,您可能需要展示一个更有意义的用例。 -
我只是举一个例子,我的第一个查询实际上返回 345 我将从一个查询中获取 id,我需要在多个更新和插入语句中使用它。只是试图保持问题尽可能小尽可能
标签: sql oracle plsql oracle11g oracle10g