我想问一些pl/sql oracle的帮助。我试图找出这个面向对象的数据库的东西,但迄今没有太大的成功。我进入编程,我也理解rdbms,已经管理了一些复杂的数据库,但这个面向对象超出了我的理解。 所以任务如下: 有老师和学生。需要制定一个有两种课程的时间表。一天和下午。 每天一班最多可有10名学生和下午5最大PL SQL关系和程序问题
以下内容我至今:
/*create student type and table*/
create type student_typ as object(
st_id char(3),
st_name varchar(50)
)
create table student_tbl of student_typ(
st_id primary key not null,
st_name not null
)
/*create teacher type and table*/
create type teacher_typ as object(
tr_id char(3),
tr_name varchar(50)
)
create table teacher_tbl of teacher_typ(
tr_id primary key not null,
tr_name not null
)
/*create array type to store the student id-s*/
create type students_arr as varray(20) of char(3);
/*create table for timetable*/
create table timetable_tbl(
t_ID char(5),
t_Date date,
t_Time varchar(5), /*store time format as 12:00*/
t_Type char(1),
teacher ref teacher_typ scope is teacher_tbl,
students students_arr,
constraint chk_type check(t_Type='D' or t_Type='N')
)
/*insert values into the tables*/
insert into teacher_tbl values ('t01','bob');
insert into teacher_tbl values ('t02','smith');
insert into student_tbl values ('s01','lara');
insert into student_tbl values ('s02','john');
/*insert values into timetable*/
insert into timetable_tbl(select 't01','01-Apr-17','09:00','D',ref(t),students_arr('s01','s02') from teacher_tbl t where t.tr_ID='t01');
insert into timetable_tbl(select 't02','01-Apr-17','19:00','N',ref(t),students_arr('s01') from teacher_tbl t where t.tr_ID='t02');
/*display timetable records*/
select t_ID, t_Date, t_Time, t_Type, deref(teacher).tr_ID,deref(teacher).tr_Name, students from timetable_tbl;
/*create procedure to add new student*/
create or replace procedure Add_Student(
v_id in student_tbl.st_id%type,
v_name in student_tbl.st_name%type,
verror out varchar2)
is begin
insert into student_tbl (st_id,st_name) values (v_id,v_name);
commit;
exception when others then
verror := sqlerrm;
end;
/*call add_student procedure*/
declare
verror varchar2(500);
begin
Add_Student('s03','sam',verror);
end;
所以这是我到目前为止所。问题在下。
这是正确的方法吗?
我该如何引用varray中的学生?我已经试过参考老师参考,但没有结果呢? students student_arr ref student_typ范围是student_tbl;此代码不起作用。 students_arr数组只应接受来自学生表的现有记录
如何创建时间表的过程?因为当t_Type是“D”时,主要的事情是,那么student_arr应该允许最多10个值 ,并且如果t_Type是“N”,那么student_arr应该只允许最多5个值。我应该做一些像add_record程序的时间表和使用if语句,但我不确定这将是一个好主意。 如果t_type = 'd',则如果 students.count < = 10 或 如果t_type = 'N' 然后 如果students.count < = 5
林种stucked现在。我看了很多关于pl sql的教程,但更加困惑。烦人的事情是,我管理与 rdbms(SQL服务器)和Java在相同的时间。但是这个语言和对象数据库现在让我很难受。
任何帮助将被占用!
我没有看到具体的PL/SQL问题。这个问题似乎是在处理[SQL中的对象引用函数](https://docs.oracle.com/cd/E11882_01/server.112/e41084/functions005.htm),这在学术上可能很有趣,但我非常自信自从8i推出以来,没有人在任何现实世界中使用过它。另外,不相关的一些字符串类型是'char'而不是'varchar2'。 'char'很少是一种有用的类型。 –
我试过了,所有的代码工作。有趣的'deref'就像是一个隐含的FK查找 - 整齐。我似乎想起了一篇Steven Feuerstein的文章,建议它的实际用途,尽管我现在想不出任何。我认为一般的“正确的做法”是避免收集和参考列,除非你有特定的需求。 –
正如我所提到的,我不太清楚这个面向对象的数据库的东西。我知道编程Java,C#和更多和RDBMS,但这东西我不明白。也许我只是想了解整个数据库概念。我需要帮助的是以正确的方式在plsql中创建场景。 – bontoo