From beb5f67ba60458efc415ec06ba5917f610646953 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Wed, 24 May 2023 06:43:49 +0000 Subject: [PATCH 01/12] Setting up GitHub Classroom Feedback From a39507daec0d92a91af2cc52a66cff63e3b03e58 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 25 May 2023 08:44:16 +0600 Subject: [PATCH 02/12] only DDL and DML --- project/DDL.sql | 55 ++++++++++++++++++++++++++ project/DML.sql | 75 +++++++++++++++++++++++++++++++++++ project/INSERT_DATA.sql | 88 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 218 insertions(+) create mode 100644 project/DDL.sql create mode 100644 project/DML.sql create mode 100644 project/INSERT_DATA.sql diff --git a/project/DDL.sql b/project/DDL.sql new file mode 100644 index 0000000..97f3c3b --- /dev/null +++ b/project/DDL.sql @@ -0,0 +1,55 @@ +--pagesize & linesize +set pagesize 1500; +set linesize 300; + +-- select +select * from profile; +select name from profile; + +--update & delete +INSERT INTO applicant VALUES ('A016', 'Venue1', timestamp '2023-05-20 09:00:00'); +update applicant set exam_venue = 'Venue5' where applicant_id = 'A016'; +delete from applicant where applicant_id = 'A016'; + +--union, intersect, except +select applicant_id,apply_time from applicant where extract (hour from apply_time)>10 +union +select applicant_id,apply_time from applicant where extract (hour from apply_time)<16; + +--with clause +with avg_number(hsc_mark) as (select avg(hsc_mark) from eligible) +select * from eligible,avg_number where eligible.hsc_mark > avg_number.hsc_mark; + +--aggregate +select count (distinct hsc_gpa) as gpa_hsc from eligible; +select max (total_mark) as exam_marks from examinee; + +--group by & having +select faculty,count(distinct dept_name) as number_of_dept from department group by faculty; +select faculty,count(distinct dept_name) as number_of_dept from department group by faculty having count(dept_name) > 2; + +--nested subquery +select name from profile where reg_no = +(select reg_no from eligible where applicant_id = +(select applicant_id from examinee where merit_place = 1 )); + +--set membership +select name from profile where reg_no in +(select reg_no from eligible where applicant_id in +(select applicant_id from examinee where merit_place >=1 and merit_place <=5 )); + +--string +select dept_name,faculty from department where dept_name like '%Engineer%'; + +--join operations +select applicant_id,total_mark,merit_place,roll_no from examinee natural join student order by merit_place asc; +select name,merit_place from profile join eligible on profile.reg_no = eligible.reg_no join examinee on eligible.applicant_id = examinee.applicant_id where merit_place<4 order by merit_place asc; + +--views +create view admission as select name,p.reg_no,a.applicant_id,hsc_gpa,ssc_gpa,gpa_mark,phy_mark,math_mark,chem_mark,eng_mark,total_mark, +e.merit_place,s.roll_no,dept_name,dept_id,faculty from profile p join eligible eg on p.reg_no = eg.reg_no +join applicant a on a.applicant_id = eg.applicant_id +join examinee e on e.applicant_id = a.applicant_id +join student s on s.merit_place = e.merit_place +join department d on d.roll_no = s.roll_no; +select * from admission; \ No newline at end of file diff --git a/project/DML.sql b/project/DML.sql new file mode 100644 index 0000000..c640690 --- /dev/null +++ b/project/DML.sql @@ -0,0 +1,75 @@ +--drop tables & views +drop view admission; +drop table eligible; +drop table student; +drop table examinee; +drop table profile; +drop table applicant; +drop table department; + + +--profile +create table profile( + reg_no varchar(30) primary key, + hsc_roll varchar(30) not null, + name varchar(30) not null, + father_name varchar(30) not null, + mother_name varchar(30) not null, + birth_date date not null, + address varchar(30) not null, + email varchar(30) unique not null, + religion varchar(30) not null check (religion in ('Islam','Hindu','Budhha','Christ')) +); + +--applicant +create table applicant( + applicant_id varchar(30) primary key, + exam_venue varchar(30) not null, + apply_time timestamp not null +); + +--eligible +create table eligible( + reg_no varchar(30), + applicant_id varchar(30), + hsc_mark numeric(3) not null check (hsc_mark<=600), + hsc_gpa numeric(3,2) not null check(hsc_gpa<=5.00), + ssc_gpa numeric(3,2) not null check(ssc_gpa<=5.00), + eligibility varchar(5) not null check(eligibility in ('yes','no')), + foreign key (reg_no) references profile (reg_no), + foreign key (applicant_id) references applicant (applicant_id) + on delete cascade +); + +--examinee +create table examinee( + applicant_id varchar(30), + phy_mark numeric(3) not null check (phy_mark<=150), + chem_mark numeric(3) not null check (chem_mark<=150), + math_mark numeric(3) not null check (math_mark<=150), + eng_mark numeric(3) not null check (eng_mark<=50), + gpa_mark numeric(3) not null check (gpa_mark<=100), + total_mark numeric(3) not null check (total_mark<=600), + merit_place numeric(5) primary key, + foreign key (applicant_id) references applicant(applicant_id) + on delete cascade +); + +--department +create table department( + roll_no varchar(30) primary key, + dept_name varchar(30) not null, + dept_id numeric(2) not null, + faculty varchar(30) not null +); + +--student +create table student( + merit_place numeric(5) not null, + roll_no varchar(30) not null, + dept_choice varchar(30) not null, + priority numeric(2) not null, + foreign key (merit_place) references examinee(merit_place), + foreign key (roll_no) references department(roll_no) + on delete cascade +); \ No newline at end of file diff --git a/project/INSERT_DATA.sql b/project/INSERT_DATA.sql new file mode 100644 index 0000000..a95e4f8 --- /dev/null +++ b/project/INSERT_DATA.sql @@ -0,0 +1,88 @@ +--INSERT INTO profile (reg_no, hsc_roll, name, father_name, mother_name, birth_date, address, email, religion) VALUES +INSERT INTO profile VALUES ('R001', 'HSC001', 'John Doe', 'Michael Doe', 'Jane Doe', date '2000-01-01', '123 Main St', 'johndoe@example.com', 'Islam'); +INSERT INTO profile VALUES ('R002', 'HSC002', 'Jane Smith', 'David Smith', 'Mary Smith', date '1998-05-15', '456 Elm St', 'janesmith@example.com', 'Hindu'); +INSERT INTO profile VALUES ('R003', 'HSC003', 'Robert Johnson', 'Thomas Johnson', 'Sarah Johnson', date '1999-08-22', '789 Oak St', 'robertjohnson@example.com', 'Budhha'); +INSERT INTO profile VALUES ('R004', 'HSC004', 'Emily Davis', 'Daniel Davis', 'Laura Davis', date '2001-03-10', '321 Pine St', 'emilydavis@example.com', 'Christ'); +INSERT INTO profile VALUES ('R005', 'HSC005', 'Michael Wilson', 'John Wilson', 'Emily Wilson', date '2002-07-17', '567 Maple St', 'michaelwilson@example.com', 'Islam'); +INSERT INTO profile VALUES ('R006', 'HSC006', 'Sarah Thompson', 'James Thompson', 'Jennifer Thompson', date '1999-11-05', '890 Cedar St', 'sarahthompson@example.com', 'Hindu'); +INSERT INTO profile VALUES ('R007', 'HSC007', 'Matthew Lee', 'Brian Lee', 'Karen Lee', date '1999-02-28', '234 Birch St', 'matthewlee@example.com', 'Budhha'); +INSERT INTO profile VALUES ('R008', 'HSC008', 'Olivia Martinez', 'Joseph Martinez', 'Maria Martinez', date '2000-06-12', '678 Oak St', 'oliviamartinez@example.com', 'Christ'); +INSERT INTO profile VALUES ('R009', 'HSC009', 'Christopher Harris', 'William Harris', 'Jessica Harris', date '2000-09-20', '912 Pine St', 'christopherharris@example.com', 'Islam'); +INSERT INTO profile VALUES ('R010', 'HSC010', 'Ava Clark', 'Christopher Clark', 'Samantha Clark', date '2001-12-08', '345 Maple St', 'avaclark@example.com', 'Hindu'); +INSERT INTO profile VALUES ('R011', 'HSC011', 'David Rodriguez', 'Andrew Rodriguez', 'Elizabeth Rodriguez', date '1998-04-18', '567 Cedar St', 'davidrodriguez@example.com', 'Budhha'); +INSERT INTO profile VALUES ('R012', 'HSC012', 'Sophia Walker', 'Jason Walker', 'Kimberly Walker', date '1999-07-25', '890 Birch St', 'sophiawalker@example.com', 'Christ'); +INSERT INTO profile VALUES ('R013', 'HSC013', 'Daniel Green', 'Mark Green', 'Patricia Green', date '2002-10-14', '123 Oak St', 'danielgreen@example.com', 'Islam'); +INSERT INTO profile VALUES ('R014', 'HSC014', 'Mia Lewis', 'Robert Lewis', 'Susan Lewis', date '2001-01-31', '456 Pine St', 'mialewis@example.com', 'Hindu'); +INSERT INTO profile VALUES ('R015', 'HSC015', 'Andrew Hill', 'David Hill', 'Nancy Hill', date '2000-06-27', '789 Maple St', 'andrewhill@example.com','Islam'); + +--INSERT INTO applicant (applicant_id, exam_venue, apply_time) VALUES +INSERT INTO applicant VALUES ('A001', 'Venue1', timestamp '2023-05-18 09:00:00'); +INSERT INTO applicant VALUES ('A002', 'Venue2', timestamp '2023-05-18 10:15:00'); +INSERT INTO applicant VALUES ('A003', 'Venue1', timestamp '2023-05-18 11:30:00'); +INSERT INTO applicant VALUES ('A004', 'Venue3', timestamp '2023-05-18 13:00:00'); +INSERT INTO applicant VALUES ('A005', 'Venue2', timestamp '2023-05-18 14:30:00'); +INSERT INTO applicant VALUES ('A006', 'Venue4', timestamp '2023-05-18 15:45:00'); +INSERT INTO applicant VALUES ('A007', 'Venue3', timestamp '2023-05-18 17:00:00'); +INSERT INTO applicant VALUES ('A008', 'Venue5', timestamp '2023-05-19 09:30:00'); +INSERT INTO applicant VALUES ('A009', 'Venue2', timestamp '2023-05-19 10:45:00'); +INSERT INTO applicant VALUES ('A010', 'Venue1', timestamp '2023-05-19 12:00:00'); +INSERT INTO applicant VALUES ('A011', 'Venue4', timestamp '2023-05-19 13:15:00'); +INSERT INTO applicant VALUES ('A012', 'Venue5', timestamp '2023-05-19 14:30:00'); +INSERT INTO applicant VALUES ('A013', 'Venue3', timestamp '2023-05-19 15:45:00'); +INSERT INTO applicant VALUES ('A014', 'Venue2', timestamp '2023-05-19 17:00:00'); +INSERT INTO applicant VALUES ('A015', 'Venue1', timestamp '2023-05-20 09:00:00'); + +--INSERT INTO eligible INSERT INTO eligible VALUES (reg_no, applicant_id, hsc_mark, hsc_gpa, ssc_gpa, eligibility) VALUES +INSERT INTO eligible VALUES ('R001', 'A001', 580, 4.50, 4.00, 'yes'); +INSERT INTO eligible VALUES ('R002', 'A002', 550, 4.00, 3.50, 'yes'); +INSERT INTO eligible VALUES ('R003', 'A003', 600, 5.00, 4.50, 'yes'); +INSERT INTO eligible VALUES ('R004', 'A004', 540, 3.75, 3.25, 'no'); +INSERT INTO eligible VALUES ('R005', 'A005', 590, 4.80, 4.20, 'yes'); +INSERT INTO eligible VALUES ('R006', 'A006', 510, 3.50, 3.00, 'yes'); +INSERT INTO eligible VALUES ('R007', 'A007', 570, 4.30, 3.75, 'yes'); +INSERT INTO eligible VALUES ('R008', 'A008', 480, 3.00, 2.75, 'no'); +INSERT INTO eligible VALUES ('R009', 'A009', 560, 4.20, 3.50, 'yes'); +INSERT INTO eligible VALUES ('R010', 'A010', 520, 3.80, 3.25, 'yes'); +INSERT INTO eligible VALUES ('R011', 'A011', 590, 4.80, 4.20, 'yes'); +INSERT INTO eligible VALUES ('R012', 'A012', 500, 3.25, 2.75, 'no'); +INSERT INTO eligible VALUES ('R013', 'A013', 550, 4.00, 3.50, 'yes'); +INSERT INTO eligible VALUES ('R014', 'A014', 580, 4.50, 4.00, 'yes'); +INSERT INTO eligible VALUES ('R015', 'A015', 530, 3.60, 3.00, 'yes'); + +--INSERT INTO examinee (applicant_id, phy_mark, chem_mark, math_mark, eng_mark, gpa_mark, total_mark, merit_place) VALUES +INSERT INTO examinee VALUES ('A001', 120, 140, 145, 40, 85, 530, 2); +INSERT INTO examinee VALUES ('A002', 110, 130, 135, 38, 75, 488, 6); +INSERT INTO examinee VALUES ('A003', 145, 150, 150, 48, 95, 588, 1); +INSERT INTO examinee VALUES ('A005', 100, 120, 125, 35, 90, 470, 8); +INSERT INTO examinee VALUES ('A006', 130, 145, 140, 42, 65, 522, 4); +INSERT INTO examinee VALUES ('A007', 90, 110, 115, 32, 80, 427, 10); +INSERT INTO examinee VALUES ('A009', 115, 135, 130, 37, 77, 494, 5); +INSERT INTO examinee VALUES ('A010', 80, 100, 105, 30, 71, 386, 11); +INSERT INTO examinee VALUES ('A011', 105, 125, 120, 36, 90, 476, 7); +INSERT INTO examinee VALUES ('A013', 95, 115, 110, 33, 75, 428, 9); +INSERT INTO examinee VALUES ('A014', 125, 140, 135, 41, 85, 526, 3); +INSERT INTO examinee VALUES ('A015', 85, 105, 100, 29, 66, 385, 12); + +--INSERT INTO department (roll_no, dept_name, dept_id, faculty) VALUES +INSERT INTO department VALUES ('R001', 'Computer Science', 07, 'Faculty of Science'); +INSERT INTO department VALUES ('R002', 'Electrical Engineering', 01, 'Faculty of Engineering'); +INSERT INTO department VALUES ('R003', 'Mechanical Engineering', 05, 'Faculty of Engineering'); +INSERT INTO department VALUES ('R004', 'Chemistry', 15, 'Faculty of Science'); +INSERT INTO department VALUES ('R005', 'Physics', 13, 'Faculty of Science'); +INSERT INTO department VALUES ('R006', 'English Literature', 19, 'Faculty of Arts'); +INSERT INTO department VALUES ('R007', 'Business Administration', 17, 'Faculty of Business'); +INSERT INTO department VALUES ('R008', 'Mathematics', 09, 'Faculty of Science'); +INSERT INTO department VALUES ('R009', 'Civil Engineering', 03, 'Faculty of Engineering'); +INSERT INTO department VALUES ('R010', 'Biology', 11, 'Faculty of Science'); + +--INSERT INTO student (merit_place, roll_no, dept_choice, priority) VALUES +INSERT INTO student VALUES (1, 'R001', 'Computer Science', 1); +INSERT INTO student VALUES (2, 'R002', 'Electrical Engineering', 1); +INSERT INTO student VALUES (3, 'R003', 'Mechanical Engineering', 1); +INSERT INTO student VALUES (4, 'R004', 'Chemistry', 2); +INSERT INTO student VALUES (5, 'R005', 'Physics', 2); +INSERT INTO student VALUES (6, 'R006', 'English Literature', 3); +INSERT INTO student VALUES (7, 'R007', 'Business Administration', 5); +INSERT INTO student VALUES (8, 'R008', 'Mathematics', 4); +INSERT INTO student VALUES (9, 'R009', 'Civil Engineering', 1); +INSERT INTO student VALUES (10, 'R010', 'Biology', 6); \ No newline at end of file From eb7052b4b9284f76b4c65b884e9bc214e3920dce Mon Sep 17 00:00:00 2001 From: Mahbub022 <126968142+Mahbub022@users.noreply.github.com> Date: Thu, 25 May 2023 08:50:35 +0600 Subject: [PATCH 03/12] Update INSERT_DATA.sql --- project/INSERT_DATA.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/project/INSERT_DATA.sql b/project/INSERT_DATA.sql index a95e4f8..6a9af9c 100644 --- a/project/INSERT_DATA.sql +++ b/project/INSERT_DATA.sql @@ -85,4 +85,5 @@ INSERT INTO student VALUES (6, 'R006', 'English Literature', 3); INSERT INTO student VALUES (7, 'R007', 'Business Administration', 5); INSERT INTO student VALUES (8, 'R008', 'Mathematics', 4); INSERT INTO student VALUES (9, 'R009', 'Civil Engineering', 1); -INSERT INTO student VALUES (10, 'R010', 'Biology', 6); \ No newline at end of file +INSERT INTO student VALUES (10, 'R010', 'Biology', 6); + From 79e64190327b69d27ade5f1512a0b60fafaadf04 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 25 May 2023 10:42:15 +0600 Subject: [PATCH 04/12] added plsql --- project/PLSQL.sql | 128 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 project/PLSQL.sql diff --git a/project/PLSQL.sql b/project/PLSQL.sql new file mode 100644 index 0000000..5963ff3 --- /dev/null +++ b/project/PLSQL.sql @@ -0,0 +1,128 @@ +--variable declare and print value +set serveroutput on +declare +roll department.roll_no%type; +dept department.dept_name%type; +faculty department.faculty%type; +begin +select dept_name,roll_no,faculty into dept,roll,faculty from department where dept_id=07; +dbms_output.put_line('Roll: '||roll||' Dept: '||dept||' Faculty: '||faculty); +end; +/ + +--insert and set default value +set serveroutput on +declare +roll department.roll_no%type:='R016'; +dept department.dept_name%type:='CSE'; +faculty department.faculty%type:='EEE'; +id department.dept_id%type:='07'; +begin +insert into department VALUES(roll,dept,id,faculty); +end; +/ +select * from department where roll_no='R016'; + +--row type +set serveroutput on +declare +dept_row department%rowtype; +begin +select roll_no, dept_name, dept_id, faculty into dept_row +from department where roll_no='R010'; +dbms_output.put_line('Roll: '||dept_row.roll_no||' Dept: '||dept_row.dept_name||' Faculty: '||dept_row.faculty); +end; +/ + +--cursor and row count with while loop +set serveroutput on +declare +cursor c is select roll_no,dept_name from department; +dept_row department%rowtype; +begin +open c; +fetch c into dept_row.roll_no,dept_row.dept_name; +while c%found loop +dbms_output.put_line('Roll: '||dept_row.roll_no||' Dept: '||dept_row.dept_name); +dbms_output.put_line('Count: '||c%rowcount); +fetch c into dept_row.roll_no,dept_row.dept_name; +end loop; +close c; +end; +/ + +--if/elseif/else +set serveroutput on +declare +cursor c is select reg_no,hsc_mark from eligible; +e_row eligible%rowtype; +begin +open c; +fetch c into e_row.reg_no, e_row.hsc_mark; +while c%found loop +if e_row.hsc_mark>540 +then dbms_output.put_line('Reg_no: '||e_row.reg_no||' HSC_Mark: '||e_row.hsc_mark||'Student rating: Outstanding'); +elsif e_row.hsc_mark>500 +then dbms_output.put_line('Reg_no: '||e_row.reg_no||' HSC_Mark: '||e_row.hsc_mark||'Student rating: Good'); +else +dbms_output.put_line('Reg_no: '||e_row.reg_no||' HSC_Mark: '||e_row.hsc_mark||'Student rating: Medium'); +end if; +dbms_output.put_line('Count: '||c%rowcount); +fetch c into e_row.reg_no, e_row.hsc_mark; +end loop; +close c; +end; +/ + +--procedure +create or replace procedure proc( + merit in examinee.merit_place%type, + id out examinee.applicant_id%type, + marks out examinee.total_mark%type +) is var varchar(30); +begin +select applicant_id,total_mark into id,marks from examinee where merit_place=merit; +end; +/ + +set serveroutput on +declare +merit examinee.merit_place%type:=1; +id examinee.applicant_id%type; +mark examinee.total_mark%type; +begin +proc(merit,id,mark); +dbms_output.put_line('Applicant_id: '||id||' Marks: '||mark||' Merit_place: '||merit); +end; +/ + +--function +create or replace function fun( + roll in department.roll_no%type +) return varchar as faculty department.faculty%type; +begin +select faculty into faculty from department where roll_no=roll; +return faculty; +end; +/ + +set serveroutput on +declare +roll department.roll_no%type:='R001'; +faculty department.dept_name%type; +dept department.dept_name%type; +cursor c is select dept_name,faculty from department where faculty= fun(roll); +begin +open c; +fetch c into dept,faculty; +while c%found loop +dbms_output.put_line('Dept: '||dept||' Faculty: '||faculty); +fetch c into dept,faculty; +end loop; +close c; +end; +/ + +--drop procedur / function +drop procedure proc; +drop function fun; \ No newline at end of file From 41d5ce28b40488cf806f254779a7ee307bf32ef2 Mon Sep 17 00:00:00 2001 From: Mahbub022 <126968142+Mahbub022@users.noreply.github.com> Date: Fri, 26 May 2023 14:13:32 +0600 Subject: [PATCH 05/12] added plsql --- project/PLSQL.sql | 128 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 project/PLSQL.sql diff --git a/project/PLSQL.sql b/project/PLSQL.sql new file mode 100644 index 0000000..70723c0 --- /dev/null +++ b/project/PLSQL.sql @@ -0,0 +1,128 @@ +--variable declare and print value +set serveroutput on +declare +roll department.roll_no%type; +dept department.dept_name%type; +faculty department.faculty%type; +begin +select dept_name,roll_no,faculty into dept,roll,faculty from department where dept_id=07; +dbms_output.put_line('Roll: '||roll||' Dept: '||dept||' Faculty: '||faculty); +end; +/ + +--insert and set default value +set serveroutput on +declare +roll department.roll_no%type:='R016'; +dept department.dept_name%type:='CSE'; +faculty department.faculty%type:='EEE'; +id department.dept_id%type:='07'; +begin +insert into department VALUES(roll,dept,id,faculty); +end; +/ +select * from department where roll_no='R016'; + +--row type +set serveroutput on +declare +dept_row department%rowtype; +begin +select roll_no, dept_name, dept_id, faculty into dept_row +from department where roll_no='R010'; +dbms_output.put_line('Roll: '||dept_row.roll_no||' Dept: '||dept_row.dept_name||' Faculty: '||dept_row.faculty); +end; +/ + +--cursor and row count with while loop +set serveroutput on +declare +cursor c is select roll_no,dept_name from department; +dept_row department%rowtype; +begin +open c; +fetch c into dept_row.roll_no,dept_row.dept_name; +while c%found loop +dbms_output.put_line('Roll: '||dept_row.roll_no||' Dept: '||dept_row.dept_name); +dbms_output.put_line('Count: '||c%rowcount); +fetch c into dept_row.roll_no,dept_row.dept_name; +end loop; +close c; +end; +/ + +--if/elseif/else +set serveroutput on +declare +cursor c is select reg_no,hsc_mark from eligible; +e_row eligible%rowtype; +begin +open c; +fetch c into e_row.reg_no, e_row.hsc_mark; +while c%found loop +if e_row.hsc_mark>540 +then dbms_output.put_line('Reg_no: '||e_row.reg_no||' HSC_Mark: '||e_row.hsc_mark||'Student rating: Outstanding'); +elsif e_row.hsc_mark>500 +then dbms_output.put_line('Reg_no: '||e_row.reg_no||' HSC_Mark: '||e_row.hsc_mark||'Student rating: Good'); +else +dbms_output.put_line('Reg_no: '||e_row.reg_no||' HSC_Mark: '||e_row.hsc_mark||'Student rating: Medium'); +end if; +dbms_output.put_line('Count: '||c%rowcount); +fetch c into e_row.reg_no, e_row.hsc_mark; +end loop; +close c; +end; +/ + +--procedure +create or replace procedure proc( + merit in examinee.merit_place%type, + id out examinee.applicant_id%type, + marks out examinee.total_mark%type +) is var varchar(30); +begin +select applicant_id,total_mark into id,marks from examinee where merit_place=merit; +end; +/ + +set serveroutput on +declare +merit examinee.merit_place%type:=1; +id examinee.applicant_id%type; +mark examinee.total_mark%type; +begin +proc(merit,id,mark); +dbms_output.put_line('Applicant_id: '||id||' Marks: '||mark||' Merit_place: '||merit); +end; +/ + +--function +create or replace function fun( + roll in department.roll_no%type +) return varchar as faculty department.faculty%type; +begin +select faculty into faculty from department where roll_no=roll; +return faculty; +end; +/ + +set serveroutput on +declare +roll department.roll_no%type:='R001'; +faculty department.dept_name%type; +dept department.dept_name%type; +cursor c is select dept_name,faculty from department where faculty= fun(roll); +begin +open c; +fetch c into dept,faculty; +while c%found loop +dbms_output.put_line('Dept: '||dept||' Faculty: '||faculty); +fetch c into dept,faculty; +end loop; +close c; +end; +/ + +--drop procedur / function +drop procedure proc; +drop function fun; \ No newline at end of file From b6e417e89ff20bcd5813bf627eb49b5e56d9d680 Mon Sep 17 00:00:00 2001 From: Mahbub022 <126968142+Mahbub022@users.noreply.github.com> Date: Fri, 26 May 2023 14:17:37 +0600 Subject: [PATCH 06/12] Update PLSQL.sql --- project/PLSQL.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project/PLSQL.sql b/project/PLSQL.sql index 70723c0..57d61bb 100644 --- a/project/PLSQL.sql +++ b/project/PLSQL.sql @@ -109,7 +109,7 @@ end; set serveroutput on declare roll department.roll_no%type:='R001'; -faculty department.dept_name%type; +faculty department.faculty%type; dept department.dept_name%type; cursor c is select dept_name,faculty from department where faculty= fun(roll); begin @@ -125,4 +125,4 @@ end; --drop procedur / function drop procedure proc; -drop function fun; \ No newline at end of file +drop function fun; From 7925e13dfd3f758358065215f4b799a8c9339617 Mon Sep 17 00:00:00 2001 From: Mahbub022 <126968142+Mahbub022@users.noreply.github.com> Date: Wed, 31 May 2023 02:11:17 +0600 Subject: [PATCH 07/12] Rename DDL.sql to UDML.sql --- project/{DDL.sql => UDML.sql} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename project/{DDL.sql => UDML.sql} (98%) diff --git a/project/DDL.sql b/project/UDML.sql similarity index 98% rename from project/DDL.sql rename to project/UDML.sql index 97f3c3b..f955cdf 100644 --- a/project/DDL.sql +++ b/project/UDML.sql @@ -52,4 +52,4 @@ join applicant a on a.applicant_id = eg.applicant_id join examinee e on e.applicant_id = a.applicant_id join student s on s.merit_place = e.merit_place join department d on d.roll_no = s.roll_no; -select * from admission; \ No newline at end of file +select * from admission; From c58b0869c3ee3739b1f2b821de44ccbba50e16b5 Mon Sep 17 00:00:00 2001 From: Mahbub022 <126968142+Mahbub022@users.noreply.github.com> Date: Wed, 31 May 2023 02:11:36 +0600 Subject: [PATCH 08/12] Rename DML.sql to DDL.sql --- project/{DML.sql => DDL.sql} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename project/{DML.sql => DDL.sql} (99%) diff --git a/project/DML.sql b/project/DDL.sql similarity index 99% rename from project/DML.sql rename to project/DDL.sql index c640690..775ebfd 100644 --- a/project/DML.sql +++ b/project/DDL.sql @@ -72,4 +72,4 @@ create table student( foreign key (merit_place) references examinee(merit_place), foreign key (roll_no) references department(roll_no) on delete cascade -); \ No newline at end of file +); From d3c61a4cb8141bb22c264f82bf7fb81d38d7b22f Mon Sep 17 00:00:00 2001 From: Mahbub022 <126968142+Mahbub022@users.noreply.github.com> Date: Wed, 31 May 2023 02:11:52 +0600 Subject: [PATCH 09/12] Rename UDML.sql to DML.sql --- project/{UDML.sql => DML.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename project/{UDML.sql => DML.sql} (100%) diff --git a/project/UDML.sql b/project/DML.sql similarity index 100% rename from project/UDML.sql rename to project/DML.sql From 76e232046ab42c0510fd75ee86c7483ed9bdf5bc Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 8 Jul 2023 21:46:00 +0600 Subject: [PATCH 10/12] trigger added in PLSQL.sql --- project/DDL.sql | 116 +++++++++++++++++++++++++++------------------- project/DML.sql | 116 +++++++++++++++++++--------------------------- project/PLSQL.sql | 13 +++++- project/marks.sql | 26 +++++++++++ 4 files changed, 153 insertions(+), 118 deletions(-) create mode 100644 project/marks.sql diff --git a/project/DDL.sql b/project/DDL.sql index 97f3c3b..69cbf20 100644 --- a/project/DDL.sql +++ b/project/DDL.sql @@ -1,55 +1,75 @@ ---pagesize & linesize -set pagesize 1500; -set linesize 300; +--drop tables & views +drop view admission; +drop table eligible; +drop table student; +drop table examinee; +drop table profile; +drop table applicant; +drop table department; --- select -select * from profile; -select name from profile; ---update & delete -INSERT INTO applicant VALUES ('A016', 'Venue1', timestamp '2023-05-20 09:00:00'); -update applicant set exam_venue = 'Venue5' where applicant_id = 'A016'; -delete from applicant where applicant_id = 'A016'; +--profile +create table profile( + reg_no varchar(30) primary key, + hsc_roll varchar(30) not null, + name varchar(30) not null, + father_name varchar(30) not null, + mother_name varchar(30) not null, + birth_date date not null, + address varchar(30) not null, + email varchar(30) unique not null, + religion varchar(30) not null check (religion in ('Islam','Hindu','Budhha','Christ')) +); ---union, intersect, except -select applicant_id,apply_time from applicant where extract (hour from apply_time)>10 -union -select applicant_id,apply_time from applicant where extract (hour from apply_time)<16; +--applicant +create table applicant( + applicant_id varchar(30) primary key, + exam_venue varchar(30) not null, + apply_time timestamp not null +); ---with clause -with avg_number(hsc_mark) as (select avg(hsc_mark) from eligible) -select * from eligible,avg_number where eligible.hsc_mark > avg_number.hsc_mark; +--eligible +create table eligible( + reg_no varchar(30), + applicant_id varchar(30), + hsc_mark numeric(3) not null check (hsc_mark<=600), + hsc_gpa numeric(3,2) not null check(hsc_gpa<=5.00), + ssc_gpa numeric(3,2) not null check(ssc_gpa<=5.00), + eligibility varchar(5) not null check(eligibility in ('yes','no')), + foreign key (reg_no) references profile (reg_no), + foreign key (applicant_id) references applicant (applicant_id) + on delete cascade +); ---aggregate -select count (distinct hsc_gpa) as gpa_hsc from eligible; -select max (total_mark) as exam_marks from examinee; +--examinee +create table examinee( + applicant_id varchar(30), + phy_mark numeric(3) not null check (phy_mark<=150), + chem_mark numeric(3) not null check (chem_mark<=150), + math_mark numeric(3) not null check (math_mark<=150), + eng_mark numeric(3) not null check (eng_mark<=50), + gpa_mark numeric(3) not null check (gpa_mark<=100), + total_mark numeric(3) check (total_mark<=600), + merit_place numeric(5) primary key, + foreign key (applicant_id) references applicant(applicant_id) + on delete cascade +); ---group by & having -select faculty,count(distinct dept_name) as number_of_dept from department group by faculty; -select faculty,count(distinct dept_name) as number_of_dept from department group by faculty having count(dept_name) > 2; +--department +create table department( + roll_no varchar(30) primary key, + dept_name varchar(30) not null, + dept_id numeric(2) not null, + faculty varchar(30) not null +); ---nested subquery -select name from profile where reg_no = -(select reg_no from eligible where applicant_id = -(select applicant_id from examinee where merit_place = 1 )); - ---set membership -select name from profile where reg_no in -(select reg_no from eligible where applicant_id in -(select applicant_id from examinee where merit_place >=1 and merit_place <=5 )); - ---string -select dept_name,faculty from department where dept_name like '%Engineer%'; - ---join operations -select applicant_id,total_mark,merit_place,roll_no from examinee natural join student order by merit_place asc; -select name,merit_place from profile join eligible on profile.reg_no = eligible.reg_no join examinee on eligible.applicant_id = examinee.applicant_id where merit_place<4 order by merit_place asc; - ---views -create view admission as select name,p.reg_no,a.applicant_id,hsc_gpa,ssc_gpa,gpa_mark,phy_mark,math_mark,chem_mark,eng_mark,total_mark, -e.merit_place,s.roll_no,dept_name,dept_id,faculty from profile p join eligible eg on p.reg_no = eg.reg_no -join applicant a on a.applicant_id = eg.applicant_id -join examinee e on e.applicant_id = a.applicant_id -join student s on s.merit_place = e.merit_place -join department d on d.roll_no = s.roll_no; -select * from admission; \ No newline at end of file +--student +create table student( + merit_place numeric(5) not null, + roll_no varchar(30) not null, + dept_choice varchar(30) not null, + priority numeric(2) not null, + foreign key (merit_place) references examinee(merit_place), + foreign key (roll_no) references department(roll_no) + on delete cascade +); \ No newline at end of file diff --git a/project/DML.sql b/project/DML.sql index c640690..97f3c3b 100644 --- a/project/DML.sql +++ b/project/DML.sql @@ -1,75 +1,55 @@ ---drop tables & views -drop view admission; -drop table eligible; -drop table student; -drop table examinee; -drop table profile; -drop table applicant; -drop table department; +--pagesize & linesize +set pagesize 1500; +set linesize 300; +-- select +select * from profile; +select name from profile; ---profile -create table profile( - reg_no varchar(30) primary key, - hsc_roll varchar(30) not null, - name varchar(30) not null, - father_name varchar(30) not null, - mother_name varchar(30) not null, - birth_date date not null, - address varchar(30) not null, - email varchar(30) unique not null, - religion varchar(30) not null check (religion in ('Islam','Hindu','Budhha','Christ')) -); +--update & delete +INSERT INTO applicant VALUES ('A016', 'Venue1', timestamp '2023-05-20 09:00:00'); +update applicant set exam_venue = 'Venue5' where applicant_id = 'A016'; +delete from applicant where applicant_id = 'A016'; ---applicant -create table applicant( - applicant_id varchar(30) primary key, - exam_venue varchar(30) not null, - apply_time timestamp not null -); +--union, intersect, except +select applicant_id,apply_time from applicant where extract (hour from apply_time)>10 +union +select applicant_id,apply_time from applicant where extract (hour from apply_time)<16; ---eligible -create table eligible( - reg_no varchar(30), - applicant_id varchar(30), - hsc_mark numeric(3) not null check (hsc_mark<=600), - hsc_gpa numeric(3,2) not null check(hsc_gpa<=5.00), - ssc_gpa numeric(3,2) not null check(ssc_gpa<=5.00), - eligibility varchar(5) not null check(eligibility in ('yes','no')), - foreign key (reg_no) references profile (reg_no), - foreign key (applicant_id) references applicant (applicant_id) - on delete cascade -); +--with clause +with avg_number(hsc_mark) as (select avg(hsc_mark) from eligible) +select * from eligible,avg_number where eligible.hsc_mark > avg_number.hsc_mark; ---examinee -create table examinee( - applicant_id varchar(30), - phy_mark numeric(3) not null check (phy_mark<=150), - chem_mark numeric(3) not null check (chem_mark<=150), - math_mark numeric(3) not null check (math_mark<=150), - eng_mark numeric(3) not null check (eng_mark<=50), - gpa_mark numeric(3) not null check (gpa_mark<=100), - total_mark numeric(3) not null check (total_mark<=600), - merit_place numeric(5) primary key, - foreign key (applicant_id) references applicant(applicant_id) - on delete cascade -); +--aggregate +select count (distinct hsc_gpa) as gpa_hsc from eligible; +select max (total_mark) as exam_marks from examinee; ---department -create table department( - roll_no varchar(30) primary key, - dept_name varchar(30) not null, - dept_id numeric(2) not null, - faculty varchar(30) not null -); +--group by & having +select faculty,count(distinct dept_name) as number_of_dept from department group by faculty; +select faculty,count(distinct dept_name) as number_of_dept from department group by faculty having count(dept_name) > 2; ---student -create table student( - merit_place numeric(5) not null, - roll_no varchar(30) not null, - dept_choice varchar(30) not null, - priority numeric(2) not null, - foreign key (merit_place) references examinee(merit_place), - foreign key (roll_no) references department(roll_no) - on delete cascade -); \ No newline at end of file +--nested subquery +select name from profile where reg_no = +(select reg_no from eligible where applicant_id = +(select applicant_id from examinee where merit_place = 1 )); + +--set membership +select name from profile where reg_no in +(select reg_no from eligible where applicant_id in +(select applicant_id from examinee where merit_place >=1 and merit_place <=5 )); + +--string +select dept_name,faculty from department where dept_name like '%Engineer%'; + +--join operations +select applicant_id,total_mark,merit_place,roll_no from examinee natural join student order by merit_place asc; +select name,merit_place from profile join eligible on profile.reg_no = eligible.reg_no join examinee on eligible.applicant_id = examinee.applicant_id where merit_place<4 order by merit_place asc; + +--views +create view admission as select name,p.reg_no,a.applicant_id,hsc_gpa,ssc_gpa,gpa_mark,phy_mark,math_mark,chem_mark,eng_mark,total_mark, +e.merit_place,s.roll_no,dept_name,dept_id,faculty from profile p join eligible eg on p.reg_no = eg.reg_no +join applicant a on a.applicant_id = eg.applicant_id +join examinee e on e.applicant_id = a.applicant_id +join student s on s.merit_place = e.merit_place +join department d on d.roll_no = s.roll_no; +select * from admission; \ No newline at end of file diff --git a/project/PLSQL.sql b/project/PLSQL.sql index 5963ff3..1c98cdf 100644 --- a/project/PLSQL.sql +++ b/project/PLSQL.sql @@ -109,7 +109,7 @@ end; set serveroutput on declare roll department.roll_no%type:='R001'; -faculty department.dept_name%type; +faculty department.faculty%type; dept department.dept_name%type; cursor c is select dept_name,faculty from department where faculty= fun(roll); begin @@ -125,4 +125,13 @@ end; --drop procedur / function drop procedure proc; -drop function fun; \ No newline at end of file +drop function fun; + +--trigger +CREATE or REPLACE TRIGGER update_total_mark +BEFORE INSERT OR UPDATE ON examinee +REFERENCING OLD AS O NEW AS n +FOR EACH ROW +BEGIN + n.total_mark := n.phy_mark + n.chem_mark + n.math_mark + n.eng_mark + n.gpa_mark; +END; \ No newline at end of file diff --git a/project/marks.sql b/project/marks.sql new file mode 100644 index 0000000..52639f0 --- /dev/null +++ b/project/marks.sql @@ -0,0 +1,26 @@ +create or replace procedure printMark(elg in eligible.eligibility%type) as +cursor mark is select applicant_id,phy_mark,chem_mark,math_mark from examinee where applicant_id in (select applicant_id from eligible where eligibility=elg); +id examinee.applicant_id%type; +pM examinee.phy_mark%type; +cM examinee.chem_mark%type; +mM examinee.math_mark%type; +begin +open mark; +fetch mark into id,pM,cM,mM; +while mark%found loop +dbms_output.put_line('Applicant id: '||id||' Phy_Mark: '||pM||' Chem_Mark: '||cM||' Math_Mark: '||mM); +fetch mark into id,pM,cM,mM; +end loop; +close mark; +end; +/ + +set serveroutput on +declare +elg eligible.eligibility%type:='yes'; +begin +printMark(elg); +end; +/ + +select applicant_id,eligibility from eligible; \ No newline at end of file From c123ef5a75dfdc892946ecfa8de465bf7cf279a1 Mon Sep 17 00:00:00 2001 From: Mahbub022 <126968142+Mahbub022@users.noreply.github.com> Date: Sat, 8 Jul 2023 21:57:15 +0600 Subject: [PATCH 11/12] merge conflict resolve --- project/DDL.sql | 4 ---- 1 file changed, 4 deletions(-) diff --git a/project/DDL.sql b/project/DDL.sql index c197fe9..d1a6416 100644 --- a/project/DDL.sql +++ b/project/DDL.sql @@ -49,11 +49,7 @@ create table examinee( math_mark numeric(3) not null check (math_mark<=150), eng_mark numeric(3) not null check (eng_mark<=50), gpa_mark numeric(3) not null check (gpa_mark<=100), -<<<<<<< HEAD total_mark numeric(3) check (total_mark<=600), -======= - total_mark numeric(3) not null check (total_mark<=600), ->>>>>>> d3c61a4cb8141bb22c264f82bf7fb81d38d7b22f merit_place numeric(5) primary key, foreign key (applicant_id) references applicant(applicant_id) on delete cascade From 443f1905b65add6a95e7e77d9966627ec27956fd Mon Sep 17 00:00:00 2001 From: Mahbub022 <126968142+Mahbub022@users.noreply.github.com> Date: Sat, 8 Jul 2023 22:00:48 +0600 Subject: [PATCH 12/12] Update DDL.sql --- project/DDL.sql | 4 ---- 1 file changed, 4 deletions(-) diff --git a/project/DDL.sql b/project/DDL.sql index d1a6416..9ef804f 100644 --- a/project/DDL.sql +++ b/project/DDL.sql @@ -72,8 +72,4 @@ create table student( foreign key (merit_place) references examinee(merit_place), foreign key (roll_no) references department(roll_no) on delete cascade -<<<<<<< HEAD ); -======= -); ->>>>>>> d3c61a4cb8141bb22c264f82bf7fb81d38d7b22f