Notes
Notes - notes.io |
/*
Dikshya Ghale
UON Id: 18406490
Lab activity: Week20
March 24
*/
SELECT site_id, location
FROM sites;
--9 rows returned
--creating the procedure named proc_imp_cursor
CREATE OR REPLACE PROCEDURE proc_imp_cursor(in_location IN sites.location%TYPE)
IS
BEGIN
DELETE FROM sites
WHERE location = in_location;
END proc_imp_cursor;
/
--PROCEDURE CREATED
SHOW ERRORS;
--NO ERRORS
--testing procedure
INSERT INTO sites(site_id,location)
VALUES(9, 'NORTHAMPTON');
--1 ROW INSERTED
--viewing the contents of sites
SELECT site_id, location
FROM sites;
--10 rows returned
--executing the procedure named proc_imp_cursor
EXEC proc_imp_cursor('NORTHAMPTON');
--procedure successfully executed
--testing if the procedure worked or not
SELECT site_id, location
FROM sites;
--9 rows returned
--location named northampton is deleted through procedure
--creating procedure named proc_imp_cursor
CREATE OR REPLACE PROCEDURE proc_imp_cursor(in_location IN sites.location%TYPE)
IS
BEGIN
DELETE FROM sites
WHERE location = in_location;
IF SQL%NOTFOUND THEN
DBMS_OUTPUT.PUT_LINE('NO SUCH LOCATION');
ELSE
DBMS_OUTPUT.PUT_LINE('DELETED '|| in_location);
END IF;
END proc_imp_cursor;
/
SHOW ERRORS;
--TESTING THE ABOVE PROCEDURE
INSERT INTO sites(site_id,location)
VALUES(9, 'NORTHAMPTON');
--executing the procedure named proc_imp_cursor passign wrong info
EXEC proc_imp_cursor('NEPAL');
--NO SUCH LOCATION
--executing the procedure named proc_imp_cursor passign right info
EXEC proc_imp_cursor('CHANDOL');
--DELETED CHANDOL
--using explicit cursors
CREATE OR REPLACE PROCEDURE proc_exp_cursor(in_cost IN courses.cost%TYPE) IS
CURSOR cur_courses IS
SELECT title, cost
FROM courses
WHERE cost>in_cost;
BEGIN
FOR rec_cur_courses IN cur_courses LOOP
DBMS_OUTPUT.PUT_LINE
--IF rec_cur_courses.cost > in_cost THEN
--DBMS_OUTPUT.PUT_LINE(in_cost);
--END IF;
END LOOP;
END proc_exp_cursor;
/
--PROCEDURE CREATED
SHOW ERRORS;
--NO ERRORS
EXEC proc_exp_cursor(1200);
--procedure executed successfully
--using rowcount which is wrong
CREATE OR REPLACE PROCEDURE proc_exp_cursor(in_cost IN courses.cost%TYPE) IS
vn_cost NUMBER(10);
CURSOR cur_courses IS
SELECT title, cost
FROM courses
WHERE cost>in_cost;
BEGIN
FOR rec_cur_courses IN cur_courses LOOP
vn_cost := in_cost%ROWCOUNT;
--DBMS_OUTPUT.PUT_LINE(vn_cost);
END LOOP;
END proc_exp_cursor;
/
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team