Compile the Proc program in Linux, and compile the Proc program in Linux.

Source: Internet
Author: User

Compile the Proc program in Linux, and compile the Proc program in Linux.

A simple Proc program needs to be written in linux. There is very little information, and a brief summary will be made after completion.
References.

1. download the following installation package from the oracle website
Select 64-bit or 32-bit based on the OS version. Sqlplus is used for connection testing and can be left empty.
Oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
Oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
Oracle-instantclient11.2-precomp-11.2.0.4.0-1.x86_64.rpm
Oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm

2. Install the SDK in the following sequence:
Install basic first. There is no limit on other orders.
Oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
Oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
Oracle-instantclient11.2-precomp-11.2.0.4.0-1.x86_64.rpm
Oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm

If you want to install it in ubuntu, You need to convert alien to deb and then install it.
You may need to download alien first.

apt-get install alien

Then:

alien -i oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm  alien -i oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm  alien -i oracle-instantclient11.2-precomp-11.2.0.4.0-1.x86_64.rpm  alien -i oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm

3. Set Environment Variables
The default installation path is/usr/lib/oracle.

export ORACLE_HOME=/usr/lib/oracle/11.2/client64/export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib

In addition,
Ldconfig/usr/lib/oracle/11.2/client64/lib ensures that the dynamic library path is updated.

4. Test
1) Run proc xx. pc for testing.
2) Run sqlplus64 user/pass @ host: port/DBNAME to test the connection.
Xx. The following code is available for pc:

5. Proc settings
After environment variables are set, proc defaults Read the configuration file from ORACLEHOME/precomp/admin. Therefore, you must configure the path of the referenced header file. Copy the copy below ORACLE_HOME/lib. Generally, you need to append the header file paths of linux, gcc, and oracle.

1) Add the following configuration under Centos6.5:

sys_include=/usr/lib/gcc/i686-redhat-linux/4.4.7/includesys_include=/usr/include/oracle/11.2/client64

2) append the following configuration under ubuntu14.04 through

sys_include=/usr/include/x86_64-linux-gnusys_include=/usr/lib/gcc/x86_64-linux-gnu/4.8/includesys_include=/usr/include/oracle/11.2/client64

For more information about pc files, see
Http://docs.oracle.com/cd/B28359_01/appdev.111/b28427/toc.htm

#include <stdio.h>#include <string.h>#include <sqlca.h>#include <oraca.h>EXEC ORACLE OPTION(ORACA=YES);int db_connect(const char* connstr){    EXEC SQL BEGIN DECLARE SECTION;    char uid[256] = {0};    EXEC SQL END DECLARE SECTION;    EXEC SQL WHENEVER SQLERROR GOTO ORACLE_ERROR;    snprintf(uid, sizeof(uid), "%s", connstr);    // Try to connect to oracle    EXEC SQL CONNECT :uid;    printf("Connect to [%s] successful\n", uid);    return 0;ORACLE_ERROR:    EXEC SQL WHENEVER SQLERROR CONTINUE;    printf("Connect to [%s] failed\n", uid);    printf("Failed code(%d), message(%s)\n",            sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);    return -1;}int db_disconnect(void){    EXEC SQL WHENEVER SQLERROR GOTO ORACLE_ERROR;    EXEC SQL ROLLBACK WORK RELEASE;    /*    printf("Disconnect successful\n");    */    return 0;ORACLE_ERROR:    EXEC SQL WHENEVER SQLERROR CONTINUE;    return -1;}int db_query(const char* name, const char* pass){    EXEC SQL BEGIN DECLARE SECTION;    char username[128] = {0};    varchar passwords[128];    int types = 0;    EXEC SQL END DECLARE SECTION;    EXEC SQL WHENEVER SQLERROR GOTO ORACLE_ERROR;    memset(&passwords, 0, sizeof(passwords));    snprintf(username, sizeof(username), "%s", name);    EXEC SQL SELECT PASSWORD, TYPE            INTO :passwords, :types    FROM USER            WHERE NAME = :username;    printf("----\n");    printf("USER_NAME = %s\nPASSWORD=%s\nUSER_TYPE=%d\n", username, (char*)passwords.arr, types[0]);    printf("----\n");    return 0;ORACLE_ERROR:    EXEC SQL WHENEVER SQLERROR CONTINUE;    return -1;}

Related Article

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.