What are the advantages of embedded query language? Give an example of an embedded SQL query.
Embedded query language - SQL could be implemented within two ways. It can be used interactively or embedded within a host language or through using API. The use of SQL commands inside a host language (e.g., C, Java, etc.) program is known as embedded query language or Embedded SQL. While same capabilities are supported for a variety of host languages, the syntax sometimes varies. A few of the advantages of embedded SQL are:
SQL statements could be used wherever a statement in the host language is permitted. It merges the strengths of two programming environments, the procedural characterises of host languages and non-procedural features of SQL.
SQL statements could refer to variables (must be prefixed through a colon in SQL statements) described in the host program. Special program variables (known as null indicators) are used to assign and retrieve the NULL values to and from the database.
The facilities available by the interactive query language are also automatically available to the host programs. Embedded SQL along with host languages could be used to accomplish extremely complex and complicated data access and manipulation tasks.
Example: The subsequent Embedded SQL statement within C inserts a row, whose column values are based on the values of the host language variables holds in it.
EXEC SQL
INSERT INTO Sailors VALUES (:c_sname, :c_sid, :c_rating, :c_age);