Domanda

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%';
È stato utile?

Soluzione

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;

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top