PLSQL??????α?????4??????
???????????? ???????[ 2012/9/20 10:00:43 ] ????????
??????????????????α????4?????????漰?????????????????????.
????????α???????? PLSQL???裺
????1??????/?????α??????????α??????????????????SELECT ???
?????????
CURSOR cursor_name[(parameter[?? parameter]…)]
[RETURN datatype]
IS
select_statement;
?????α????????????????????????
????parameter_name [IN] datatype [{:= | DEFAULT} expression]
??????????????????????????ó??????????NUMBER(4)??CHAR(10) ??????????
????[RETURN datatype]???????????α?????????????????????????????select_statement?е?????б?????????????????????????????????????“%ROWTYPE”???????
????2?????α???????α????????SELECT ???????????????????????????????????????????????α????????????α???????д???FOR UPDATE???OPEN ??仹???????????????α????????????????С?
?????????
????OPEN cursor_name[([parameter =>] value[?? [parameter =>] value]…)];
?????????α???????????????????????????????????????λ??????????????????PL/SQL ????????OPEN ????????????α?
????3??????α???????????????????е??????У??????????????????С?
?????????
????FETCH cursor_name INTO {variable_list | record_variable };
???????FETCH????????η???????????У??????????α?????????????????С??????????????????????????????FETCH??????????????????α?????%NOTFOUND???TRUE??????????????FETCH????????α?????%NOTFOUND?????ж?FETCH????????г????????????????У??????????????????????????
????4????α??????????????α????????????????????α????????α????????????????????α????????????Ч???????????FETCH ???????????????????α???????OPEN ??????′???
?????????
????CLOSE cursor_name;
????????????????????????
CREATE OR REPLACE PROCEDURE testcur IS
CURSOR c_cursor(r_no NUMBER DEFAULT 5)IS
SELECT ISBN?? TITLE
FROM BOOKS
WHERE rownum < r_no
FOR UPDATE;
v_isbn BOOKS.ISBN%TYPE;
v_title BOOKS.TITLE%TYPE;
BEGIN
--OPEN c_cursor(5);
OPEN c_cursor(r_no=>7);
DBMS_OUTPUT.PUT_LINE('opened cursor'); --afater open
--DBMS_LOCK.SLEEP(30);
FETCH c_cursor
INTO v_isbn?? v_title;
DBMS_OUTPUT.PUT_LINE('fetched cursor');
--DBMS_LOCK.SLEEP(30);
WHILE c_cursor%FOUND LOOP
DBMS_OUTPUT.PUT_LINE(v_isbn || '---' || to_char(v_title));
FETCH c_cursor
INTO v_isbn?? v_title;
END LOOP;
CLOSE c_cursor;
DBMS_OUTPUT.PUT_LINE('closed cursor');
ROLLBACK;
DBMS_OUTPUT.PUT_LINE('ended transaction');
END testcur;
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11