幾個簡單的Oracle問題

因為正在學習Oracle..

模擬試題有幾個小問題,想依樣畫葫蘆請達人幫小弟解答一下看看該怎麼寫....

1.宣告一個記錄型態my_work_type,此記錄型態與WORK資料表結構相同。2.宣告一個my_work_type記錄型態的變數v_work_rec。3.將以下的值指定給記錄v_work_rec變數,WORK_ID(WP)、WORK_TITLE(Java Programmer)、MIN_SALARY(1000)、MAX_SALARY(20000)。4.將記錄變數新增到WORK資料表。

要怎麼讓他宣告的型態與WORK結構一樣?所謂結構一樣是指欄位名稱一樣嗎??

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

1.宣告兩個變數region_id與region_name,型態與REGION資料表對應的欄位相同。2.利用FOR迴圈輸出REGION資料表中所有資料

要求2.他說的for我怎麼知道1到多少?是他提示的4比所以1..4嗎?

1 Answer

Rating
  • 9 years ago
    Best Answer

    set serveroutput on

    declare

    type my_job_type is record

    (v_work_id work.work_id%type,

    v_work_title work.work_title%type,

    v_min_salary work.min_salary%type,

    v_max_salary work.max_salary%type);

    v_work_rec my_work_type;

    begin

    v_work_rec.v_work_id := 'JP';

    v_work_rec.v_work_title := 'Java Programmer';

    v_work_rec.v_min_salary := 1000;

    v_work_rec.v_max_salary := 20000;

    insert into work values v_work_rec;

    end;

    ==================================================

    set serveroutput on

    declare

    type region_name is table of

    region.region_name%type

    index by pls_integer;

    my_rept_table region_name;

    loop_count number :=4;

    reptno number:=0;

    begin

    for i in 1..loop_count

    loop

    reptno := reptno +1;

    select region_name into my_rept_table(reptno)

    from region

    where region.region_id = reptno;

    dbms_output.put_line(reptno||' '||my_rept_table(reptno));

    end loop;

    end;

    Source(s): 腦袋瓜
Still have questions? Get your answers by asking now.