declare i number;
begin
select count(1) into i from TEST_TB where id=1 and TNAME='sky';
if i=0 then
begin
insert into TEST_TB(id, tname)values(1, 'sky');
end;
end if;
end;這樣寫就是OK的。我再加個變量就出錯了declare i number;
declare j number;
begin
select count(1) into i from TEST_TB where id=1 and TNAME='sky';
if i=0 then
begin
insert into TEST_TB(id, tname)values(1, 'sky');
end;
else
j:=2;
end if;
end;Error report:
ORA-06550: line 2, column 1:
PLS-00103: Encountered the symbol "DECLARE" when expecting one of the following: begin function package pragma procedure subtype type use <ID>
<外加雙引號的分界 ID> form current cursor
The symbol "begin" was substituted for "DECLARE" to continue.
ORA-06550: line 12, column 4:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with <ID>
<外加雙引號的分界 ID>
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
i NUMBER;
j NUMBER;
BEGIN
SELECT COUNT (1)
INTO i
FROM test_tb
WHERE ID = 1 AND tname = 'sky'; IF i = 0
THEN
BEGIN
INSERT INTO test_tb
(ID, tname
)
VALUES (1, 'sky'
);
END;
ELSE
j := 2;
END IF;
END;语句应该没问题,看看是不是用户权限不够?