Oracle EXECUTE IMMEDIATE語句裡面的引號處理
例子中的語句使用動態SQL建立了一個儲存過程
將單引號 ' 改寫為兩個單引號 ''
BEGIN
EXECUTE IMMEDIATE 'create or replace PROCEDURE SMDP_CLEAN_SUBSCRIPTIONS AS
CURSOR subscriptions_cur
IS
SELECT * FROM SMDP_SUBSCRIPTIONS where N_STATUS = 5;
TYPE subscriptions_aat IS TABLE OF subscriptions_cur%ROWTYPE
INDEX BY PLS_INTEGER;
l_subscriptions subscriptions_aat;
limit_in Number(10,0);
STATUS_LOADED integer :=3;
STATUS_ERROR integer :=4;
STATUS_GARBAGE integer :=5;
CURSOR CUR_SUB is
-- ALL subscriptions with status LOADED (=> check if their profile are still in DEMO mode)
select s.N_SUBSCRIPTION_ID, s.N_STATUS, p.C_MNO_TRIGRAM, p.C_PROFILE_ID
from SMDP_SUBSCRIPTIONS s, SMDP_SUBSCRIPTION_PROFILES p where (s.N_STATUS=STATUS_LOADED or s.N_STATUS=STATUS_ERROR) and p.N_SUBSCRIPTIONPROFILE_ID=s.N_SUBSCRIPTIONPROFILE_ID;
TYPE res_table IS TABLE OF CUR_SUB%ROWTYPE;
res res_table;
oaps_param varchar2(40);
oaps_value varchar2(40);
BEGIN
OPEN CUR_SUB;
FETCH CUR_SUB BULK COLLECT INTO res;
FOR indx IN 1 .. res.COUNT LOOP
oaps_param:=''profile.''||res(indx).C_MNO_TRIGRAM||''.''||res(indx).C_PROFILE_ID||''.mode'';
dbms_output.put_line(''id=''||res(indx).N_SUBSCRIPTION_ID||'' status=''||res(indx).N_STATUS||'' oaps=''||oaps_param);
-- Get OAPS parameter associated with its profile
begin
oaps_value := ''PROD'';
select UPPER(C_PARAM_VALUE) into oaps_value from OAPS_PARAMETERS where C_PRODUCT_TYPE=''SMDP'' and C_PARAM_NAME=oaps_param;
dbms_output.put_line(''FlagMode=''||oaps_value);
-- if no param found, (PROD, DEMO or PROD_RETRY??), do nothing...
exception when NO_DATA_FOUND then null;
end;
-- if subscription is as LOADED and not in demo mode then set the status to READY_TO_GARBAGE
IF oaps_value <> ''DEMO'' THEN
update SMDP_SUBSCRIPTIONS set N_STATUS=STATUS_GARBAGE where SMDP_SUBSCRIPTIONS.N_SUBSCRIPTION_ID=res(indx).N_SUBSCRIPTION_ID;
dbms_output.put_line(''Set to GARBAGE'');
END IF;
end loop;
CLOSE CUR_SUB;
limit_in := 1000;
OPEN subscriptions_cur;
LOOP
FETCH subscriptions_cur
BULK COLLECT INTO l_subscriptions LIMIT limit_in;
FORALL indx IN 1 .. l_subscriptions.COUNT
delete from SMDP_SUBSCRIPTIONS where N_SUBSCRIPTION_ID = l_subscriptions(indx).N_SUBSCRIPTION_ID;
commit;
FORALL indxDiversified IN 1 .. l_subscriptions.COUNT
delete from SMDP_DIVERSIFIED_SCRIPTS where N_SUBSCRIPTION_ID = l_subscriptions(indxDiversified).N_SUBSCRIPTION_ID;
commit;
EXIT WHEN l_subscriptions.COUNT < limit_in;
END LOOP;
CLOSE subscriptions_cur;
END SMDP_CLEAN_SUBSCRIPTIONS;';
END;
將單引號 ' 改寫為兩個單引號 ''
BEGIN
EXECUTE IMMEDIATE 'create or replace PROCEDURE SMDP_CLEAN_SUBSCRIPTIONS AS
CURSOR subscriptions_cur
IS
SELECT * FROM SMDP_SUBSCRIPTIONS where N_STATUS = 5;
TYPE subscriptions_aat IS TABLE OF subscriptions_cur%ROWTYPE
INDEX BY PLS_INTEGER;
l_subscriptions subscriptions_aat;
limit_in Number(10,0);
STATUS_LOADED integer :=3;
STATUS_ERROR integer :=4;
STATUS_GARBAGE integer :=5;
CURSOR CUR_SUB is
-- ALL subscriptions with status LOADED (=> check if their profile are still in DEMO mode)
select s.N_SUBSCRIPTION_ID, s.N_STATUS, p.C_MNO_TRIGRAM, p.C_PROFILE_ID
from SMDP_SUBSCRIPTIONS s, SMDP_SUBSCRIPTION_PROFILES p where (s.N_STATUS=STATUS_LOADED or s.N_STATUS=STATUS_ERROR) and p.N_SUBSCRIPTIONPROFILE_ID=s.N_SUBSCRIPTIONPROFILE_ID;
TYPE res_table IS TABLE OF CUR_SUB%ROWTYPE;
res res_table;
oaps_param varchar2(40);
oaps_value varchar2(40);
BEGIN
OPEN CUR_SUB;
FETCH CUR_SUB BULK COLLECT INTO res;
FOR indx IN 1 .. res.COUNT LOOP
oaps_param:=''profile.''||res(indx).C_MNO_TRIGRAM||''.''||res(indx).C_PROFILE_ID||''.mode'';
dbms_output.put_line(''id=''||res(indx).N_SUBSCRIPTION_ID||'' status=''||res(indx).N_STATUS||'' oaps=''||oaps_param);
-- Get OAPS parameter associated with its profile
begin
oaps_value := ''PROD'';
select UPPER(C_PARAM_VALUE) into oaps_value from OAPS_PARAMETERS where C_PRODUCT_TYPE=''SMDP'' and C_PARAM_NAME=oaps_param;
dbms_output.put_line(''FlagMode=''||oaps_value);
-- if no param found, (PROD, DEMO or PROD_RETRY??), do nothing...
exception when NO_DATA_FOUND then null;
end;
-- if subscription is as LOADED and not in demo mode then set the status to READY_TO_GARBAGE
IF oaps_value <> ''DEMO'' THEN
update SMDP_SUBSCRIPTIONS set N_STATUS=STATUS_GARBAGE where SMDP_SUBSCRIPTIONS.N_SUBSCRIPTION_ID=res(indx).N_SUBSCRIPTION_ID;
dbms_output.put_line(''Set to GARBAGE'');
END IF;
end loop;
CLOSE CUR_SUB;
limit_in := 1000;
OPEN subscriptions_cur;
LOOP
FETCH subscriptions_cur
BULK COLLECT INTO l_subscriptions LIMIT limit_in;
FORALL indx IN 1 .. l_subscriptions.COUNT
delete from SMDP_SUBSCRIPTIONS where N_SUBSCRIPTION_ID = l_subscriptions(indx).N_SUBSCRIPTION_ID;
commit;
FORALL indxDiversified IN 1 .. l_subscriptions.COUNT
delete from SMDP_DIVERSIFIED_SCRIPTS where N_SUBSCRIPTION_ID = l_subscriptions(indxDiversified).N_SUBSCRIPTION_ID;
commit;
EXIT WHEN l_subscriptions.COUNT < limit_in;
END LOOP;
CLOSE subscriptions_cur;
END SMDP_CLEAN_SUBSCRIPTIONS;';
END;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2132167/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle動態執行語句(Execute Immediate)Oracle
- 處理sqlcommand裡面的引數SQL
- execute immediate 語法小結
- MySQL 預處理語句prepare、execute、deallocate的使用MySql
- execute immediate的簡單用法(oracle)Oracle
- TSM裡面的sql語句(轉)SQL
- PL/SQL 中 execute immediate,select 語句沒有into 執行未報錯SQL
- 複習execute immediate動態sql語法SQL
- 【轉義】使用SQL生成SQL語句時單引號的轉義處理SQL
- EXECUTE IMMEDIATE dynamic sql in procedureSQL
- ORACLE 查詢語句處理過程(Oracle
- oracle動態sql語句處理(轉)OracleSQL
- PLSQL Language Referenc-PL/SQL動態SQL-本地動態SQL(EXECUTE IMMEDIATE語句)SQL
- oracle 裡的單引號與雙引號Oracle
- 引號的處理方式
- 通過xml處理sql語句時對小於號與大於號的處理轉換XMLSQL
- 【轉義】使用SQL生成SQL語句時單引號的轉義處理之q'{}'方法SQL
- EXECUTE IMMEDIATE 呼叫動態過程
- EXECUTE IMMEDIATE 儲存過程中 許可權不足及EXECUTE IMMEDIATE的除錯避坑儲存過程除錯
- 訊號處理基本引數
- Oracle一個SQL語句的處理過程(轉)OracleSQL
- DML 語句處理過程
- 批處理刪除語句
- 儲存過程中慎用 execute immediate儲存過程
- Oracle釋出一個SQL語句的處理過程OracleSQL
- oracle execute immediate動態sql組合執行comment小記OracleSQL
- 字串中包含單引號和雙引號怎麼處理字串
- SQL語句的處理過程SQL
- 動態 SQL、EXECUTE IMMEDIATE、using、into、returningSQL
- EXECUTE IMMEDIATE動態SQL的使用總結SQL
- MySQL 5.7 PREPARE、EXECUTE、DEALLOCATE語句介紹MySql
- oracle儲存過程中單引號及字串拼接處理Oracle儲存過程字串
- mysql常用語句及問題處理MySql
- SQL語句的處理過程修正SQL
- MySQL 遊標(PREPARE預處理語句)MySql
- 在ORACLE SQL語句中,單引號和雙引號的使用OracleSQL
- mysql開發-動態語句編寫-引號使用MySql
- 使用預處理PreparedStatement執行Sql語句SQL