Dear Readers, can you help me change the code below into
a procedure (Create or Replace Procedure) and then an
anonymous block to execute it. Unfortunately I do not
have the skills to do it. Thankyou very much. Jack
--Force any entries from the prompt to upper case
set sqlcase upper
set verify off
set serveroutput on
--Prompt for Member ID
accept mem_id prompt 'Enter Member ID: '
--Prompt for Video Title
accept video_title prompt 'Enter Title of Video: '
--Declaration section for variables that will be used --within the procedure
DECLARE
v_duedate DATE;
v_count NUMBER;
v_count2 NUMBER;
v_copy_id NUMBER;
v_title_id NUMBER;
v_title_name VARCHAR2(25);
v_cost NUMBER(10,2) := 100;
v_fname VARCHAR2(25);
v_lname VARCHAR2(25);
v_street VARCHAR2(25);
v_city VARCHAR2(15);
v_phone CHAR(11);
BEGIN
--Make sure we have a valid member
select count(1) INTO v_count from s_member where member_id=&mem_id;
IF v_count<1 THEN
DBMS_OUTPUT.PUT_LINE('You have entered and invalid Membership ID');
END IF;
--Make sure its a valid video title
select count(1) into v_count2 from s_title_copy where title_name='&video_title';
IF v_count2<1 THEN
DBMS_OUTPUT.PUT_LINE('That video is not in our inventory or you have typed the name incorrectly');
END IF;
--If either the member number or video title is incorrect indicate that program should rerun and abort.
IF v_count < 1 OR v_count2 < 1 THEN
DBMS_OUTPUT.PUT_LINE('Rerun the program and enter valid data');
ELSE
--Get the Member's Information
SELECT FIRST_NAME, LAST_NAME, STREET, CITY, PHONE
INTO v_fname, v_lname, v_street, v_city, v_phone
FROM S_MEMBER
WHERE MEMBER_ID=&mem_id;
--Output the Member's Information to the screen
DBMS_OUTPUT.PUT_LINE('Member Information');
DBMS_OUTPUT.PUT_LINE(v_fname||' '||v_lname||' '||v_street||' '||v_city||' '||v_phone);
--Get the Info for the video if it is in the store **THIS IS QUERY A1
select TITLE_ID, TITLE_NAME, MAX(COPY_ID)
INTO v_title_id, v_title_name, v_copy_id
FROM S_TITLE_COPY
WHERE STATUS='IN STORE'
AND TITLE_NAME='&video_title'
GROUP BY TITLE_ID, TITLE_NAME;
--If the video was in the store, update the S_TITLE_COPY table to indicate that the movie
--is being checked out.
UPDATE S_TITLE_COPY
SET STATUS='OUT'
WHERE TITLE_ID=v_title_id
and copy_id=v_copy_id;
--Insert a record into the S_RESULTS table indicating tying this movie to this particular member
--I'm not sure of the purpose of this table...seems redundant
INSERT INTO S_RESULTS
VALUES(&mem_id, v_fname, v_lname, v_phone, v_title_id, v_title_name, 'Checked Out');
--Get the due date for the movie
SELECT SYSDATE+3 INTO v_duedate FROM DUAL;
--Insert a record into the S_RENTAL table indicating that this movie was rented by this member
--along with a due date and a null for the actual returned date
INSERT INTO S_RENTAL
VALUES(sysdate, v_copy_id, &mem_id, v_title_id, NULL, v_duedate);
--Print receipt
DBMS_OUTPUT.PUT_LINE ('_______________________________________');
DBMS_OUTPUT.PUT_LINE ('ROBS RIPOFF VIDEO RECEIPT');
DBMS_OUTPUT.PUT_LINE (' ');
DBMS_OUTPUT.PUT_LINE ('Date '||to_char(sysdate, 'MM/DD/YYYY'));
DBMS_OUTPUT.PUT_LINE ('Movie Rented '||v_title_name);
DBMS_OUTPUT.PUT_LINE ('Your Rental Cost: $'||v_cost);
DBMS_OUTPUT.PUT_LINE (' ');
DBMS_OUTPUT.PUT_LINE ('THANK YOU!!!');
END IF;
--If the movie requested was not in the store no records would be found in QUERY A1 and this exception
--handler would take care of entering a record into the S_RESERVATION table.
EXCEPTION
when no_data_found then
DBMS_OUTPUT.PUT_LINE ('_______________________________________');
DBMS_OUTPUT.PUT_LINE('The video you requested is out. Try again later');
SELECT DISTINCT(TITLE_ID) INTO v_title_id FROM S_TITLE_COPY WHERE TITLE_NAME='&video_title';
INSERT INTO S_RESERVATION VALUES(SYSDATE, &mem_id, v_title_id);
COMMIT;
END;
a procedure (Create or Replace Procedure) and then an
anonymous block to execute it. Unfortunately I do not
have the skills to do it. Thankyou very much. Jack
--Force any entries from the prompt to upper case
set sqlcase upper
set verify off
set serveroutput on
--Prompt for Member ID
accept mem_id prompt 'Enter Member ID: '
--Prompt for Video Title
accept video_title prompt 'Enter Title of Video: '
--Declaration section for variables that will be used --within the procedure
DECLARE
v_duedate DATE;
v_count NUMBER;
v_count2 NUMBER;
v_copy_id NUMBER;
v_title_id NUMBER;
v_title_name VARCHAR2(25);
v_cost NUMBER(10,2) := 100;
v_fname VARCHAR2(25);
v_lname VARCHAR2(25);
v_street VARCHAR2(25);
v_city VARCHAR2(15);
v_phone CHAR(11);
BEGIN
--Make sure we have a valid member
select count(1) INTO v_count from s_member where member_id=&mem_id;
IF v_count<1 THEN
DBMS_OUTPUT.PUT_LINE('You have entered and invalid Membership ID');
END IF;
--Make sure its a valid video title
select count(1) into v_count2 from s_title_copy where title_name='&video_title';
IF v_count2<1 THEN
DBMS_OUTPUT.PUT_LINE('That video is not in our inventory or you have typed the name incorrectly');
END IF;
--If either the member number or video title is incorrect indicate that program should rerun and abort.
IF v_count < 1 OR v_count2 < 1 THEN
DBMS_OUTPUT.PUT_LINE('Rerun the program and enter valid data');
ELSE
--Get the Member's Information
SELECT FIRST_NAME, LAST_NAME, STREET, CITY, PHONE
INTO v_fname, v_lname, v_street, v_city, v_phone
FROM S_MEMBER
WHERE MEMBER_ID=&mem_id;
--Output the Member's Information to the screen
DBMS_OUTPUT.PUT_LINE('Member Information');
DBMS_OUTPUT.PUT_LINE(v_fname||' '||v_lname||' '||v_street||' '||v_city||' '||v_phone);
--Get the Info for the video if it is in the store **THIS IS QUERY A1
select TITLE_ID, TITLE_NAME, MAX(COPY_ID)
INTO v_title_id, v_title_name, v_copy_id
FROM S_TITLE_COPY
WHERE STATUS='IN STORE'
AND TITLE_NAME='&video_title'
GROUP BY TITLE_ID, TITLE_NAME;
--If the video was in the store, update the S_TITLE_COPY table to indicate that the movie
--is being checked out.
UPDATE S_TITLE_COPY
SET STATUS='OUT'
WHERE TITLE_ID=v_title_id
and copy_id=v_copy_id;
--Insert a record into the S_RESULTS table indicating tying this movie to this particular member
--I'm not sure of the purpose of this table...seems redundant
INSERT INTO S_RESULTS
VALUES(&mem_id, v_fname, v_lname, v_phone, v_title_id, v_title_name, 'Checked Out');
--Get the due date for the movie
SELECT SYSDATE+3 INTO v_duedate FROM DUAL;
--Insert a record into the S_RENTAL table indicating that this movie was rented by this member
--along with a due date and a null for the actual returned date
INSERT INTO S_RENTAL
VALUES(sysdate, v_copy_id, &mem_id, v_title_id, NULL, v_duedate);
--Print receipt
DBMS_OUTPUT.PUT_LINE ('_______________________________________');
DBMS_OUTPUT.PUT_LINE ('ROBS RIPOFF VIDEO RECEIPT');
DBMS_OUTPUT.PUT_LINE (' ');
DBMS_OUTPUT.PUT_LINE ('Date '||to_char(sysdate, 'MM/DD/YYYY'));
DBMS_OUTPUT.PUT_LINE ('Movie Rented '||v_title_name);
DBMS_OUTPUT.PUT_LINE ('Your Rental Cost: $'||v_cost);
DBMS_OUTPUT.PUT_LINE (' ');
DBMS_OUTPUT.PUT_LINE ('THANK YOU!!!');
END IF;
--If the movie requested was not in the store no records would be found in QUERY A1 and this exception
--handler would take care of entering a record into the S_RESERVATION table.
EXCEPTION
when no_data_found then
DBMS_OUTPUT.PUT_LINE ('_______________________________________');
DBMS_OUTPUT.PUT_LINE('The video you requested is out. Try again later');
SELECT DISTINCT(TITLE_ID) INTO v_title_id FROM S_TITLE_COPY WHERE TITLE_NAME='&video_title';
INSERT INTO S_RESERVATION VALUES(SYSDATE, &mem_id, v_title_id);
COMMIT;
END;