Oracle SQL用户定义的功能
我正在尝试编写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
I am trying to write Oracle SQL function. The should take country code, min year and max year as inputs and should return table which contains information for that country in the specified years. This is what I tried to write, but I am new to SQL functions. This is how the data looks and I will be glad for any help.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要:
v_ret
声明之后删除表
。african_crisis_row
对象构造器的呼叫中,包括第三banking_crisis
值。返回
和最终结束
语句之后,请包括;
语句终结者。(Oracle使用
varchar2
和varchar
是与varchar2
的别名。)类似的东西:
db< > fiddle
You need to:
table
after thev_ret
declaration.banking_crisis
value in the call to theafrican_crisis_row
object constructor.;
statement terminators after thereturn
and finalend
statements.(Oracle uses
VARCHAR2
andVARCHAR
is an alias toVARCHAR2
.)Something like this:
db<>fiddle here