sql - 我在 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;
/
以下应该有效:
- 创建一个新的空白页。将名称设置为测试。我的页码默认为 29,您可能需要在下面调整页码。
- 向页面添加新区域。将Title设置为Tests,将Type设置为Classic Report,将Table Name设置为TEST。
- 右键单击Tests区域下的Columns,然后选择Create Virtual Column。单击Target的No Link Defined按钮。将Page设置为比当前页面高一页(对我来说是 30)。在 Set Items 下,将P30_TEST_ID放入Name列和&ID。在同一行的值列中。将清除缓存设置为30,然后单击确定。设置链接文本(在目标下)进行测试. 如果您运行该页面,您应该会看到带有指向测试页面的链接的测试报告(它将无法正常工作)。
- 返回到构建器并创建另一个空白页面。页码应该比上一页高一页(对我来说是 30)。将名称设置为问题。
- 向页面添加新区域。设置标题以回答以下问题。
- 向区域添加新项目。将Name设置为P30_TEST_ID并将Type设置为Hidden。
- 将另一个项目添加到该区域。将Name设置为P30_QUESTION_ID并将Type设置为Hidden。
- 将另一个项目添加到该区域。将Name设置为Question并将Type设置为Display Only。
将另一个项目添加到该区域。将Name设置为P30_CHOICES并将Type设置为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 查询字段下禁用显示额外值和显示空值。
这个 unpivot 会将列转换为行,以便它与 Radio Group 一起使用。用户将看到选项的文本,但将返回选项编号 (1-4)。
右键单击Pre-Rendering下的Before Header并选择 Create Process。将Name设置为Init 页面并将以下代码复制粘贴到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;
- 向区域添加一个按钮。将按钮名称设置为NEXT_QUESTION。
在处理选项卡下,右键单击处理并选择创建进程。将名称设置为选择下一个问题并将以下代码复制粘贴到 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;
此时,如果返回上一页并运行它,应该可以选择一个测试并看到第一个问题。您还应该能够从可用选项中进行选择,并使用“下一个问题”按钮查看下一个问题。
这是一个最小可行的例子。到目前为止,我还没有为您提供验证答案的方法——尽管如果您愿意,我可以这样做。我建议您首先使用我在此处描述的技术进行尝试:Alert message after submit and validation page in oracle apex
我也没有考虑很多其他事情:安全性,当你在最后一个问题时不要显示下一个问题按钮等等。我没有做任何这些,因为我只是想给你关于事情如何运作的想法。您肯定会根据自己的要求进行许多调整。
最后,在玩了一点之后,我可能会为选择/答案添加第三个表——尽管它不会像你之前定义的那样工作。它只会将答案存储在行而不是列中,这使它们更容易以关系方式使用(例如,无需取消透视)。
推荐阅读
- node.js - 无法读取 Fastify 抛出的未定义错误的 .sign
- ios - iOS按比例缩放元素与视口的相对距离
- cakephp - 如何修复 Cakephp3 应用程序中的“加载的文件没有有效的 JavaScript MIME 类型”错误
- c# - 从 Mongo 异步获取用户产品
- google-apps-script - 链接公式更改时如何在谷歌表格中创建时间戳
- c# - 从本地系统帐户向不同帐户添加凭据
- sql - 提取月份编号并将其转换为 SQL Server 中的月份名称
- django - 我们可以自定义整个 Django 管理站点吗?
- entity-framework - 使用 dotnet ef 迁移创建数据库时如何设置字符集?
- angular - 角度形式不采用初始值