4
WITH Q (L) AS
(
SELECT 1 FROM DUAL
UNION ALL
SELECT L + 1
FROM Q
WHERE L < 99
)
SELECT MIN(L)
INTO next_priority
FROM Q
LEFT JOIN gxrdird on gxrdird_priority = L
and gxrdird_pidm = aPidm_in and gxrdird_ap_ind = 'Y'
WHERE L NOT IN (select gxrdird_priority
from gxrdird where gxrdird_pidm = aPidm_in);
此查詢返回手動運行時所需的結果。我試圖把它放在包過程中,但我得到:Oracle過程正在關注在過程外運行良好的select查詢
51/5 PL/SQL: SQL Statement ignored
55/22 PL/SQL: ORA-00932: inconsistent datatypes: expected NUMBER got -
對應於行「選擇L + 1」在列L是有沒有辦法申報得到爲NUMBER特別在with子句中?我一直在Google上搜索一個小時,並且我可以發現有些子句的幾個例子中有參數不會將它們聲明爲任何類型。
這使我瘋狂,沒有更簡單的查詢,我可以拿出,給了我正確的結果。
編輯,添加背景:
CURSOR xxx_cur IS
SELECT ROWID, GXRDIRD_PRIORITY
FROM GXRDIRD
WHERE GXRDIRD_PIDM = aPidm_in
AND GXRDIRD_AP_IND = 'A'
AND GXRDIRD_ATYP_CODE IS NULL
AND GXRDIRD_ADDR_SEQNO IS NULL
ORDER BY GXRDIRD_PRIORITY DESC;
xxx_rec xxx_cur%ROWTYPE;
next_priority NUMBER;
BEGIN
OPEN xxx_cur;
LOOP
FETCH xxx_cur INTO xxx_rec;
EXIT WHEN xxx_cur%NOTFOUND;
-- Here we should update that particular row, but we can't just increment it.
WITH Q (L) AS
(
SELECT 1 FROM DUAL
UNION ALL
SELECT L + 1
FROM Q
WHERE L < 99
)
SELECT MIN(L)
INTO next_priority
FROM Q
LEFT JOIN gxrdird on gxrdird_priority = L and gxrdird_pidm = aPidm_in and gxrdird_ap_ind = 'Y'
WHERE L NOT IN (select gxrdird_priority from gxrdird where gxrdird_pidm = aPidm_in);
-- The above query found the lowest-numbered unused priority, and now we'll set this record to that.
UPDATE GXRDIRD SET GXRDIRD_PRIORITY = next_priority WHERE ROWID = xxx_rec.ROWID;
-- If the above record was originally 7 and the lowest was 15, now 7 is free and will be used if we loop
-- again.
DBMS_OUTPUT.PUT_LINE(OBJECT_NAME || '.P_RESEQUENCE_INACTV_ACCNTS - Changed priority ' || xxx_rec.GXRDIRD_PRIORITY || ' into ' || next_priority);
END LOOP;
線51:帶Q(L)AS
55行:SELECT L + 1
奇數。我會認爲它會起作用。你可以嘗試使用顯式轉換...'SELECT CAST(1 as INT)as L FROM dual' *(儘管我沒有檢查Oracle語法。)* – MatBailie 2012-08-14 18:25:38
我假設你至少使用了Oracle 11.2,因爲這是遞歸子查詢介紹。你使用的是什麼網點版本(當然,這可能是一個錯誤)。是否有一個原因,你需要一個遞歸子查詢,而不是一個簡單的(R)'與Q爲(選擇水平從雙連接水平<99)'? – 2012-08-14 18:27:26
已經嘗試過,都使用to_number()和cast()。 – 2012-08-14 18:28:39