我編寫了一個包含if..else if..end的過程,如下所示。 雖然編譯它引發錯誤作爲If..else在Oracle中不工作
錯誤(103,8):PLS-00103:出現符號 「LOOP」 期待當下列中的一個:如果 錯誤(113,4):PLS-00103 :出現符號「檔案結尾」期待之一時,以下:到底要不要編譯最終實例化爲了重寫靜態成員的構造圖
我無法找到錯誤的原因,因爲我認爲我有正確關閉所有IF。任何人都可以請求幫助。以下是我的整個過程
CREATE OR REPLACE PROCEDURE proc_ntitems_update
AS
CURSOR cur_systeminfo
IS
SELECT location,
childseq,
btproduct,
product,
questionid
FROM systeminfo;
vproduct tblsysteminfo_products.product%TYPE;
vquestionid tblsysteminfo_products.questionid%TYPE;
vlocation systeminfo.location%TYPE;
vchildseq systeminfo.childseq%TYPE;
verror VARCHAR2 (200);
consrgsitename VARCHAR2 (100);
consrgsite VARCHAR2 (100);
conmgsitename VARCHAR2 (100);
intname NUMBER;
vsicount NUMBER;
BEGIN
OPEN cur_systeminfo;
LOOP
FETCH cur_systeminfo
INTO vlocation, vchildseq, vbtproduct, vproduct, vquestionid;
EXIT WHEN cur_systeminfo%NOTFOUND;
IF INSTR (vlocation, '_') > 0
THEN
vquestionid := consrgsitename;
IF SUBSTR (vlocation, 1, LENGTH (consrgsite)) = consrgsite
THEN
intname := LENGTH (consrgsite);
vquestionid := consrgsitename;
ELSE
IF SUBSTR (vlocation, 1, LENGTH (consrg50site)) = consrg50site
THEN
intname := LENGTH (consrgsite);
vquestionid := consrgsitename;
vlocation :=
vlocation
|| SUBSTR (vlocation, intname + 1, LENGTH (vlocation));
--Check if this item is for a DATA site. These have a Location of locations_data_n where n is the site number.
ELSE
IF LOWER (SUBSTR (vlocation, 1, 14)) = 'locations_data'
THEN
vsitename := 'Yes';
vquestionid := 'txtLocationName';
ELSE
IF LOWER (SUBSTR (vlocation, 1, 14)) = 'locations_data'
AND vchildseq = '0'
THEN
BEGIN
SELECT COUNT (location)
INTO vsicount
FROM systeminfo
WHERE LOWER (vlocation) = 'locations_1';
EXCEPTION
WHEN nodatafound
THEN
verror :=
' proc_ntitems_update '
|| SUBSTR (
TO_CHAR (SQLCODE) || ' - ' || SQLERRM,
1,
480);
WHEN OTHERS
THEN
verror :=
' proc_ntitems_update '
|| SUBSTR (
TO_CHAR (SQLCODE) || ' - ' || SQLERRM,
1,
480);
END;
IF vsicount = 0
THEN
vsitename := 'No';
intname := LENGTH (vlocation);
vquestionid := 'txtLocationName';
END IF;
ELSE
IF LOWER (SUBSTR (vlocation, 1, 14)) =
'locations_data'
AND vchildseq > '0'
THEN
vquestionid := 'txtLocationName';
ELSE
IF LOWER (SUBSTR (vlocation, 1, 5)) = 'ripe_'
THEN
vremotesitenumber :=
SUBSTR (
vlocation,
-1,
(LENGTH (vloaction) - INSTR (vlocation, '_')));
vproduct := 'MMRemote';
vquestionid := 'cboRemoteType' || vremotesitenumber;
vsitename := vecvalue || ' ' || vremotesitenumber;
ELSE
IF LOWER (
SUBSTR (vlocation,
1,
LENGTH (conmerchandisesite))) =
conmerchandisesite
THEN
vsitename := conmerchandisesite;
ELSE
vsitename := btproduct;
END IF;
BEGIN
UPDATE tblntitems
SET location = vlocation,
childseq = vchildseq,
sitename = vbtproduct,
product = vproduct,
questionid = vquestionid
WHERE questionid = vquestionid;
EXCEPTION
WHEN OTHERS
THEN
verror :=
'proc_ntitems_update '
|| SUBSTR (
TO_CHAR (SQLCODE)
|| ' - '
|| SQLERRM,
1,
480);
END;
END IF;
END loop;
CLOSE cur_systeminfo;
EXCEPTION
WHEN OTHERS
THEN
verror := 'proc_ntitems_update ' || substr (to_char (sqlcode) || ' - ' || sqlerrm, 1, 480);
INSERT INTO log_import_errors VALUES ('sysdate', verror);
END;
在PL/SQL中,我們使用'elsif'而不是'else if'來表示這種邏輯。你可以使用else if,但是你開始一個新的if塊,並且每個實例都需要一個end if。 –