oracle procedure儲存過程輸入引數之動態sql傳入(括號及,逗號的特殊處理
--某同事說報表sql相關的儲存過程的輸入引數如傳入一個大字串報錯,真是如些嗎
---建立業務表(訂單表)所引用的訂單型別資料
SQL> create table zidian(order_type varchar2(10));
Table created
SQL> insert into zidian values('100000');
1 row inserted
SQL> insert into zidian values('100001');
1 row inserted
SQL> insert into zidian values('100002');
1 row inserted
SQL> insert into zidian values('100003');
1 row inserted
SQL> insert into zidian values('100004');
1 row inserted
SQL> commit;
Commit complete
SQL> create table zidian(order_type varchar2(10));
Table created
SQL> insert into zidian values('100000');
1 row inserted
SQL> insert into zidian values('100001');
1 row inserted
SQL> insert into zidian values('100002');
1 row inserted
SQL> insert into zidian values('100003');
1 row inserted
SQL> insert into zidian values('100004');
1 row inserted
SQL> commit;
Commit complete
--建立業務表並插入資料
SQL> create table t_order(order_id int,order_type varchar2(10));
Table created
SQL> create table t_order(order_id int,order_type varchar2(10));
Table created
SQL> insert into t_order values(1,'100000');
1 row inserted
SQL> insert into t_order values(2,'100001');
1 row inserted
SQL> insert into t_order values(3,'100002');
1 row inserted
SQL> commit;
Commit complete
SQL> select * from zidian;
ORDER_TYPE
----------
100000
100001
100002
100003
100004
SQL> select * from t_order;
ORDER_ID ORDER_TYPE
--------------------------------------- ----------
1 100000
2 100001
3 100002
SQL> ---實現filter掉order_type為100000的訂單資料
SQL> select * from t_order where order_type in ('100001','100002','100003','100004');
ORDER_ID ORDER_TYPE
--------------------------------------- ----------
2 100001
3 100002
ORDER_TYPE
----------
100000
100001
100002
100003
100004
SQL> select * from t_order;
ORDER_ID ORDER_TYPE
--------------------------------------- ----------
1 100000
2 100001
3 100002
SQL> ---實現filter掉order_type為100000的訂單資料
SQL> select * from t_order where order_type in ('100001','100002','100003','100004');
ORDER_ID ORDER_TYPE
--------------------------------------- ----------
2 100001
3 100002
---如果用儲存過程又如何實現上述功能呢
SQL> create or replace procedure proc_filter(in_filter varchar2)
2 as
3 v_sql varchar2(4000);
4 v_cnt pls_integer;
5 begin
6 v_sql:='select count(*) from t_order where order_type in'||in_filter;
7 dbms_output.put_line(v_sql);
8 execute immediate v_sql into v_cnt;
9 dbms_output.put_line(v_cnt);
10 end;
11 /
Procedure created
SQL> exec proc_filter('(''100001'',''100002'',''100003'',''100004'')');
select count(*) from t_order where order_type in('100001','100002','100003','100004')
2
PL/SQL procedure successfully completed
2 as
3 v_sql varchar2(4000);
4 v_cnt pls_integer;
5 begin
6 v_sql:='select count(*) from t_order where order_type in'||in_filter;
7 dbms_output.put_line(v_sql);
8 execute immediate v_sql into v_cnt;
9 dbms_output.put_line(v_cnt);
10 end;
11 /
Procedure created
SQL> exec proc_filter('(''100001'',''100002'',''100003'',''100004'')');
select count(*) from t_order where order_type in('100001','100002','100003','100004')
2
PL/SQL procedure successfully completed
小結;1,還是跳脫字元的使用
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-753763/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle procedure 儲存過程輸入及輸出in out示例Oracle儲存過程
- oracle儲存過程中單引號及字串拼接處理Oracle儲存過程字串
- SQL Server-儲存過程(Procedure),帶入引數和出引數SQLServer儲存過程
- oracle procedure儲存過程輸入引數用於sql like模糊匹配2演算法Oracle儲存過程SQL演算法
- Oracle帶輸入輸出引數的儲存過程Oracle儲存過程
- oracle父儲存過程呼叫子儲存過程procedure與輸出引數Oracle儲存過程
- oracle儲存過程procedure_輸入引數varchar2與char報錯Oracle儲存過程
- oracle儲存過程(procedure)中執行動態SQL小記Oracle儲存過程SQL
- C#中呼叫SQL儲存過程(帶輸入輸出引數的例子)C#SQL儲存過程
- oracle儲存過程procedure輸入引數為空_如果顯示錶列不為 null的記錄Oracle儲存過程Null
- 單引號在動態SQL中的處理SQL
- SQL 建立儲存過程PROCEDURESQL儲存過程
- 用oracle procedure儲存過程實現自表(列存在null)查詢不等於輸入引數的記錄Oracle儲存過程Null
- oracle動態sql儲存過程示例OracleSQL儲存過程
- 儲存過程單引號問題儲存過程
- 動態呼叫帶引數的儲存過程儲存過程
- PL/SQL 05 儲存過程 procedureSQL儲存過程
- 儲存過程輸入引數型別定義引起的問題儲存過程型別
- oracle儲存過程將引數字串分割sqlOracle儲存過程字串SQL
- 在sqlplus中呼叫in out輸入輸出引數的儲存過程SQL儲存過程
- MySQL入門--儲存過程(PROCEDURE)和儲存函式(FUNCTION)MySql儲存過程儲存函式Function
- MyBatis引數傳入集合之foreach動態sqlMyBatisSQL
- input禁止輸入特殊符號符號
- XML中輸入特殊符號XML符號
- 帶輸出引數的儲存過程儲存過程
- 如何在Mac上快速輸入特殊符號?Mac快速輸入特殊符號小技巧Mac符號
- [Procedure]Oracle之分頁儲存過程Oracle儲存過程
- Oracle 基礎 ----procedure(儲存過程)Oracle儲存過程
- oracle procedure plsql 動態sql之動態傳遞表OracleSQL
- 自動編號的儲存過程 (轉)儲存過程
- sqlserver 針對預處理sql傳入引數的處理方式SQLServer
- oracle procedure輸入引數為date日期小記Oracle
- Oracle Pl/SQL 之 儲存過程OracleSQL儲存過程
- 使用帶有輸出引數的儲存過程儲存過程
- 表格中輸入特殊符號和公式符號公式
- Java呼叫儲存過程(帶輸出引數)Java儲存過程
- JavaScript中圓括號()和方括號[]的一個特殊用法JavaScript
- tcbs_批量儲存過程_輸入引數為空與非空的分支編寫儲存過程