VARCHAR strings in Oracle 7?
Date: 1995/09/29
Message-ID: <44h5kn$mhb_at_nntp.Stanford.EDU>#1/1
I am trying to write a very simple Pro*C procedure under 7.1.3 on a
Sun SPARC 5, SunOS 4.1.3. All I want to do is retrieve a person's
first name, given the last name. Under SQL*Plus, the following select
statement works fine:
select name_first
NAME_FIRST
Can anyone see what I am doing wrong. It seems so simple!
#include <stdio.h>
EXEC SQL INCLUDE sqlca.h;
void sql_error();
main(argc, argv)
int argc;
{
strcpy((char *) oracle_user.arr, "oracle", 20);
oracle_user.len = strlen((char *) oracle_user.arr);
strcpy((char *) oracle_password.arr, "*****", 20);
oracle_password.len = strlen((char *) oracle_password.arr);
strcpy((char *) name_last.arr, argv[1], 25);
name_last.len = strlen((char *) name_last.arr);
name_last.arr[name_last.len] = '\0';
EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--\n");
from PROFILE
where name_last = 'GOEBEL'
;
PATRICK
However, the following Pro*C code (which compiles without error) fails
to retrieve the data -- I get a "Not Found" condition -- when given
the string GOEBEL as input.
#include <ctype.h>
varchar oracle_user[20];
varchar oracle_password[20];
varchar name_last[25];
varchar name_first[25];
char *argv[];
EXEC SQL CONNECT :oracle_user IDENTIFIED BY :oracle_password;
EXEC SQL WHENEVER NOT FOUND GOTO notfound;
EXEC SQL SELECT name_first
INTO :name_first FROM PROFILE WHERE name_last = :name_last;
printf("%s",name_first.arr);
exit(0);
notfound:
printf("-1");
exit(1);
}
void
sql_error(msg)
char *msg;
{
char err_msg[128];
int buf_len, msg_len;
EXEC SQL WHENEVER SQLERROR CONTINUE;
printf("\n%s\n", msg);
buf_len = sizeof (err_msg);
sqlglm(err_msg, &buf_len, &msg_len);
printf("%.*s\n", msg_len, err_msg);
EXEC SQL ROLLBACK RELEASE;
exit(1);
}
Received on Fri Sep 29 1995 - 00:00:00 CET