Friday, December 4, 2009

Exercise Oracle package and package body


To practice the exercise you need the schema. You can found the schema from the post http://arjudba.blogspot.com/2009/12/basic-oracle-sql-exercise.html and before practice these exercises you must first run those sqls so that you can get tables and data to practice. After you know the answer of each step please post your PL/SQL inside comment section so that other can check and understand it and you will be more clear about it.


Scenario/Summary
This week we are going to take the three program units that were created in lab 3 and combine them into a single functioning unit called a package. Packages allow use to group procedures and functions that deal with a common process together.
Back to topFor the lab you will need to create a script file containing the PL/SQL code that will address the lab steps below. Run the script file in your SQL*Plus session using the SET ECHO ON session command at the beginning to capture both the PL/SQL block code and output from Oracle after the block of code has executed. You will be running tests identical to those run in lab 3 once your package has been created. Spool your output and name your files with your last name plus lab 4 and give the file a text (txt) extension. For example, if you last name was Johnson then the file would be named johnson_lab4.txt. Submit both the spooled output files AND the script file for grading of the lab.

L A B S T E P

Step 1: Creating the Package Specifications
Back to top
Before you begin there are several things you will want to do to get ready for the lab.
  1. Refresh your database tables by running the movierental.sql script. This will restore all of the data back to where it was in the beginning for the course.
  2. Drop the two procedures and the function created in lab 3. BE sure that you have your script file from lab 3 so you can copy the procedure and function code from it.
Now you are ready to create you package specification. Your package name should be MM_RENTALS_PKG and it will contain the two procedures and the one function that were created in lab 3. Remember that for the specification you only need to list the procedure and function header data (CREATE statement with parameters).
Test your package specification by running the script in SQL*Plus. If you have any errors then debug them and once you have a clean compile then move on to step 2.
Back to top
Step 2: Creating the Package Body




Creating the package body should be simple since you already have the code for the two procedures and the function, and you know it works. Remember that the name for the package body must match the name of the specifications, and that the procedure and function header in the body must match that of the specification exactly.
Once you have created the body then run the script in your SQL*Plus session. Once you have a clean compile then move on to step three to do your testing.


Step 3: Testing the Package





To test your package you will need to run the same exact tests you did in lab 3. The following outlines what you will test for:
Testing the first procedure -
  1. No movie for the id supplied (use 13, 10, and 2 for the parameters).
  2. No member for the id supplied (use 10, 20, and 2 for the parameters).
  3. No payment method for the id supplied (use 10, 10 and 7 for the parameters).
  4. A successful rental (use 5, 10 and 2 for the parameters).
  5. No movie available for the id supplied (use 5, 11, and 2 for the parameters). Since there is only one movie available for id 5 you will get this exception.
Testing the second procedure -
  1. No rental for the id supplied (use 20 for the parameter).
  2. A successful rental return (use 1 for the parameter).
  3. Try to return the same rental in step 2.
Testing the function -
  1. Test for a movie in stock using movie id 11.
  2. Test for a movie not in stock using movie id 5 (from your tests of the second procedure above the quantity should be 0).
  3. Test for an invalid movie id using movie id 20.
IMPORTANT: Remember that all of your testing needs to be saved in a spool session so that it can be submitted to the Drop Box for grading.


Step 4: Determining Dependencies



Having created a package that contains program units to support the movie rental process is a major step in customizing the new database. As application modifications are made in the future however we need to be able to identify all object dependencies to test changes. For this step in the lab you are to use either data dictionary views or the dependency tree utility found in Doc Sharing (utldtree.sql file) to compile a list of dependencies for all the More Movies database objects. Remember that an object is anything that was created using the CREATE statement. Present your finding in a separate word document in a tabular format as in the following sample. Each dependency type should be listed as either direct or indirect.
NOTE: If using the utldtree.sql utility for this step then be sure to read the instructions in the comment area of the file. In executing the DEPTREE_FILL procedure that will be created by the script you will need to supply your schema name (user id) for the middle parameter of the parameter list in the execute command when your call the procedure.




Object Name
Dependent Object
Dependency Type



Oracle Procedure and Function Practice


To practice the exercise you need the schema. You can found the schema from the post http://arjudba.blogspot.com/2009/12/basic-oracle-sql-exercise.html and before practice these exercises you must first run those sqls so that you can get tables and data to practice. After you know the answer of each step please post your PL/SQL inside comment section so that other can check and understand it and you will be more clear about it.


Step 1: Creating the first procedure


Your first procedure is to be named MOVIE_RENTAL_SP and is going to provide functionality to process movie rentals. Based on data that will represent the movie id, member id and payment method your procedure will need to generate a rental id and then insert a new row of data into the mm_rental table. The process will also need to update the quantity column in the mm_movie table to reflect that there is one less copy of the rented movie in stock. Along with the processing you will also need to define some user-defined exception handlers that will be used in validating the input data. Since you may ned to recreate your procedure several times during the debugging process it is suggested that you use the CREATE OR REPLACE syntax at the beginning of the CREATE statement.
The following steps will help you in setting up your code.
  1. You will need to define three parameters, one each for movie id, member id, and payment method. Make sure that each one matches the data type of the associated column in the database tables.
  2. You will have several other variables that will need to be identified and defined. It might be easier to read through the rest of the specs before you start trying to define these (look for hints in the specifications.
  3. You will need to define four user-defined exceptions; one for unknown movies, one for unknown member, one for unknown payment method, and one for if a movie is unavailable.
  4. You will need to validate each of the three pieces of data passed to the procedure. One easy way to do this might be to use a SELECT statement with the COUNT function to return a value into a variable based on a match in the database table against the piece of data that you are validating. If the query returns a zero then there is no match and the data is invalid; any value greater than zero means a match was found and thus the data is valid. You will need the following validations.
    1. Validate the movie id to make sure it is valid. If not then raise the unknown movie exception.
    2. Validate the member id to make sure one exists for that id. If not then raise the unknown member exception.
    3. Validate the payment method to make sure it exists. If not then raise the unknown payment method exception.
    4. Check the movie quantity to make sure that there is a movie to be rented for the movie id. If not then raise the unavailable movie exception.
  5. If all the data passes validation then you will need to create a new rental id. This process should be in a nested block with it's own EXCEPTION section to catch a NO_DATA_FOUND exception if one should happen. You can generate a new rental id by find the largest rental id value in the mm_rental table (Hint: MAX function) and then increasing that value by one. The NO_DATA_FOUND exception would only be raised if there were no rental id's in the table.
  6. Now you are ready to insert a new row of data into the mm_rental table. Use the SYSDATE function for the check out date and NULL for the check in date.
  7. Now update the mm_rental table to reflect one less movie for the associated movie id.
  8. Finally you will need to set up an EXCEPTION section for all of your exception handling. For each exception output you want to state what the problem is, the invalid data value and a note that the rental cannot proceed. For example, for an invalid movie id number you might say "There is no movie with id: 13 - Cannot proceed with rental". You also want to include a WHEN OTHERS exception handler.
Compile and check your code. If you get a PROCEDURE CREATED WITH COMPILATION ERRORS message then type in SHOW ERRORS and look in your code for the line noted in the error messages (be sure to compile your code with the session command SET ECHO ON). Once you have a clean compile then your are ready to test.


Step 2: Testing the first procedure


You will need to test for scenarios that will allow both a clean movie rental and test each exception. This means that you will need to run at least 5 test cases. One each for the following:
  1. No movie for the id supplied (use 13, 10, and 2 for the parameters).
  2. No member for the id supplied (use 10, 20, and 2 for the parameters).
  3. No payment method for the id supplied (use 10, 10 and 7 for the parameters).
  4. A successful rental (use 5, 10 and 2 for the parameters).
  5. No movie available for the id supplied (use 5, 11, and 2 for the parameters). Since there is only one movie available for id 5 you will get this exception.
You output from the testing should look similar to (this would be the output for the first test above):
exec movie_rent_sp(13, 10, 2);
Output:
There is no movie with id: 13
Cannot proceed with rental
PL/SQL procedure successfully completed.

Be sure that when you have verified that everything works you run your testing in a spools session and save the file to be turned in.


Step 3: Creating the second procedure


Your second procedure should be named MOVIE_RETURN_SP and should facilitate the process of checking a movie rental back in. For this procedure you will only need to pass one piece of data to the procedure; the rental id. You will need two user-defined exceptions; one for no rental record and one for already returned. You will be able to use several of the same techniques you used in the first procedure for your validation.
The following steps will help in setting up your code.
  1. You will need to define only one parameter for the rental id number. Make sure that it matches the data type of the associated column in the database table.
  2. You will have several other variables that will need to be identified and defined. It might be easier to read through the rest of the specs before you start trying to define these (look for hints in the specifications.
  3. You will need to define the two user-defined exceptions mentioned above.
  4. You will need to validate the rental id that is passed to the procedure. If it is not a valid one then raise the associated exception.
  5. If it is valid then get the movie id and check in date from the mm_rental table.
  6. Now check the check in date to make sure that it is NULL. If it is not then raise the associated exception.
  7. If everything checks out then update the mm_rental table for the rental id you have and use the SYSDATE function for the check in date.
  8. Now you can update the quantity in the mm_movie table for the associated movie id to reflect that the movie is back in stock.
  9. Last, set up your exception section using appropriate error message text and data.
Compile and check your code. If you get a PROCEDURE CREATED WITH COMPILATION ERRORS message then type in SHOW ERRORS and look in your code for the line noted in the error messages (be sure to compile your code with the session command SET ECHO ON). Once you have a clean compile then your are ready to test.




Step 4: Testing the second procedure


You will need to test for scenarios that will allow both a clean rental return and test each exception. This means that you will need to run at least 3 test cases. One each for the following:


  1. No rental for the id supplied (use 20 for the parameter).
  2. A successful rental return (use 1 for the parameter).
  3. Try to return the same rental in step 2.
You output from the testing should look similar to (this would be the output for the first test above):


exec movie_return_sp(20);
Output:
There is no rental record with id: 20
Cannot proceed with return
PL/SQL procedure successfully completed.

Be sure that when you have verified that everything works you run your testing in a spools session and save the file to be turned in.


Step 5: Creating the function


Your function should be named MOVIE_STOCK_SF and will be used to return a message telling the user whether a movie title is available or not based on the movie id passed to the function. The exception handling that will be needed is for NO_DATA_FOUND but we are going to set it up as a RAISE_APPLICATION_ERROR.
The following steps will help in setting up your code.
  1. You will need to define only one parameter for the movie id number. Make sure that it matches the data type of the associated column in the database table. Also, since you will be returning a notification message you will want to make sure your RETURN statement references a data type that can handle that (Hint: variable length data type).
  2. You will have several other variables that will need to be identified and defined. It might be easier to read through the rest of the specs before you start trying to define these (look for hints in the specifications.
  3. You will not be doing any validation so the first thing you need to do is retrieve the movie title and quantity available from the mm_movie table based on the id passed to the function.
  4. Now you need to determine if any are available. IF the value in the quantity column is greater than zero then you will be returning a message saying something like "Star Wars is available: 0 on the shelf", ELSE if the value is zero then you should return a message saying something like "Star Wars is currently not available". Hint: A good way to return a test string is to assign it to a variable and then simply use the variable name in the RETURN clause.
  5. Finally, set up your exception section to use a RAISE_APPLICATION_ERROR for the NO_DATA_FOUND exception handler. Assign an error number of -20001 to it and an error message that states there is no movie available for the id (be sure to include the id in the message).
Compile and check your code. If you get a FUNCTION CREATED WITH COMPILATION ERRORS message then type in SHOW ERRORS and look in your code for the line noted in the error messages (be sure to compile your code with the session command SET ECHO ON). Once you have a clean compile then your are ready to test.




Step 6: Testing the function


You will need to test for all three possible scenarios.


  1. Test for a movie in stock using movie id 11.
  2. Test for a movie not in stock using movie id 5 (from your tests of the second procedure above the quantity should be 0).
  3. Test for an invalid movie id using movie id 20.
For test number 2 you may need to manipulate the quantity amount in the database which will be fine.
Test your function by using a select statement against the DUAL table like in the example below:


select movie_stock_sf(20) from dual;
Be sure that when you have verified that everything works you run your testing in a spools session and save the file to be turned in.




Practice Exercise for Oracle PL/SQL

To practice the exercise you need the schema. You can found the schema from the post http://arjudba.blogspot.com/2009/12/basic-oracle-sql-exercise.html and before practice these exercises you must first run those sqls so that you can get tables and data to practice. After you know the answer of each step please post your PL/SQL inside comment section so that other can check and understand it and you will be more clear about it.


Step 1:


As business is becoming strong and the movie stock is growing for the More Movie Rentals, the manager wants to do more inventory evaluations. One item of interest concerns any movie for which the company is holding $75 or more in value. The manager wants to focus on these movies in regards to their revenue generation to ensure the stock level is warranted. To make these stock queries more efficient, the application team decides that a column should be added to the MM_MOVIE table named STK_FLAG that will hold a value '*' if stock is $75 or more. Otherwise the value should be NULL. Add the new column to the MM_MOVIE table as a CHAR data type.
Execute a DESC MM_MOVIE on the table both before you add the new column and after the column is added.
Note: Since this is code will be in your script file you will need to comment it out after the first time you have execute the ALTER TABLE statement successfully to avoid getting errors each additional time your script file is run.




Step 2:


Create an anonymous block of PL/SQL code that contains a CURSOR FOR loop to accomplish the task described above in step 1. Your loop will need to interrogate the value (using an IF statement) found in the movie_qty field of the cursor loop variable to see if it is >= 75. If this is true then you will need to update the new column in the table with an '*' WHERE CURRENT OF the table. If the quantity is not >= 75 (the ELSE side of the IF statement) then update the new column with a NULL.
Execute a SELECT * from MM_MOVIE both before and after you execute the new PL/SQL block of code to show that the process works.




Step 3:


Here is a block that retrieves the movie title and rental count based on a movie id provided via a host variable.
SET SERVEROUTPUT ON
VARIABLE g_movie_id NUMBER
BEGIN
:g_movie_id := 4;
END;
/

DECLARE
v_count NUMBER;
v_title mm_movie.movie_title%TYPE;
BEGIN
SELECT m.movie_title, COUNT(r.rental_id)
INTO v_title, v_count
FROM mm_movie m, mm_rental r
WHERE m.movie_id = r.movie_id
AND m.movie_id = :g_movie_id
GROUP BY m.movie_title;

DBMS_OUTPUT.PUT_LINE(v_title || ': ' || v_count);
END;
/

Modify the block of code to add exception handlers for errors that you can and cannot anticipate. You will need to execute the entire code listing shown above each time you wish to test it by changing the value of :g_movie_id for each test.
Once finished then test your exception handling by running the modified block for the following values of :g_movie_id. Be sure that you can capture the value in the :g_movie_id host variable.
  • 2 - normal output will display title and number of rentals
  • 13 - exception - there is no movie ID for 13
  • 1 - exception - Movie with ID 1 has never been rented

Basic Oracle Sql Exercise

Here goes database schema. We will use this schema to test in our exercise. So before exercising the steps run these sqls/ create table/ insert statements in your oracle database schema.

DROP TABLE MM_MOVIE_TYPE CASCADE CONSTRAINTS PURGE;
DROP TABLE mm_pay_type CASCADE CONSTRAINTS PURGE;
DROP TABLE mm_member CASCADE CONSTRAINTS PURGE;
DROP TABLE mm_movie CASCADE CONSTRAINTS PURGE;
DROP TABLE mm_rental CASCADE CONSTRAINTS PURGE;
DROP SEQUENCE mm_rental_seq;


CREATE TABLE mm_movie_type
(movie_cat_id NUMBER(2),
movie_category VARCHAR(12),
CONSTRAINT movie_cat_id_pk PRIMARY KEY (movie_cat_id));
CREATE TABLE mm_pay_type
(payment_methods_id NUMBER(2),
payment_methods VARCHAR(14),
CONSTRAINT payment_methods_id_pk PRIMARY KEY (payment_methods_id));
CREATE TABLE mm_member
(member_id NUMBER(4),
last VARCHAR(12),
first VARCHAR(8),
license_no VARCHAR(9),
license_st VARCHAR(2),
credit_card VARCHAR(12),
suspension VARCHAR(1) DEFAULT 'N',
mailing_list VARCHAR(1),
CONSTRAINT cust_custid_pk PRIMARY KEY (member_id),
CONSTRAINT cust_credcard_ck CHECK (LENGTH(credit_card) = 12));
CREATE TABLE mm_movie
(movie_id NUMBER(4),
movie_title VARCHAR(40),
movie_cat_id NUMBER(2) NOT NULL,
movie_value DECIMAL(5,2),
movie_qty NUMBER(2),
CONSTRAINT movies_id_pk PRIMARY KEY (movie_id),
CONSTRAINT movie_type_fk FOREIGN KEY (movie_cat_id)
REFERENCES mm_movie_type(movie_cat_id),
CONSTRAINT movies_value_ck CHECK (movie_value BETWEEN 5 and 100));
CREATE TABLE mm_rental
(rental_id NUMBER(4),
member_id NUMBER(4),
movie_id NUMBER(4),
checkout_date DATE DEFAULT SYSDATE,
checkin_date DATE,
payment_methods_id NUMBER(2),
CONSTRAINT rentals_pk PRIMARY KEY (rental_id),
CONSTRAINT member_id_fk FOREIGN KEY (member_id)
REFERENCES mm_member(member_id),
CONSTRAINT movie_id_fk FOREIGN KEY (movie_id)
REFERENCES mm_movie(movie_id),
CONSTRAINT pay_id_fk FOREIGN KEY (payment_methods_id)
REFERENCES mm_pay_type(payment_methods_id));
Create sequence mm_rental_seq start with 13;
INSERT INTO mm_member (member_id, last, first, license_no, license_st, credit_card)
VALUES (10, 'Tangier', 'Tim', '111111111', 'VA', '123456789111');
INSERT INTO mm_member (member_id, last, first, license_no, license_st, credit_card, mailing_list)
VALUES (11, 'Ruth', 'Babe', '222222222', 'VA', '222222222222', 'Y');
INSERT INTO mm_member (member_id, last, first, license_no, license_st, credit_card, mailing_list)
VALUES (12, 'Maulder', 'Fox', '333333333', 'FL', '333333333333', 'Y');
INSERT INTO mm_member (member_id, last, first, license_no, license_st, credit_card)
VALUES (13, 'Wild', 'Coyote', '444444444', 'VA', '444444444444');
INSERT INTO mm_member (member_id, last, first, license_no, license_st, credit_card, mailing_list)
VALUES (14, 'Casteel', 'Joan', '555555555', 'VA', '555555555555', 'Y');
INSERT INTO mm_movie_type (movie_cat_id, movie_category)
VALUES ( '1', 'SciFi');
INSERT INTO mm_movie_type (movie_cat_id, movie_category)
VALUES ( '2', 'Horror');
INSERT INTO mm_movie_type (movie_cat_id, movie_category)
VALUES ( '3', 'Western');
INSERT INTO mm_movie_type (movie_cat_id, movie_category)
VALUES ( '4', 'Comedy');
INSERT INTO mm_movie_type (movie_cat_id, movie_category)
VALUES ( '5', 'Drama');
INSERT INTO mm_movie (movie_id, movie_title, movie_cat_id, movie_value, movie_qty)
VALUES (1, 'Alien', '1', 10.00, 5);
INSERT INTO mm_movie (movie_id, movie_title, movie_cat_id, movie_value, movie_qty)
VALUES (2, 'Bladerunner', '1', 8.00, 3);
INSERT INTO mm_movie (movie_id, movie_title, movie_cat_id, movie_value, movie_qty)
VALUES (3, 'Star Wars', '1', 15.00, 11);
INSERT INTO mm_movie (movie_id, movie_title, movie_cat_id, movie_value, movie_qty)
VALUES (4,'Texas Chainsaw Masacre', '2', 7.00, 2);
INSERT INTO mm_movie (movie_id, movie_title, movie_cat_id, movie_value, movie_qty)
VALUES (5, 'Jaws', '2', 7.00,1);
INSERT INTO mm_movie (movie_id, movie_title, movie_cat_id, movie_value, movie_qty)
VALUES (6, 'The good, the bad and the ugly', '3', 7.00,2);
INSERT INTO mm_movie (movie_id, movie_title, movie_cat_id, movie_value, movie_qty)
VALUES (7, 'Silverado', '3', 7.00,1);
INSERT INTO mm_movie (movie_id, movie_title, movie_cat_id, movie_value, movie_qty)
VALUES (8, 'Duck Soup', '4', 5.00,1);
INSERT INTO mm_movie (movie_id, movie_title, movie_cat_id, movie_value, movie_qty)
VALUES (9, 'Planes, trains and automobiles', '4', 5.00,3);
INSERT INTO mm_movie (movie_id, movie_title, movie_cat_id, movie_value, movie_qty)
VALUES (10, 'Waking Ned Devine', '4', 12.00,4);
INSERT INTO mm_movie (movie_id, movie_title, movie_cat_id, movie_value, movie_qty)
VALUES (11, 'Deep Blue Sea', '5', 14.00,3);
INSERT INTO mm_movie (movie_id, movie_title, movie_cat_id, movie_value, movie_qty)
VALUES (12, 'The Fifth Element', '5', 15.00,5);
INSERT INTO mm_pay_type (payment_methods_id, payment_methods)
VALUES ('1', 'Account');
INSERT INTO mm_pay_type (payment_methods_id, payment_methods)
VALUES ('2', 'Credit Card');
INSERT INTO mm_pay_type (payment_methods_id, payment_methods)
VALUES ('3', 'Check');
INSERT INTO mm_pay_type (payment_methods_id, payment_methods)
VALUES ('4', 'Cash');
INSERT INTO mm_pay_type (payment_methods_id, payment_methods)
VALUES ('5', 'Debit Card');
INSERT INTO mm_rental (rental_id, member_id, movie_id, payment_methods_id)
VALUES (1,'10', '11', '2');
INSERT INTO mm_rental (rental_id, member_id, movie_id, payment_methods_id)
VALUES (2,'10', '8', '2');
INSERT INTO mm_rental (rental_id, member_id, movie_id, payment_methods_id)
VALUES (3,'12', '6', '2');
INSERT INTO mm_rental (rental_id, member_id, movie_id, payment_methods_id)
VALUES (4,'13', '3', '5');
INSERT INTO mm_rental (rental_id, member_id, movie_id, payment_methods_id)
VALUES (5,'13', '5', '5');
INSERT INTO mm_rental (rental_id, member_id, movie_id, payment_methods_id)
VALUES (6,'13', '11', '5');
INSERT INTO mm_rental (rental_id, member_id, movie_id, payment_methods_id)
VALUES (7,'14', '10', '2');
INSERT INTO mm_rental (rental_id, member_id, movie_id, payment_methods_id)
VALUES (8,'14', '7', '2');
INSERT INTO mm_rental (rental_id, member_id, movie_id, payment_methods_id)
VALUES (9,'12', '4', '4');
INSERT INTO mm_rental (rental_id, member_id, movie_id, payment_methods_id)
VALUES (10,'12', '12', '4');
INSERT INTO mm_rental (rental_id, member_id, movie_id, payment_methods_id)
VALUES (11,'12', '3', '4');
INSERT INTO mm_rental (rental_id, member_id, movie_id, payment_methods_id)
VALUES (12,'13', '4', '5');
UPDATE mm_rental
SET checkout_date = '04-JUN-03';
COMMIT;

Step 1:
Within SQL*Plus, list names of the tables that you have created whose name starts with MM. (Hint: use data dictionary view USER_TABLES).

Step 2:
Use DESCRIBE (in short: DESC) command in SQL*Plus for each of these tables to show columns and their datatypes.

Step 3:
Use SELECT * command to display all data from each of the tables in the MoreMovies schema. Make sure that the LINESIZE and PAGESIZE have large enough values, and that you format columns so that the report looks good. you should end up with five queries and result sets.

Step 4:
Using the mm_movie and mm_movie_type tables, write a query that will list all movie categories together with the count of movies in each category. Give the column with the count in it a meaningful name such as IN STOCK.

Step 5:
Using the mm_movie and mm_rental tables, write a query that will list titles and checkout dates for all movies that were signed out by Wild Coyote (MEMBER_ID=13).

Step 6:
Using the same two tables used in step 5 write an SQL sub-query that will list all movies (movie ids and titles) of all movies that have never been rented.

Step 7:
Using the mm_member and mm_rental tables, write a query that will list all members (member id, first name and last name) and the number of movies they have rented who have have rented at least one movie. Order the result set so that it shows the largest number of movies rented as the first row.

Step 8:
What a query that will display the largest number of movies rented by one member and that members name. Give the output column a meaningful name such as MAXIMUM NUMBER.

Step 9:
Using the mm_member and mm_rental tables, write a query that will display member id, last name, first name, and the number of movies rented for each member. Give the column with the number of movies rented a meaningful name such as NUMBER RENTED.

Step 10:
Using the mm_member, mm_movie and mm_rental tables, write the query that will prepare a report that shows who rented which movie. Use member names (first and last) and movie title rather than the corresponding ids. Order the report by member names, and for a single member by the movie titles.

Based on these steps requirement try to found out solution and please post those inside comment step wise so that everyone can share your answer and learn things.

Related Documents

Basic Oracle Sql Exercise

Tuesday, December 1, 2009

ORA-00106: cannot startup/shutdown database when connected to a dispatcher

Problem Description
We are running a multi-threaded server and are trying to shutdown the database using Oracle Enterprise Manager. But it fails through below message

ORA-00106:
cannot startup/shutdown database when connected to a dispatcher

In simplest, ORA-00106 means following according to oracle documentation.

ORA-00106:
cannot startup/shutdown database when connected to a dispatcher
Cause: An attempt was made to startup/shutdown database when connected to a shared server via a dispatcher.
Action: Re-connect as user INTERNAL without going through the dispatcher. For most cases, this can be done by connect to INTERNAL without specifying a network connect string.

Cause of the Problem
The problem happened because you are trying to shutdown the database while connected to a shared server process. Because you cannot startup or shutdown a database while connected to a shared server process via a dispatcher. To shutdown or startup a database you must connect via a dedicated server process.

Solution of the Problem


In order to startup/shutdown a database, you must connect via a dedicated server process and not a shared process.
If you are connecting to database server through TNS entry then add the following entry to your tnsnames.ora file in the address_list section:

(SERVER=DEDICATED)

Example of a TNS entry that establish a dedicated connection:

 service_name= 
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(PROTOCOL = PROTOCOL_NAME)
(Host = server_name)
(Port = port_number)
)
)
(CONNECT_DATA =
(SID = sid_name)
(SERVER=DEDICATED)
)
)

Another solution is login to the server and issue startup/shutdown from that computer by connecting as sysdba without any TNS entry.
Related Documents
http://arjudba.blogspot.com/2008/05/startup-fails-with-oracle-error-ora.html
http://arjudba.blogspot.com/2008/09/database-startup-fails-with-ora-27302.html
http://arjudba.blogspot.com/2008/07/database-startup-fails-with-error-ora.html
http://arjudba.blogspot.com/2008/08/startup-fails-with-ora-01261-parameter.html
http://arjudba.blogspot.com/2008/09/database-startup-fails-with-ora-00444.html
http://arjudba.blogspot.com/2008/05/database-startup-fails-with-errors-ora.html

http://arjudba.blogspot.com/2009/05/ora-27100-shared-memory-realm-already.html

You must have CREATE TARGET privilege to perform this operation

Problem Description
In the Enterprise Manager main page (connected with SYS as SYSDBA or as SYSTEM), when I click on performance tab, it gives me following notification.

MemberShip Configuration
The membership configured for the cluster database does not match the instance list of the database. Please update your configuration from the following link:

Database Configuration

And when I click on Database Configuration link, it drops the following error:
Error
You must have CREATE TARGET privilege to perform this operation.

Cause of the Problem
The error may mislead you and you may wonder your login user has not proper privilege and it might need CREATE TARGET privilege. But in fact the problem happens if you configure dbconsole of your RAC cluster database instance for a single database, not for cluster daratabase.

Solution of the Problem
You need to configure your RAC database dbconcole with the -cluster keyword. So rerun the following command in your RAC database instance. One thing you should keep you in mind that your unique database name would be RAC database, it does not indicate any single instance of the RAC database.
$emca -config dbcontrol db -repos recreate -cluster
STARTED EMCA at Dec 1, 2009 10:08:50 AM
EM Configuration Assistant, Version 10.2.0.1.0 Production
Copyright (c) 2003, 2005, Oracle. All rights reserved.

Enter the following information:
Database unique name: EAIAPP
Database Control is already configured for the database EAIAPP
You have chosen to configure Database Control for managing the database EAIAPP
This will remove the existing configuration and the default settings and perform a fresh configuration
Do you wish to continue? [yes(Y)/no(N)]:
Listener port number: 1522
Cluster name: EAIAPP
.
.

You have specified the following settings

Database ORACLE_HOME ................ /opt/oracle/product/dbs

Database instance hostname ................ db1-eai.prod.stl.cw.intraisp.com
Listener port number ................ 1522
Cluster name ................ EAIAPP
Database unique name ................ EAIAPP
Email address for notifications ...............
Outgoing Mail (SMTP) server for notifications ...............
ASM ORACLE_HOME ................ /opt/oracle/product/asm
ASM port ................ 1522
ASM user role ................ SYSDBA
ASM username ................ SYS
Do you wish to continue? [yes(Y)/no(N)]: yes
Dec 1, 2009 10:17:00 AM oracle.sysman.emcp.EMConfig perform
INFO: This operation is being logged at /opt/oracle/product/dbs/cfgtoollogs/emca/EAIAPP/emca_2009-12-01_10-10-40-AM.log.
Dec 1, 2009 10:17:01 AM oracle.sysman.emcp.util.DBControlUtil stopOMS
INFO: Stopping Database Control (this may take a while) ...
Dec 1, 2009 10:17:05 AM oracle.sysman.emcp.EMReposConfig dropRepository
INFO: Dropping the EM repository (this may take a while) ...
Dec 1, 2009 10:18:08 AM oracle.sysman.emcp.EMReposConfig invoke
INFO: Repository successfully dropped
Dec 1, 2009 10:18:08 AM oracle.sysman.emcp.EMReposConfig createRepository
INFO: Creating the EM repository (this may take a while) ...
Dec 1, 2009 10:19:36 AM oracle.sysman.emcp.EMReposConfig invoke
INFO: Repository successfully created
Dec 1, 2009 10:19:38 AM oracle.sysman.emcp.EMDBCConfig instantiateOC4JConfigFiles
INFO: Propagating /opt/oracle/product/dbs/oc4j/j2ee/OC4J_DBConsole_db1-eai_EAIAPP1 to remote nodes ...
Dec 1, 2009 10:19:38 AM oracle.sysman.emcp.EMDBCConfig instantiateOC4JConfigFiles
INFO: Propagating /opt/oracle/product/dbs/oc4j/j2ee/OC4J_DBConsole_db2-eai_EAIAPP2 to remote nodes ...
Dec 1, 2009 10:19:38 AM oracle.sysman.emcp.EMDBCConfig copyAndPropagateOC4JDir
INFO: Propagating /opt/oracle/product/dbs/oc4j/j2ee/isqlplus_db1-eai.prod.stl.cw.intraisp.com to remote nodes ...
Dec 1, 2009 10:19:39 AM oracle.sysman.emcp.EMDBCConfig copyAndPropagateOC4JDir
INFO: Propagating /opt/oracle/product/dbs/oc4j/j2ee/isqlplus_db2-eai.prod.stl.cw.intraisp.com to remote nodes ...
Dec 1, 2009 10:19:41 AM oracle.sysman.emcp.EMAgentConfig deployStateDirs
INFO: Propagating /opt/oracle/product/dbs/db1-eai_EAIAPP1 to remote nodes ...
Dec 1, 2009 10:19:42 AM oracle.sysman.emcp.EMAgentConfig deployStateDirs
INFO: Propagating /opt/oracle/product/dbs/db2-eai_EAIAPP2 to remote nodes ...
Dec 1, 2009 10:19:43 AM oracle.sysman.emcp.util.DBControlUtil secureDBConsole
INFO: Securing Database Control (this may take a while) ...
Dec 1, 2009 10:57:56 AM oracle.sysman.emcp.EMDBPostConfig performConfiguration
INFO: Database Control started successfully
Dec 1, 2009 10:57:56 AM oracle.sysman.emcp.EMDBPostConfig performConfiguration
INFO: >>>>>>>>>>> The Database Control URL is https://db1-eai.prod.stl.cw.intrais.com:1158/em <<<<<<<<<<<
Dec 1, 2009 10:57:57 AM oracle.sysman.emcp.EMDBPostConfig showClusterDBCAgentMessage
INFO:
**************** Current Configuration ****************
INSTANCE NODE DBCONTROL_UPLOAD_HOST
---------- ---------- ---------------------

EAIAPP1 db1-eai db1-eai.prod.stl.cw.intrais.com
EAIAPP2 db2-eai db1-eai.prod.stl.cw.intrais.com


Enterprise Manager configuration completed successfully
FINISHED EMCA at Dec 1, 2009 10:57:57 AM

And you are done.

Related Documents