国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

使用oralce Cursor

2024-07-21 02:41:08
字體:
來源:轉載
供稿:網友

   使用Cursor:
  declare

RoomID       Room.RoomID%Type;

RoomName     Room.RoomName%Type;

cursor crRoom  is

  select RoomID,RoomName

     from Room;

  begin

open crRoom;

loop;

fetch crRoom into RoomID,RoomName;

exit when crRoom%notFound;

  end loop;

close crRoom;

end;

 
3.1在游標使用入口參數
在SQL語句的Where 子句中恰當使用 相關語句簡化邏輯,本來需要使用兩個游標,把相關入口參數放入到SQL語句的Where 子句中,一個就搞定了:

cursor    crRoom    is
      select 
        distinct  樓層,房屋用途
        from      TT_沒有處理的房屋  t
        where     數據級別>= 0
            and   房屋處理類別= 3
            and   產權編號=p_產權編號
            and   拆遷房屋類別=p_拆遷房屋類別
            and   面積>0
            and   (not p_房屋用途 is null
                   and 房屋用途=p_房屋用途
                   or p_房屋用途 is null); 

另外一個例子:

CREATE OR REPLACE PROCEDURE PrintStudents(
  p_Major IN students.major%TYPE) AS
  CURSOR c_Students IS
    SELECT first_name, last_name
      FROM students
      WHERE major = p_Major;
BEGIN
  FOR v_StudentRec IN c_Students LOOP
    DBMS_OUTPUT.PUT_LINE(v_StudentRec.first_name ' '
                         v_StudentRec.last_name);
  END LOOP;
END;

 

Oracle帶的例子examp6.sql

DECLARE
    CURSOR bin_cur(part_number NUMBER) IS SELECT amt_in_bin
        FROM bins
        WHERE part_num = part_number AND
     
       amt_in_bin > 0
            ORDER BY bin_num
            FOR UPDATE OF amt_in_bin;
    bin_amt         bins.amt_in_bin%TYPE;
    total_so_far    NUMBER(5) := 0;
    amount_needed   CONSTANT NUMBER(5) := 1000;
    bins_looked_at  NUMBER(3) := 0;
BEGIN
    OPEN bin_cur(5469);
    WHILE total_so_far < amount_needed LOOP
        FETCH bin_cur INTO bin_amt;
        EXIT WHEN bin_cur%NOTFOUND;
             /* If we exit, there's not enough to *
              * satisfy the order.                */
        bins_looked_at := bins_looked_at + 1;
        IF total_so_far + bin_amt < amount_needed THEN
            UPDATE bins SET amt_in_bin = 0
                WHERE CURRENT OF bin_cur; 
                    -- take everything in the bin
            total_so_far := total_so_far + bin_amt;
        ELSE        -- we finally have enough
            UPDATE bins SET amt_in_bin = amt_in_bin
                - (amount_needed - total_so_far)
                WHERE CURRENT OF bin_cur;
            total_so_far := amount_needed;
        END IF;
    END LOOP;
    CLOSE bin_cur;
    INSERT INTO temp VALUES (NULL, bins_looked_at, '<- bins looked at');
    COMMIT;
END;

 

 

-- Created on 2004-8-9 by ADMINISTRATOR
declare
  --帶有變量的Cursor
cursor crBooks(c_bookTitle varchar2) is
     select *
       from books  a
      
where a.title like  c_bookTitle'%';
begin
  for v_Books in crBooks('Oracle8') loop
    dbms_output.put_line(v_Books.author1);
  end loop;
end;

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 买车| 大安市| 台东县| 苏尼特左旗| 苍山县| 威远县| 景谷| 连江县| 吉安市| 徐汇区| 永丰县| 馆陶县| 会宁县| 兴义市| 中方县| 十堰市| 安泽县| 海口市| 阿克陶县| 乌拉特后旗| 福鼎市| 龙胜| 稻城县| 府谷县| 汤原县| 钦州市| 奇台县| 岢岚县| 根河市| 肥东县| 淄博市| 获嘉县| 绥宁县| 冷水江市| 三原县| 淳化县| 伊金霍洛旗| 肇源县| 博客| 霞浦县| 罗江县|