Ognacの雑感

木漏れ日々

目次

Blog 利用状況

書庫

ギャラリ

Oracle ArrayBindは認知度が低いの?

Oracleの機能にArrayBindがあります。
ストアードなどの PL/SQの列パラメータに配列を渡せる機能です。

    ID      名字  価格
     --------------------------
 1 木村 102
 10 那賀側 104
 15 北側 155
 20 甲村 1443
 30 高騰 225
 40 抜粋 545
 50 鈍伝 445

このような3列でn行からなるデータを登録するとき、行ごとにInsert文を発行すると、7回Insert文を発行するのは、冗長です。バルクインサートなどの方法もありますが、もっと手軽に早く実行できる仕組みとして、 ArrayBind機能があります。

CREATE OR REPLACE PROCEDURE 挿入(a_id NUMBER, a_A VARCHAR2 ,a_B number)
IS  BEGIN
 INSERT INTO TBL (id, A, B) VALUES (a_id,a_A, a_B);
END;

というストアードを登録しておいて、

           各列を1つの配列化してパラメータ登録して

            cmd.ArrayBindCount = DT.Rows.Count
            cmd.CommandText = "挿入"
            cmd.CommandType = CommandType.StoredProcedure
            Dim i As Integer = cmd.ExecuteNonQuery()

とするだけで処理してくれます。

            cmd.ArrayBindCount = 配列.Length  ここで、要素数をセットするだけです。

速度は、体感ですが、クライアントでLoopした時と比べると、数倍以上早いです。
早い上に、ソースもすっきり書けます。

 ところが、ほとんど、知られていなくて、周知徹底するのに、画策しないとイケないのは、チト悲し感が有りました。
知っているだろうと独断するのでなく、些細なとでも、便利機能と思うことは、声に出して、叫んだほうが良いみたい。
「そんなこと知っているよ」と言われそうなことでも、「知らなかった」と言われる確率が結構高いことに今更吃驚しています。

このストアードを、拡張して、PK項目で判定して、なければ挿入、有れば更新という風に、すれば、もっと使い手がよくなりそうに思います。 Merge文は使う前段の処理がチト面倒なので、反応は今一でした。

投稿日時 : 2008年7月16日 1:12

Feedback

# <url>http://www.findfreeinsurancequotes.net/|cheap auto insurance</url> 951 <url>http://www.freeinsurquotes.com/|car insurance online</url> :]] 2012/08/24 18:42 Mavrick

<url>http://www.findfreeinsurancequotes.net/|cheap auto insurance</url> 951 <url>http://www.freeinsurquotes.com/|car insurance online</url> :]]

# <url>http://www.findautoinsurplans.com/|auto insurance</url> 26971 <url>http://www.get-autoinsurance.com/|auto insurance</url> liqizg <url>http://www.oldstylelist.com/|affordable auto insurance</url> 424 <url>http 2012/10/14 23:24 Lillah

<url>http://www.findautoinsurplans.com/|auto insurance</url> 26971 <url>http://www.get-autoinsurance.com/|auto insurance</url> liqizg <url>http://www.oldstylelist.com/|affordable auto insurance</url> 424 <url>http://www.locateonlinecolleges.com/|online college</url> xcvv

# http://www.crazyraid.com 2012/10/22 4:12 cheap wow gold

Great delivery. Great arguments. Keep up the amazing effort.

# It's in fact very complex in this full of activity life to listen news on Television, therefore I only use web for that reason, and get the latest information. 2021/08/01 20:20 It's in fact very complex in this full of activity

It's in fact very complex in this full of activity life to listen news on Television, therefore I only use web for that
reason, and get the latest information.

# It's in fact very complex in this full of activity life to listen news on Television, therefore I only use web for that reason, and get the latest information. 2021/08/01 20:20 It's in fact very complex in this full of activity

It's in fact very complex in this full of activity life to listen news on Television, therefore I only use web for that
reason, and get the latest information.

# It's in fact very complex in this full of activity life to listen news on Television, therefore I only use web for that reason, and get the latest information. 2021/08/01 20:21 It's in fact very complex in this full of activity

It's in fact very complex in this full of activity life to listen news on Television, therefore I only use web for that
reason, and get the latest information.

# It's in fact very complex in this full of activity life to listen news on Television, therefore I only use web for that reason, and get the latest information. 2021/08/01 20:21 It's in fact very complex in this full of activity

It's in fact very complex in this full of activity life to listen news on Television, therefore I only use web for that
reason, and get the latest information.

タイトル
名前
Url
コメント