一個不錯的存儲過程,用到了不少知識:
自定義table類型,遊標,異常。
這樣的存儲過程卻是能夠解決開發中的很多問題,但是問題來了....
phoneNum_message_collection := t_dept_phoneNum_message_table();
--實例對象
調用 phoneNum_message_collection
怎麼調用啊,目前來講沒有找到答案。大家羣策羣力吧!
CREATE OR REPLACE TYPE t_dept_phoneNum_message_type AS
OBJECT(
cell_phone varchar2(30) , --根據業務需要要獲取的cell_phone
號碼
message
varchar2(1000)
--組織獲取短信內容
)
create or replace type t_dept_phoneNum_message_table as table of
t_dept_phoneNum_message_type
---特別注意,上面的命令一定需要和下面的存儲過程分開執行。決不可一起執行!
create or replace procedure pro_borrow_alarm_first(phoneNum_message_collection out t_dept_phoneNum_message_table) is
cellphonenumber VARCHAR2(30);
message varchar2(1000);
sp_id_real VARCHAR2(10); --配件Id
sp_id_prefix VARCHAR2(10);
sp_id_suffix VARCHAR2(10);
startTime varchar2(100);
productNo varchar2(100);
ownername varchar2(100);
i BINARY_INTEGER := 0; --for 遍歷CUR_SP_IDS 中需要一個同步變量。 SP不是Int類型,不能用。
CURSOR CUR_SP_IDS IS --聲明顯式遊標
select id from T_BNS_SP sp where sp_state='借出' ; --查詢所有借出的工單號
SP CUR_SP_IDS%ROWTYPE; --定義遊標變量,該變量的類型爲基於遊標CUR_SP_IDS的記錄
begin
phoneNum_message_collection := t_dept_phoneNum_message_table();
--實例對象
for SP in
CUR_SP_IDS loop
sp_id_real:=
SP.id;
sp_id_prefix:= SP.id||',';
sp_id_suffix:= ','||SP.id;
BEGIN
select sm.cell_phone,sm.start_time,sm.product_no
,sm.ower_name into
cellphonenumber,startTime,productNo,ownername
from T_BNS_SP_BORROW_MAIN sm
where sm.sp_id=sp_id_real
and (sysdate - sm.start_time)>30 and rownum =
1;
EXCEPTION
WHEN no_data_found THEN
GOTO point1; --這是循環跳轉應用
END;
i:=i+1;
message := '您好:'||ownername || '請儘快歸還您在'|| startTime
||'借的備件'||productNo ;
phoneNum_message_collection.EXTEND;--如果不加執行的時候會報ORA-06533,實際上集合沒有存儲空間
--phoneNum_message_collection(i):=user_id;
phoneNum_message_collection(i) :=
t_dept_phoneNum_message_type(cellphonenumber,message);
dbms_output.put_line(cellphonenumber);
dbms_output.put_line(message);
cellphonenumber:= null;
startTime:=null;
productNo:=null;
--end if;
<<point1>>
--這是斷點設置
NULL;
end loop;
end ;
//oracle_cs =
(OracleCallableStatement)oracle_conn.prepareCall("{call
pro_borrow_alarm_first(?)}");
//oracle_cs.registerOutParameter(1,OracleTypes.JAVA_OBJECT);
//oracle_cs.registerOutParameter(1, OracleTypes.STRUCT,
"t_dept_phoneNum_message_table".toUpperCase());
//cstmt.registerOutParameter(1, OracleTypes.ARRAY,
"person_table_type.toUpperCase()");
//cstmt.execute();
//ARRAY array = oracle_cs.getARRAY(1);
//oracle_cs.registerOutParameter(1, OracleTypes.ARRAY,
"t_dept_phoneNum_message_table".toUpperCase());
//oracle_cs.execute();
//ARRAY array = (ARRAY) oracle_cs.getObject(1);
//System.out.println(array.length());
//ResultSet rs = array.getResultSet();
//
Object[] attr = struct.getAttributes();
//
STRUCT struct = (STRUCT) oracle_cs.getObject(1);
//
Object[] attr = struct.getAttributes();
//
System.out.println(struct.longValue());
以上是我亂貼的一些代碼,都是從網上找的,總結的。不過我這裏沒有測試成功,還望高手們指教