[英]I have a problem with a system I am developing in 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;
/
以下应该工作:
向该区域添加另一个项目。 将名称设置为P30_CHOICES并将类型设置为Radio Group 。 在值列表下,将类型设置为SQL 查询并将以下内容复制粘贴到SQL 查询字段中:
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 查询字段下禁用显示额外值和显示空值。
此逆枢轴会将列转换为行,以便与无线电组一起使用。 用户将看到选项的文本,但将返回选项编号 (1-4)。
右键单击Pre-Rendering下的Before Header ,然后选择 Create Process。 将Name设置为Init page并将以下代码复制粘贴到PL/SQL Code字段中。
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;
在 processing 选项卡下,右键单击Processing并选择Create Process 。 将名称设置为选择下一个问题并将以下代码复制粘贴到 PL/SQL 代码字段中:
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;
此时,如果您返回上一页并运行它,您应该可以选择一个测试并看到第一个问题。 您还应该能够从可用选项中进行选择并使用“下一个问题”按钮查看下一个问题。
这是一个最小可行的例子。 到目前为止,我还没有为您提供验证答案的方法 - 尽管如果您愿意,我可以这样做。 我建议您首先使用我在此处描述的技术进行尝试: oracle apex 中提交和验证页面后的警报消息
我也没有考虑很多其他的事情:安全,当你在最后一个问题上时不要显示下一个问题按钮,等等。我没有做任何这些,因为我只是想给你关于事情如何运作的想法。 根据您的要求,您肯定会想要调整很多东西。
最后,在玩了一会儿之后,我可能会为选择/答案添加第三个表 - 尽管它不会像您之前定义的那样工作。 它只会将答案存储在行中,而不是列中,这使它们更容易进行相关处理(例如,无需逆向旋转)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.