From 6bcccea044f5296ca9db198544d39c611f349edc Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Thu, 1 Jun 2023 06:31:37 +0000 Subject: [PATCH 1/6] Setting up GitHub Classroom Feedback From f2c06f494a6f4934df730b960eaea46ef67caeaf Mon Sep 17 00:00:00 2001 From: Sadia Afrin <116829514+meerror6d@users.noreply.github.com> Date: Sat, 3 Jun 2023 19:51:27 +0600 Subject: [PATCH 2/6] Add files via upload --- ddl.sql | 29 +++++++++++++++++ dml.sql | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ dml2.sql | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ pl_sql.sql | 84 +++++++++++++++++++++++++++++++++++++++++++++++ table.sql | 66 +++++++++++++++++++++++++++++++++++++ 5 files changed, 371 insertions(+) create mode 100644 ddl.sql create mode 100644 dml.sql create mode 100644 dml2.sql create mode 100644 pl_sql.sql create mode 100644 table.sql diff --git a/ddl.sql b/ddl.sql new file mode 100644 index 0000000..80cc907 --- /dev/null +++ b/ddl.sql @@ -0,0 +1,29 @@ +alter table product_category add description number(10); + +alter table product_category modify description varchar(20); + +alter table product_category rename column description to descrip; + +alter table products add availability number(20); + +alter table products modify availability varchar(20); + +alter table products rename column availability to status; + +alter table userlist add address varchar(10); + +alter table userlist modify address varchar(20); + +alter table userlist rename column address to location; + +alter table user_payment add payment_status number(20); + +alter table user_payment modify payment_status varchar(10); + +alter table user_payment rename column payment_status to payment; + +alter table order_detail add order_status number(10); + +alter table order_detail modify order_status varchar(10); + +alter table order_detail rename column order_status to order_; \ No newline at end of file diff --git a/dml.sql b/dml.sql new file mode 100644 index 0000000..47f17d2 --- /dev/null +++ b/dml.sql @@ -0,0 +1,96 @@ +---DATA INSERT--- + +insert into product_category(category_id,category_name,created_at,modified_at) values (100,'Laptop','01-02-22','02-12-22'); +insert into product_category(category_id,category_name,created_at,modified_at) values (101,'Phone','01-02-22','02-12-22'); +insert into product_category(category_id,category_name,created_at,modified_at) values (102,'Keyboard','01-02-22','02-12-22'); +insert into product_category(category_id,category_name,created_at,modified_at) values (103,'Mouse','01-02-22','02-12-22'); +insert into product_category(category_id,category_name,created_at,modified_at) values (104,'Headphone','01-02-22','02-12-22'); +insert into product_category(category_id,category_name,created_at,modified_at) values (105,'speaker','01-02-22','02-12-22'); +insert into product_category(category_id,category_name,created_at,modified_at) values (106,'smartwatch','01-02-22','02-12-22'); +insert into product_category(category_id,category_name,created_at,modified_at) values (107,'Camera','01-02-22','02-12-22'); +insert into product_category(category_id,category_name,created_at,modified_at) values (108,'Printer','01-02-22','02-12-22'); +insert into product_category(category_id,category_name,created_at,modified_at) values (109,'TV','01-02-22','02-12-22'); + + +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at) values (200,'Laptop','HP',100,62000,5000,'01-01-23','01-05-23'); +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at) values (201,'Phone','Xiomi',101,25000,5000,'01-01-23','01-05-23'); +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at) values (202,'Keyboard','Havit',102,7000,0,'01-01-23','01-05-23'); +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at) values (203,'Mouse','Legitech',103,1800,300,'01-01-23','01-05-23'); +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at) values (204,'Headphone','Boat',104,2000,200,'01-01-23','01-05-23'); +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at) values (205,'Speaker','Boat',105,2200,200,'01-01-23','01-05-23'); +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at) values (206,'smartwatch','Samsung',106,7000,500,'01-01-23','01-05-23'); +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at) values (207,'Camera','Canon',107,6200,10000,'01-01-23','01-05-23'); +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at) values (208,'Printer','Canon',108,15000,3000,'01-01-23','01-05-23'); +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at) values (209,'TV','Sharp',109,62000,1200,'01-01-23','01-05-23'); + + +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at) values (1000,'Sornaly','error','Sadia','Afrin',01726632220,200,'Laptop','01-02-23','05-05-23'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at) values (1001,'Sabnaj','error1','Sabnaj','Akter',01777258450,201,'Phone','02-02-23','05-06-23'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at) values (1002,'Shama','error2','Farhatun','Shama',01726632221,202,'Keyboard','05-02-23','09-05-23'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at) values (1003,'Arpita','error3','Arpita','Kundu',01726632222,200,'Laptop','09-02-23','01-05-23'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at) values (1004,'Deya','error4','Lamisa','Binte',01726632223,204,'Headphone','23-02-23','03-05-23'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at) values (1005,'Raha','error5','Rubaiya','Raktin',01726632224,205,'Speaker','11-02-23','06-05-23'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at) values (1006,'Subah','error6','Subah','Noshin',01726632225,200,'Laptop','17-02-23','05-07-23'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at) values (1007,'Mahila','error7','Mahila','Mohiuddin',01726632226,207,'Camera','14-02-23','02-09-23'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at) values (1008,'Shongi','error8','Taslima','Jannat',01726632227,208,'Printer','09-02-23','05-08-23'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at) values (1009,'Mridula','error9','Safwada','Prodhan',01726632228,200,'Laptop','01-02-23','05-01-23'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at) values (1010,'Sornaly','error','Sadia','Afrin',01726632220,200,'Laptop','01-02-23','05-05-23'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at) values (1011,'Sornaly','error','Sadia','Afrin',01726632220,202,'Keyboard','01-02-23','05-05-23'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at) values (1012,'Sornaly','error','Sadia','Afrin',01726632220,203,'Speaker','01-02-23','05-05-23'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at) values (1013,'Sornaly','error','Sadia','Afrin',01726632220,204,'Headphone','01-02-23','05-05-23'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at) values (1014,'Sornaly','error','Sadia','Afrin',01726632220,209,'TV','01-02-23','05-05-23'); + + +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry) values (3000,1000,'COD','NULL',1234567,'20-08-23'); +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry) values (3001,1001,'Agent','BKash',01726632220,'21-08-23'); +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry) values (3002,1002,'COD','NULL',12345234,'20-09-23'); +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry) values (3003,1003,'Agent','Rocket',1234567,'20-08-23'); +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry) values (3004,1004,'COD','NULL',01726632222,'20-09-23'); +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry) values (3005,1005,'Agent','Nogod',01726632223,'20-08-23'); +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry) values (3006,1006,'COD','NULL',1234567,'20-08-23'); +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry) values (3007,1007,'COD','NULL',1234567,'20-08-23'); +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry) values (3008,1008,'Agent','BKash',01726632227,'20-08-23'); +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry) values (3009,1009,'COD','NULL',1234568,'20-08-23'); + +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at) values (4000,1000,620000,2,3000,'05-02-23','06-02-23'); +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at) values (4001,1001,820000,1,3001,'05-03-23','06-12-23'); +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at) values (4002,1002,420000,7,3002,'05-01-23','06-12-23'); +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at) values (4003,1003,620000,2,3003,'05-04-23','06-07-23'); +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at) values (4004,1004,920000,1,3004,'05-05-23','06-02-23'); +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at) values (4005,1005,1220000,2,3005,'05-08-23','06-05-23'); +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at) values (4006,1006,670000,3,3006,'05-12-23','06-04-23'); +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at) values (4007,1007,640000,1,3007,'05-03-23','06-12-23'); +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at) values (4008,1008,600000,2,3008,'05-07-23','06-11-23'); +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at) values (4009,1009,600000,1,3009,'05-08-23','06-10-23'); + + + +---COMMANDS--- +set pagesize 550 +set linesize 550 + +select table_name from user_tables; + +select * from product_category; +select * from products; +select * from userlist; +select * from user_payment; +select * from order_detail; + +select * from product_category where category_id>105; +select * from products where price>=5000; +select * from userlist where username='Sornaly'; +select * from user_payment where provider='BKash'; +select * from order_detail where total_amount>=50000; +select * from order_detail where quantity>2; + +select username from userlist where product_name=(select product_name from products where product_id=200); +select username from userlist where product_name=(select product_name from products where product_id=202); + +update userlist set username='me_error' where username='Sornaly' and product_name='Laptop'; +select * from userlist; +---update userlist set username='me_error' where username='Sornaly' except product_name='Speaker'; +---select * from userlist; + +delete from userlist where username='Sornaly' and product_name='Speaker'; +select * from userlist; \ No newline at end of file diff --git a/dml2.sql b/dml2.sql new file mode 100644 index 0000000..35b3d5e --- /dev/null +++ b/dml2.sql @@ -0,0 +1,96 @@ +---DATA INSERT--- + +insert into product_category(category_id,category_name,created_at,modified_at,descrip) values (100,'Laptop','01-02-22','02-12-22','For Students'); +insert into product_category(category_id,category_name,created_at,modified_at,descrip) values (101,'Phone','01-02-22','02-12-22','Budget-friendly'); +insert into product_category(category_id,category_name,created_at,modified_at,descrip) values (102,'Keyboard','01-02-22','02-12-22','RGB'); +insert into product_category(category_id,category_name,created_at,modified_at,descrip) values (103,'Mouse','01-02-22','02-12-22','RGB'); +insert into product_category(category_id,category_name,created_at,modified_at,descrip) values (104,'Headphone','01-02-22','02-12-22','Noise cancellation'); +insert into product_category(category_id,category_name,created_at,modified_at,descrip) values (105,'Speaker','01-02-22','02-12-22',' '); +insert into product_category(category_id,category_name,created_at,modified_at,descrip) values (106,'Smartwatch','01-02-22','02-12-22',' '); +insert into product_category(category_id,category_name,created_at,modified_at,descrip) values (107,'Camera','01-02-22','02-12-22',' '); +insert into product_category(category_id,category_name,created_at,modified_at,descrip) values (108,'Printer','01-02-22','02-12-22','Mini'); +insert into product_category(category_id,category_name,created_at,modified_at,descrip) values (109,'TV','01-02-22','02-12-22','Smart-TV'); + + +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at,status) values (200,'Laptop','HP',100,62000,5000,'01-01-23','01-05-23','available'); +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at,status) values (201,'Phone','Xiomi',101,25000,5000,'01-01-23','01-05-23','available'); +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at,status) values (202,'Keyboard','Havit',102,7000,0,'01-01-23','01-05-23','Null'); +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at,status) values (203,'Mouse','Legitech',103,1800,300,'01-01-23','01-05-23','available'); +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at,status) values (204,'Headphone','Boat',104,2000,200,'01-01-23','01-05-23','Null'); +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at,status) values (205,'Speaker','Boat',105,2200,200,'01-01-23','01-05-23','available'); +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at,status) values (206,'smartwatch','Samsung',106,7000,500,'01-01-23','01-05-23','Null'); +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at,status) values (207,'Camera','Canon',107,62000,10000,'01-01-23','01-05-23','Null'); +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at,status) values (208,'Printer','Canon',108,15000,3000,'01-01-23','01-05-23','available'); +insert into products(product_id,product_name,description,category_id,price,discount,created_at,modified_at,status) values (209,'TV','Sharp',109,62000,1200,'01-01-23','01-05-23','available'); + + +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at,location) values (1000,'Sornaly','error','Sadia','Afrin',01726632220,200,'Laptop',01-02-23','05-05-23','Mymensingh'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at,location) values (1001,'Sabnaj','error1','Sabnaj','Akter',01777258450,201,'Phone',02-02-23','05-06-23','Dhaka'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at,location) values (1002,'Shama','error2','Farhatun','Shama',01726632221,202,'Keyboard',05-02-23','09-05-23','Chittagong'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at,location) values (1003,'Arpita','error3','Arpita','Kundu',01726632222,200,'Laptop','09-02-23','01-05-23','Khulna'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at,location) values (1004,'Deya','error4','Lamisa','Binte',01726632223,204,'Headphone',23-02-23','03-05-23','Sylhet'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at,location) values (1005,'Raha','error5','Rubaiya','Raktin',01726632224,205,'Speaker','11-02-23','06-05-23','Rajshahi'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at,location) values (1006,'Subah','error6','Subah','Noshin',01726632225,200,'Laptop','17-02-23','05-07-23','Narsingdi'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at,location) values(1007,'Mahila','error7','Mahila','Mohiuddin',01726632226,207,'Camera',14-02-23','02-09-23','Foridpur'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at,location) values (1008,'Shongi','error8','Taslima','Jannat',01726632227,208,'Printer','09-02-23','05-08-23','Bogra'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at,location) values (1009,'Mridula','error9','Safwada','Prodhan',01726632228,200,'Laptop','01-02-23','05-01-23','Cox's Bazar'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at,location) values (1010,'Sornaly','error','Sadia','Afrin',01726632220,200,'Laptop','01-02-23','05-05-23','Joypurhat'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at,location) values (1011,'Sornaly','error','Sadia','Afrin',01726632220,202,'Keyboard','01-02-23','05-05-23','Rangpur'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at,location) values (1012,'Sornaly','error','Sadia','Afrin',01726632220,203,'Speaker','01-02-23','05-05-23','Cumilla'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at,location) values (1013,'Sornaly','error','Sadia','Afrin',01726632220,204,'Headphone','01-02-23','05-05-23','Barisal'); +insert into userlist(id,username,password,first_name,last_name,phone,product_id,product_name,create_at,modified_at,location) values (1014,'Sornaly','error','Sadia','Afrin',01726632220,209,'TV','01-02-23','05-05-23','Jossore'); + + +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry,payment) values (3000,1000,'COD','NULL',1234567,'20-08-23','Done'); +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry,payment) values (3001,1001,'Agent','BKash',01726632220,'21-08-23','Pending'); +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry,payment) values (3002,1002,'COD','NULL',12345234,'20-09-23','Done'); +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry,payment) values (3003,1003,'Agent','Rocket',1234567,'20-08-23','Done'); +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry,payment) values (3004,1004,'COD','NULL',01726632222,'20-09-23','Pending'); +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry,payment) values (3005,1005,'Agent','Nogod',01726632223,'20-08-23','Pending'); +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry,payment) values (3006,1006,'COD','NULL',1234567,'20-08-23','Done'); +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry,payment) values (3007,1007,'COD','NULL',1234567,'20-08-23','Pending'); +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry,payment) values (3008,1008,'Agent','BKash',01726632227,'20-08-23','Done'); +insert into user_payment(user_payment_id,id,payment_type,provider,account,expiry,payment) values (3009,1009,'COD','NULL',1234568,'20-08-23','Done'); + +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at,order_) values (4000,1000,620000,2,3000,'05-02-23','06-02-23','Pending'); +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at,order_) values (4001,1001,820000,1,3001,'05-03-23','06-12-23','Delivered'); +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at,order_) values (4002,1002,420000,7,3002,'05-01-23','06-12-23','Delivered'); +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at,order_) values (4003,1003,620000,2,3003,'05-04-23','06-07-23','Pending'); +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at,order_) values (4004,1004,920000,1,3004,'05-05-23','06-02-23','Delivered'); +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at,order_) values (4005,1005,1220000,2,3005,'05-08-23','06-05-23','Pending'); +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at,order_) values (4006,1006,670000,3,3006,'05-12-23','06-04-23','Delivered'); +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at,order_) values (4007,1007,640000,1,3007,'05-03-23','06-12-23','Pending'); +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at,order_) values (4008,1008,600000,2,3008,'05-07-23','06-11-23','Delivered'); +insert into order_detail(order_id,id,total_amount,quantity,user_payment_id,created_at,modified_at,order_) values (4009,1009,600000,1,3009,'05-08-23','06-10-23','Delivered'); + + + +---COMANDS--- +set pagesize 550 +set linesize 550 + +select table_name from user_tables; + +select * from product_category; +select * from products; +select * from userlist; +select * from user_payment; +select * from order_detail; + +select * from product_category where category_id>105; +select * from products where price>=5000; +select * from userlist where username='Sornaly'; +select * from user_payment where provider='BKash'; +select * from order_detail where total_amount>=50000; +select * from order_detail where quantity>2; + +select username from userlist where product_name=(select product_name from products where product_id=200); +select username from userlist where product_name=(select product_name from products where product_id=202); + +update userlist set username='me_error' where username='Sornaly' and product_name='Laptop'; +select * from userlist; +---update userlist set username='me_error' where username='Sornaly' except product_name='Speaker'; +---select * from userlist; + +delete from userlist where username='Sornaly' and product_name='Speaker'; +select * from userlist; \ \ No newline at end of file diff --git a/pl_sql.sql b/pl_sql.sql new file mode 100644 index 0000000..122b460 --- /dev/null +++ b/pl_sql.sql @@ -0,0 +1,84 @@ +---see customer id,name,first_name,last_name from userlist table--- + +set SERVEROUTPUT on + +declare +userid userlist.id%type; +user_name userlist.username%type; +fname userlist.first_name%type; +lname userlist.last_name%type; + +begin +select id,username,first_name,last_name into userid,user_name,fname,lname from userlist where id=1002; +dbms_output.put_line('userid:' || userid ||',username:'|| user_name || ',first name:'|| fname || ',last name:' || lname); +end; +/ + +---see arpita's info from userlist---- +set SERVEROUTPUT on + +declare +userid userlist.id%type; +user_name userlist.username%type; +fname userlist.first_name%type; +lname userlist.last_name%type; + +begin +select id,username,first_name,last_name into userid,user_name,fname,lname from userlist where username='Arpita'; +dbms_output.put_line('userid:' || userid ||',username:'|| user_name || ',first name:'|| fname || ',last name:' || lname); +end; +/ + + +---count product row--- + +set serveroutput on +declare +products_row products%rowtype; +begin +select product_id,product_name,description,category_id,price,discount,created_at,modified_at into products_row.product_id,products_row.product_name,products_row.description,products_row.category_id,products_row.price,products_row.discount,products_row.created_at,products_row.modified_at from products where product_id=200; +end; +/ + +---show everything using cursor from products table--- +set serveroutput on +declare +cursor product_cursor is +select * from products; +products_row products%rowtype; +begin +open product_cursor; +fetch product_cursor into products_row.product_id,products_row.product_name,products_row.description,products_row.category_id,products_row.price,products_row.discount,products_row.created_at,products_row.modified_at; +while product_cursor%found +loop +dbms_output.put_line('product id: '||products_row.product_id|| ', product name: '||products_row.product_name||',Description: '||products_row.description||',category id: '||products_row.category_id||',price: '||products_row.price||',discount: '||products_row.discount||',created at'||products_row.created_at||',modified at'||products_row.modified_at); +dbms_output.put_line('Row count: '|| product_cursor%rowcount); +fetch product_cursor into products_row.product_id,products_row.product_name,products_row.description,products_row.category_id,products_row.price,products_row.discount,products_row.created_at,products_row.modified_at; +end loop; +close product_cursor; +end; +/ + + + + + + + + + + +---INTRODUCTION--- + +set SERVEROUTPUT on; +begin +dbms_output.put_line(' '); +dbms_output.put_line(' '); +dbms_output.put_line(' '); +dbms_output.put_line(' '); +dbms_output.put_line('-------------------------------------------------------------------------------------------------------- '); +dbms_output.put_line('Project Name : Gadget Store Management System'); +dbms_output.put_line('Created by : Sadia Afrin'); +dbms_output.put_line('Roll : 1907037'); +end; +/ \ No newline at end of file diff --git a/table.sql b/table.sql new file mode 100644 index 0000000..3281a3f --- /dev/null +++ b/table.sql @@ -0,0 +1,66 @@ +drop table order_detail; +drop table user_payment; +drop table userlist; +drop table products; +drop table product_category; + + +create table product_category( +category_id number(10)NOT NULL, +category_name varchar(10), +created_at varchar(10), +modified_at varchar(10), +primary key(category_id) +); + +create table products( +product_id number(10) NOT NULL, +product_name varchar(10), +description varchar(10), +category_id number(10) NOT NULL, +price number(15), +discount number(15), +created_at varchar(10), +modified_at varchar(10), +primary key(product_id), +foreign key(category_id) references product_category(category_id) +); + +create table userlist( +id number(10) NOT NULL, +username varchar(10) NOT NULL, +password varchar(10), +first_name varchar(10), +last_name varchar(10), +phone number(11), +product_id number(10) NOT NULL, +product_name varchar(10), +create_at varchar(10), +modified_at varchar(10), +primary key(id), +foreign key(product_id) references products(product_id) +); + +create table user_payment( +user_payment_id number(10)NOT NULL, +id number(20) NOT NULL, +payment_type varchar(20), +provider varchar(20), +account number(30), +expiry varchar(20), +primary key(user_payment_id), +foreign key(id)references userlist(id) +); + +create table order_detail( +order_id number(10)NOT NULL, +id number(10)NOT NULL, +total_amount number(15), +quantity number(10), +user_payment_id number(10) NOT NULL, +created_at varchar(10), +modified_at varchar(10), +primary key(order_id), +foreign key(id) references userlist(id), +foreign key(user_payment_id) references user_payment(user_payment_id) +); \ No newline at end of file From 9e6b42366ca40703e7aa41dcdb3fd9e209907fd6 Mon Sep 17 00:00:00 2001 From: Sadia Afrin <116829514+meerror6d@users.noreply.github.com> Date: Sun, 9 Jul 2023 03:43:16 +0600 Subject: [PATCH 3/6] Add files via upload --- Trigger.sql | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Trigger.sql diff --git a/Trigger.sql b/Trigger.sql new file mode 100644 index 0000000..014d62c --- /dev/null +++ b/Trigger.sql @@ -0,0 +1,72 @@ +--This trigger sets the default value for the username column as "Sornaly" before inserting a new row into the userlist table. + +CREATE OR REPLACE TRIGGER trg_userlist_insert +BEFORE INSERT ON userlist +FOR EACH ROW +BEGIN + IF :NEW.username IS NULL THEN + :NEW.username := 'Sornaly'; + END IF; +END; +/ + + + +--This trigger displays a message indicating that a product's information has been updated whenever a row is updated in the products table. + +CREATE OR REPLACE TRIGGER trg_products_update +AFTER UPDATE ON product +FOR EACH ROW +BEGIN + DBMS_OUTPUT.PUT_LINE('Product information is updated: ' || :NEW.product_name); +END; +/ + + +--This trigger prevents the deletion of a product if their create_id is below '12-05-23' and raises an exception. + + +CREATE OR REPLACE TRIGGER trg_product_delete +BEFORE DELETE ON product_name +FOR EACH ROW +BEGIN + IF :OLD.create_id < 18 THEN + RAISE_APPLICATION_ERROR('12-05-23', 'Cannot delete product. you have it.'); + END IF; +END; +/ + + + +-- This trigger deletes all products from the products table that belong to the product_category being deleted. + + +CREATE OR REPLACE TRIGGER trg_product_category_delete +AFTER DELETE ON product_category +FOR EACH ROW +BEGIN + DELETE FROM products WHERE category_id = :OLD.category_id; +END; +/ + + + +--This trigger deletes all orders records of a user when that user is deleted. + + +CREATE OR REPLACE TRIGGER trg_order_details_delete +AFTER DELETE ON userlist +FOR EACH ROW +BEGIN + DELETE FROM order_details WHERE order_id = :OLD.order_id; +END; +/ + + + + + + + + + From c89e96ef48ff74d0bb4e98465b8546ac6bc70432 Mon Sep 17 00:00:00 2001 From: Sadia Afrin <116829514+meerror6d@users.noreply.github.com> Date: Sun, 9 Jul 2023 08:28:34 +0600 Subject: [PATCH 4/6] Update pl_sql.sql --- pl_sql.sql | 238 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 155 insertions(+), 83 deletions(-) diff --git a/pl_sql.sql b/pl_sql.sql index 122b460..cd108a0 100644 --- a/pl_sql.sql +++ b/pl_sql.sql @@ -1,84 +1,156 @@ ----see customer id,name,first_name,last_name from userlist table--- - -set SERVEROUTPUT on - -declare -userid userlist.id%type; -user_name userlist.username%type; -fname userlist.first_name%type; -lname userlist.last_name%type; - -begin -select id,username,first_name,last_name into userid,user_name,fname,lname from userlist where id=1002; -dbms_output.put_line('userid:' || userid ||',username:'|| user_name || ',first name:'|| fname || ',last name:' || lname); -end; +---see customer id,name,first_name,last_name from userlist table--- + +set SERVEROUTPUT on + +declare +userid userlist.id%type; +user_name userlist.username%type; +fname userlist.first_name%type; +lname userlist.last_name%type; + +begin +select id,username,first_name,last_name into userid,user_name,fname,lname from userlist where id=1002; +dbms_output.put_line('userid:' || userid ||',username:'|| user_name || ',first name:'|| fname || ',last name:' || lname); +end; +/ + +---see arpita's info from userlist---- +set SERVEROUTPUT on + +declare +userid userlist.id%type; +user_name userlist.username%type; +fname userlist.first_name%type; +lname userlist.last_name%type; + +begin +select id,username,first_name,last_name into userid,user_name,fname,lname from userlist where username='Arpita'; +dbms_output.put_line('userid:' || userid ||',username:'|| user_name || ',first name:'|| fname || ',last name:' || lname); +end; +/ + + +---count product row--- + +set serveroutput on +declare +products_row products%rowtype; +begin +select product_id,product_name,description,category_id,price,discount,created_at,modified_at into products_row.product_id,products_row.product_name,products_row.description,products_row.category_id,products_row.price,products_row.discount,products_row.created_at,products_row.modified_at from products where product_id=200; +end; +/ + +---show everything using cursor from products table--- +set serveroutput on +declare +cursor product_cursor is +select * from products; +products_row products%rowtype; +begin +open product_cursor; +fetch product_cursor into products_row.product_id,products_row.product_name,products_row.description,products_row.category_id,products_row.price,products_row.discount,products_row.created_at,products_row.modified_at; +while product_cursor%found +loop +dbms_output.put_line('product id: '||products_row.product_id|| ', product name: '||products_row.product_name||',Description: '||products_row.description||',category id: '||products_row.category_id||',price: '||products_row.price||',discount: '||products_row.discount||',created at'||products_row.created_at||',modified at'||products_row.modified_at); +dbms_output.put_line('Row count: '|| product_cursor%rowcount); +fetch product_cursor into products_row.product_id,products_row.product_name,products_row.description,products_row.category_id,products_row.price,products_row.discount,products_row.created_at,products_row.modified_at; +end loop; +close product_cursor; +end; +/ + +---array,if,else,loop use--- + +set serveroutput on +declare +counter number:=1; +pro_name products.product_name%type; +type namearray is varray(5) of products.pro_name%type; +a_name namearray:=namearray('laptop','phone','mouse','keyboard','watch'); + +begin +counter:=1; + +for x in 12..16 +loop +select product_name into pro_name from products where products_id=100000; +if pro_name='laptop' +then +dbms_output.put_line(pro_name); + +elsif pro_name='phone' +then +dbms_output.put_line(pro_name); +else +dbms_output.put_line('other gadgets'); + +end if; + +end loo; + +end; + + +---procedure--- +set serveroutput on +CREATE OR REPLACE PROCEDURE proc2( + var1 IN varchar1, + var2 OUT VARCHAR2, + var3 IN OUT NUMBER +) +AS + t_show CHAR(30); +BEGIN + t_show := 'From procedure: '; + SELECT product_name INTO var2 FROM products WHERE category_id IN (SELECT category_id FROM product_category created_at = var1); + var3 := var1 + 1; + DBMS_OUTPUT.PUT_LINE(t_show || var2 || ' is added in list at ' || var1 || ' and price is ' || var3); +END; +/ + + +set serveroutput on +declare +created_date products.created_date%type; +pro_name products.product_name%type; +price number; +begin +proc2(pro_id,pro_name,price); +end; +/ + + +---function--- + +set serveroutput on +create or replace function fun(var1 in varchar) return varchar AS +value products.product_name%type; +begin + select product_name into pro_name from products where pro_id=var1; + return value; +end; +/ + +set serveroutput on +declare +value varchar(20); +begin +value:=fun(10000); +end; +/ + + +---INTRODUCTION--- + +set SERVEROUTPUT on; +begin +dbms_output.put_line(' '); +dbms_output.put_line(' '); +dbms_output.put_line(' '); +dbms_output.put_line(' '); +dbms_output.put_line('-------------------------------------------------------------------------------------------------------- '); +dbms_output.put_line('Project Name : Gadget Store Management System'); +dbms_output.put_line('Created by : Sadia Afrin'); +dbms_output.put_line('Roll : 1907037'); +end; / - ----see arpita's info from userlist---- -set SERVEROUTPUT on - -declare -userid userlist.id%type; -user_name userlist.username%type; -fname userlist.first_name%type; -lname userlist.last_name%type; - -begin -select id,username,first_name,last_name into userid,user_name,fname,lname from userlist where username='Arpita'; -dbms_output.put_line('userid:' || userid ||',username:'|| user_name || ',first name:'|| fname || ',last name:' || lname); -end; -/ - - ----count product row--- - -set serveroutput on -declare -products_row products%rowtype; -begin -select product_id,product_name,description,category_id,price,discount,created_at,modified_at into products_row.product_id,products_row.product_name,products_row.description,products_row.category_id,products_row.price,products_row.discount,products_row.created_at,products_row.modified_at from products where product_id=200; -end; -/ - ----show everything using cursor from products table--- -set serveroutput on -declare -cursor product_cursor is -select * from products; -products_row products%rowtype; -begin -open product_cursor; -fetch product_cursor into products_row.product_id,products_row.product_name,products_row.description,products_row.category_id,products_row.price,products_row.discount,products_row.created_at,products_row.modified_at; -while product_cursor%found -loop -dbms_output.put_line('product id: '||products_row.product_id|| ', product name: '||products_row.product_name||',Description: '||products_row.description||',category id: '||products_row.category_id||',price: '||products_row.price||',discount: '||products_row.discount||',created at'||products_row.created_at||',modified at'||products_row.modified_at); -dbms_output.put_line('Row count: '|| product_cursor%rowcount); -fetch product_cursor into products_row.product_id,products_row.product_name,products_row.description,products_row.category_id,products_row.price,products_row.discount,products_row.created_at,products_row.modified_at; -end loop; -close product_cursor; -end; -/ - - - - - - - - - - ----INTRODUCTION--- - -set SERVEROUTPUT on; -begin -dbms_output.put_line(' '); -dbms_output.put_line(' '); -dbms_output.put_line(' '); -dbms_output.put_line(' '); -dbms_output.put_line('-------------------------------------------------------------------------------------------------------- '); -dbms_output.put_line('Project Name : Gadget Store Management System'); -dbms_output.put_line('Created by : Sadia Afrin'); -dbms_output.put_line('Roll : 1907037'); -end; -/ \ No newline at end of file From ea569c1f78d01b359efbca6b34ab3cf148202b27 Mon Sep 17 00:00:00 2001 From: Sadia Afrin <116829514+meerror6d@users.noreply.github.com> Date: Sun, 9 Jul 2023 08:30:36 +0600 Subject: [PATCH 5/6] Update pl_sql.sql --- pl_sql.sql | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pl_sql.sql b/pl_sql.sql index cd108a0..76df72a 100644 --- a/pl_sql.sql +++ b/pl_sql.sql @@ -30,8 +30,6 @@ end; / ----count product row--- - set serveroutput on declare products_row products%rowtype; @@ -41,6 +39,7 @@ end; / ---show everything using cursor from products table--- + ---count product row--- set serveroutput on declare cursor product_cursor is @@ -153,4 +152,4 @@ dbms_output.put_line('Project Name : Gadget Store Management System'); dbms_output.put_line('Created by : Sadia Afrin'); dbms_output.put_line('Roll : 1907037'); end; -/ +/ From 39280bff3c855d54be5347be262ca861f9540740 Mon Sep 17 00:00:00 2001 From: Sadia Afrin <116829514+meerror6d@users.noreply.github.com> Date: Sun, 9 Jul 2023 08:40:32 +0600 Subject: [PATCH 6/6] Update Trigger.sql --- Trigger.sql | 146 ++++++++++++++++++++++++++-------------------------- 1 file changed, 74 insertions(+), 72 deletions(-) diff --git a/Trigger.sql b/Trigger.sql index 014d62c..22b88a6 100644 --- a/Trigger.sql +++ b/Trigger.sql @@ -1,72 +1,74 @@ ---This trigger sets the default value for the username column as "Sornaly" before inserting a new row into the userlist table. - -CREATE OR REPLACE TRIGGER trg_userlist_insert -BEFORE INSERT ON userlist -FOR EACH ROW -BEGIN - IF :NEW.username IS NULL THEN - :NEW.username := 'Sornaly'; - END IF; -END; -/ - - - ---This trigger displays a message indicating that a product's information has been updated whenever a row is updated in the products table. - -CREATE OR REPLACE TRIGGER trg_products_update -AFTER UPDATE ON product -FOR EACH ROW -BEGIN - DBMS_OUTPUT.PUT_LINE('Product information is updated: ' || :NEW.product_name); -END; -/ - - ---This trigger prevents the deletion of a product if their create_id is below '12-05-23' and raises an exception. - - -CREATE OR REPLACE TRIGGER trg_product_delete -BEFORE DELETE ON product_name -FOR EACH ROW -BEGIN - IF :OLD.create_id < 18 THEN - RAISE_APPLICATION_ERROR('12-05-23', 'Cannot delete product. you have it.'); - END IF; -END; -/ - - - --- This trigger deletes all products from the products table that belong to the product_category being deleted. - - -CREATE OR REPLACE TRIGGER trg_product_category_delete -AFTER DELETE ON product_category -FOR EACH ROW -BEGIN - DELETE FROM products WHERE category_id = :OLD.category_id; -END; -/ - - - ---This trigger deletes all orders records of a user when that user is deleted. - - -CREATE OR REPLACE TRIGGER trg_order_details_delete -AFTER DELETE ON userlist -FOR EACH ROW -BEGIN - DELETE FROM order_details WHERE order_id = :OLD.order_id; -END; -/ - - - - - - - - - +--This trigger sets the default value for the username column as "Sornaly" before inserting a new row into the userlist table. + +CREATE OR REPLACE TRIGGER trg_userlist_insert +BEFORE INSERT ON userlist +FOR EACH ROW +BEGIN + IF :NEW.username IS NULL THEN + :NEW.username := 'Sornaly'; + END IF; +END; +/ + + + +--This trigger displays a message indicating that a product's information has been updated whenever a row is updated in the products table. + +CREATE OR REPLACE TRIGGER trg_products_update +AFTER UPDATE ON product +FOR EACH ROW +BEGIN + DBMS_OUTPUT.PUT_LINE('Product information is updated: ' || :NEW.product_name); +END; +/ + + +--This trigger prevents the deletion of a product if their created_at is below '12-05-23' and raises an exception. + + +CREATE OR REPLACE TRIGGER trg_product_delete +BEFORE DELETE ON product_name +FOR EACH ROW +BEGIN + IF :OLD.created_at < '12-0-23' THEN + RAISE_APPLICATION_ERROR('12-05-23', 'Cannot delete product. you have it.'); + END IF; +END; +/ + + + +-- This trigger deletes all products from the products table that belong to the product_category being deleted. + + +CREATE OR REPLACE TRIGGER trg_product_category_delete +AFTER DELETE ON product_category +FOR EACH ROW +BEGIN + DELETE FROM products WHERE category_id = :OLD.category_id; +END; +/ + + + +--This trigger deletes all orders records of a user when that user is deleted. + + +CREATE OR REPLACE TRIGGER trg_order_details_delete +AFTER DELETE ON userlist +FOR EACH ROW +BEGIN + DELETE FROM order_details WHERE id = :OLD.id; +END; +/ + +select * from user_triggers; +drop trigger trg_order_details_delete; +drop trigger trg_product_category_delete; +drop trigger trg_product_delete; +drop trigger trg_userlist_insert; + + + + +