Professional Documents
Culture Documents
06 - Pengulangan HR
06 - Pengulangan HR
Gunakan Database HR
Gunakan database HR
Contoh Basic Loops menambah data
Example:
DECLARE
countryid locations.country_id%TYPE := 'CA';
loc_id locations.location_id%TYPE;
counter NUMBER(2) := 1;
new_city locations.city%TYPE := 'Montreal';
BEGIN
SELECT MAX(location_id) INTO loc_id FROM locations
WHERE country_id = countryid;
LOOP
INSERT INTO locations(location_id, city, country_id)
VALUES((loc_id + counter), new_city, countryid);
counter := counter + 1;
EXIT WHEN counter > 3;
END LOOP;
END;
/
Contoh Basic Loops menambah data
select * from locations
where country_id='CA' Melihat data locations sebelum ditambah
Example:
DECLARE
countryid locations.country_id%TYPE := 'CA';
loc_id locations.location_id%TYPE;
counter NUMBER(2) := 1;
new_city locations.city%TYPE := 'Montreal';
BEGIN
SELECT MAX(location_id) INTO loc_id FROM locations
WHERE country_id = countryid;
LOOP
INSERT INTO locations(location_id, city, country_id)
VALUES((loc_id + counter), new_city, countryid);
counter := counter + 1;
EXIT WHEN counter > 3;
END LOOP;
END;
Tabel regions_xxx :
select * from regions_xxx
Jawaban lat 2 : program mengisi data tabel regions_xxx yang sama
dengan data regions
Jawab :
CREATE TABLE jobs_123
(job_id varchar2(10) NOT NULL PRIMARY KEY, job_title
varchar2(35) NOT NULL , min_salary number(6), max_salary
number (6))
• Tambah FIELD table JOBS
• alter table jobs add (id number(2));
• Isi data ID dari 1 s.d 5 dengan perintah update
• update jobs set id=1 where job_id='AD_PRES' Periksa Tabel jobs :
• update jobs set id=2 where job_id='AD_VP' select * from jobs
• update jobs set id=3 where job_id='AD_ASST'
• update jobs set id=4 where job_id='FI_MGR'
• update jobs set id=5 where job_id='FI_ACCOUNT‘
• Tambah FIELD table JOBS_123
• alter table jobs_123 add (id number(2));
• Tampilkan Tabel jobs_123 :
• select * from jobs_123
• Keterangan :
• NIM diisi dengan NIM sendiri