SQL游标在程序中

时间:2010-02-22 20:11:33

标签: sql

我想用光标写一个程序,这会让患者感到第一个免费的医生(此时没有任何访问,但我不知道什么会更容易

  • 在程序中宣布像'IN'的小时,然后在此时找到一名免费的医生
  • 或者从这个时间到医疗中心关闭找一位免费医生,知道一次访问最后15分钟)。

任何提示如何做到这一点?

下面是我的表格结构。如果你认为我的例子对于有功能的程序不好,你可以给我一个不同的例子(因为它必须通过任何与我的医疗中心相关的功能的程序)。

我有四张桌子

  • 患者(int Id_patient,char(11)name,char(20)姓氏,char(30)地址)
  • Doctor(int Id_doctor,char(11)name,char(20)surname)
  • 访问(#Id_patient,#Id_doctor,Id_visit,char(20)疾病,时间time_of_visit)
  • Work_hour(#Id_doctor,int Id_Workhour,char(11)name_of_day,time from_hour,time to_hour)

1 个答案:

答案 0 :(得分:0)

这样的东西?

create or replace procedure sho_doc(p_hour in varchar2)
is
  cursor get_free_time_cur
  is
  select doctor_name
    from doctor_table
   where status = 'FREE'
     and slot = p_hour_in;
begin
   for idx in get_free_time_cur
   loop
      //Do some thing here
   end loop
end;

我假设您使用的是Oracle。我不知道表结构。所以,只是假设一些事情。