Minggu, 20 Oktober 2013



Pemrograman Basis Data

Dosen : Titik Lusiani, M.Kom., OCP

1.    Your stored procedure, GET_BUDGET, has a logic problem and must be modified. The script that contains the procedure code has been misplaced. Which data dictionary view can you query to capture the source code for this procedure?
    1. USER_SOURCE
  User source memuat nama,type procedure,line number dan isi dari user source
2.    The database administrator has informed you that the CREATE PROCEDURE privilege has been granted to your account. Which objects can you now create?
D.       procedures, functions, and packages
Privilege (Hak Akses) merupakan tipe khusus dari pernyataan SQL untuk mengakses object dari user lain. dua jenis privilege yaitu : system privilege dan object privilege.
Ø System privilege adalah hak untuk  user agar bisa mengeksekusi perintah ke databasenya. ada tujuh system privilege yang disediakan oleh ORACLE.
                            1.       create table = ijin buat table
                            2.       create any tabel= ijin buat tabel di user lain
                            3.       create sequence = ijin buat sequence
                            4.       create view = ijin buat view
                            5.       create indextype= ijin buat index
                            6.       create procedure= ijin buat stored procedure
                            7.       create session = ijin login database

Ø Object privilege : hak akses user unutk bisa mengakses database user lain berikut object privilege yang terdapat dalam oracle :
·         select = ijin melihat data
·         insert = ijin memasukkan data
·         update = ijin melakukan perubahan data
·         delete = ijin menghapus data
·         alter = ijin mengubah struktur table
·         index = ijin membuat index
·         references = ijin membuat foreign key pada kolom tabel
3.    Which data dictionary table can you query to determine all stand-alone procedures that reference the THEATER_PCK package?
D.    USER_DEPENDENCIES
 User_dependencies merupakan data dictionary yang saling terkait antar object.
4.    Which data dictionary view can you query to examine all the dependencies between the objects that you own?
C.  USER_DEPENDENCIES
          User_dependencies dapat melakukan refenerce untuk data dictionary view.
5.     Due to a change to a particular table, you are concerned with the number of stored procedures and functions that may have been affected. Which table can you query to check the status of each subprogram and determine which procedures and functions must be recompiled?
C.  USER_OBJECTS
     User_object memuat informasi tentang semua object yang dimiliki, valid tidaknya suatu procedure.
6.    You have lost the script file that contains the source code for the THEATER_PCK package. Which command will produce the source code stored in the database?
A.    SELECT text FROM user_source WHERE name = 'THEATER_PCK';
          Perintah yang digunakan untuk memanggil tehater_pck adalah seperti syntax diatas.
7.    Which view can you query to determine the validity of a particular procedure?
C.USER_OBJECTS
          User_object digunakan untuk memvalidasi suatu prosedure.
8.    Which data dictionary view must you query to determine when a particular procedure or function was created?
C.USER_OBJECTS
          User_object melihat semua informasi tentang object yang dimiliki.
9.        All users in the HR_EMP role have UPDATE privileges on the EMPLOYEE table. You create the UPDATE_EMPLOYEE procedure. HR_EMP users should only be able to update the EMPLOYEE table using this procedure. Which two statements should you execute? (Choose two.)
C.REVOKE UPDATE ON employee FROM hr_emp;
E.GRANT EXECUTE ON update_employee TO hr_emp;
    GRANT, merupakan perintah yang digunakan untuk mengizinkan seorang user
untuk mengakses tabel pada database tertentu. Seorang administrator database biasanya akan melakukan pembatasan hak akses user terhadap tabel dalam database. Tujuan akhirnya adalah untuk manajemen keamanan database.
REVOKE, merupakan perintah yang digunakan untuk mencabut hak akses seorang user pada tabel dalam database tertentu. REVOKE digunakan untuk mencabut hak akses seorang user mengakses tabel dalam database tertentu. Pencabutan hak akses ini dengan klausa REVOKE. Pemakai adalah nama user yang akan dicabut hak aksesnya.
10.    Which statement concerning the use of a procedure is true?
C . A user needs only the privilege to execute the procedure and does not need privileges on the underlying tables.
User menggunakan hak akses (privilege) untuk membuat prosedure. Pada lingkungan multi-user, dapat mengatur keamanan dari akses database dan mengontrol akses user. Security dari database Oracle mengijinkan untuk:
·         Mengontrol akses ke database
·         Memberikan akses terhadap objek-objek tertentu di dalam database
·         Mengkonfirmasi privilege yang diberikan dan diterima melalui data dictionary
·         Menciptakan synonym untuk objek-objek database
11.    Examine this procedure:
            CREATE OR REPLACE PROCEDURE update_theater (v_name IN VARCHAR2) IS
            BEGIN
            DELETE theater WHERE id = 34;
            END update_theater;
            This procedure is owned by PROD. The user JSMITH must execute this procedure. Which command(s) must PROD execute to grant the necessary privileges to JSMITH?
A.    GRANT EXECUTE ON update_theater TO jsmith
GRANT EXECUTE digunakan untuk memberi hak akses melalui sebuah prosedure yang bernama update_theater kepada JSMITH.
12.    You have just successfully dropped the CALC_COMM procedure and deleted the script file containing the source code. Which command can you execute to recover this procedure?
D.  Only the database administrator can recover this procedure using backups.
Drop digunakan untuk melakukan penghapusan tabel. Melakukan penghapusan table dengan perintah DROP, berarti mengerjakan hal berikut :
->Semua data dan struktur dari table akan dihapus
->Semua transaksi pending akan di-commit
->Semua indeks akan dihapus
->Perintah drop ini tidak bisa di-rollback
Hanya database administrator yang dapat merecovernya.
13.              Examine this procedure:
            CREATE OR REPLACE PROCEDURE remove_department (v_deptno IN NUMBER) IS
            BEGIN
            DELETE dept WHERE deptno = v_deptno;
            END;
            After executing this procedure, you receive this message:
            ORA-02292: integrity constraint (SCOTT.FK_DEPTNO) violated - child record found
            What must be added to the procedure to handle this error?
D.      Declare a new exception and associate it with error code -2292. Create an exception section, and add code to handle this non-predefined exception that you just declared.
Handling Exceptions merupakan salah satu kelebihan dari PL/SQL yang digunakan untuk menangani error yang terjadi pada saat run time.
Sebagai contoh, pada saat kita menuliskan sebuah query, dan data tersebut tidak ditemukan di dalam database, maka oracleakan membangkitkan eksepsi NO_DATA_FOUND  dengan kode ORA-01403 yang berarti data tidak ditemukan.
16.    Examine this procedure:
            CREATE PROCEDURE add_theater IS
            BEGIN
            INSERT INTO theater
            VALUES (35, 'Riverplace Theatre', '1222 River Drive, Austin, Tx.');
            END;
            This procedure already exists in the database. You have made a change to the code and want to recreate the procedure. Which command must you now use to prevent an error?
D .CREATE OR REPLACE PROCEDURE
Command yang digunakan untuk mengubah database yang telah ada sebelumnya yaitu menggunakan CREATE or REPLACE PROCUDERE.
Schema Trigger:
CREATE [ OR REPLACE ] TRIGGER [ schema. ]trigger
{ BEFORE | AFTER | INSTEAD OF }
{ dml_event_clause
| { ddl_event [ OR ddl_event ]...
          | database_event [ OR database_event ]...
  } ON { [ schema. ]SCHEMA
           | DATABASE
           }
}
[ WHEN (condition) ]
{ pl/sql_block | call_procedure_statement } ;
19.              You execute this code:
          CREATE OR REPLACE PROCEDURE find_seats_sold (v_movie_id IN NUMBER DEFAULT 34) IS
          v_seats_sold gross_receipt.seats_sold%TYPE;
          BEGIN
          null;
          END;
          Which statement is true?
A.    The statement compiles, and the procedure is created.
Pernyataan yang benar yang benar yang dapat dijalankan dari code diatas yaitu procedure berhasil dibuat.
23.    Which statement about formal parameters is true?
B.  An IN OUT formal parameter does not require a value before returning to the calling environment.
Perlu diketahui lebih dahulu, parameter yang terdapat pada Procedure dinamakan Formal Parameter. Sedangkan Parameter yang terdapat pada si pemanggil Procedure adalahActual Parameter.
Tipe Parameter pada Procedure ada 3 :
  1. IN parameter, Merupakan Tipe parameter yang didefinisikan pada aktual parameter untuk kemudian ditangkap oleh formal parameter. Kita tidak perlu menuliskan IN untuk mendefinisikan parameter tersebut, karena parameter IN telah didefinisikan secara DEFAULT oleh Oracle.
  2. OUT parameter. Merupakan  tipe parameter pada procedure yang nilainya dapat digunakan oleh si pemanggil procedure dan bisa dibilang OUT parameter merupakan kebalikan dari IN parameter.
  3. IN OUT parameter. Tipe parameter yang digunakan untuk mengirimkan sebuah nilai ke procedure yang kemudian akan diproses dan dikembalikan kepada si pemanggil procedure.
  1. Examine this procedure:
            CREATE OR REPLACE PROCEDURE find_seats_sold
            (v_movie_id IN NUMBER DEFAULT 34, v_theater_id IN NUMBER) IS
            v_seats_sold gross_receipt.seats_sold%TYPE;
            BEGIN
            SELECT seats_sold INTO v_seats_sold
            FROM gross_receipt
            WHERE movie_id = v_movie_id AND theater_id = v_theater_id;
            END;
            Which command will successfully invoke this procedure in SQL*Plus?
     C.     EXECUTE find_seats_sold (v_theater_id => 500);
Command yang digunakan untuk memanggil procedure find_seat_sold adalah EXECUTE find_seat_sold(v_thetater_id =>500);,v_movie_id telah diisi dengan 34 karena di default dan v_theater_id diisi 500.
27.              Which statement about declaring parameters is true?
B .Data type and maximum length are required.
Pendeklarasian parameter yang benar dalam oracle dengan tipe varchar2 yaitu harus menambahkan data type dan maximum length.
29.    The CALC_COMM procedure is no longer needed and should be removed. Which command will successfully remove this procedure from the database?
A.    DROP calc_comm;
DROP digunakan untuk menghapus suatu object database tertentu.
3     30.  Examine this procedure:
     CREATE PROCEDURE add_theater IS
     BEGIN
     INSERT INTO theater
     VALUES (35, 'Riverplace Theatre', '1222 River Drive, Austin, Tx.');
     END;
     Which three statements about this procedure are true? (Choose three.)
A.    The ADD_THEATER procedure is written in SQL.
B.     The ADD_THEATER procedure can be shared by multiple programs.
C.     The ADD_THEATER procedure will be stored in the database as a schema object.

Tidak ada komentar:

Posting Komentar