sql—根据if语句单击按钮时插入记录

ymzxtsji  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(287)

大家好,我想在我的oracle表单中创建一个save按钮,这个表单有很多症状复选框,当选中时会记录一个1,我想用一种方法将这些症状计数到一个名为count\u symptoms的列中,如果这个数字大于3,那么结果列的值将是“正”,如果不是,它将是“负”,是的,它是一个covid19项目:),最后它将提交\u表单;
这张table是这样的:

[ ID  NAME  FEVER COUGH HEADACHE.....NO_OF_SYMPTOMS RESULT
 123. SCOTT  1.    1.    1.             3.      POSITIVE ]

我以前尝试过这个create table语句,但它不起作用,所以现在我想如果我用button pl语句来实现它,它可能会起作用

create table covid(ID NUMBER(7) , NAME VARCHAR2(32) ,DEPT VARCHAR2(16) , FEVER NUMBER(1) , COUGH NUMBER(1) ,
TIREDNESS NUMBER(1) , SHORT_BREATH NUMBER(1) ,SORE_THROAT NUMBER(1) ,CHEST_PAIN NUMBER(1) ,
LOSE_SENSES NUMBER(1),RUNNY_NOSE NUMBER(1), TEST_DATE DATE , 
SYMPTOMS NUMBER(16) ,
(CASE
WHEN SYMPTOMS >= 3 THEN 'POSITIVE' ELSE 'NEGATIVE' 
END AS RESULT));
/

提前谢谢!

r1zk6ea1

r1zk6ea11#

首先,在我看来,数据模型是错误的。应该至少有3个表来处理:patients、symptoms和[patient x symptom],其中包含每个患者的“活跃”症状数据。像这样:

SQL> create table patient
  2    (id_pat number       primary key,
  3     name   varchar2(20) not null
  4    );

Table created.

SQL> create table symptom
  2    (id_sym number       primary key,
  3     name   varchar2(20) not null
  4    );

Table created.

SQL> create table patxsym
  2    (id_pat number constraint fk_pxs_pat references patient,
  3     id_sym number constraint fk_pxs_sym references symptom,
  4                   --
  5                   constraint pk_pxs primary key (id_pat, id_sym)
  6    );

Table created.

样本数据:

SQL> insert into patient (id_pat, name)
  2    select 1, 'Little' from dual union all
  3    select 2, 'Foot'   from dual;

2 rows created.

SQL> insert into symptom (id_sym, name)
  2    select 1, 'fever'        from dual union all
  3    select 2, 'cough'        from dual union all
  4    select 3, 'headache'     from dual union all
  5    select 4, 'short breath' from dual union all
  6    select 5, 'sore throat'  from dual;

5 rows created.

每个患者的症状:以表格形式, patient 会是一个主块,而 patxsym 将是它的细节块(表格布局),所以你可以添加许多必要的症状。
这个选项可以很好地扩展。如果出现新的症状,你只要把它们加到 symptom 表和表单使用新添加的症状。
你的选择就像一只山羊,你想教它怎么飞,也就是说,它根本不会飞。对于任何新的症状,你必须
alter table并添加新列(针对新症状)
运行forms builder并按编辑表单
为新症状添加新复选框
修改代码 INSERT s INTO (因为您有新列和新复选框)
修改您可能编写的任何报告
那是一场无尽的噩梦。如果我是你,我就不会这么做。
所以:有一些症状的患者的样本数据:

SQL> insert into patxsym (id_pat, id_sym)
  2    select 1, 1 from dual union all
  3    select 1, 4 from dual union all
  4    select 1, 5 from dual union all
  5    --
  6    select 2, 2 from dual;

4 rows created.

报告:
每位患者的症状数:

SQL> select p.id_pat,
  2         p.name patient_name,
  3         count(*) no_of_symptoms,
  4         case when count(*) >= 3 then 'positive'
  5              else 'negative'
  6         end result
  7  from patient p join patxsym x on p.id_pat = x.id_pat
  8  group by p.id_pat, p.name;

    ID_PAT PATIENT_NAME         NO_OF_SYMPTOMS RESULT
---------- -------------------- -------------- --------
         1 Little                            3 positive
         2 Foot                              1 negative

SQL>

每位患者的症状:

SQL> select p.name patient_name,
  2         s.name symptom,
  3         case when x.id_sym is not null then 'Yes'
  4              else 'No'
  5         end patient_has_symptom
  6  from patient p cross join symptom s
  7  left join patxsym x on x.id_pat = p.id_pat
  8                     and x.id_sym = s.id_sym
  9  order by p.name, s.name;

PATIENT_NAME         SYMPTOM              PAT
-------------------- -------------------- ---
Foot                 cough                Yes
Foot                 fever                No
Foot                 headache             No
Foot                 short breath         No
Foot                 sore throat          No
Little               cough                No
Little               fever                Yes
Little               headache             No
Little               short breath         Yes
Little               sore throat          Yes

10 rows selected.

SQL>

相关问题