What is Embedded SQL with multiple steps?

In my previous article I have given difference between anonymous block and subprogram. In this article I would like to give more information on Embedded SQL with multiple examples as well as diagrams. I would like to cover the important topics related to embedded SQL which are below :

1.What is Embedded SQL with diagrammatic representation?

2.Types of Embedded SQL

3.How to use Embedded SQL?

4.Advantages and Disadvantages of Embedded SQL?

What is Embedded SQL ?

Embedded SQL statements or queries can be inserted using the embedded SQL technique into the code of a host language, which is a computer language. An embedded SQL preprocessor analyzes the inserted SQL because the host language is unable to interpret it. A reliable and practical way to combine the computing power of a programming language with SQL’s specialized data management and manipulation capabilities is through embedded SQL. At runtime, these embedded SQL statements
are transformed into executable, efficient code.

Embedded SQL 1
Embedded SQL

Types of Embedded SQL:

There are two types of Embedded SQL :

1.Simple Embedded SQL:

Only values from a single row can be returned by a straightforward Embedded SQL query. For insert, update, and delete operations on a single row as well as other SQL operations, simple embedded SQL can be utilized.

2.Cursor Based Embedded SQL:

An Embedded SQL query with a cursor can repeatedly iterate through a result set, returning values from various rows. It is also possible to perform multiple row updates and delete SQL operations using cursor-based embedded SQL.

What is Dynamic SQL?

SQL statements that are created and executed dynamically are known as dynamic SQL. An SQL command’s preparation and execution are distinct procedures in Dynamic SQL. InterSystems IRIS’s Dynamic SQL allows you to develop similarly to an ODBC or JDBC application (except that you are executing the SQL statement within the same process context as the database engine). Invoked from an ObjectScript program is Dynamic SQL.
The preparation of dynamic SQL queries occurs during program execution, not compilation. This means that preprocessor macros cannot be used with Dynamic SQL and that the compiler cannot check for mistakes at the time of compilation. Additionally, it implies that running applications have the ability to construct unique Dynamic SQL queries in response to user or other input.

How to add Embedded SQL in your code?

In a ProAda program, only embedded SQL commands—not SQLPlus commands—are accepted. Additional commands in SQL*Plus are available for describing tables, producing reports, and configuring environment variables. These are incompatible with embedded SQL.

SQL Statements

SQL statements inserted within an application program are referred to as embedded SQL. The application program is referred to as a host program since it contains the SQL statements, and the language used to write it is referred to as the host language. For instance, Pro*C/C++ enables you to embed specific SQL statements in a host application written in C or C++.
The INSERT, UPDATE, DELETE, and SELECT commands are used to modify and query Oracle data. Database tables can be expanded by using INSERT, updated by using UPDATE, deleted by using DELETE, and then selected by using SELECT to find rows that match your search criteria.

Embedded SQL
Embedded SQL

Set ROLE statement :

You can manage database privileges dyna.mically using the powerful SET ROLE statement. A named group of associated system and/or object privileges that are granted to users or other roles is known as a role. The Oracle data dictionary contains role definitions. The SET ROLE statement can be used by your apps to enable and disable roles as necessary.

SQL PLUS statements not allowed:

In an application program, only SQL statements—not SQLPlus statements—are acceptable. (SQLPlus has more statements for editing, formatting reports, and setting environment variables.)


All interactive SQL statements as well as others that enable data transfer between Oracle and a host software are included in embedded SQL. Embedded SQL statements might be either instructions or executable statements. Calls to the runtime library SQLLIB result from statements that are executed.

On the other hand, directives don’t involve using Oracle data or calling SQLLIB. They are used to declare SQL variables, communications areas, and Oracle objects.

Embed in C and C++ :

We connect to Oracle using them, define, query, and work with Oracle data using them, manage access to Oracle data using them, and execute transactions using them. They can be inserted anywhere that executable statements of the C or C++ languages are allowed.

Advantages of Embedded SQLs:

SQL operates quickly and effectively. Analytical queries in a relational database can be used to quickly query, manipulate, and calculate on data.
● The fact that SQL doesn’t necessitate in-depth programming and coding skills is one of the factors contributing to its popularity. Basic SQL keywords like SELECT, INSERT INTO, UPDATE, and others can perform operations. The rules of synta are straightforward and simple to understand.
● As was already mentioned, SQL is a relational database query language that has been approved by ISO and ANSI.
● It turns into an interactive language for its users because it has straightforward commands for all purposes. It is simple to understand, and non-programmers can also understand the commands.
● It can be used in PCs, servers, and standalone laptops running any operating system, including Windows, Linux, and Mac, demonstrating its high portability. It may also be integrated into other programs.

Disadvantages of Embedded SQLs :

● SQL Server Standard has a yearly cost of about $1,418. For some programmers, its high price makes it challenging to use.
● SQL has a bad user interface because it makes everything appear much more complicated than it actually is! Users find it difficult to work with the databases because of their challenging interface.
● Databases are not completely within the authority of SQL users.
● No matter the SQL version, databases in SQL are constantly at risk because they store a lot of sensitive information.
● Preprocessing of directives is required, with nuances affecting other code.

I hope you like this article on Embedded SQL wth its advantages and disadvantages. If you like this article or if you have any issues with the same kindly comment in comments section.

Leave a Reply

Your email address will not be published. Required fields are marked *