embedded sqfinall

Upload: djaidka

Post on 30-May-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 Embedded Sqfinall

    1/12

    EMBEDDED SQLEMBEDDED SQLBy Suprotim RaoBy Suprotim Rao

  • 8/9/2019 Embedded Sqfinall

    2/12

    IntroductionIntroduction

    SQL is a DUAL mode database language,SQL is a DUAL mode database language,

    which can be used in two ways.which can be used in two ways.

    It can be used interactively to define aIt can be used interactively to define adatabase objects and query and updatedatabase objects and query and update

    operations.operations.

    It can also embedded in a programmingIt can also embedded in a programming

    language, so called as EMBEDDED SQL.language, so called as EMBEDDED SQL.

  • 8/9/2019 Embedded Sqfinall

    3/12

    What is Embedded SQLWhat is Embedded SQL

    Embedded SQL is a method of combiningEmbedded SQL is a method of combiningthe computing power of a programmingthe computing power of a programminglanguage and the database manipulationlanguage and the database manipulation

    capabilities of SQLcapabilities of SQL Embedded statements are SQLEmbedded statements are SQL

    statements written within applicationstatements written within application

    programming language such a C/C++ andprogramming language such a C/C++ andpre processed by anSQL prepre processed by anSQL pre--processorprocessorbefore the application program is compiledbefore the application program is compiled

  • 8/9/2019 Embedded Sqfinall

    4/12

    In Embedded SQL approach, the SQL statementsIn Embedded SQL approach, the SQL statements

    are embedded directly into the programs sourceare embedded directly into the programs source

    code, along with other programming languagecode, along with other programming language

    statements.statements.

    Special Delimiters specify the beginning and endSpecial Delimiters specify the beginning and end

    of the SQL statements in the program.of the SQL statements in the program.

    A special precompiler accepts the combinedA special precompiler accepts the combinedsource code and the embedded SQL statements.source code and the embedded SQL statements.

    It compiles the combined code and converts intoIt compiles the combined code and converts into

    the executable formthe executable form

  • 8/9/2019 Embedded Sqfinall

    5/12

    Embedded SQLs are SQL statementsEmbedded SQLs are SQL statements

    included in the programming language. Theincluded in the programming language. The

    Programming language in which the SQLProgramming language in which the SQLstatements are included is called the Hoststatements are included is called the Host

    Language.Language.

  • 8/9/2019 Embedded Sqfinall

    6/12

    FEATURES OF EMBEDDED SQL

    1.) SQL is CASE INSENSITIVE and usually it iswritten in the style of host language.

    2.) Embedded SQL are prefixed by EXEC SQL todistinguish it from host language.

    3.) DELIMITER terminates every embedded SQL, InCOBOL it is END-EXEC and in C it is a semicolon.

    4.) SQL statements can refer host variables byprefixing colon(:) with name of variable.

  • 8/9/2019 Embedded Sqfinall

    7/12

    RETRIEVING DATA USING EMBEDDEDRETRIEVING DATA USING EMBEDDED

    SQL AND CURSORSSQL AND CURSORS

    Embedded SQL divides queries into two groups :

    SINGLE-ROW queries

    Where the query result contains at most one row ofdata. These are handled by the SELECT INTO

    statement which is similar to SELECT statement with anextra INTO clause specifying the names of the hostvariables to receive the query result.

    For example :

    To retrieve details of empno 100. We will write : EXEC SQL SELECT ENAME,SAL,JOB INTOINTO

    :EMPNAME,:SALARY, :JOB FROM EMPWHEREempno =100:

  • 8/9/2019 Embedded Sqfinall

    8/12

    MULTIMULTI--ROW QueriesROW Queries

    Where the query results may contain any number of rows,which may be zero, one or more. When a database querycan return arbitrary number of rows, embedded SQL uses

    cursors to return the data. A cursor must be declared andopened before it can be used, and it must be closed todeactivate it after it is no longer required.

    FORMAT :

    EXEC SQL DECLARE CURSOR cursorname FOR selectstatement

    EXEC SQL OPEN cursorname;

    EXEC SQL FETCH cursorname INTO{hostvariabe[indicator variable][, ]}

    EXEC SQL CLOSE cursorName;

  • 8/9/2019 Embedded Sqfinall

    9/12

    TypesTypes

    StaticStatic

    DynamicDynamic

  • 8/9/2019 Embedded Sqfinall

    10/12

    Systems That Support EmbeddedSystems That Support Embedded

    SQLSQL IBM DB2IBM DB2

    Pro*ADA(Oracle Corporation)Pro*ADA(Oracle Corporation)

    AltibaseAltibase

    Data Flex 3.2(DAC)Data Flex 3.2(DAC)

  • 8/9/2019 Embedded Sqfinall

    11/12

    Systems That Do Not SupportSystems That Do Not Support

    Embedded SQLEmbedded SQL Microsoft SQL ServerMicrosoft SQL Server

    MySQLMySQL

    SybaseSybase

  • 8/9/2019 Embedded Sqfinall

    12/12

    Thank YouThank You