Under Linux oracle11g proc*c development environment to build __ Small program

Source: Internet
Author: User
Tags strlen
 1. Make proc precompiled commands available

After/etc/profile, add the following:

Ld_library_path= $ORACLE _home/lib:/usr/lib/usr/local/lib

Export Ld_library_path

Note: Need to reboot 2. Configure Pcscfg.cfg files

Pcscfg.cfg is located in the $oracle_home/precomp/admin/directory and is added after Pcscfg.cfg

Sqlcheck=semantics

Parse=none

Parse=none to qualify all host variables must be defined in the declaration segment, and only precompiled directives in the declaration segment will be recognized.

Note: Oracle's environment variables need to be introduced into the . Bash_profile 3. Sample Programs
3.1 editing login.pc files

[HTML] View Plain copy print? <span style= "font-size: 18px;" > #include  <stdio.h>   #include  <stdlib.h>   #include  < string.h>      exec sql include sqlca;      exec  sql begin declare section;   varchar username[20];   varchar  password[20];   exec sql end declare section;      int    Main (void)    {       strcpy (username.arr,  "HR");       username.len = strlen ("hr");       strcpy ( password.arr,  "HR");       password.len = strlen ("hr");           exec sql connect :username identified by  :p assword;       if (sqlca.sqlcode == 0) {           printf ("login success\ n ");       }else{            printf ("login failed\n");       }           exit (0);  }</span>  

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

EXEC SQL include Sqlca;

EXEC SQL BEGIN DECLARE section;
varchar USERNAME[20];
varchar PASSWORD[20];
EXEC SQL end DECLARE section;

int
main (void)
{
    strcpy (Username.arr, "HR");
    Username.len = strlen ("hr");
    strcpy (Password.arr, "HR");
    Password.len = strlen ("hr");

    EXEC SQL Connect:username identified by:p Assword;
    if (Sqlca.sqlcode = = 0) {
        printf ("Login success\n");
    } else{
        printf ("Login failed\n");
    }

    Exit (0);
}
3.2 Compiling PC files

executes proc login.pc, generating Login.lis and LOGIN.C in the current directory. 3.3 compiling. c Files

Gcc-o Login Login.c

There will be an error:

/tmp/ccalqsqm.o:in function ' main ':

LOGIN.C: (. text+0x20f): Undefined reference to ' SQLCXT ' collect2:ld return 1

This error is due to the compile time to use the Oracle library, the library is not the default path, you need to manually specify, the following compilation can be:

Gcc-o login Login.c-l/home/oracle/oracle11g/lib/-l clntsh

When the compilation succeeds, the executable file login is generated in the directory, and the file can be executed to log in to the specified user of the database.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.