create table issue(--问题表
is_id number(8) primary key,--问题ID
is_content varchar2(50) not null,--问题
is_amenddate date,
is_amenstaff varchar2(50)
);
create sequence seq_issue;create table answer(--答案表
an_id number(8) primary key,
an_issueid number(8),--对应问题表ID
an_content varchar2(120),--答案
an_amenddate date,
an_amenstaff varchar2(50)
);create sequence seq_answer;alter table ANSWER
  add foreign key (AN_ISSUEID)
  references ISSUE (IS_ID);
  insert into issue values(seq_issue.nextval,'zhangsan',sysdate,'张三');
insert into issue values(seq_issue.nextval,'张有多少画?',sysdate,'张三');
insert into issue values(seq_issue.nextval,'五加五等于多少?',sysdate,'张三');
insert into answer values(seq_answer.nextval,1,'create', sysdate,'李石');
insert into answer values(seq_answer.nextval,2,'7',sysdate,'王武');
insert into answer values(seq_answer.nextval,2,'不知道',sysdate,'王武');
-----------------------------------------------------------------------------------------
--自定义函数获得返回值
create or replace function ims_ing(content  in varchar2)return varchar2
 is
  v_content varchar2(120);
  BEGIN 
   
   select a.an_content into v_content from answer a where a.an_issueid in(select i.is_id from issue  i where i.is_content=content);
   RETURN v_content;
   exception   
  when no_data_found then   
    raise_application_error(-20001,'你输入的问题无效或没有答案!'); 
  END;
  
  
     select ims_ing('张有多少画?') from dual; 
-----------------------------------------------------------------------------------------------
有错误 函数不可以编译 因为有时候有多个返回值 但是我只想要一个返回值怎么办? 一定要在函数里面用到游标!!!
-------------:
create or replace function ims_ing(content  in varchar2)return varchar2
 is
  v_content varchar2(120);
  v_content varchar2(120);
declare cura is 
select a.an_content into v_content from answer a where a.an_issueid in(select i.is_id from issue  i where i.is_content=content);
  BEGIN 
   open cura;
   fetch cura into v_content;
   if cura%notfound then
      -- 未找到
   else
      -- 多个没有判断,只取第一个
      null;
   end if;
   close cura;
   RETURN v_content;
   exception   
  when no_data_found then   
    raise_application_error(-20001,'你输入的问题无效或没有答案!'); 
  END;