mysql 的sql語句

來源:互聯網
上載者:User

標籤:.sh   null   false   and   close   mode   while   OLE   proc   

1 procdure 預存程序 用遊標迴圈
BEGIN
DECLARE devsn varchar(100) default null;
DECLARE serialNo varchar(40) default null;
DECLARE fcloor int(11) DEFAULT NULL ;
DECLARE nextIntime dateTime default null;
Declare modelName varchar(200) default null;
Declare maintainName varchar(200) default null;
Declare propertyName varchar(200) default null;
DECLARE flg boolean default true;
DECLARE name varchar(200) default null;
// 擷取結果集遊標
DECLARE cur CURSOR FOR
select * from ems.sheet3 where ems.sheet3. 裝置註冊代碼 not in (select ems.tbl_user_dev.user_dev_sn
from ems.tbl_user_dev );
// 當不能發現時設定為false
DECLARE CONTINUE HANDLER FOR NOT FOUND SET flg = false;

 open cur;                 while(flg) do                FETCH cur into devsn,name,serialNo,nextIntime,fcloor,propertyName,maintainName;                    if(flg) then                    insert into tbl_user_dev (tbl_user_dev.user_dev_sn,               tbl_user_dev.factory_no,                        tbl_user_dev.user_dev_model_id,                        tbl_user_dev.maintenance_organization_id,                        tbl_user_dev.using_organization_id)                    select devsn,serialNo,                (select tbl_user_dev_model.id from tbl_user_dev_model where tbl_user_dev_model.model_name=name),                (select tbl_org.id from tbl_org where tbl_org.org_name=maintainName and tbl_org.org_type=‘01‘),                (select tbl_org.id from tbl_org where tbl_org.org_name=propertyName and tbl_org.org_type=‘02‘);                             insert into tbl_elevator (             tbl_elevator.user_dev_id,            tbl_elevator.nextin_spection_date,            tbl_elevator.floor )            select (select tbl_user_dev.id from tbl_user_dev where tbl_user_dev.user_dev_sn=devsn),                        nextIntime,                        fcloor;                end if;        end WHILE; close cur;

end

// 注意:當插入的值要去繼續尋找時要用select 而不是 values() 而且將select的結果用擴好括起來

mysql 的sql語句

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.