1.建立實體表及初始化資料
create table presidents(
id number(10) not null,
name varchar(32) not null,
birthdate date not null,
party char(1) not null,
primary key (id)
) insert into presidents (id, name, birthdate, party) values (1, 'george w. bush', to_date('07/06/1946','mm
/dd/yyyy'),'r');
insert into presidents (id, name, birthdate, party) values (2, 'bill clinton', to_date('08/19/1946','mm/dd/yyyy'),'d');
insert into presidents (id, name, birthdate, party) values (3, 'george h. w. bush', to_date('06/12/1924','mm/dd/yyyy'),'r');
insert into presidents (id, name, birthdate, party) values (4, 'ronald w. reagan', to_date('02/06/1911','mm/dd/yyyy'),'r');
insert into presidents (id, name, birthdate, party) values (5, 'jimmy carter', to_date('10/01/1924','mm/dd/yyyy'),'d');
insert into presidents (id, name, birthdate, party) values (6, 'gerald r. ford', to_date('07/14/1913','mm/dd/yyyy'),'r');
insert into presidents (id, name, birthdate, party) values (7, 'richard m. nixon', to_date('01/09/1913','mm/dd/yyyy'),'r');
insert into presidents (id, name, birthdate, party) values (8, 'lyndon b. johnson', to_date('08/27/1908','mm/dd/yyyy'),'d');
insert into presidents (id, name, birthdate, party) values (9, 'john f. kennedy', to_date('05/29/1917','mm/dd/yyyy'),'d');
insert into presidents (id, name, birthdate, party) values (10, 'dwight d. eisenhower', to_date('10/14/1890','mm/dd/yyyy'),'r');
2.建立臨時表以控制在函式與儲存之間的資料
create global temporary table temp_presidents(
id number(10) not null,
name varchar(32) not null,
birthdate date not null,
party char(1) not null
) on commit preserve rows;
3.建立儲存
create procedure load_temp_presidents (
partyparam char)as
begin
execute immediate 'truncate table temp_presidents';
commit;
insert into temp_presidents
select
id, name, birthdate, party from presidents where party = partyparam;
commit;
end;
/ 4.建立乙個需要從函式返回的資料型別
create or replace type president_type as object (
id number(10),
name varchar2(32),
birthdate date,
party char(1)
); 5.建立乙個以president_type為型別的表型別
create or replace type president_type_table as table of president_type;
6.建立函式
create or replace function presidents_func (
partyparam char
)return president_type_table pipelined
ispragma autonomous_transaction;
type ref0 is ref cursor;
mycursor ref0;
out_rec president_type := president_type(0, null, null, null);
begin
load_temp_presidents(partyparam);
open mycursor for
select
id,name,
birthdate,
party
from temp_presidents;
loop fetch mycursor into
out_rec.id,
out_rec.name,
out_rec.birthdate,
out_rec.party;
exit when mycursor%notfound;
pipe row(out_rec);
end loop;
close mycursor;
return;
end;
在ASP中呼叫儲存過程
dim objcnn dim objcmd dim rs const o id 112 建立connection物件 set objcnn server.createobject adodb.connection objcnn.open driver server localhost uid sa ...
在PB script 中呼叫儲存過程
在pb script中呼叫儲存過程有兩種方式 一是直接在指令碼中編寫語句呼叫儲存過程。一般語句如下 declare name procedure for pro indatabase 引數1,引數2,if sqlca.sqlcode 0 then messagebox pro indatabase ...
Delphi中如何呼叫儲存過程
估計有很多朋友用delphi寫過與sql server 2000資料結合的一些mis系統,對於大量的資料儲存,及資料更新.常常考慮到用儲存過程來實現.今天我寫了乙個簡單的例子,希望能給一些朋友一點幫助.1 當然,我們要在sql server 2000中建好我們的資料庫及資料表。我這裡用的資料庫是re...