<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                轉載自:https://www.jb51.net/article/70677.htm **** **1. 什么是光標(游標)** 查詢語句可能會有多條記錄,在存儲過程或函數中使用光標可以逐條獲取結果集中的記錄。 <br/> **2. 光標的使用步驟** ```sql 1. 聲明光標 # 光標必須聲明在處理程序之前,在變量和條件之后 DECLARE cursor_name CURSOR FOR select_statement; 2. 打開光標 OPEN cursor_name; 3. 使用光標 FETCH cursor_name INTO var_name[, var_name, ...]; 4. 關閉光標 # 每個光標不再需要時應該關閉,以便釋放光標所占的資源 # 對于聲明過的光標不需要再次聲明,直接用open打開即可使用 CLOSE cursor_name; - cursor_name:自定義的光標名稱 - select_statement:select 查詢語句 - var_name:select 語句查詢出來的信息存入該變量中,該變量必須在聲明光標之前定義好 ``` **3. 演示** 將表`account`的數據復制一份到表`account_copy`中。 ```sql # 1. 數據準備 drop table if exists account; create table account ( id int primary key auto_increment not null, username varchar(255) not null, password varchar(255) not null ); insert into account values(1, '張三', 'zhangsan'); insert into account values(2, '李四', 'lisi'); drop table if exists account_copy; create table account_copy ( id int primary key auto_increment not null, uname varchar(255) not null, pass varchar(255) not null ); # 2. 在存儲過程中使用光標 delimiter $ create procedure proce_cur() begin declare id_ int(11); declare count_ int(11); declare uname_ varchar(255); declare pass_ varchar(255); -- 聲明光標 declare cursor_account cursor for select * from account; declare continue handler for sqlstate '02000' set @info = 'ERROR'; select count(id) into count_ from account; -- 打開光標 open cursor_account; repeat -- 使用光標,將光標中的值賦值給下面三個變量 fetch cursor_account into id_, uname_, pass_; insert into account_copy values(id_, uname_, pass_); set count_ = count_ - 1; until count_ <= 0 end repeat; -- 關閉光標 close cursor_account; end $ # 3. 調用存儲過程 call proce_cur() $ # 4. 查看結果 mysql> select * from account_copy $ +----+--------+----------+ | id | uname | pass | +----+--------+----------+ | 1 | 張三 | zhangsan | | 2 | 李四 | lisi | +----+--------+----------+ ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看