您好,登錄后才能下訂單哦!
這篇文章主要介紹Oracle如何實現帶輸入輸出參數存儲過程,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
begin /*這里不能直接執(zhí)行select語句但可以直接執(zhí)行update、delete、insert語句*/ end里面不能接執(zhí)行select語句,聲明會話級臨時表必須有“execute immediate 'TRUNCATE TABLE 表名'
;”這一句不然其他的session無法drop(TRUNCATE TABLE 表名 必須在 ‘drop table 表名' 這一句前執(zhí)行)
create or replace procedure p_DevData(p_id IN varchar2(150),pageIndex in NUMBER,pageCount in NUMBER,totalCount in NUMBER,p_cur out sys_refcursor) AUTHID CURRENT_USER as begin declare Num_Id number; toCount NUMBER; strSql varchar2(1000); begin strSql:='insert into TEMP_ROBOT_Id select id,robot_typeid from ROBOT where ID=:p_id and IS_DEL=0 and STATUS=1'; execute immediate 'TRUNCATE TABLE TEMP_ROBOT_Id'; execute immediate 'drop table TEMP_ROBOT_Id'; execute immediate 'Create Global Temporary Table TEMP_ROBOT_Id(ro_id varchar2(150),robot_typeid number)On Commit Preserve Rows';--創(chuàng)建會話級臨時表 execute immediate strSql using p_id; execute immediate 'Commit'; execute immediate 'TRUNCATE TABLE TEMP_Dev_Table'; execute immediate 'drop table TEMP_Dev_Table '; execute immediate 'Create Global Temporary Table TEMP_Dev_Table (id varchar2(150),DEVICE_CODE varchar2(150),NAME varchar2(150))On Commit Preserve Rows';--創(chuàng)建會話級臨時表 execute immediate 'insert into TEMP_Dev_Table select distinct bai.ID,bai.DEVICE_CODE,bai.NAME from DEVICE_BASE_INFO bai WHERE bai.ROBOT_ID =(select ro_id from TEMP_ROBOT_Id) and IS_DEL=0 and STATUS=1'; execute immediate 'Commit'; execute immediate 'TRUNCATE TABLE TEMP_Dev_data_Table'; execute immediate 'drop table TEMP_Dev_data_Table '; execute immediate ' Create Global Temporary Table TEMP_Dev_data_Table (id varchar2(150),DEVICE_CODE varchar2(150), NAME varchar2(150),type_name varchar2(100),YY_NUM varchar2(10),MM_NUM varchar2(10),Day_NUM varchar2(10), HH_NUM varchar2(10) )On Commit Preserve Rows';--創(chuàng)建會話級臨時表 select Count(1) Into toCount from TEMP_ROBOT_Id; if toCount>0 then select robot_typeid Into Num_Id from TEMP_ROBOT_Id; if Num_Id=1 then dbms_output.put_line('視頻沒有數據'); elsif Num_Id=2 then dbms_output.put_line('井蓋數據不通'); elsif Num_Id=3 then execute immediate 'TRUNCATE TABLE TEMP_SMOKE_ALARM_INFO'; execute immediate 'drop table TEMP_SMOKE_ALARM_INFO '; execute immediate 'CREATE GLOBAL TEMPORARY table TEMP_SMOKE_ALARM_INFO ON COMMIT Preserve ROWS as select * from SMOKE_ALARM_INFO';--創(chuàng)建會話級臨時表 execute immediate 'Commit'; insert into TEMP_Dev_data_Table select t.ID,t.DEVICE_CODE,t.NAME,t.type_name,t.YY_NUM,t.MM_NUM,t.Day_NUM,t.HH_NUM from ( select tab.ID,tab.NAME,tab.DEVICE_CODE,'煙感報警'as type_name, (select count(s.DEVICE_BASE_INFOID) HH_NUM from TEMP_SMOKE_ALARM_INFO s where s.DEVICE_BASE_INFOID=tab.ID group by to_char(s.CREATE_DATE,'YYYY'),s.DEVICE_BASE_INFOID) as YY_NUM from TEMP_Dev_Table tab)t where t.yy_num is not null; Commit; elsif Num_Id=4 then dbms_output.put_line('未知類型'); elsif Num_Id=5 then dbms_output.put_line('未知類型'); else dbms_output.put_line('未知類型'); end if; end if; end; if totalCount<=0 then open p_cur for select * from ( select row_.*, rownum rownum_ from ( select t.* from TEMP_Dev_data_Table t order by t.id desc ) row_ where rownum <=case when pageCount <> 0 then pageCount*1 else rownum end /*每頁顯示多少條*頁數*/ ) where rownum_>=case when pageCount <> 0 then /*(頁數-1)=0 說明為第一頁則(頁數-1)*每頁顯示多少條否則(頁數-1)*每頁顯示多少條+1*/ case when (pageIndex-1)=0 then ((pageIndex-1)*1) else (((pageIndex-1)*pageCount)+1) end else rownum_ end; /*(頁數-1)*每頁顯示多少條+1*/ else open p_cur for select Count(1) as totalCount from TEMP_Dev_data_Table; end if; end p_DevData;
以上是“Oracle如何實現帶輸入輸出參數存儲過程”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業(yè)資訊頻道!
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。