Presentation is loading. Please wait.

Presentation is loading. Please wait.

Embedded SQL (Cont.) Pertemuan 10 Matakuliah: T0413/Current Popular IT II Tahun: 2007.

Similar presentations


Presentation on theme: "Embedded SQL (Cont.) Pertemuan 10 Matakuliah: T0413/Current Popular IT II Tahun: 2007."— Presentation transcript:

1 Embedded SQL (Cont.) Pertemuan 10 Matakuliah: T0413/Current Popular IT II Tahun: 2007

2 Bina Nusantara Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu menciptakan aplikasi sistem basisdata menggunakan konsep embeded SQL di dalam program

3 Bina Nusantara Outline Materi Using host language variables with SQL Using SQLCODE and SQLSTATE Updating cursors Indicator variables Examples

4 Bina Nusantara Using Host language variables with SQL We can use variables from the host program in embedded SQL state Host variable must : – Be declared in a SQL DECLARE SECTION – Compatible data type

5 Bina Nusantara Using Host language variables with SQL (Cont.) Be assign a value at the time they are used in the SQL statement Be preceed by a colon (:)

6 Bina Nusantara DECLARING VARIABLE BEGIN DECLARE SECTION END BEGIN SECTION

7 Bina Nusantara RETRIEVING VALUES INTO VARIABLE Use SELECT INTO Constraint : can’t retrieves multiple rows and inserted into the same variables at the same time

8 Bina Nusantara USING CURSOR Example : EXEC SQL DECLARE cursor londonstate FOR SELECT * FROM salesPeople WHERE city = ‘London’

9 Bina Nusantara USING CURSOR FETCH OPEN CURSOR CLOSE CURSOR

10 Bina Nusantara USING SQL CODE AND SQL STATE SQL CODE SQL STATE

11 Bina Nusantara UPDATING CURSOR Use cursor to select a group of rows from a table that can be Updated and Deleted Example : increasing the comission of all sales people who have customers with a rating of 300 in the following example

12 Bina Nusantara EXAMPLE UPDATING CURSOR EXEC SQL OPEN CURSOR High_Cust while SQLSTATE=‘00000’ do begin EXECT SQL FETCH High_Cust INTO : id_num, :salesperson, :loc, :comm; end; EXECT SQL UPDATE salespeople SET comm = comm +.01 WHERE CURRENT OF High_cust; end; EXECT SQL CLOSE CURSOR High_Cust;

13 Bina Nusantara INDICATOR VARIABLES SQLNULL SQLSTATE SQLCODE SQL EXACT NUMERIC

14 Bina Nusantara OTHER USES OF INDICATOR VARIABLES USED TO INDICATE TRUNCATION TO ASSIGN NULL VALUES


Download ppt "Embedded SQL (Cont.) Pertemuan 10 Matakuliah: T0413/Current Popular IT II Tahun: 2007."

Similar presentations


Ads by Google