Oracle SYS_REFCURSOR couldn't use as a return type

后端 未结 2 1179
庸人自扰
庸人自扰 2021-01-25 00:29

I need to extract and display all the years for all the records in db using member function in oracle 11g.

CREATE or replace TYPE BODY student_t AS 
MEMBER FUNCT         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-25 01:21

    I'm not sure what you are trying to achieve but I think you misunderstood concept of object in oracle. In my example i'm assuming
    1) Table studens is create with this script create table student of student_t;

    drop table student;

    Create type spec and body.

    create or replace type student_t as object(
    stno char(4),
    dob date,
    member function getYear return number
    
    )
    ;
    
    create or replace type body student_t as
    
        member function getYear return number is 
        begin 
                return  EXTRACT(YEAR FROM self.dob);
        end;
    
    end;
    

    Create table of studnets

    create table student of student_t;
    

    Populate tabel

    declare 
      v_student student_t;
    begin 
    for i in 0 .. 10 loop 
      insert into student values(student_t('ST'||+mod(i,3),to_date('01-01-'||to_char(2000+i),'dd-mm-yyyy')));
    end loop;
    commit;
    end; 
    

    And the query.

    select s.*,s.getYear() from student s;

提交回复
热议问题