Declare a host variable like this: "char hLikeVar[64];". Then string copy "%[empl name]%" into it. For [empl name] use the input you got from the user. Then you can do this:
... WHERE NAME LIKE :hLikeVar;
문제
How do I use LIKE with Pro*C? The code below doesn't work. I need to search records in database.
cout<<"Employee name\t\t: ";
cin.getline(name,50);
EXEC SQL SELECT NAME INTO :nameResult FROM EMPLOYEE WHERE NAME LIKE '%:name%';
해결책
Declare a host variable like this: "char hLikeVar[64];". Then string copy "%[empl name]%" into it. For [empl name] use the input you got from the user. Then you can do this:
... WHERE NAME LIKE :hLikeVar;
다른 팁
so Pro * C provides varchar
structures, where you aren't required to handle many things. So if you are declaring
varchar LikeVar[Length_of_Variable];
and use
strcpy(LikeVar.arr); /* .arr is the character array */
LikeVar.len = strlen(LikeVar.arr);
after this you can use directly: with in the sql statement.