From 8363b11fd637b8e6cde0f4a2e824db12d4c9f435 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Sat, 27 May 2023 03:47:31 +0000 Subject: [PATCH 1/2] Setting up GitHub Classroom Feedback From 8564250c38c867b2bcc99f09b5427f73f2dfebe2 Mon Sep 17 00:00:00 2001 From: Jesiara Date: Wed, 31 May 2023 09:49:17 +0600 Subject: [PATCH 2/2] Poject Folder added --- .../DDL.sql | 56 ++++ .../DML.sql | 258 ++++++++++++++++++ .../PL_SQL.sql | 170 ++++++++++++ 3 files changed, 484 insertions(+) create mode 100644 1907011_Online_Mobile_Shop_Management_System/DDL.sql create mode 100644 1907011_Online_Mobile_Shop_Management_System/DML.sql create mode 100644 1907011_Online_Mobile_Shop_Management_System/PL_SQL.sql diff --git a/1907011_Online_Mobile_Shop_Management_System/DDL.sql b/1907011_Online_Mobile_Shop_Management_System/DDL.sql new file mode 100644 index 0000000..1c5ad8c --- /dev/null +++ b/1907011_Online_Mobile_Shop_Management_System/DDL.sql @@ -0,0 +1,56 @@ +create table member( + mem_id number(5) check(length(mem_id)=5) not null primary key, + username varchar(50) not null, + password varchar(20) check(length(password)>=6) not null, + email varchar(50) unique not null, + address varchar(50), + phone varchar(11) check(length(phone)=11) not null + ); + + +create table mobile( + pro_id number(5) check(length(pro_id)=5) not null primary key, + pro_name varchar(50) not null, + pro_model number(10) not null, + pro_desc varchar(450), + amount number(30) not null, + color varchar(20)); + +create table rating( + rating_id number(4) check(length(rating_id)=4) not null primary key, + mem_id number(5) check(length(mem_id)=5) not null, + pro_id number(5) check(length(pro_id)=5) not null, + value number(2,1) not null, + foreign key(mem_id) references member(mem_id) on delete cascade, + foreign key(pro_id) references mobile(pro_id) on delete cascade); + + +create table cart( + cart_id number(4) check(length(cart_id)=4) not null primary key, + mem_id number(5) check(length(mem_id)=5) not null, + pro_id number(5) check(length(pro_id)=5) not null, + quantity number not null, + foreign key(mem_id) references member(mem_id) on delete cascade, + foreign key(pro_id) references mobile(pro_id) on delete cascade); + + +create table transaction( + transaction_id number(4) check(length(transaction_id)=4) not null primary key, + mem_id number(5) check(length(mem_id)=5) not null, + cart_id number(4) check(length(cart_id)=4) not null, + payment_amount number(20) not null, + payment_date DATE not null, + foreign key(mem_id) references member(mem_id) on delete cascade, + foreign key(cart_id) references cart(cart_id) on delete cascade); + + +--1.add column +alter table member add name char(20); +--2.modify column +alter table member modify name varchar(50); +--3.rename column +alter table member rename column name to fullname; +--4.delete column +alter table member drop column fullname; + + diff --git a/1907011_Online_Mobile_Shop_Management_System/DML.sql b/1907011_Online_Mobile_Shop_Management_System/DML.sql new file mode 100644 index 0000000..8958cae --- /dev/null +++ b/1907011_Online_Mobile_Shop_Management_System/DML.sql @@ -0,0 +1,258 @@ +insert into member (mem_id, username, password, email, address, phone) values (11111, 'Jesi', 'password1', 'jesi@gmail.com', 'Khulna', '01790078350'); +insert into member (mem_id, username, password, email, address, phone) values (22222, 'Luna', 'password2', 'luna@email.com', 'Bornali,Rajshahi', '01790078351'); +insert into member (mem_id, username, password, email, address, phone) values (33333, 'Jezz', 'password3', 'jezz@email.com', 'Bongura,Comilla', '01790078352'); +insert into member (mem_id, username, password, email, address, phone) values (44444, 'Nova', 'password4', 'nova@email.com', 'Mirpur-14,Dhaka', '01790078353'); +insert into member (mem_id, username, password, email, address, phone) values (55555, 'Ruby', 'password5', 'ruby@email.com', 'Natore', '01790078354'); +insert into member (mem_id, username, password, email, address, phone) values (66666, 'Ivy', 'password6', 'ivy@email.com', 'Bogura', '01790078355'); +insert into member (mem_id, username, password, email, address, phone) values (77777, 'Finn', 'password7', 'finn@email.com', 'Sylhet', '01790078356'); +insert into member (mem_id, username, password, email, address, phone) values (88888, 'Max', 'password8', 'max@email.com', 'Pabna', '01790078357'); +insert into member (mem_id, username, password, email, address, phone) values (99999, 'Milo', 'password9', 'milo@email.com', 'Luxmipur,Rajshahi', '01790078358'); +insert into member (mem_id, username, password, email, address, phone) values (10101, 'Semon', 'password10', 'semon@email.com', 'Shaheb Bajar,Rajshahi', '01790078359'); + + + +insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10001, 'Xiaomi Redmi Note 12', 111,'1.6.67-inch Super AMOLED display + 2.Snapdragon 4 Gen 1 chipset,4GB RAM + 3.85.0% screen-to-body ratio + 4.Corning Gorilla Glass 3 + 5.48MP primary, 8MP ultrawide, and a 2MP additional lens + 6.5000mAh battery with 33W fast charging' , 20000, 'Green'); + +insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10002, 'Oppo F19 pro+', 222, '1.6.43-inch Super AMOLED display + 2.800U Octa Core processor,8GB RAM,128GB storage + 3.84.9% screen-to-body ratio + 4.Corning Gorilla Glass 5 + 5.48MP primary, 2MP macro, and a 2MP depth sensor + 6.4310mAh battery with 50W fast charging', 18000, 'Gray'); +insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10003, 'Redmi Note 10 Pro', 333, '1.AMOLED display + 2.Snapdragon 4 Gen 1 chipset,4GB RAM + 3.85.0% screen-to-body ratio + 4.Corning Gorilla Glass 3 + 5.48MP primary, 8MP ultrawide, and a 2MP additional lens + 6.5020mAh battery with 33W fast charging', 20000, 'Ocean Blue'); +insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10004, 'iQOO Z7 5G', 444, '1.6.38-inch AMOLED display + 2.MediaTek Dimensity 920 chipset,6GB RAM,128GB ROM + 3.84.14% screen-to-body ratio + 4.Corning Gorilla Glass 3 + 5. 64MP primary and a 2MP additional lens + 6.5000mAh battery with 33W fast charging', 18999, 'Blue'); +insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10005, 'Realme 10', 555, '1.6.4-inch Super AMOLED display + 2. MediaTek Helio G99 SoC,4GB RAM + 3.84.4% screen-to-body ratio + 4.Corning Gorilla Glass 3 + 5.50MP primary and a 2MP additional lens. + 6.5000mAh battery with 33W fast charging', 14450, 'Gray'); +insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10006, 'Realme 8', 666, '1.AMOLED display + 2.4GB RAM,128GB ROM + 3.85.0% screen-to-body ratio + 4.Corning Gorilla Glass 3 + 5.48MP primary, 8MP ultrawide, and a 2MP additional lens + 6.5000mAh battery with 30W fast charging', 20000, 'Green'); +insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10007, 'Xiaomi Redmi Note 11 SE', 777, '1.6.43-inch Super AMOLED display + 2.MediaTek Helio G95 chipset with 6GB RAM + 3.83.53% screen-to-body ratio + 4.Corning Gorilla Glass 3 + 5.64MP primary, 8MP ultrawide, and a 2MP additional lens + 6.5000mAh battery with 33W fast charging', 11999, 'Green'); +insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10008, 'Samsung Galaxy M32', 888, '1.6.4-inch Super AMOLED display + 2.MediaTek Helio G80 chipset with 4GB RAM + 3.98.9% screen-to-body ratio + 4.Corning Gorilla Glass 3 + 5.64MP primary, 8MP ultrawide, and a 2MP additional lens + 6.6000mAh battery with 33W fast charging', 13399, 'Green'); +insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10009, 'Poco X5', 999, '1.6.67-inch Super AMOLED display + 2.Snapdragon 695 chipset,6GB RAM + 3.85.02% screen-to-body ratio + 4.Corning Gorilla Glass 3 + 5.48MP primary, 8MP ultrawide, and a 2MP additional lens + 6.5000mAh battery with 33W fast charging', 18999, 'Green'); +insert into mobile (pro_id, pro_name, pro_model, pro_desc, amount, color) values (10010, 'Motorola Moto G71', 101, '1.6.4-inch AMOLED display + 2.Snapdragon 4 Gen 1 chipset,4GB RAM + 3.85.0% screen-to-body ratio + 4.Corning Gorilla Glass 3 + 5.48MP primary, 8MP ultrawide, and a 2MP additional lens + 6.5000mAh battery with 33W fast charging', 19000, 'Arctic Blue'); + +insert into rating (rating_id, mem_id, pro_id, value) values (1111, 11111, 10001, 9.9); +insert into rating (rating_id, mem_id, pro_id, value) values (2222, 11111, 10002, 7.9); +insert into rating (rating_id, mem_id, pro_id, value) values (3333, 22222, 10001, 6.9); +insert into rating (rating_id, mem_id, pro_id, value) values (4444, 33333, 10001, 9.5); +insert into rating (rating_id, mem_id, pro_id, value) values (5555, 55555, 10001, 9.7); +insert into rating (rating_id, mem_id, pro_id, value) values (6666, 11111, 10003, 8.9); +insert into rating (rating_id, mem_id, pro_id, value) values (7777, 11111, 10004, 7.9); +insert into rating (rating_id, mem_id, pro_id, value) values (8888, 88888, 10008, 5.9); +insert into rating (rating_id, mem_id, pro_id, value) values (9999, 33333, 10006, 8.9); +insert into rating (rating_id, mem_id, pro_id, value) values (1010, 77777, 10006, 9.9); + +insert into cart (cart_id, mem_id, pro_id, quantity) values (1001, 11111, 10001, 2); +insert into cart (cart_id, mem_id, pro_id, quantity) values (1002, 22222, 10005, 1); +insert into cart (cart_id, mem_id, pro_id, quantity) values (1003, 77777, 10001, 2); +insert into cart (cart_id, mem_id, pro_id, quantity) values (1004, 33333, 10002, 3); +insert into cart (cart_id, mem_id, pro_id, quantity) values (1005, 11111, 10006, 1); +insert into cart (cart_id, mem_id, pro_id, quantity) values (1006, 11111, 10007, 1); +insert into cart (cart_id, mem_id, pro_id, quantity) values (1007, 88888, 10009, 1); +insert into cart (cart_id, mem_id, pro_id, quantity) values (1008, 88888, 10002, 1); +insert into cart (cart_id, mem_id, pro_id, quantity) values (1009, 44444, 10001, 2); +insert into cart (cart_id, mem_id, pro_id, quantity) values (1010, 33333, 10003, 1); + + +insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1011, 11111, 1001, 40000, date '2023-05-01'); +insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1022, 22222, 1002, 14450, date '2023-05-04'); +insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1033, 77777, 1003, 40000, date '2023-04-02'); +insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1044, 33333, 1004, 54000, date '2023-05-09'); +insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1055, 11111, 1005, 20000, date '2023-04-08'); +insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1066, 11111, 1006, 11999, date '2023-05-09'); +insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1077, 88888, 1007, 18999, date '2023-05-08'); +insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1088, 88888, 1008, 18000, date '2023-05-04'); +insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1099, 44444, 1009, 40000, date '2023-05-20'); +insert into transaction (transaction_id, mem_id, cart_id, payment_amount, payment_date) values (1012, 33333, 1010, 20000, date '2023-05-06'); + + + + + +--QUERY + +---Displaying data using select command-- +--1 +select * from member; +--2 +select * from mobile; +--3 +select * from rating; +--4 +select * from cart; +--5 +select * from transaction; +--6 +select * from rating where mem_id=11111; +--7 +select * from rating where value=9.9; + + + + +--Nested subquery +--8 +select username from member where mem_id=(select mem_id from rating where rating_id=1111); +--9 +select pro_name from mobile where pro_id=(select pro_id from cart where cart_id=(select cart_id from transaction where payment_date=date '2023-05-01')); + +--Updating data +--10 +update member set username='Jesu' where mem_id=11111; +select * from member; + +--Deleting a row +--11 +insert into member (mem_id, username, password, email, address, phone) values (10111, 'Semn', 'password11', 'semn@email.com', 'Shaheb Bajar,Rajshahi', '01790078309'); +delete from member where mem_id=10111; + + + +--Select Distinct/all +--12 +select distinct mem_id from transaction; +--13 +select all mem_id from transaction; +--14 +select distinct(amount),pro_name from mobile; + +--Select with arithmetic operation +--15 +select pro_model,amount/10 as dis_amount from mobile; + + +--The where clause +--16 +select pro_id from rating where value>7; +--17 +select member.username,mobile.pro_name from member,mobile where amount>19000; + +--Rename Operation +--18 +select m.username,mob.pro_name from member m,mobile mob where amount>19000; + +--String Operation +--19 +select username from member where username like 'J%'; +--20 +select username,email from member where username like '___' or username like '____'; + + +--Order by Clause-- +--21 +select username,email from member order by email; + +--Where clause predicates +--22 +select pro_name,amount from mobile where amount between 15000 and 19000; + +--Set operations(union,intersection) +--23 +select username from member where username like 'J___' union select username from member where username like '___'; +--24 +select username from member where username like 'J___' intersect select username from member where username like '___'; + + +--25-Agregate Functions +select count(cart_id) as no_of_cart from transaction; +--26 +select avg(payment_amount) from transaction group by cart_id; +--27 +select sum(amount) from mobile; +--28 +select max(amount) from mobile; +--29 +select min(amount) from mobile; + + +--Group by and Having +--30 +select pro_id,avg(quantity) from cart group by pro_id having avg(quantity)>=2; + +--Set Membership +--31 +select mem_id from cart where pro_id = 10001 and mem_id in (select mem_id from cart where pro_id=10007); +--32 +select mem_id from cart where pro_id = 10001 and mem_id not in (select mem_id from cart where pro_id=10002); + + +--Some/All/Exists +--33 +select * from cart where quantity> some(select quantity from cart where quantity>=2); +--34 +select * from cart where quantity> all(select quantity from cart where quantity>=1); +--35 +select * from rating where value>=8 and exists(select * from member where username like 'J%'); + +--With clause +--36 +with max_amount(val) as (select max(amount) from mobile) +select pro_name,amount from mobile,max_amount where mobile.amount=max_amount.val; + +--Join-- +--37 +select * from member natural join rating where mem_id=11111; +--38 +select username,value from member join rating using(mem_id); +--39 +select username,value from member join rating on member.mem_id=rating.mem_id; +--40 +select username,value from member left outer join rating using(mem_id); +--41 +select username,value from member right outer join rating using(mem_id); +--42 +select username,value from member full outer join rating using(mem_id); + + +--View-- +--43 +create view user_details as select username,email from member; +select * from user_details; +--44 +create view products as select pro_name from mobile where pro_id=(select pro_id from cart where quantity>2); +select * from products; +--45 +create view user_details2 as select * from user_details where username like 'J___'; +select * from user_details2; \ No newline at end of file diff --git a/1907011_Online_Mobile_Shop_Management_System/PL_SQL.sql b/1907011_Online_Mobile_Shop_Management_System/PL_SQL.sql new file mode 100644 index 0000000..a5823ed --- /dev/null +++ b/1907011_Online_Mobile_Shop_Management_System/PL_SQL.sql @@ -0,0 +1,170 @@ +--1.PL/SQL variable declaration and print value +set serveroutput on +declare +mem_id member.mem_id%type; +username member.username%type; +email member.email%type; +begin +select mem_id,username,email into mem_id,username,email from member where mem_id=11111; +dbms_output.put_line('Mem_id: '||mem_id|| ' Username: '||username || ' Email: '||email); +end; +/ + +--2.Insert and set default value +set serveroutput on +declare +mem_id member.mem_id%type:=12121; +username member.username%type:='Mim'; +password member.password%type:='1234456'; +email member.email%type:='mim@gmail.com'; +address member.address%type:='Khulna'; +phone member.phone%type:='01788355555'; +begin +insert into member values(mem_id, username, password, email, address, phone); +end; +/ + +--3.Row type +set serveroutput on +declare +mem_row member%rowtype; +begin +select mem_id,username,email into mem_row.mem_id,mem_row.username,mem_row.email from member where mem_id=11111; +end; +/ + +--4.Cursor and Row count +set serveroutput on +declare +cursor c is select * from member; +mem_row member%rowtype; +begin +open c; +fetch c into mem_row.mem_id,mem_row.username,mem_row.password,mem_row.email,mem_row.address,mem_row.phone; +while c%found loop +dbms_output.put_line('Mem_id: '||mem_row.mem_id|| ' Username: '||mem_row.username || ' Email: '||mem_row.email); +dbms_output.put_line('Row count: '|| c%rowcount); +fetch c into mem_row.mem_id,mem_row.username,mem_row.password,mem_row.email,mem_row.address,mem_row.phone; +end loop; +close c; +end; +/ +--5.with extent() function +set serveroutput on +declare + counter number; + pro_name2 mobile.pro_name%type; + TYPE NAMEARRAY IS VARRAY(5) OF mobile.pro_name%type; + A_NAME NAMEARRAY:=NAMEARRAY(); +begin + counter:=1; + for x in 10001..10003 + loop + select pro_name into pro_name2 from mobile where pro_id=x; + A_NAME.EXTEND(); + A_NAME(counter):=pro_name2; + counter:=counter+1; + end loop; + counter:=1; + WHILE counter<=A_NAME.COUNT + LOOP + DBMS_OUTPUT.PUT_LINE(A_NAME(counter)); + counter:=counter+1; + END LOOP; +end; +/ + +--6.without extend() function +set serveroutput on +declare + counter number; + pro_name2 mobile.pro_name%type; + TYPE NAMEARRAY IS VARRAY(3) OF mobile.pro_name%type; + A_NAME NAMEARRAY:=NAMEARRAY('pro 1', 'pro 2', 'pro 3'); +begin + counter:=1; + for x in 10001..10003 + loop + select pro_name into pro_name2 from mobile where pro_id=x; + A_NAME(counter):=pro_name2; + counter:=counter+1; + end loop; + counter:=1; + WHILE counter<=A_NAME.COUNT + LOOP + DBMS_OUTPUT.PUT_LINE(A_NAME(counter)); + counter:=counter+1; + END LOOP; +end; +/ + +--7.if-else +set serveroutput on +declare + counter number; + pro_name2 mobile.pro_name%type; + TYPE NAMEARRAY IS VARRAY(3) OF mobile.pro_name%type; + A_NAME NAMEARRAY:=NAMEARRAY('pro 1', 'pro 2', 'pro 3'); +begin + counter:=1; + for x in 10001..10003 + loop + select pro_name into pro_name2 from mobile where pro_id=x; + if pro_name2='Oppo F19 pro+' + then + dbms_output.put_line(pro_name2||' is '||'best'); + elsif pro_name2='Xiaomi Redmi Note 12' + then + dbms_output.put_line(pro_name2||' is a '||'good one'); + else + dbms_output.put_line(pro_name2||' is '||'not so good'); + end if; + END LOOP; +end; +/ + +--8.Procedure +CREATE OR REPLACE PROCEDURE proc2( + var1 IN NUMBER, + var2 OUT VARCHAR2, + var3 IN OUT NUMBER +) +AS + t_show CHAR(30); +BEGIN + t_show := 'From procedure: '; + SELECT pro_name INTO var2 FROM mobile WHERE amount=var1; + var3 := var1 + 1; + DBMS_OUTPUT.PUT_LINE(t_show || var2 || ' amount is ' || var1 || ' In out parameter: ' || var3); +END; +/ + + + +set serveroutput on +declare +amount mobile.amount%type:=19000; +pro_name mobile.pro_name%type; +extra number; +begin +proc2(amount,pro_name,extra); +end; +/ + +--9.Function +set serveroutput on +create or replace function fun(var1 in varchar) return varchar AS +value member.username%type; +begin + select username into value from member where mem_id=var1; + return value; +end; +/ +set serveroutput on +declare +value varchar(20); +begin +value:=fun(11111); +dbms_output.put_line(value); +end; +/ \ No newline at end of file