我有2個表格,外加第三個表格,將數據輸入到表格中。PL/SQL遊標幫助
表是:
SQL> select *
2 from paydata1;
IDNO NAME J SALARY PAYHR
---- ------------------------- - ---------- ----------
1111 Ann French S 75000 0
2222 Robert Costa H 0 45
3333 Linda Ames H 0 50
4444 Scott Brooks S 78000 0
5555 Susan Ash S 57000 0
6666 James Smith S 55000 0
7777 Mary Jones H 0 36
8888 John Morse H 0 39
和
SQL> select *
2 from paytran1;
IDNO PRO HOURSWK
---- --- ----------
1111 123 20
1111 456 10
1111 789 15
2222 123 17
2222 456 24
2222 789 20
3333 123 20
3333 789 20
4444 123 10
4444 456 28
4444 789 5
5555 456 40
6666 456 44
7777 456 30
7777 789 15
8888 123 10
8888 456 25
8888 789 5
的問題是:寫的PL/SQL程序中使用遊標來讀取文件和寫出來的工作總時間每個員工。
我的PL/SQL代碼爲:
SET SERVEROUTPUT ON
DECLARE
v_idno paydata1.idno%TYPE;
v_name paydata1.name%TYPE;
v_idno1 paytran1.idno%TYPE;
v_hourswk paytran1.hourswk%TYPE;
CURSOR paydata1_cursor IS
SELECT idno, name FROM paydata1
ORDER BY idno;
CURSOR paytran1_cursor IS
SELECT idno, hourswk FROM paytran1
WHERE v_idno1 = idno
order BY idno;
BEGIN
OPEN paydata1_cursor;
LOOP
FETCH paydata1_cursor INTO v_idno, v_name;
EXIT WHEN paydata1_cursor%NOTFOUND;
IF paytran1_cursor%ISOPEN THEN
CLOSE paytran1_cursor;
END IF;
OPEN paytran1_cursor;
LOOP
FETCH paytran1_cursor INTO v_idno1, v_hourswk;
EXIT WHEN paytran1_cursor%NOTFOUND;
END LOOP;
INSERT into allinfo
VALUES(v_idno, v_name, v_hourswk);
CLOSE paytran1_cursor;
END LOOP;
CLOSE paydata1_cursor;
END;
/
SET SERVEROUTPUT OFF
我allinfo表的結果是:
SQL> select *
2 from allinfo;
IDNO EMPLOYEE HOURS
---- --------------- ----------
1111 Ann French
2222 Robert Costa
3333 Linda Ames
4444 Scott Brooks
5555 Susan Ash
6666 James Smith
7777 Mary Jones
8888 John Morse
爲什麼心不是在hourswk正在與IDNO組合並顯示在allinfo表和名字?
我使用了你的修復程序,它仍然不會計數hourswk,就像我以前的輸出 –
做了一些改變。它現在工作嗎?我很抱歉我的甲骨文有點生疏。 –
我不得不重新插入訂單,以使其起作用,但仍未插入到理貨或小時工 –