SQL> CREATE TABLE test (ID VARCHAR2(20),xxx NUMBER);
Table created
SQL> INSERT INTO test SELECT lpad(ROWNUM,4,'0'),mod(ROWNUM,34) FROM dual CONNECT BY LEVEL < 2000;
1999 rows inserted
Oracle lpad函數(shù)將左邊的字符串填充一些特定的字符,其語(yǔ)法格式如下:
lpad( string1, padded_length, [ pad_string ] )
其中string1是需要粘貼字符的字符串
padded_length是返回的字符串的數(shù)量,如果這個(gè)數(shù)量比原字符串的長(zhǎng)度要短,lpad函數(shù)將會(huì)把字符串截取成padded_length;
pad_string是個(gè)可選參數(shù),這個(gè)字符串是要粘貼到string1的左邊,如果這個(gè)參數(shù)未寫(xiě),lpad函數(shù)將會(huì)在string1的左邊粘貼空格。
例如:
lpad('tech', 7); 將返回' tech'
lpad('tech', 2); 將返回'te'
lpad('tech', 8, '0'); 將返回'0000tech'
lpad('tech on the net', 15, 'z'); 將返回 'tech on the net'
lpad('tech on the net', 16, 'z'); 將返回 'ztech on the net'
SQL> commit;
Commit complete
SQL> set serverout on;
SQL> select count(*) from test where id = 33;
COUNT(*)
----------
1
SQL> select count(*) from test where xxx = 33;
COUNT(*)
----------
58
SQL> select count(*) from test where xxx <> 33;
COUNT(*)
----------
1941
SQL>
SQL> declare
2 -- 數(shù)組變量,保存查詢(xún)條件
3 TYPE t_id IS TABLE OF test.id%TYPE;
4 v_t_id t_id;
5
6 CURSOR c IS
7 SELECT id FROM test where xxx <> 33;
8 -- 循環(huán)次數(shù)
9 cnt NUMBER := 0;
10 BEGIN
11 OPEN c;
12 LOOP
13 cnt := cnt + 1;
14 -- 批量更新,一次更新100條數(shù)據(jù) ,取出數(shù)據(jù)放到變量v_t_id中
15 fetch c bulk collect into v_t_id LIMIT 100;
16 -- 這里用forall效率更高
17 FORALL i IN 1 .. v_t_id.COUNT
18 UPDATE test SET xxx = 33 WHERE id = v_t_id(i);
19
20 -- 提交
21 COMMIT;
22 -- 循環(huán)退出
23 exit when c%NOTFOUND;
24
25 END LOOP;
26
27 dbms_output.put_line('循環(huán)次數(shù):' || cnt);
28
29 CLOSE c;
30 COMMIT;
31 end;
32 /
循環(huán)次數(shù):20
PL/SQL procedure successfully completed
SQL> select count(*) from test where xxx = 33;
COUNT(*)
----------
1999
SQL> select count(*) from test where xxx <> 33;
COUNT(*)
----------
0
SQL>
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元

