「動的SQL」の編集履歴(バックアップ)一覧に戻る

動的SQL - (2005/11/15 (火) 11:36:32) のソース

*動的SQL
-解析のオーバーヘッドがかなりあるらしいが。
**例
***単純な例
> execute immediate 'select * from hoge';
***オブジェクト名の指定
> execute immediate 'select * from ' || hoge;
-オブジェクト名はバインド不可。
***バインド変数で値を指定。
> execute immediate 'select * from hoge where id = :id' using id;
***結果を取得(単一行)
> rec hoge%rowtype; --レコード変数の定義
> execute immediate 'select * from hoge where id = :id' into rec using id;
-取得結果はレコード変数に。
-単一行を戻さない場合はエラー
***結果を取得(複数行)
> type ctype is ref cursor;
> c ctype; --カーソル変数の定義。syscursorでもよいが。
> open c for 'select * from hoge where id = :id' using id;
> loop
>   fetch c into rec;
>   exit when c%notfound;
>   ...
> end loop;
> close c;
-open for と fetchを利用する。
----
*なんかあればどうぞ
#comment(vsize=2,nsize=20,size=40)
記事メニュー
人気記事ランキング
目安箱バナー