- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between EXECUTE IMMEDIATE and EXECUTE WITH PREPARE in DB2?
The EXECUTE IMMEDIATE and EXECUTE PREPARE are the forms of dynamic SQL. In case of EXECUTE immediate, we can give the SQL statement in the host variable and pass this host variable in EXECUTE IMMEDIATE.
Following example demonstrates these forms.
Example
01 WS-SQL-DECLARE 05 WS-SQL-LEN PIC S9(04) COMP. 05 WS-SQL-QUERY PIC X(70). MOVE +80 TO WS-SQL-LEN MOVE “UPDATE ORDERS SET ORDER_PAID = ‘YES’ WHERE ORDER_DATE = ‘14-08-2020’” TO WS-SQL-QUERY EXEC SQL EXECUTE IMMEDIATE :WS-SQL-DECLARE END-EXEC
In case of EXECUTE PREPARE, the SQL statement is first prepared and then executed. We can use this form of dynamic SQL as shown below.
Example
01 WS-SQL-DECLARE 05 WS-SQL-LEN PIC S9(04) COMP. 05 WS-SQL-QUERY PIC X(70). MOVE +80 TO WS-SQL-LEN MOVE “UPDATE ORDERS SET ORDER_PAID = ‘YES’ WHERE ORDER_DATE = ‘14-08-2020’” TO WS-SQL-QUERY EXEC SQL PREPARE RUNFORM FROM :WS-SQL-DECLARE END-EXEC EXEC SQL EXECUTE RUNFORM END-EXEC
- Related Articles
- What is the difference between execute(), executeQuery() and executeUpdate() methods in JDBC?
- How to execute a COBOL-DB2 program PROGA of plan PLANA?
- What is the difference between DB2 JOIN and UNION? Explain with the help of an example
- What are TRIGGERS in DB2? What is the difference between TRIGGERS and STORED PROCEDURES?
- What are QMF and SPUFI? What is the difference between them for accessing DB2 tables?
- Execute INSERT if table is empty in MySQL?
- Execute a script when the file is unavailable in HTML?
- Execute a script when the element is invalid in HTML?
- Execute a script before the document is printed in HTML?
- Execute a script after the document is printed in HTML?
- Difference between CORRELATED and UNCORRELATED subqueries in DB2
- Difference between UNION and UNION ALL in DB2
- How to execute a Javascript function in Python with Selenium?
- What are the steps to execute Flow API in Java 9?
- Does finally always execute in Java?

Advertisements