Oralce database development (2). Configure proc in Linux
20070606
Papayas
I. Summary
The previous section briefly introduced proc configuration development in windows. This time, we use the Linux platform to configure Oracle proc again.
Development Environment (RedHat Linux 9 + Oracle 92 ).
Oracle Database development (1). Configure and use proc in windows and Oracle Database Development (2). Configure and use proc in Linux
The purpose of these two articles is to give a basic introduction. As for the Oracle proc compilation parameters and the proc makefile in Linux
Relevant content, which will be gradually introduced in subsequent articles.
In one word, it is easy and difficult.
Ii. database environment
Similar to Windows, make sure that the component is installed-
Pro C-C ++. After installation, the corresponding executable file will be generated in $ ORACLE_HOME/bin, in $ ORACLE_HOME/precomp/demo/proc
Generate some makefile files and examples.
Iii. Example File
Main. PC
---------------------------------------------------------
# Include "sqlca. H"
# Include <stdio. h>
# Include <string. h>
# Include <stdlib. h>
Void SQL _error (char * MSG)
{
Printf ("/n % S % s/n", MSG, (char *) sqlca. sqlerrm. sqlerrmc );
Exec SQL rollback release;
Exit (0 );
}
Int main (){
Exec SQL include sqlca;
Exec Oracle option (release_cursor = yes );
Exec SQL whenever sqlerror do SQL _error ("<error> ");
Exec SQL begin declare section;
Varchar limit N [30];
Exec SQL end declare section;
Strcpy (Limit N. Arr, "system/manager @ linuxdb ");
Limit N. Len = strlen (Limit N. Arr );
Limit N. Arr [limit N. Len] = '/0 ';
Exec SQL CONNECT: Limit N;
Printf ("/n [OK connected!] ");
Return 0;
}
The code is actually the original version of Windows.
Iv. Compile and run
You do not need to modify any parameter files, that is, directly create main. PC after installation, and execute the following command:
$ Proc parse = none INAME = Main. PC
Pro * C/C ++: Release 9.2.0.4.0-production on Thu Jun 7 14:17:05 2007
Copyright (c) 1982,200 2, Oracle Corporation. All rights reserved.
System Default Option values taken from:/home/ora/ora9/Oracle/precomp/admin/pcscfg. cfg
$ Gcc-g-o main. C-I/home/ora/ora9/Oracle/precomp/public-L/home/ora/ora9/Oracle/lib-lclntsh
$./Main
<Error> ORA-12541: TNS: No listener
After compilation and running, you can also use the example in Proc dynamic SQL example (method 1, 2, 3,
Replace all the // comments with null to compile.
Http://blog.csdn.net/liwei_cmg/archive/2006/05/29/759963.aspx
However, there will be an alarm:
/Tmp/ccc7e6qe. O (. Text + 0xea): In function 'db _ connect ':
/Home/ora/develop/src/DB. C: 385: The 'gets' function is dangerous and shoshould not be used.
This is because the gets function is used. For details, see the man manual of gets:
Bugs
Never use gets (). Because it is impossible to tell without knowing
Data in advance how many characters gets () will read, and because
Gets () will continue to store characters past the end of the buffer, it
Is extremely dangerous to use. It has been used to break computer
Security. Use fgets () instead.
It is not advisable to mix callto input functions from the stdio
Library with low-level callto read () for the file descriptor asso-
Ciated with the input stream; the results will be undefined and very
Probably not what you want.
To solve this problem, use the scanf function to replace gets and obtain the screen input. For example, scanf ("% s", CMD ).