我正在嘗試撰寫 Oracle SQL 函式。應將國家代碼、最小年份和最大年份作為輸入,并應回傳包含該國家在指定年份的資訊的表。這是我試圖寫的,但我是 SQL 函式的新手。這就是資料的樣子,我會很高興得到任何幫助。

create or replace type african_crisis_row as object(
country_abv varchar(4),
year number(5),
banking_crisis varchar(10)
);
create or replace type t_african_crisis_table as table of african_crisis_row;
create or replace function african_crisis (
country_abv in varchar,
year_min in number,
year_max in number
)
return t_african_crisis_table as v_ret table t_african_crisis_table;
begin
select
african_crisis_row(country_abv, year)
bulk collect into
v_ret
from
africancrisisdata
where
country_abv = country_abv and year between year_min and year_max;
return v_ret
end african_crisis
uj5u.com熱心網友回復:
你需要:
table宣告后洗掉v_ret。- 在對物件建構式
banking_crisis的呼叫中包含第三個值。african_crisis_row - 在陳述句和最終陳述句之后包括
;陳述句終止符。returnend - 不要使用與列值相同的名稱來命名函式引數。
(Oracle 使用VARCHAR2并且VARCHAR是 的別名VARCHAR2。)
像這樣的東西:
create or replace function african_crisis (
i_country_abv in varchar2,
i_year_min in number,
i_year_max in number
) return t_african_crisis_table
as
v_ret t_african_crisis_table;
begin
select african_crisis_row(country_abv, year, banking_crisis)
bulk collect into v_ret
from africancrisisdata
where country_abv = i_country_abv
and year between i_year_min and i_year_max;
return v_ret;
end african_crisis;
/
db<>在這里擺弄
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/496466.html
上一篇:Python打字機函式在輸入中使用時不回傳任何內容?
下一篇:從函式回傳二維陣列上的指標
