---
title: "存储过程更新表"
author: "freeman983"
date: "2009-12-07T14:25:39Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2009-12-07T14:25:39Z"
id: 543291
url: "https://freeman983.iteye.com/blog/543291"
---

```
declare
  i integer;
begin
  i := 0;
  for rr in (select rowid from salebilltable where usercode is null) loop
    i := i + 1;
    update salebilltable
       set usercode = substr(userid, 1, 6)
     where rowid = rr.rowid;
    commit;
    if (mod(i, 10000) = 0) then
      dbms_output.put_line('update ' || i || 'rows');
    end if;
  
  end loop;
  dbms_output.put_line('update ' || i || ' rows');
  dbms_output.put_line('Done Successfully!');

exception
  when others then
    rollback;
    dbms_output.put_line(sqlcode);
end;
```