Issue with fetch in Pro*C [message #397520] |
Sat, 11 April 2009 14:17 |
oracle123
Messages: 56 Registered: March 2009
|
Member |
|
|
Hi all,
I have a issue with FETCH operation using CURSORS in Pro*C.
Consider the following table structure:
desc emp
ename varchar2(10);
dept varchar2(5);
Data in the emp table is as follows:
ename dept
------- --------
scott sales
john sales
matt inven
rodd sales
I have the following code written in Pro*C
int cmp;
EXEC SQL BEGIN DECLARE SECTION;
char emp_name[10];
EXEC SQL END DECLARE SECTION;
EXEC SQL DECLARE cur_emp_name CURSOR FOR
SELECT ENAME
FROM EMP
WHERE DEPT = 'sales'
ORDER BY ENAME;
EXEC SQL OPEN cur_emp_name;
EXEC SQL WHENEVER NOT FOUND DO break;
for(;;)
{
EXEC SQL FETCH cur_emp_name INTO :emp_name ;
cmp = strcmp(emp_name, 'scott');
/* Strings are equal */
if (cmp == 0)
printf("EQUAL \n");
else
printf("NOT EQUAL \n");
}
EXEC SQL CLOSE cur_ftr_num;
Output for the above code is:
NOT EQUAL
NOT EQUAL
NOT EQUAL
Whereas I expect it to print EQUAL in the case of ename='scott'
When I printed 'emp_name' to output for each record, this is the output (Note- 'X' represents a whitespace in the following output):
'scottXXXXX'
'johnXXXXXX'
'roddXXXXXX'
Is this default behavior of Pro*C to append whitespaces for the rest of string array?
Please suggest me how can we eliminate those whitespaces?
Thanks,
Scott.
|
|
|
|
Re: Issue with fetch in Pro*C [message #397522 is a reply to message #397520] |
Sat, 11 April 2009 17:01 |
oracle123
Messages: 56 Registered: March 2009
|
Member |
|
|
Michel,
Thanks for your prompt reply.
But if I declare "emp_name" as VARCHAR datatype, I am getting error at this line
cmp = strcmp(emp_name, 'scott');
As strcmp accepts CHAR datatype opposed to VARCHAR datatype.
Please advice me.
Thanks,
Scott.
|
|
|
|
|
|
|