oracle 添加 账号密码是什么格式oracle通过function函数返回结果集(示例讲解)

自己理解分三步走

1.创建数据对象,用于保存结果集中的结果。

create or replace type room as object(  roomid varchar2(12),  roomarea varchar2(12),  kogicode varchar2(10),  structureid varchar2(12),  campusid varchar2(12),  isoffice varchar2(1));

2.创建类表对象,用于保存要返回的结果。

create or replace type roomtable is table of room

3.创建函数。

create or replace function get511(iyear in number ) --get511为函数名称,iyear为输入参数  return roomtable --返回表  as  --定义变量  roomobj room;   itable roomtable  := roomtable();  xtyear varchar(4) :=to_char(sysdate,'yyyy');   cursor newtestrooms is       select sri.room_id,sri.room_area,srui.kogi_code,sri.structures_id,ssi.campus_id,srui.use_isoffice from sf_roominfo sri ,sf_structuresinfo ssi,sf_roomuseinfo srui where srui.room_id=sri.room_id and ssi.structures_id=sri.structures_id and ssi.structures_state <> 6 and ssi.structures_state <> 1;   cursor hisrooms is           select t.room_id from sf_roominfo t ;begin  --判断输入的年份  if xtyear <= iyear    then      --用户输入的年份为当前年份或者之后  for cur in newtestrooms loop     roomobj :=room(cur.room_id, curoracle账号.room_area ,cur.kogi_code,cur.structures_id,cur.campus_id,cur.use_isoffice);    itable.extend();    itable(itable.count) := roomobj;   end loop;  return itable;  end if;  if xtyear > iyear    then      --用户输入的年份为当前年份之前   for hcur in hisrooms loop         roomobj :=room(i, i*i,xtyear ,'小于',i+i,'1');    itable.extend();    itable(itable.count) := roomobj;  end loop;  return itable;  end if;end get511;

以上函数没有写完,需要自己这边的表,不能直接调用。

要调用的话直接

select * from table(get511(2018))

OK。大功告成

此条目发表在oracle metalink账号分类目录,贴了标签。将固定链接加入收藏夹。