sql只能呼叫帶有輸入引數,不能帶有輸出,輸入輸出函式。
sql不能使用pl/sql的特有資料型別(boolean,table,record等)。
sql語句中呼叫的函式不能包含insert,update和delete語句。
--定義行型別
create or replace type t_operation as object(operation_no number (2));
--以行型別定義乙個表型別
create or replace type t_operation_table is table of t_operation;
--事務性臨時表
create global temporary table operation_table
(patient_id varchar2(16),visit_id number(4),operating_date date,operating_end_date date,operation_no number(2))
on commit preserve rows;
-----示例一
create or replace function ret_emp_sal(v_ename varchar2)
return t_operation_table pipelined
asv_recode t_operation;
begin
for item in (select operation_no from operation)
loop
v_recode:=t_operation(item.operation_no);
pipe row(v_recode);
end loop;
return;
end ret_emp_sal;
-----示例二
create or replace function ret_emp_sal(starttime date, endtime date)
return t_operation_table pipelined
asv_recode t_operation;
begin
insert into operation_table
select distinct o.patient_id,
o.visit_id,
o.operating_date,
o.operating_end_date,
o.operation_no
from pat_visit t, operation o
where t.patient_id = o.patient_id
and t.visit_id = o.visit_id
and o.operation_type = '0'
and t.discharge_date_time >= starttime
and t.discharge_date_time <= endtime;
commit;
for item in (select operation_no from operation)
loop
v_recode:=t_operation(item.operation_no);
pipe row(v_recode);
end loop;
return;
end ret_emp_sal;
-----示例三
create or replace function f_get_operation(starttime date, endtime date)
return t_operation_table --返回表
pipelined as --管道函式
pragma autonomous_transaction; --自治事務
v_recode t_operation; --行型別
begin
--事務性臨時表插入資料
insert into operation_table
select distinct o.patient_id,
o.visit_id,
o.operating_date,
o.operating_end_date,
o.operation_no
from pat_visit t, operation o
where t.patient_id = o.patient_id
and t.visit_id = o.visit_id
and o.operation_type = '0'
and t.discharge_date_time >= starttime
and t.discharge_date_time <= endtime;
for item in (select patient_id, visit_id
from operation_table
group by patient_id, visit_id) loop
declare --定義引數
i number :=0;
starttime date;
endtime date;
begin
for sub in (select * from operation_table where patient_id = item.patient_id and visit_id = item.visit_id order by operating_date)
loop
if i < 1 then starttime := sub.operating_date; endtime := sub.operating_end_date; v_recode := t_operation(sub.operation_no);
else
if endtime < sub.operating_date then starttime := sub.operating_date; endtime := sub.operating_end_date;
v_recode := t_operation(sub.operation_no);
else continue;
end if;
end if;
end loop;
pipe row(v_recode);
end;
end loop;
commit;
return;
end f_get_operation;
Oracle降低HWM的集中方法
轉 url high water mark hwm 指的是當我們建立乙個segment的時候,在segment內的乙個指標,界定了segment 內曾經配置過的block水位。剛建立segment時尚未insert資料,hwm通常在segment header附近,當你不斷地insert資料使用了更...
Java中方法引數的使用
基本型別的引數完成的是值的拷貝,改變的只是引數的值,並不會改變方法外面變數的值,下面輸出結果還是0 public static void changea int a public static void main string args person為物件引用作為引數,引數拷貝的是這個物件的引用,形...
OC中方法與函式的區別
方法 方法是objective c獨有的一種結構,只能在objective c中宣告 定義和使用,c語言不能宣告 定義和使用。1 類方法以 號開頭,物件方法以 號開頭 void init 類方法 void show 物件方法 2 在 inte ce和 end之間宣告,在 implementation...