Presentation is loading. Please wait.

Presentation is loading. Please wait.

Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-1 CHAPTER 11: EMBEDDED SQL.

Similar presentations


Presentation on theme: "Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-1 CHAPTER 11: EMBEDDED SQL."— Presentation transcript:

1 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-1 CHAPTER 11: EMBEDDED SQL

2 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-2 Structured Query Language can be used in conjunction with many different procedural and object-oriented programming host languages.Structured Query Language can be used in conjunction with many different procedural and object-oriented programming host languages. This approach to programming is termed embedded SQL, and simply means that the host language includes the ability to use SQL statements to both retrieve and store records in a non-procedural fashion.This approach to programming is termed embedded SQL, and simply means that the host language includes the ability to use SQL statements to both retrieve and store records in a non-procedural fashion. EMBEDDED SQL

3 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-3 Database processing is primarily accomplished through use of the ActiveX Data Objects (ADO) control.Database processing is primarily accomplished through use of the ActiveX Data Objects (ADO) control. This specialized control enables a computer programmer to connect an application program written in Visual Basic to an existing database.This specialized control enables a computer programmer to connect an application program written in Visual Basic to an existing database. It is easy to create the database connection.It is easy to create the database connection. Embedding SQL in Visual Basic 6.0

4 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-4 Figure 11.1 shows an example employee processing form with an ADO control.

5 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-5 The ADO control is used to process employee records.The ADO control is used to process employee records. The employee processing form displays a subset of the data columns from the employee table.The employee processing form displays a subset of the data columns from the employee table. The ADO control provides First, Previous, Next, and Last buttons (arrows) to make it easy to navigate from one row of data to the next.The ADO control provides First, Previous, Next, and Last buttons (arrows) to make it easy to navigate from one row of data to the next. When one of the ADO control navigation buttons is clicked, the form display updates to a new record.When one of the ADO control navigation buttons is clicked, the form display updates to a new record. The ADO control also has properties that can be visually programmed to make a database connection.The ADO control also has properties that can be visually programmed to make a database connection. ADO Control

6 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-6 The ConnectionString property stores a character string that specifies how to connect to a database.The ConnectionString property stores a character string that specifies how to connect to a database. Part of the ConnectionString information specifies where the database is located.Part of the ConnectionString information specifies where the database is located. The ConnectionString also specifies the type of database as well as information about provider software that is used to make a database connection. In the coding segment shown in the following VB6 Example, a connection is made to an Oracle database named Company.The ConnectionString also specifies the type of database as well as information about provider software that is used to make a database connection. In the coding segment shown in the following VB6 Example, a connection is made to an Oracle database named Company. REM VB6 ExampleREM VB6 Example ConnectionString = "Provider=MSDAORA.1; User ID=dbock; Password=mypassword; Data Source=Company; Persist Security Info=True"ConnectionString = "Provider=MSDAORA.1; User ID=dbock; Password=mypassword; Data Source=Company; Persist Security Info=True" (Note: All of the above code will be entered on a single coding line.) ADO Control

7 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-7 The CommandType property specifies how data will be retrieved from a database.The CommandType property specifies how data will be retrieved from a database. Data rows are retrieved from disk and stored in a memory object called a recordset.Data rows are retrieved from disk and stored in a memory object called a recordset. The RecordSource property stores the actual SQL statement used to create a recordset.The RecordSource property stores the actual SQL statement used to create a recordset. The records displayed for the recordset in Figure 11.1 were retrieved with the SELECT statement shown in VB6 Example 11.2.The records displayed for the recordset in Figure 11.1 were retrieved with the SELECT statement shown in VB6 Example 11.2. REM VB6 Example 11.2REM VB6 Example 11.2 SELECT emp_last_name, emp_first_name, emp_middle_name, emp_ssn,SELECT emp_last_name, emp_first_name, emp_middle_name, emp_ssn, emp_address, emp_city, emp_state, emp_zip FROM employee WHERE emp_zip = '62025'; ADO Control

8 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-8 ADO Control There are two additional properties for each textbox control that must be set in order for a Visual Basic form to display database data.There are two additional properties for each textbox control that must be set in order for a Visual Basic form to display database data. These are the DataField and DataSource properties shown in Figure 11.2 that displays a Visual Basic property window that is associated with the textbox control that displays the employee first name.These are the DataField and DataSource properties shown in Figure 11.2 that displays a Visual Basic property window that is associated with the textbox control that displays the employee first name.

9 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-9 The DataSource property of each textbox is set to the name of the ADO control.The DataSource property of each textbox is set to the name of the ADO control. Here the ADO control is named adoEmployee.Here the ADO control is named adoEmployee. Setting the DataSource property of a textbox links the textbox control to the ADO control.Setting the DataSource property of a textbox links the textbox control to the ADO control. DataField property is set to the appropriate column name from the employee table in order to specify the exact value to display in a textbox.DataField property is set to the appropriate column name from the employee table in order to specify the exact value to display in a textbox. Each textbox on the employee processing form will have the same value for the DataSource property, but the DataField property for each textbox will reflect the column of data to be displayed in that particular textbox.Each textbox on the employee processing form will have the same value for the DataSource property, but the DataField property for each textbox will reflect the column of data to be displayed in that particular textbox. ADO Control

10 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-10 This is achieved by storing the value entered into the InputBox to a Visual Basic memory variable that stores string or character data.This is achieved by storing the value entered into the InputBox to a Visual Basic memory variable that stores string or character data. The Visual Basic code to produce the InputBox and store the value is shown in VB6 Example 11.4.The Visual Basic code to produce the InputBox and store the value is shown in VB6 Example 11.4. The value entered for the social security number is stored to the strSSN variable.The value entered for the social security number is stored to the strSSN variable. REM VB6 SQL Example 11.4REM VB6 SQL Example 11.4 Dim strSSN As String strSSN = InputBox("Enter Employee SSN:", _Dim strSSN As String strSSN = InputBox("Enter Employee SSN:", _ "Employee SSN Search", vbOKCancel) "Employee SSN Search", vbOKCancel) Selecting Data Specified by a User Inputted Value

11 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-11 The program stores the SELECT statement to a second string variable named strSQL in the code segment shown in VB6 Example 11.5.The program stores the SELECT statement to a second string variable named strSQL in the code segment shown in VB6 Example 11.5. Each piece of the SELECT statement is a string of characters that are concatenated together with the Visual Basic concatenation operator (the ampersand – &). The WHERE clause has the emp_ssn column name set equal to the value stored to the strSSN variable that was captured through use of the InputBox.Each piece of the SELECT statement is a string of characters that are concatenated together with the Visual Basic concatenation operator (the ampersand – &). The WHERE clause has the emp_ssn column name set equal to the value stored to the strSSN variable that was captured through use of the InputBox. Selecting Data Specified by a User Inputted Value

12 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-12 At execution time, the SELECT statement stored to the strSQL variable includes the social security number stored to the strSSN variable.At execution time, the SELECT statement stored to the strSQL variable includes the social security number stored to the strSSN variable. REM VB6 Example 11.5REM VB6 Example 11.5 'Store SQL statement to a string variable'Store SQL statement to a string variable strSQL = "SELECT emp_last_name, emp_first_name, " & _strSQL = "SELECT emp_last_name, emp_first_name, " & _ "emp_middle_name, emp_ssn, emp_address, " & _ "emp_middle_name, emp_ssn, emp_address, " & _ "emp_city, emp_state, emp_zip" & _ "emp_city, emp_state, emp_zip" & _ "FROM employee" & _ "FROM employee" & _ "WHERE emp_ssn = " & strSSN "WHERE emp_ssn = " & strSSN Selecting Data Specified by a User Inputted Value

13 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-13 The RecordSource property of the ADO control is updated by storing the strSQL string variable to the RecordSource property as shown in VB6 Example 11.6.The RecordSource property of the ADO control is updated by storing the strSQL string variable to the RecordSource property as shown in VB6 Example 11.6. The ADO control is refreshed with the Refresh method. The Refresh method automatically creates a new recordset, and the correct employee row will be retrieved and displayed on the employee processing form.The ADO control is refreshed with the Refresh method. The Refresh method automatically creates a new recordset, and the correct employee row will be retrieved and displayed on the employee processing form. REM VB6 Example 11.6REM VB6 Example 11.6 'Update the recordset retrieved by the ADO control'Update the recordset retrieved by the ADO control adoEmployee.RecordSource = strSQL adoEmployee.Refresh Selecting Data Specified by a User Inputted Value

14 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-14 Visual Basic 6.0 uses the ActiveX Data Objects (ADO) approach to connect to databases through OLEDB providers (software drivers).Visual Basic 6.0 uses the ActiveX Data Objects (ADO) approach to connect to databases through OLEDB providers (software drivers). ADO has evolved into ADO.NET in Visual Basic.NET. ADO.NET still uses OLEDB providers to connect to databases such as Oracle, Microsoft SQL Server, and Microsoft Access.ADO has evolved into ADO.NET in Visual Basic.NET. ADO.NET still uses OLEDB providers to connect to databases such as Oracle, Microsoft SQL Server, and Microsoft Access. The major tasks facing a database programmer are:The major tasks facing a database programmer are: –Connecting to a database. –Executing SQL statements to add, delete, modify, or retrieve table rows. –Working with datasets. Datasets replace the recordsets used in VB 6.0. Embedding SQL in Visual Basic.net

15 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-15 A sample VB.NET connection string for an Oracle database named Company is shown in VB.NET Example 11.1.A sample VB.NET connection string for an Oracle database named Company is shown in VB.NET Example 11.1. REM VB.NET Example 11.1REM VB.NET Example 11.1 strConnection = "Provider=MSDAORA.1; User ID=dbock; Password=mypassword; Data Source=Company; Persist Security Info=True"strConnection = "Provider=MSDAORA.1; User ID=dbock; Password=mypassword; Data Source=Company; Persist Security Info=True" The connection string value is stored to a string constant named strConnection. VB.NET Example 11.2 shows the declaration of a connection object named objConnection.The connection string value is stored to a string constant named strConnection. VB.NET Example 11.2 shows the declaration of a connection object named objConnection. Making a Database Connection

16 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-16 The value of the strConnection constant is passed to the objConnection object as an argument inside parentheses. Following this the database connection is opened by using the Open method.The value of the strConnection constant is passed to the objConnection object as an argument inside parentheses. Following this the database connection is opened by using the Open method. REM VB.NET Example 11.2REM VB.NET Example 11.2 Module MyConnectionModule MyConnection Private Const strConnection As String = & _ Private Const strConnection As String = & _ "Provider = MSDAORA.1; User ID=dbock; Password=mypassword; & _ "Provider = MSDAORA.1; User ID=dbock; Password=mypassword; & _ "Data Source=Company; Persist Security Info=False" "Data Source=Company; Persist Security Info=False" Sub Main() Sub Main() Dim objConnection As New _ Dim objConnection As New _ System.Data.OleDb.OleDbConnection(strConnection) System.Data.OleDb.OleDbConnection(strConnection) objConnection.Open() objConnection.Open() End Sub End Sub End ModuleEnd Module Making a Database Connection

17 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-17 Visual Basic.NET uses a command object (OleDBCommand) to execute SQL statements.Visual Basic.NET uses a command object (OleDBCommand) to execute SQL statements. The approach is again similar to that used in Visual Basic 6.0 in that a programmer creates a string memory variable to store the SQL statement to be executed.The approach is again similar to that used in Visual Basic 6.0 in that a programmer creates a string memory variable to store the SQL statement to be executed. The SELECT statement is shown in VB.NET Example 11.3.The SELECT statement is shown in VB.NET Example 11.3. REM VB.NET Example 11.3REM VB.NET Example 11.3 SELECT emp_last_name, emp_first_name, emp_middle_name, emp_ssn,SELECT emp_last_name, emp_first_name, emp_middle_name, emp_ssn, emp_address, emp_city, emp_state, emp_zip emp_address, emp_city, emp_state, emp_zip FROM employee WHERE emp_zip = '62025'; Executing SQL Statements

18 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-18 The.NET code module named MyConnection shown earlier in VB.NET Example 11.2 needs to be modified to accommodate reading data.The.NET code module named MyConnection shown earlier in VB.NET Example 11.2 needs to be modified to accommodate reading data. The modified code is shown in VB.NET Example 11.4.The modified code is shown in VB.NET Example 11.4. Note that the strSQL memory variable stores the SELECT command as a series of concatenated character strings.Note that the strSQL memory variable stores the SELECT command as a series of concatenated character strings. A command object named objCommand is created and the value of strSQL and the objConnection connection object are passed to the objCommand object as parameters inside parentheses.A command object named objCommand is created and the value of strSQL and the objConnection connection object are passed to the objCommand object as parameters inside parentheses. A reader object (objReader) is created to store the actual rows returned when the ExecuteReader method of the objCommand object executes.A reader object (objReader) is created to store the actual rows returned when the ExecuteReader method of the objCommand object executes. Executing SQL Statements

19 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-19 REM VB.NET Example 11.4REM VB.NET Example 11.4 Module MyConnectionModule MyConnection Private Const strConnection As String = & _ Private Const strConnection As String = & _ "Provider = MSDAORA.1; User ID=dbock; Password=mypassword; & _ "Provider = MSDAORA.1; User ID=dbock; Password=mypassword; & _ "Data Source=Company; Persist Security Info=False" "Data Source=Company; Persist Security Info=False" Sub Main() Sub Main() Dim strSQL As String Dim strSQL As String strSQL = "SELECT emp_last_name, emp_first_name, " & _ strSQL = "SELECT emp_last_name, emp_first_name, " & _ "emp_middle_name, emp_ssn, emp_address, " & _ "emp_middle_name, emp_ssn, emp_address, " & _ "emp_city, emp_state, emp_zip " & _ "emp_city, emp_state, emp_zip " & _ "FROM employee " & _ "FROM employee " & _ "WHERE emp_zip = '62025';" "WHERE emp_zip = '62025';" Dim objConnection As New _ Dim objConnection As New _ System.Data.OleDb.OleDbConnection(strConnection) System.Data.OleDb.OleDbConnection(strConnection) Dim objCommand As New _ Dim objCommand As New _ System.Data.OleDb.OleDbCommand(strSQL, objConnection) System.Data.OleDb.OleDbCommand(strSQL, objConnection) Dim objReader As _ Dim objReader As _ System.Data.OleDB.OleDBReader System.Data.OleDB.OleDBReader objConnection.Open() objConnection.Open() objReader = objCommand.ExecuteReader() objReader = objCommand.ExecuteReader() 'Additional code goes here to process the rows returned 'Additional code goes here to process the rows returned 'by the SQL query. 'by the SQL query. End Sub End Sub End ModuleEnd Module Executing SQL Statements

20 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-20 Data Division Modifications The Data Division of a COBOL program is used to declare both the structure of files or databases that a program will access.The Data Division of a COBOL program is used to declare both the structure of files or databases that a program will access. It is also used to declare memory variables known as Working-Storage variables.It is also used to declare memory variables known as Working-Storage variables. The Working-Storage Section of a COBOL program is also used to declare tables in memory that will store data rows that are retrieved from database tables.The Working-Storage Section of a COBOL program is also used to declare tables in memory that will store data rows that are retrieved from database tables. Embedding SQL in COBOL

21 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-21 EXEC SQL and END-EXEC commands are used to mark the beginning and end of SQL statements so that a COBOL compiler can properly compile the program.EXEC SQL and END-EXEC commands are used to mark the beginning and end of SQL statements so that a COBOL compiler can properly compile the program. The code in COBOL Example 11.1 shows the declaration of a table named employee that will store data rows retrieved from the employee table of our Company database.The code in COBOL Example 11.1 shows the declaration of a table named employee that will store data rows retrieved from the employee table of our Company database. This code is located in the Working-Storage Section.This code is located in the Working-Storage Section. You will also note that only the table columns that will be retrieved for processing need to be defined in the table.You will also note that only the table columns that will be retrieved for processing need to be defined in the table. The other columns in the employee table are ignored.The other columns in the employee table are ignored. Embedding SQL in COBOL

22 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-22 –* COBOL Example 11.1 –EXEC SQL – DECLARE EMPLOYEE TABLE – (EMP_SSN CHAR(9), – EMP_LAST_NAME CHAR(25), – EMP_FIRST_NAME CHAR(25), – EMP_MIDDLE_NAME CHAR(25), – EMP_ADDRESS CHAR(50), – EMP_CITY CHAR(25), – EMP_STATE CHAR(2), – EMP_ZIP CHAR(9) ) –END-EXEC. In order to process the employee table, rows that are retrieved are stored to standard COBOL variables.In order to process the employee table, rows that are retrieved are stored to standard COBOL variables. These are also declared in the Working-Storage Section.These are also declared in the Working-Storage Section. Embedding SQL in COBOL

23 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-23 In order to process the employee table, rows that are retrieved are stored to standard COBOL variables.In order to process the employee table, rows that are retrieved are stored to standard COBOL variables. These are also declared in the Working-Storage Section.These are also declared in the Working-Storage Section. Row data are moved from the employee table to the COBOL variables. The Working-Storage declaration of these variables is shown in COBOL Example 11.2.Row data are moved from the employee table to the COBOL variables. The Working-Storage declaration of these variables is shown in COBOL Example 11.2. –* COBOL Example 11.2 –01 EMPLOYEE-WORK. – 05 EMP-SSN PIC X(9). – 05 EMP-LAST-NAME PIC X(25). – 05 EMP-FIRST-NAME PIC X(25). – 05 EMP-MIDDLE-NAME PIC X(25). – 05 EMP-ADDRESS PIC X(50). – 05 EMP-CITY PIC X(25). – 05 EMP-STATE PIC X(2). – 05 EMP-ZIP PIC X(9). Embedding SQL in COBOL

24 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-24 In order to process SQL statements and the employee_data table declared in COBOL Example 11.2, a SQL communications area (SQLCA) must be defined in the server's memory.In order to process SQL statements and the employee_data table declared in COBOL Example 11.2, a SQL communications area (SQLCA) must be defined in the server's memory. The SQL communications area includes a SQLCODE parameter. The SQLCODE parameter stores coded values that represent what occurs within an information system whenever any SQL statement executes.The SQL communications area includes a SQLCODE parameter. The SQLCODE parameter stores coded values that represent what occurs within an information system whenever any SQL statement executes. The normal execution of an SQL statement causes the SQLCODE parameter to store a value of zero.The normal execution of an SQL statement causes the SQLCODE parameter to store a value of zero. Program code must be written for the COBOL program Procedure Division in order to test the value ofProgram code must be written for the COBOL program Procedure Division in order to test the value ofContd. Embedding SQL in COBOL

25 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-25 SQLCODE through the use of IF statements. The IF statements will determine if a given SQL statement executes successfully.The IF statements will determine if a given SQL statement executes successfully. The SQL communications area is created by the INCLUDE command shown in COBOL example 11.3.The SQL communications area is created by the INCLUDE command shown in COBOL example 11.3. * COBOL Example 11.3* COBOL Example 11.3 EXEC SQLEXEC SQL INCLUDE SQLCA INCLUDE SQLCA END-EXEC.END-EXEC. Embedding SQL in COBOL

26 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-26 Procedure Division Modifications The retrieval of data rows through use of an embedded SQL SELECT statement in COBOL requires the storage of data values to host variables.The retrieval of data rows through use of an embedded SQL SELECT statement in COBOL requires the storage of data values to host variables. For the employee table, this simply means that data row values will be stored to the 01 EMPLOYEE-WORK memory variable created in COBOL Example 11.2.For the employee table, this simply means that data row values will be stored to the 01 EMPLOYEE-WORK memory variable created in COBOL Example 11.2. A SELECT statement embedded in a Procedure Division looks like the one shown in COBOL Example 11.4.A SELECT statement embedded in a Procedure Division looks like the one shown in COBOL Example 11.4. Note that the host variables are preceded by a colon ( : ) symbol that is used to differentiate these variables to the program compiler.Note that the host variables are preceded by a colon ( : ) symbol that is used to differentiate these variables to the program compiler. Embedding SQL in COBOL

27 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-27 The SELECT statement is NOT ended by a semicolon when it is embedded in COBOL.The SELECT statement is NOT ended by a semicolon when it is embedded in COBOL. The code is located within a paragraph named PROCESS-EMPLOYEE-DATA.The code is located within a paragraph named PROCESS-EMPLOYEE-DATA. –* COBOL Example 11.4 –PROCESS-EMPLOYEE-DATA. – EXEC SQL – SELECT EMP_SSN, EMP_LAST_NAME, EMP_FIRST_NAME, – EMP_MIDDLE_NAME, EMP_ADDRESS, – EMP_CITY, EMP_STATE, EMP_ZIP – INTO :EMP-SSN, :EMP-LAST-NAME, :EMP-FIRST-NAME, – :EMP-MIDDLE-NAME, :EMP-ADDRESS, :EMP-CITY, – :EMP-STATE, :EMP-ZIP – FROM EMPLOYEE – WHERE EMP_ZIP = "62025" – END-EXEC. Contd. Embedding SQL in COBOL

28 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-28 –IF SQLCODE = 0 –* (Place additional code here to process the employee row) – ELSE –* (Insert additional code here to handle the retrieval –* error – no employees with the specified Zip Code) –END IF. Additional code would be added to process the data rows retrieved from the employee table by calling the PROCESS-EMPLOYEE-DATA paragraph through use of a standard PERFORM UNTIL command within COBOL.Additional code would be added to process the data rows retrieved from the employee table by calling the PROCESS-EMPLOYEE-DATA paragraph through use of a standard PERFORM UNTIL command within COBOL. The embedded SQL command replaces the use of a COBOL READ command for the simple retrieval of data.The embedded SQL command replaces the use of a COBOL READ command for the simple retrieval of data. Embedding SQL in COBOL

29 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-29 Data can be inserted into the employee table by using the SQL INSERT statement in place of the COBOL WRITE command as shown in COBOL Example 11.5.Data can be inserted into the employee table by using the SQL INSERT statement in place of the COBOL WRITE command as shown in COBOL Example 11.5. Let's assume that the data values to be inserted have already been moved to the work variables defined within the 01 EMPLOYEE-WORK memory variable created earlier.Let's assume that the data values to be inserted have already been moved to the work variables defined within the 01 EMPLOYEE-WORK memory variable created earlier. This could be accomplished by using a series of ACCEPT commands to enable data entry from the keyboard.This could be accomplished by using a series of ACCEPT commands to enable data entry from the keyboard. Alternatively, the data values could be READ from a sequential or indexed data file.Alternatively, the data values could be READ from a sequential or indexed data file. Embedding SQL in COBOL

30 Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-30 * COBOL Example 11.5* COBOL Example 11.5 EXEC SQLEXEC SQL INSERT INTO EMPLOYEE (EMP_SSN, EMP_LAST_NAME, INSERT INTO EMPLOYEE (EMP_SSN, EMP_LAST_NAME, EMP_FIRST_NAME, EMP_MIDDLE_NAME, EMP_ADDRESS, EMP_FIRST_NAME, EMP_MIDDLE_NAME, EMP_ADDRESS, EMP_CITY, EMP_STATE, EMP_ZIP) EMP_CITY, EMP_STATE, EMP_ZIP) VALUES (:EMP-SSN, :EMP-LAST-NAME, :EMP-FIRST- NAME, VALUES (:EMP-SSN, :EMP-LAST-NAME, :EMP-FIRST- NAME, :EMP-MIDDLE-NAME, :EMP-ADDRESS, :EMP-CITY, :EMP-MIDDLE-NAME, :EMP-ADDRESS, :EMP-CITY, :EMP-STATE, :EMP-ZIP) :EMP-STATE, :EMP-ZIP) END-EXEC.END-EXEC. Note that the values inserted from the Working-Storage variables match up on a one-for-one basis with the column names defined for the employee table in the Working-Storage Section of the program.Note that the values inserted from the Working-Storage variables match up on a one-for-one basis with the column names defined for the employee table in the Working-Storage Section of the program. Embedding SQL in COBOL


Download ppt "Bordoloi and BockCopyright 2004 Prentice Hall, Inc.11-1 CHAPTER 11: EMBEDDED SQL."

Similar presentations


Ads by Google