標籤:
declare
--類型定義
strsql string(500);
v_ErrorCode NUMBER; -- Variable to hold the error message code
v_ErrorText VARCHAR2(200); -- Variable to hold the error message text
cursor c_eventstate
is
Select CampaignId,phonenumber,PolicyNumber from mkt_eventstate a where synstate =0 and packagestate = 2 and errorcode = 6;
--定義一個遊標變數v_cinfo c_emp%ROWTYPE ,該類型為遊標c_emp中的一行資料類型
c_row c_eventstate%rowtype;
begin
for c_row in c_eventstate loop
begin
strsql:=‘select * from mkt_userprizeinfo t where t.campaignid=‘||c_row.CampaignId||‘ and t.userid=‘||c_row.phonenumber||‘ and t.PolicyNumber=‘‘‘||c_row.PolicyNumber||‘‘‘‘;
execute immediate strsql ;
dbms_output.put_line(c_row.CampaignId||‘-‘||c_row.phonenumber||‘-‘||c_row.PolicyNumber);
-- RAISE_APPLICATION_ERROR(-20001,‘數值不能為0‘);
EXCEPTION
--捕捉異常
WHEN others THEN
begin
v_ErrorCode := SQLCODE;
v_ErrorText := SUBSTR(SQLERRM, 1, 200);
DBMS_OUTPUT.put_line(‘捕獲了錯誤begin‘);
dbms_output.put_line(c_row.CampaignId||‘-‘||c_row.phonenumber||‘-‘||c_row.PolicyNumber||‘-‘||v_ErrorCode || ‘::‘||v_ErrorText);
DBMS_OUTPUT.put_line(‘捕獲了錯誤end‘);
end;
end;
end loop;
end;
oracle 遊標迴圈, 查詢,異常捕獲,繼續執行