​A selection of topics on IT and its application to finance. 
​Send me your comments, questions ​or suggestions by clicking
h​ere


elmama
A simple Embedded C/SQL program showing the use of embedded PL/SQL 


#include <stdio.h>
#include <stdlib.h>

EXEC SQL INCLUDE "sqlca.h";

void sql_error();
void db_connect();
void get_tables();



EXEC SQL BEGIN DECLARE SECTION;
    char dbtab[1000][31];
    int i = 0;
    int nr_tables = 0;
EXEC SQL END DECLARE SECTION;

EXEC SQL VAR dbtab IS STRING;


main()
{
    EXEC SQL WHENEVER SQLERROR do sql_error();

    db_connect();

    /* START OF EMBEDDED PL/SQL */
    exec sql execute
    declare
        n binary_integer := 0;
    BEGIN
        FOR c1_rec in (select table_name from user_tables)
        Loop

            n := n + 1;
            :dbtab(n) := c1_rec.table_name;
        End Loop;
        :nr_tables := n;
    END;
    end-exec;
    /* END OF EMBEDDED PL/SQL */


    for(i=1;i<nr_tables;i++)
        printf("table = %s\n",dbtab[i]);


}


void sql_error()
{

    fprintf(stdout,"Error number = %d\n",sqlca.sqlcode);
    fprintf(stdout,"Error message = %s\n",sqlca.sqlerrm.sqlerrmc);
    exit(-1);
}

void db_connect()
{
    EXEC SQL BEGIN DECLARE SECTION;
    char *username = "scott";
    char *password = "tiger";
    EXEC SQL END DECLARE SECTION;


    EXEC SQL CONNECT :username IDENTIFIED BY :password;
}