Reference articles on history, science, culture and more
Encyclopedia

Embedded SQL

Computer programming method

Embedded SQL is a method of combining the computing power of a programming language and the database manipulation capabilities of SQL. Embedded SQL statements are SQL statements written inline with the program source code, of the host language. The embedded SQL statements are parsed by an embedded SQL preprocessor and replaced by host-language calls to a code library. The output from the preprocessor is then compiled by the host compiler. This allows programmers to embed SQL statements in programs written in any number of languages such as C/C++, COBOL and Fortran. This differs from SQL-derived programming languages that don't go through discrete preprocessors, such as PL/SQL and T-SQL.

The SQL standards committee defined the embedded SQL standard in two steps: a formalism called Module Language was defined, then the embedded SQL standard was derived from Module Language. The SQL standard defines embedding of SQL as embedded SQL and the language in which SQL queries are embedded is referred to as the host language. A popular host language is C. Host language C and embedded SQL, for example, is called Pro*C in Oracle and Sybase database management systems, ESQL/C in Informix, and ECPG in the PostgreSQL database management system. SQL may also be embedded in languages like PHP etc.

The SQL standard SQL:2023 is available through purchase and contains chapter 21 Embedded SQL and its syntax rules.

01Database systems that support embedded SQL

Altibase

C/C++
APRE is an embedded SQL precompiler provided by Altibase Corp. for its DBMS server.

IBM Db2

IBM Db2 for Linux, UNIX and Windows supports embedded SQL for C, C++, Java, COBOL, FORTRAN and REXX although support for FORTRAN and REXX has been deprecated.

IBM Informix

IBM Informix version 14.10 for Linux, Unix, and Windows supports embedded SQL for C. }

Microsoft SQL Server

C/C++
Embedded SQL for C has been deprecated as of Microsoft SQL Server 2008 although earlier versions of the product support it.

Mimer SQL

Mimer SQL for Linux, macOS, OpenVMS and Windows support embedded SQL.

C/C++
Embedded SQL for C/C++ is supported on Linux, macOS, OpenVMS and Windows.
COBOL
Embedded SQL for COBOL is supported on OpenVMS.
Fortran
Embedded SQL for Fortran is supported on OpenVMS.

Oracle Database

Ada
Pro*Ada was officially desupported by Oracle in version 7.3. Starting with Oracle8, Pro*Ada was replaced by SQL*Module but appears to have not been updated since. SQL*Module is a module language that offers a different programming method from embedded SQL. SQL*Module supports the Ada83 language standard for Ada.
C/C++
Pro*C became Pro*C/C++ with Oracle8. Pro*C/C++ is currently supported as of Oracle Database 11g.
COBOL
Pro*COBOL is currently supported as of Oracle Database 11g.
Fortran
Pro*FORTRAN is no longer updated as of Oracle8 but Oracle will continue to issue patch releases as bugs are reported and corrected.
Pascal
Pro*Pascal was not released with Oracle8.
PL/I
Pro*PL/I was not released with Oracle8. The Pro*PL/I Supplement to the Oracle Precompilers Guide, however, continued to make appearances in the Oracle Documentation Library until release 11g. As of release 12c, the Pro*PL/I has been removed from the Oracle Documentation Library.

PostgreSQL

C/C++
ECPG is part of PostgreSQL since version 6.3.
COBOL
Cobol-IT is now distributing a COBOL precompiler for PostgreSQL
Micro Focus provides support via their OpenESQL preprocessor

SAP Sybase

SAP Sybase ASE 15.7 supports embedded SQL for C and COBOL as part of the Software Developer Kit Sybase.

SAP Sybase SQL Anywhere supports embedded SQL for C and C++ as part of the SQL Anywhere database management system SQL Anywhere.

SAP Sybase IQ supports embedded SQL for C and C++ as part of the Sybase IQ database management system Sybase IQ.

02Embedded SQL through domain-specific languages

Watch videos about Embedded SQLExplainers and documentaries on YouTube (opens in a new tab)

Sources and credits

This article is adapted from the Wikipedia article Embedded SQL, written by its contributors and licensed under CC BY-SA 4.0. Fathomly has changed the layout, removed citation markers, navigation and maintenance notices, and adjusted punctuation. This adapted version is shared under the same license. For references, see the original article.

Fathomly is not affiliated with or endorsed by the Wikimedia Foundation. Spotted a problem? Tell us.