Home » Developer & Programmer » Precompilers, OCI & OCCI » help me to compile first proc (Oracle 11gR2)
help me to compile first proc [message #592655] Sat, 10 August 2013 09:50
sd07501
Messages: 1
Registered: August 2013
Junior Member
Hi all,

I am a beginner of proc programming. After install Oracle 11gR2 on Ubuntu, I try to build a sample from oracle procdemo.pc using the command

$ORACLE_HOME/sdk/proc iname=procdemo.pc parse=none

but got an error about undefined identifier as below

Semantic error at line 113, column 42, file procdemo.pc:
EXEC SQL FETCH salespeople INTO :emp_rec_ptr;
.........................................1
PCC-S-02322, found undefined identifier

Please help me to solve it. Thank you very much and look forward to your reply. I enclose here the file procdemo.pc for your reference.

/*
* procdemo.pc
*
* This program connects to ORACLE, declares and opens a cursor,
* fetches the names, salaries, and commissions of all
* salespeople, displays the results, then closes the cursor.
*/

#include <stdio.h>
#include <string.h>
#include <sqlca.h>
#include <stdlib.h>
#include <sqlda.h>
#include <sqlcpr.h>

#define UNAME_LEN 20
#define PWD_LEN 11

/*
* Use the precompiler typedef'ing capability to create
* null-terminated strings for the authentication host
* variables. (This isn't really necessary--plain char *'s
* would work as well. This is just for illustration.)
*/
typedef char asciiz[PWD_LEN];

EXEC SQL TYPE asciiz IS CHARZ(PWD_LEN) REFERENCE;
asciiz username;
asciiz password;

struct emp_info
{
asciiz emp_name;
float salary;
float commission;
};

void sql_error(msg)
char *msg;
{
char err_msg[512];
size_t buf_len, msg_len;

EXEC SQL WHENEVER SQLERROR CONTINUE;

printf("\n%s\n", msg);

/* Call sqlglm() to get the complete text of the
* error message.
*/
buf_len = sizeof (err_msg);
sqlglm(err_msg, &buf_len, &msg_len);
printf("%.*s\n", msg_len, err_msg);

EXEC SQL ROLLBACK RELEASE;
exit(EXIT_FAILURE);
}

void main()
{
struct emp_info *emp_rec_ptr;

//declare host variables
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR username[32];
VARCHAR password[32];
EXEC SQL END DECLARE SECTION;



/* Allocate memory for emp_info struct. */
if ((emp_rec_ptr =
(struct emp_info *) malloc(sizeof(struct emp_info))) == 0)
{
fprintf(stderr, "Memory allocation error.\n");
exit(EXIT_FAILURE);
}

/* Connect to ORACLE. */
strcpy(username, "scott");
strcpy(password, "tiger");

EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--");

EXEC SQL CONNECT :username IDENTIFIED BY :password;
printf("\nConnected to ORACLE as user: %s\n", username);

/* Declare the cursor. All static SQL explicit cursors
* contain SELECT commands. 'salespeople' is a SQL identifier,
* not a (C) host variable.
*/
EXEC SQL DECLARE salespeople CURSOR FOR
SELECT ENAME, SAL, COMM
FROM EMP
WHERE JOB LIKE 'SALES%';

/* Open the cursor. */
EXEC SQL OPEN salespeople;

/* Get ready to print results. */
printf("\n\nThe company's salespeople are--\n\n");
printf("Salesperson Salary Commission\n");
printf("----------- ------ ----------\n");

/* Loop, fetching all salesperson's statistics.
* Cause the program to break the loop when no more
* data can be retrieved on the cursor.
*/
EXEC SQL WHENEVER NOT FOUND DO break;

for (;;)
{
EXEC SQL FETCH salespeople INTO :emp_rec_ptr;
printf("%s %9.2f %12.2f\n", emp_rec_ptr->emp_name,
emp_rec_ptr->salary, emp_rec_ptr->commission);
}

/* Close the cursor. */
EXEC SQL CLOSE salespeople;

printf("\nGOOD-BYE!!\n\n");

EXEC SQL COMMIT WORK RELEASE;
exit(EXIT_SUCCESS);
}
  • Attachment: procdemo.txt
    (Size: 2.99KB, Downloaded 70 times)
Previous Topic: Pro*C++ Resultset Data types question
Next Topic: not all variable bound
Goto Forum:
  


Current Time: Mon Sep 15 20:54:32 CDT 2014

Total time taken to generate the page: 0.06092 seconds