再会,
我有一个如下的 PL-SQL 查询。我正在尝试执行查询并将结果存储到变量中。到目前为止,我有这个有效的查询:
SELECT DECODE(COUNT(*), 0, 'N', 'Y') REC_EXISTS
FROM
(SELECT
COUNT(*) AS TOTAL_COUNT
FROM DEV.BASEOBJECT INNER JOIN
DEV.ANIMAL ON DEV.BASEOBJECT.ID = DEV.ANIMAL.BASEOBJECT_ID
GROUP BY DEV.BASEOBJECT.ID,
DEV.BASEOBJECT.FIRST_NAME,
DEV.BASEOBJECT.LAST_NAME,
DEV.BASEOBJECT.CITY,
DEV.BASEOBJECT.STATE,
DEV.BASEOBJECT.ZIP,
DEV.ANIMAL.ID,
DEV.ANIMAL.NAME,
DEV.ANIMAL.BREED,
DEV.ANIMAL.DATE_OF_BIRTH,
DEV.ANIMAL.GENDER,
DEV.ANIMAL.SPECIES
HAVING (COUNT(*) > 1));
但是,当我尝试使用此查询将结果保存到变量中时:
DECLARE
v_name VARCHAR2(2);
BEGIN
SELECT DECODE(COUNT(*), 0, 'N', 'Y') REC_EXISTS
INTO v_name
FROM
(SELECT
COUNT(*) AS TOTAL_COUNT
FROM DEV.BASEOBJECT INNER JOIN
DEV.ANIMAL ON DEV.BASEOBJECT.ID = DEV.ANIMAL.BASEOBJECT_ID
GROUP BY DEV.BASEOBJECT.ID,
DEV.BASEOBJECT.FIRST_NAME,
DEV.BASEOBJECT.LAST_NAME,
DEV.BASEOBJECT.CITY,
DEV.BASEOBJECT.STATE,
DEV.BASEOBJECT.ZIP,
DEV.ANIMAL.ID,
DEV.ANIMAL.NAME,
DEV.ANIMAL.BREED,
DEV.ANIMAL.DATE_OF_BIRTH,
DEV.ANIMAL.GENDER,
DEV.ANIMAL.SPECIES
HAVING (COUNT(*) > 1));
END
我收到一个错误:
ERROR
ORA-06550: line 1, column 8:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin function package pragma procedure subtype type use
<an identifier> <a double-quoted delimited-identifier> form
current cursor
The symbol "" was ignored.
最终,这将是一个存储过程,但我还没有准备好那部分,因为我想验证我所拥有的到目前为止是否有效。
TIA,
科森