Sql 我在Oracle Apex中开发的系统有问题
我正在使用Oracle Apex为大学开发一个在线考试系统, 我开发了系统的大部分,在学生面前展示考试时遇到了问题, 考试部分使用的表格: -测试 -问题 -回答 这是表之间关系的图片: 我需要显示问题表中的问题,下面是四个选项, 第一选择,第二选择,等等。。。 选择后,我需要将学生所做的选择与答案表中的答案进行比较。 这个过程重复五次,这是每次考试的总题目。 然后显示结果。Sql 我在Oracle Apex中开发的系统有问题,sql,oracle,oracle-apex,Sql,Oracle,Oracle Apex,我正在使用Oracle Apex为大学开发一个在线考试系统, 我开发了系统的大部分,在学生面前展示考试时遇到了问题, 考试部分使用的表格: -测试 -问题 -回答 这是表之间关系的图片: 我需要显示问题表中的问题,下面是四个选项, 第一选择,第二选择,等等。。。 选择后,我需要将学生所做的选择与答案表中的答案进行比较。 这个过程重复五次,这是每次考试的总题目。 然后显示结果。 非常感谢。与编程中的所有事情一样,根据需求,可以采取许多不同的方法。根据我们目前讨论的内容,我将向您展示一种方法 鉴于以
非常感谢。与编程中的所有事情一样,根据需求,可以采取许多不同的方法。根据我们目前讨论的内容,我将向您展示一种方法 鉴于以下表格和数据:
create table test (
id number generated by default on null as identity
constraint test_id_pk primary key,
name varchar2(255)
);
create table question (
id number generated by default on null as identity
constraint question_id_pk primary key,
test_id number
constraint question_test_id_fk
references test on delete cascade,
question varchar2(4000),
ch1 varchar2(4000),
ch2 varchar2(4000),
ch3 varchar2(4000),
ch4 varchar2(4000),
correct_ch number constraint question_correct_ch_cc
check (correct_ch in (1,2,3,4))
);
declare
l_id number;
begin
insert into test (name) values ('Math') returning id into l_id;
insert into question (
test_id,
question,
ch1,
ch2,
ch3,
ch4,
correct_ch
) values (
l_id,
'What is 1+2?',
'3',
'2',
'4',
'1',
1
);
insert into question (
test_id,
question,
ch1,
ch2,
ch3,
ch4,
correct_ch
) values (
l_id,
'What is 10*0?',
'10',
'0',
'1',
'100',
2
);
insert into test (name) values ('Science') returning id into l_id;
insert into question (
test_id,
question,
ch1,
ch2,
ch3,
ch4,
correct_ch
) values (
l_id,
'How many planets are there?',
'10',
'7',
'9',
'8',
4
);
insert into question (
test_id,
question,
ch1,
ch2,
ch3,
ch4,
correct_ch
) values (
l_id,
' What is the biggest planet in our solar system?',
'Jupiter',
'Earth',
'Mars',
'Pluto',
1
);
end;
/
以下方面应起作用:
select val d,
choice_num r
from question
unpivot (val for choice_num in (ch1 as '1', ch2 as '2', ch3 as '3', ch4 as '4'))
where test_id = :P30_TEST_ID
and id = :P30_QUESTION_ID
在SQL查询字段下禁用显示额外值和显示空值
此unpivot将把列转换为行,以便与无线电组一起工作。用户将看到选项的文本,但会返回选项编号(1-4)declare
l_question_rec question%rowtype;
begin
if :P30_QUESTION_ID is null
then
select id
into :P30_QUESTION_ID
from question
where test_id = :P30_TEST_ID
order by id
fetch first 1 row only;
end if;
select *
into l_question_rec
from question
where id = :P30_QUESTION_ID;
:P30_QUESTION := l_question_rec.question;
:P30_CHOICES := null;
end;
select id
into :P30_QUESTION_ID
from question
where test_id = :P30_TEST_ID
and id > :P30_QUESTION_ID
order by id
fetch first 1 row only;
最后,在玩了一点之后,我可能会添加第三个表来显示选项/答案——尽管它不会像您之前定义的那样工作。它只是将答案存储在行中,而不是列中,这使得它们在关系上更容易处理(例如,不需要取消PIVOT) 评论不用于扩展讨论;这段对话已经结束了。谢谢你,先生,我会努力的。我需要添加一些内容,例如为问题添加时间,将学生的答案保存在分数表中,然后计算总分并在最后一个问题后打印结果