Tuesday, June 16, 2009

(Tutorial : SQL) Introduction To Embedded SQL

Why embed SQL in programs?
a. Perform dynamic selection functions
- ala OPNQRYF, except more flexible
b. Perform set-at-a-time functions under program control
c. Even to replace HLL I/O operations
- e.g., READ, WRITE, UPDATE, CHAIN

What can be embedded?
a. The SQL statements we have seen so far
- e.g., SELECT, UPDATE, INSERT, CREATE TABLE, etc.
b. Program control statements
- e.g., DECLARE CURSOR, OPEN, CLOSE, FETCH, COMMIT, ROLLBACK

RPG Interface - Source

a. Retrieve column/field values into program variables
b. One-to-one correspondence between SELECT list and INTO
list
c. SELECT....INTO expects only a SINGLE row/record
- multiple rows require the use of cursor operations

Sample:
* No F spec needed !
D EmpNbr S 5 0
D Name S 25
D Job S 1
C/EXEC SQL
C+ SELECT NAME, POS
C+ INTO :Name, :Job
C+ FROM EMPL
C+ WHERE NBR = :EmpNbr
C/END-EXEC


You Might Also Want To Visit The Following Tutorial Posts:
AS/400 For Dummies
AS/400 Tutorial
SQL/400 Tutorial
Query/400 Tutorial


No comments:

Post a Comment