2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SQL初心者がIBMiの組み込みSQLで躓いた点

Last updated at Posted at 2025-10-17

環境情報

今回の検証ではi Learning社の公開しているQEOLのライブラリーの
TOKMSP(得意先マスター)を使用しています。
https://www.i-learning.jp/service/selfstudy/eol.html

SQL初心者が組み込みSQLを学習して躓いた点

SQL初心者が組み込みSQLの学習をした際に躓いた点を記載。
今回は得意先マスター(TOKMSP)から全件データを抜き出すシンプルな処理で説明。

対話型SQL(サンプル)

得意先マスター(TOKMSP)全件データ抜き出し
SQLで得意先マスター(TOKMSP)のデータを全件抜き出そうとすると以下のSQL文となる。
RPGだとREADで1件ずつ抜き出す事になる。
組み込みSQLでREADのように1件ずつデータを処理する場合はCURSORとFETCHを使用する。

      SELECT * 
      FROM QEOL.TOKMSP

image.png

組み込みSQLでCURSORとFETCHを使用する理由

RPGとSQLの処理単位の違い

RPGはレコード単位(1件ずつ)で処理する仕組みとなっていて、
複数のレコードを一括で処理することが出来ない。
逆にSQLは一括処理が基本。
SQLで1件ずつ処理したい時に使用するのがCURSORとFETCH。
そのため従来RPGで行っていた処理を組み込みSQLで実行する場合、
CURSORとFETCHが必須となる。

組み込みSQL(サンプル)

image.png

各文の簡単な説明

image.png

CURSOR(カーソル)

image.png
image.png

FETCH(フェッチ)

image.png
image.png

SQLSTATE

image.png

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?