Resume Pemrograman Basis Data II (Pertemuan 3)

# Interacting with the Oracle Server #

DBMS Language
  • Data Definition Language (DDL) : bahasa dalam DBMS yang digunakan untuk membuat atau mendefinisikan obyek-obyek di dalam database. Secara umum digunakan untuk membuat obyek table dan view. DDL ini berfungsi lebih ke dalam memanipulasi struktur dari database. Contohnya DDL  bisa digunakan untuk membuat tabel atau menghapus tabel. Kita juga bisa membuat key atau index dengan menggunakan DDL , membuat relasi antar tabel juga bisa dilakukan dengan DDL .
    • CREATE TABLE, bertugas untuk membuat tabel
    • ALTER TABLE, bertugas untuk merubah struktur suatu tabel
    • DROP TABLE, bertugas untuk menghapus suatu tabel
    • CREATE INDEX, bertugas untuk membuat suatu index dalam tabel
    • DROP INDEX, bertugas untuk menghapus suatu index dalam tabel
  • Data Manipulation Language (DML) : adalah kumpulan perintah SQL yang berhubungan dengan pekerjaan mengolah data di dalam table - dan tidak terkait dengan perubahan struktur dan definisi tipe data dari objek database seperti table, column, dan sebagainya.
    • SELECT === > Menampilkan data.
      • Syarat penulisan Select :
        • Select (Pembanding) (operator) (Yang di bandingkan)
        • where
        • Group by
        • Having
        • Order by
        • ascending dan descending
    • INSERT === > Memasukan data
      • Syarat penulisan insert:
        • Insert into ...... Values
        • Pada insert tidak diperbolehkan menggunakan where
    • UPDATE === >Koreksi data
      • Syarat penulisan Update
        • Update (nama tabel)
        • Set (nama kolom)
        • where
    • DELETE === > Menghapus data
      • Syarat penulisan Delete
        • Delete from (nama tabel)
    • MERGE === > Menggabungkan dua tabel.
  • Data Control Language (DCL)merupakan perintah SQL yang berhubungan dengan pengaturan hak akses user MySQL, baik terhadap server, database, tabel maupun field. Perintah SQL yang termasuk dalam DCL antara lain :
    • GRANT : Perintah ini digunakan untuk memberikan hak / izin akses oleh administrator (pemilik utama) server kepada user (pengguna biasa). Hak akses tersebut berupa hak membuat (CREATE), mengambil (SELECT), menghapsu (DELETE), mengubah (UPDATE) dan hak khusus berkenaan dengan sistem databasenya. 
    •  REVOKE : perintah ini memiliki kegunaan terbalik dengan GRAND, yaitu untuk menghilangkan atau mencabut hak akses yang telah diberikan kepada user oleh administrator.
  • Jenis - jenis join :
    • INNER JOIN : hanya akan menampilkan baris untuk data yang memiliki nilai yang sama pada field kunci dengan tabel yang berelasi
    • LEFT JOIN : hanya menampilkan data dengan mengacu pada tabel yang ada disebelah kiri.
    • RIGHT JOIN : hanya menampilkan data dengan mengacu pada tabel yang ada disebelah kanan.
    • FULL JOIN : merupakan gabungan dari LEFT JOIN dan RIGHT JOIN
Pembahasan Soal :

  1. 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?
    1. GRANT EXECUTE ON update_theater TO jsmith;
(“karena GRANT EXECUTE ON update_theater TO jsmith; mempunyai hak akses untuk mengexecute procedure diatas”)
  1. 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?
    1. Only the database administrator can recover this procedure using backups.
(“karena hanya database administrator yang bisa merecoveri procedure untuk dibackup”)
  1. 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?
    1. 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.
(“karena menampilkan error handle dari procedure”)
  1. Examine this procedure:
            CREATE OR REPLACE PROCEDURE FIND_ORDERS (v_total IN sales_order.total%TYPE)                            IS
            CURSOR c1 IS SELECT order_id FROM sales_order
            WHERE total > v_total;
            BEGIN
            FOR sales_order_rec in c1 LOOP
            --process the row
            END LOOP;
            END;
This procedure returns all orders with a total greater than an amount that is passed in the V_TOTAL parameter. Occasionally, a user might want to process all orders regardless of the total amount. They could do this by passing 0 in the V_TOTAL parameter, however, they would prefer not to pass anything. Which change can you make to the procedure to allow a user to process all orders in the SALES_ORDER table without having to pass a 0 total amount?
    1. Use (v_total IN sales_order.total%TYPE DEFAULT 0) as the parameter definition.
(“karena v_total IN sales_order.total%TYPE DEFAULT 0 digunakan sebagai parameter atau nama sebuah procedure”)
  1. Examine this procedure:
            CREATE PROCEDURE update_theater IS
            BEGIN
            UPDATE theater SET name = v_name
            WHERE id = 34;
            END;
Because a value for the new theater name must be passed to this procedure upon invocation, you decide to create a parameter called V_NAME to hold the value. To be successful, which additional change must you make to this procedure?
    1. Add (v_name IN VARCHAR2) immediately before the IS keyword.
(“karena untuk memanggil v_name sebelumnya harus dideklarasikan dulu sebelum keyword IS”)
  1. 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?
    1. CREATE OR REPLACE PROCEDURE
(“karena perintah untuk mengcreate procedure harus CREATE OR REPLACE PROCEDURE nama procedure”)
  1. Examine this procedure:
            CREATE OR REPLACE PROCEDURE find_cpt
            (v_movie_id {argument mode} NUMBER, v_cost_per_ticket {argument mode} NUMBER) IS
            BEGIN
            IF v_cost_per_ticket > 8.50 THEN
            SELECT cost_per_ticket INTO v_cost_per_ticket
            FROM gross_receipt WHERE movie_id = v_movie_id;
            END IF;
            END;
            Which argument mode should be used for V_MOVIE_ID?
    1. IN
(“karena merupakan nilai default”)
  1. Which statement about declaring arguments for procedures is true?
    1. Formal arguments allow you to transfer values to and from the calling environment.
(“karena untuk menstranfer nilai dan kemudian memanggilnya”)
  1. 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?
    1. The statement compiles, and the procedure is created.
(“karena perintah untuk procedurenya sudah memenuhi syarat,sehingga bisa dicreate”)
  1. Which statement about error propagation is true?
    1. When an exception is raised in a called procedure, control goes to the exception section of that block.
(“karena pada saat memanggil procedure terjadi error,maka control akan menunjukkan block mana yang menyebabkan error”)

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 komentar:

Posting Komentar