Use of Pro * C

xiaoxiao2021-03-06  37

Use of Pro * C

An Overview of Pro * C Program:

1. What is Pro * C program

In Oracle Database Management and System, there are three ways to access the database;

(1) With SQL * Plus, it has the SQL command to access the database with an application for interaction;

(2) Use the application of the fourth-generation language application development tool to access the database, these tools have SQL * froms, QL * ReportWriter, SQL * MENU, etc .;

(3) Use the SQL language or Oracle library function calls embedded in the third-generation language.

Pro * c belongs to one of the third development tools, which combines process-based language C and non-processed language SQL, with complete process processing capabilities, and completes any database processing tasks, users Various types of reports can be completed by programming. In the Pro * C program, you can embed the SQL language. Use these SQL languages ​​to complete dynamically, modify, and delete the tables in the database, you can also query, insert, modify, and delete lines in the database table, you can also implement transaction And roll back.

In the Pro * C program, the PL / SQL block can also be embedded to improve the performance of the application, especially in a network environment, can reduce the total overhead of network transmission and processing.

2. Pro * c programming

Popular, the Pro * C program is actually embedded with a SQL statement or a PL / SQL block, so its composition is similar to the C program. But because of its embedded SQL statement or PL / SQL block, it also contains different ingredients. In order to let everyone have an inductive understanding of Pro * C, the difference is as follows:

C's full variable description

C Source Program Function 1: Tong Function K.

Function 2: That with functions K.

C Partial Variable Description

Function K

Executable statement

Application header C's external variable description

External Description (Oracle Variable Description)

Communication area description

Pro * C Source Process 1: With Function K.

Function 2: That with functions K.

C local variable description

Interior of the program, some internal description segments

Communication area description

Performance statement of function K C

Executable statement of executable statement SQL

Or PL / SQL block

two. Composition of Pro * C Programs

Each Pro * C program includes two parts: (1) application header; (2) application body

The application first defines the relevant variables of the Oracle database, and prepares for manipulating the Oracle database in the C language. The application body is basically called by Pro * C SQL statement. Mainly refer to SELECT, INSERT, UPDATE, DELETE and other statements.

The composition structure of the application is shown in the figure:

Application first

Description section

SQL communication area

Application program

EXEC SQL Begin Declare Section

(Definition of SQL variable)

Exec SQL End Declare Section;

EXEC SQL include Sqlla;

EXEC SQL Connect:

Identified by:

SQL statement and cursor use

1. Application header

The first part of the application is the beginning of Pro * C. It includes three parts: L C variable description section;

l SQL variable description section (Declare part);

l SQL communication area.

(1). Declare part (description section)

Description section describes the SQL variable of the program, the defined portion is ended with Exec SQL Begin Declare Section; ending with EXEC SQL End Declare Section; It can appear in the main sector of the program, can also appear on topical

l SQL variable description and use

The data type specified by the segment can be specified for the SQL variable is shown in the table:

type of data

description

Charr

Char (n)

Int

Short

Long

Float

Double

VARCHAR

Single character

N character arrays

Integer

Short integer

Single precision floating point

Double precision floating point

Growth string

These data types are actually the data type of C language, where varchar is expanded to the C data type. This is talking later.

The use of SQL variables should be aware of the following points:

l must be clearly defined in the description

l Must use the same case in which it is defined.

l When you are used in the SQL statement, you must add a ":" (colon) before it, but you don't need to colon when you are referenced in the C statement.

l Can't be the reserved word in the SQL command.

l You can take an indication variable.

For example: Exec SQL Begin Declare Sections;

Varchar Programe [30];

INT PORGSAL, PEMPNO;

Exec SQL End Declare Section;

Exec SQL SELECT ENAME, SAL

INTO: Program,: Progctions

From EMP

WHERE Empno =: pempno;

(2). Description and reference of the indicator variable

The indication variable is actually a class of SQL variables that are used to manage host variables associated therewith (ie, the variables that are input or output in the SQL statement). Each host variable can define an indicator variable, mainly for processing null values ​​(NULL)

The instructions of the indicator variable are basically the same as general SQL variables, but must define 2 bytes of integers, such as short, int. When referenced in the SQL statement, it should also be added ":" (colon), and must be attached to the associated host variable, can be used independently in the C statement. When the indicator variable is -1, a null value is indicated. E.g:

EXEC SQL Begin Declare Section;

INT DEPT- NUMBER;

Short Ind - Num;

Char Emp -Name;

Exec SQL End Declare Section;

Scanf ("90D% S", & DEPT- Number, DEPT - NAME);

IF (DEPT - Number == 0)

IND - NUM = -1;

Else

IND - NUM = 0;

Exec SQL INSERT INTO DEPT (DEPTNO, DNAME)

VALUES (: DEPT - NUMBER: IND- NUM,: DEPT - NAME);

Where IND-NUM is the indicator variable of DEPT - NUMBER. When the input DEPT-Number value is 0, an empty value is inserted to the DEPTNO column of the DEPT table.

(3). Description and use of the pointer SQL variable

The pointer SQL variable must also be described in the DECLARE section before reference. It illustrates the format as C language. When referenced in the SQL statement, the pointer is prefixed before the name is ":" (colon) without adding "*". Usage in the C statement like a pointer variable in the C language. (4). Description and reference for array SQL change

When references the array in the SQL statement, just write an array name (before the name before the name), do not need to write the subscript, the usage in the C statement is like the array variables in the C language.

Using an array can greatly reduce network transmission overhead. To insert 100 row data to a table, if there is no array, you must repeat 100 times, and after reference, you only need to execute an insert statement will insert it. E.g:

EXEC SQL Begin Declare Section;

INT EMP_NUMBER [100];

Char EMP_NAME [100] [15];

FLOAT SALY [100], CommsSion [100];

INT dept_number;

Exec SQL End Declare Section;

.

Exec SQL SELECT Empno, ENAME, SAL, COMM

INTO: EMP_NUMBER,: EMP_NAME,: SALARY,: CommIions

From EMP

WHERE deptno =: dept_number;

When using arrays, pay attention to the following points;

l Does not support the argument array

l Only one-dimensional array, and EMP-NAME [100] [15] is deemed to be a one-dimensional string

The maximum number of ports in the L is 32767

l When references multiple arrays in a SQL statement, these array dimensions should be the same.

l In values, set, into, or where subsets, not allowing simple SQL variables to mix with array SQL variables.

l Can't initialize the array in Delare part

For example: The following reference is illegal

EXEC SQL Begin Declare Section;

INT DEPT - NUM [3] = {10, 20, 30};

Exec SQL End Declare Section;

Exec SQL SELECT Empno, ENAME, SAL

INTO: EMP - NUM [I],: Emp - Name [i],: salarg [i]

From EMP

(5) Description and reference of pseudo type varchar

VARCHAR variables must also be described in the description before reference, and the maximum string must be pointed out.

Length, such as:

EXEC SQL Begin Declare Section;

INT book - Number;

VARCHAR BOOK - NAME [50];

Exec SQL End Declare Section;

When prepared, Book - Name is translated into a structural variable in C language;

Struct {UNSIGNED SHORT LEN;

UNSIGNED Chart Arr [20];

} Boo - Name

As a result, VarChar variables are actually a structural variables that contain length members and array members. When referenced in the SQL statement, reference should be referenced to the structure name prefixed with a colon, and the standard member is referenced in the C statement.

When the VARCHAR variable is automatically set by Oracle, when as an input variable, the program should put the string into an array member, and the length is deposited in the length member, and then reference it in the SQL statement. E.g:

Main ()

{....... SCANF ("90S, 90D ', BOOK - Name .arr, & Book - Number);

Book - name .len = strlen (Book - name .arr);

EXEC SQL UPDATE BOOK

SET BNAME =: Book - Name;

BDESC =: BOOK - NUMBER;

}

(6) SQL communication area

The SQL communication area is described in the following statement:

EXEC SQL include Sqlca;

This section provides the failure or failure of the user running program.

SQLCA composition

SQLCA is a structural type variable that is an interface of Oracle and an application. When executing the Pro * C program, Oracle stores the status information performed by each embedded SQL statement into SQLCA. According to this information, it can determine whether the execution of the SQL statement is successful, the number of rows, error information, etc., the composition is Down:

Struct Sqlca

{char sqlcaid [8]; ---- à identity communication area

Long SQLABC; --- à The length of the communication area

Long Sqlcode; - à Reserved the status code of the recently executed SQL statement

Struct {unsigned short sqlerrml; ----- à information text length

SQlerrm;

Char sqlerrp [8];

Long SQlerRD [6];

Char sqlwarn [8];

Char sqlext [8];

}

Struct Sqlca SQLCA;

Where SQLCode is most common in the program, it retains the status code of the recently executed SQL statement. The programmer makes the corresponding processing based on these status code. These status code values ​​are as follows:

0: Indicates that the SQL statement is executed correctly, no errors and exceptions.

> 0: Oracle executes this statement, but encounter an exception (if you didn't find any data).

<0: Indicates that Oracle does not execute the SQL statement due to errors of databases, systems, networks, or applications.

When this error occurs, the current transaction should generally be rolled back.

2. Application program

In the Pro * C program, you can freely mix writing SQL statements and C statements, and can use SQL variables in the SQL statement, the writing literacy of embedded SQL statements is:

l Start with keyword EXEC SQL

l Terminal with the C language statement (semicolon)

The role of the SQL statement is mainly used to deal with the database. The C language program is used to control, input, output, and data processing, etc..

(1) Connect to Oracle Database

Before you get the data inventory, you must first connect the program to the Oracle database. Log in to Oracle. The connected command should be the first executable command of the application. The connection command format is as follows:

EXEC SQL Connect: Identified by:

Or Exec SQL Connect: /

When logging in using the two formats described above, you should first define the user name and password first in the description segment.

SQL variables and setting them before performing Connect, otherwise the login failed. E.g:

EXEC SQL Begin Declare Section;

VARCHAR Usename [20];

VARCHAR Password [20];

EXEC SQL END DECLARE

........

STRCPY (useename.arr, "csott ');

Usename.len = Strlen (username.arr);

STRCPY (Password.arr, "Tiger ');

Password .len = Strlen (Password .arr);

EXEC SQL WHENEVER SQLERROR GOTO SQLERR;

Exec SQL Connect: UserName InditiFied by: Password;

Note: You cannot write the username and password to the Connect statement, or the letter string enclosed in quotation marks (') in the Connect statement, as ineffective below.

EXEC SQL Connect Scott inentified by Tiger;

EXEC SQL Connect 'Scott' Identified by 'Tiger'

(2). Insert, update, and delete

After telling the SQL language, it has been speaking, which is not explained here.

(3). Database query and cursor

In Pro * C, the query can be divided into two types:

l Return to a single line or a query;

l Return to multi-line queries. This query requires a cursor to control each row or each group (the main variable array).

1) Return to a single line or fixed number of queries

The query SQL SELECT statement in Pro * C consists of several clauses:

SELECT

INTO

From

WHERE

CONNECT BY

Union

INTERSECT

Minus

GROUP BY

Having

ORDER BY

Where the query condition in the WHERE clause can be a collection of attributes or multiple properties, which can be placed in the WHERE clause in execution. The main variable used in the Where clause is called the input main variable. Such as:

SELECT Empno, Job, Sal

INTO: PNAME,: PJOB,: PSAL

From EMP

WHERE Empno =: pempno;

If you do not find a defined line, Sqlca.sqlcode returns " 1403", indicating that "not found".

The main variable quantity of the INTO clause outputs the main variable, which provides the information required when queries.

Before any item is given to the primary variable, it is required to convert these items to the data type of the main variable. For numbers, it is done by truncation (eg 9.23 converted to 9).

If you have determined that the query only returns a row, you don't have to use a cursor, you can only add an INTO clause to the SELECT statement. How many output primary variables have multiple output main variables in the query in the query in the query in the query in the query in the query. If the number of expressions in the SELECT item is not equal to the number of main variables in the INTO clause, set SQLCA.SQLWARN [3] to "W".

2) Multi-line inquiry and cursor use

If the query returns multiple lines or does not know how many rows returned, use the SELECT statement with the Oracle Cursor (CURSOR).

The cursor is Oracle and Pro * C store the work area of ​​the query results. A cursor (named) is associated with a SELECT statement. Operating cursor has 4 commands: (1) DECLARE CURSOR; (2) Open cursor; (3) fetch; (4) Close Cursor.

A. Defining a cursor

A cursor must first be defined before it can use it. The syntax is:

EXEC SQL DECLARE Corsor for

Select

From

E.g:

Exec SQL Declare Csor, Cursor Fortelect Ename, Job, Sal

From EMP

WHERE deptno =: deptno;

When it is assigned to a cursor Cursor associated with the query, it is possible to return multiple lines from the database when the SELECT queries EMP, which is a activity area of ​​Cursor.

note:

1) Defining the cursor must be completed before the cursor operation;

2) Pro * c cannot reference the undefined cursor;

3) After the cursor is defined, its scope is the entire program. So for a program, it is wrong to define two identical cursors.

B. Open the cursor

Open the Open statement of the cursor is mainly used to enter the content of the main variable, these mainly the main variable used in WHERE. Opening the cursor is: Exec SQL Open

When the cursor is opened, more than one row can be taken from the related queries. All rows that meet the query standards are called "Cursor Activity Set". By taking the operation, each row in the activity set or each group is a return. After the query is completed, the cursor can be turned off. as the picture shows:

Define cursors: Declare

Start inquiry: SELECT

Open the cursor: Open

Jump data from activity: Fetch

Query completion

Close Cursor: Close

Note: 1) The cursor is in front of the first line of the active set;

2) If you change the input main variable, you must re-open the cursor.

C. Take data

Remove the process of taking out a line or a group of procedures to send the results to the output main variable. The definition of the output main variable is taken in the data statement. Take the statement of the data is as follows:

Exec SQL FETCH INTO: Main Variable 1, Main Variable 2, ...

Fetch's work is as shown in the figure:

search result

cursor

Fetch

search result

After the cursor is opened

Output to current

......

The query result shown in the figure refers to the result of the query condition. Use fetch to pay attention to the following points:

l The cursor must be defined first.

l Only the FETCH statement is performed only after the cursor is opened.

l The FETCH statement is executed once, from the current line or the current group, the next line or the next set is moved up. The row or group of the cursor is the current line or the current group, and Fetch is the data specified by the target each time.

l When the cursor activity is vacant, Orcle returns a SQLCA. SQLCA (= 1403).

l If you want this cursor to operate, you must first turn it off again.

l You can open a memory space in the C program to store the results of the operation, so you can use the open space to flexibly manipulate the results of the query.

D. Close a cursor

After all the rows in the event is taken, the cursor must be closed to release resources related to the cursor.

The format of the shutdown cursor is:

EXEC SQL Close Tour Name;

E.g:

EXEC SQL Close C1;

Oracle V5.0 supports SQL format "Current of Cursor". This statement will point to the latest rows in a cursor for modifying and deleting operations. This statement must be used after the operation, it is equivalent to storeing a ROWID and uses it.

(4). Example

EXEC SQL DECLARE SALESPEOPEOPE CURSOR for

SELECT SSNO, Name, SalaryFrom Employee

WHERE DNAME = 'Sales';

EXEC SQL OPEN SALESPEOPLE;

EXEC SQL FETCH SALESPEOPLE

INTO: SS,: NAME,: SAL

EXEC SQL Close Salespeople;

(5) Method and application of SQL nested

Embedded SQL and interactive SQL have the following differences in the form:

1) Increase the prefix "Exec SQL" before the SQL statement, which is easy to identify when the precompilation is precompiled to process each SQL as a high-level language.

2) Each SQL statement is divided into two major classes of the illustrative statement and the executable statement. The executable statement is divided into data definition, data control, data manipulation, and data retrieval.

The executable SQL statement is written in the executive of the advanced language; the illustrative SQL statement is written in the descriptive place in the advanced language.

For example, establish a table structure called BOOK in the Pro * C program, the process is as follows:

#include

EXEC SQL Begin Declare Section;

VARCHAR UID [20], PWD [20];

Exec SQL End Declare Section;

EXEC SQL include Sqlca;

Main ()

{

/ * login data * /

STRCPY (Uid.arr, 'wu');

Uid.len = Strlen (UID, ARR);

STRCPY (pwd.arr, 'wu');

PWD.LEN = Strlen (PWD.arr);

EXEC SQL Connect: Uid Identifeed by: PWD;

Exec SQL CREATE TABLE BOOK

Acqnum Number, COPIES NUMBER, Price Number;

EXEC SQL Commit Work Release;

EXIT;

Pro * C can be very easy and flexibly accessing data in the ORCLE database, while also having a high speed of C language, so that some Oracle products cannot be completed, such as one of the following fixed special format output results.

SQL nested source program example

#unclude

Typedef char asciz [20];

EXEC SQL Begin Declare Section;

EXEC SQL TYPE Asciz Is String (20) Reference;

Asciz Username;

Asciz password;

Asciz EMP_NAME (5);

INT EMP_NUMBER (5A);

Float Salry [5];

Exec SQL End Declare Section;

EXEC SQL include Sqlca;

Void Print_Rows ();

Void sqlerror ();

Main ()

{

INT Num_Ret;

STRCPY (UserName, "Scott ');

STRCPY (Password, "Tyger");

Exec SQL WHENEVER SQLEC DO SQLERROR ();

EXEC SQL Connect: UserName Identified by: Password;

Print ("/ NConnected to Oracle AS User:% S / N", UserName);

EXEC SQL DECLARE C1 CURSOR FORSELECT EMPNO, ENAME, SAL FROM EMP

EXEC SQL OPEN C1;

NUM_RET = 0;

For (;;)

{

Exec SQL WHENEVER NOT DO BREAK;

EXEC SQL FETCH C1 INTO: EMP_NUMBER,: EMP_NAME,: SALARY

Print_Rows (Sqlca.sqlerrd [2] - Num_Ret);

Num_ret = sqlca.sqlerrd [2];

}

IF ((Sqlca.sqlerrd [2] - Num_Ret)> 0);

Print _Rows (Sqlca.sqlerrd [2] -Num_ret);

EXEC SQL Close C1;

Printf ("/ have a good day./n");

EXEC SQL Commit Work Release;

}

Void Print_Rows (N);

Int n;

{

INT I;

Printf ("/ nNumber Employee Salary / N");

Printf ("-------------------------- / n");

For (i = 0; i

Printf ("% - 9D% - 8S% 9.2F / N", EMP-NUMBER [I], EMP --- Name [i], SALARY [i];

}

Void sqlerror ()

{

Exec SQL WHENEVER SQLERROR Continue;

Printf ("/ Noracle Error Detected: / n");

Printf ('/ n% .70s / n ", sqlca.sqlerrm.sqlerrmc);

Exec SQL ROLLBACK WORK RELEASE

Exit (1);

}

(6) Error detection and recovery

When using SQL statements and Pro * C, there are often field null values, unconditional deletion, no row return, data overflow, and truncation, etc., this phenomenon can be detected by SQLCA and indicator variables.

1 SQLCA structure

In the Pro * C program, the SQLCA structure is as follows:

Struct sqlca {

Char sqlcaid [8];

Long SQLABC;

Long Sqlcode;

Struct {

Unsigned sqlerrm1;

Char sqlerrmc [10];

SQlerrm;

Char sqlerrp [8];

Long SQlerRD [6];

Char sqlwarn [8];

Char sqlext [8];

}

among them:

1) Sqlca.sqlerrm.sqlerrmc: With SQLCA. Sqlcode's error body.

2) Sqlca.sqlerrd: The current Oracle status, only SQLCA.SQlerRD [2] meaningful, indicating the number of rows processed by the DML statement.

3) Sqlca.sqlwarn: Provides the conditions that may encounter.

After each SQL statement is executed, Oracle puts the return result in SQLCA, but except the statement.

Use SQLCA to view the execution result of the SQL statement. There are often three results:

= 0: Perform success;

SQLCA.SQLCODE => 0: Perform a status value of success;

<0: Failure, does not allow continued execution.

2 indicator variable

The indicator variable is sometimes referred to as an indication variable. The indication variable is associated with a primary variable, indicating the return of the main variable.

= 0: The return value is not empty, not truncated, and the value is placed in the main variable;

Return value => 0: The return value is empty, ignores the value of the primary variable; <0: The main variable length is not cut off.

Use instruction variables to pay attention:

l The indication variable cannot be used in the WHERE clause. Test null values ​​with NULL properties.

For example, the following subsequence:

SELECT ...

From ...

WHERE ENAME IS NULL;

It is correct, and

Where eName =: peme: peme1

it's wrong.

l The indication variable is -1 before inserting a null value.

l You can output a null value.

3 WHENEVER statement

WHENEVER is a description statement, does not return SQLCode, just specify related measures based on the return code in SQLCA. Format

EXEC SQL WHENEVER [SQLERROR | SQLWARNING | NOTFORUND]

[STOP | Continue | Goto ];

among them

(1) The default value of [STOP | Continue | GOT ] is Continue.

(2) SQLERROR: SQLCA.SQLCODE <0;

(3) Sqlwarnign: Sqlca.sqlwarn [0] = "w";

(4) NOTFOUND: SQLCA.SQLCODE = 1403;

A program is given below to illustrate the use of WHENEVER:

EXEC SQL Begin Deeelection;

VARCHAR UID [20];

VARCHAR PASW [20];

......

Exec SQL End Declare Section;

EXEC SQL include Sqlca;

Main ()

{

... EXEC SQL WHENEVER SQLERROR GOTO ERR;

EXEC SQL Connect: Uid /: PWD;

......

EXEC SQL DECLARE CSOR1 CURSOR for

SELECT

Form

Exec SQL Open Csor1;

SQL

......

EXEC SQL WHENEVER NOT Found Goto Good;

For (;;)

EXEC SQL FETCH CSOR, INTO ...

Good:

......

Printf ("/ n query end / N");

EXEC SQL Close C1;

EXEC SQL WHENEVER SQLERROR Continue.

EXEC SQL Commit Work Release:

Exit ();

Printf ("/ n% 70s | n", sqlca.sqlerrm.sqlerrmc);

EXEC SQL ROLLBACK WORK RELEASE:

Exit (1);

}

(7) Dynamic definition statement

SQL statements Dynamic definition statements and static definition statements:

(1) Static definition statement: The SQL statement is written in advance, and the target program is formed after compiling the precompiler. Boj, then perform the target program.

(2) Dynamic definition statement: Some statements cannot be embedded in the Pro * C program in advance, and the user is entered from the input device (such as the terminal) in real time from the input device (such as the terminal) in accordance with the program operation. Dynamic definition statement:

l execute lydiate;

l Prepare and Execute;

l Prepare and Fetch and Open;

l Bind and Define Descriptor.

1. EXECUTE IMMEDIATE statement

This statement indicates immediate execution, and only returns the execution result to SQLCA, no other information. E.g:

EXEC SQL Begin Declare Section;

VARCHAR ABCD [89];

VARCHAR DEAY [20];

Exec SQL End Declare Section;

/ ** Output string to abcd ** /

EXEC SQL EXECUTE IMMEDIATE: ABCD;

note:

1) Execute immediate can only run dynamic statements with a parameter. Among them, ABCD is parameter, not a keyword.

2) The prerequisites used by Execute Immediate are: SQL statements cannot include the primary variable; the SQL statement cannot be queried statements.

3) Any primary variable can be used as the parameter of Execute Immediate; it is also possible to use a string as the main variable.

2. PREPARE and EXECUTE statement

This statement represents "precompiled / executed". This statement is able to pre-transder a multiple times. The syntax is:

EXEC SQL prepare from: main variable

EXEC SQL EXECUTE [USING: Replace the main variable];

PREPARE statement is two things:

(1) Pre-compiled SQL statement;

(2) Give the statement name of the SQL statement.

note:

l SQL statement cannot be a query statement;

l Prepare and Execute include the main variable;

l PREPARE cannot be executed multiple times.

For example:

#define username "scott"

#define password "Tiger"

#include

EXEC SQL include Sqlca;

EXEC SQL Begin Declare Section;

Char * username = usrname;

CHAR * password = password;

VARCHAR SQLSTMT [80];

Int Emp_number;

VARCHAR EMP_NAME [15];

VARCHAR JOB [50];

Exec SQL End Declare Section;

Main ()

{

Exec SQL WHENEVER SQLEC SQLERROR GOTO: SQLERROR;

EXEC SQL Connect: UserName Identified by: Password;

SQLSTMT.LEN = Sprintf (SQLSTMT.ARR, "INSERT INTO EMP (Empno, Ename, Job, SAL)

VALUES (: V1,: V2,: V3,: V4) ");

PUTS (SQLSTMT.ARR);

Exec SQL Prepare S from: SQLSTMT;

For (;;) {

Printf ("/ NENTER EMPLOYEE NUMBER:");

Scanf ("% D", & EMP_NUMBER);

IF (EMP_NUMBER == 0) BREAK;

Printf ("/ NENTER EMPLOYEE NAME:");

Scanf ("% s", & EMP_NAME.ARR);

EMP_NAME.LEN = Strlen (EMP_NAME.ARR);

Printf ("/ NENTER EMPLOYEE JOB:");

Scanf ("% s", Job.arr);

Job.len = Strlen (Job.arr);

Printf ("/ NENTER EMPLOYEE SALY:");

Scanf ("% f", & Salary;

}

EXEC SQL EXECUTE S Using: EMP_NUMBER,: EMP_NAME,: JOB,: SALARY

}

3. FETCH statement and Open statement

FETCH statements and Open statements This set of dynamic statements is to operate on the cursor, and the execution process is as follows:

PREPARE From

;

Declare For

Open [USING: Replacement Variable 1 [,: Replace Variables "]]]]

FETCH INTO: Main Variable 1 [,: Main Variable 2 ...]

Close

note:

l SQL statement allows the query statement to be used;

l The column name in the SELECT clause cannot be dynamically changed, only preset;

l WHERE and ORDER BY clauses can dynamically change the conditions.

First, Pro * C Compilation and Run

1. First use the Oracle Pre-Code Translation PROC to prepare the Pro * C program, the compiler translates the SQL language embedded in the source into a C language, generating a C language compiler that can directly compile. The extension of the generated file is .c

2. Compile the file with .c file with the C language compiler Cc, generate a target code file, its extension is .o

3. Use the make command, connect to the target code file, generate a run file

For example: compiling the above EXAMPLE.PC

Proc iname = esample.pc

CC EXAMPLE.C

Make exe = example = "eXample.o"

EXAMPLE

转载请注明原文地址:https://www.9cbs.com/read-52348.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.043, SQL: 9