khanzada19
asked on
How to call store procedure in pro c
I am trying to call a store procedure in pro c (I am new to it) below, how I am passing 5 parameters and it would return a parameter. how do I store that parameter in variable in tried INTO but was getting error. Any help would be appreciated.
strcpy(sqlstmt.arr,
"SELECT package1.procedure2(:p1, "
":p2, "
":p3, "
":p4, "
":p5) "
"FROM dual");
sqlstmt.len = strlen(sqlstmt.arr);
/*EXEC SQL PREPARE S FROM :sqlstmt;*/
EXEC SQL EXECUTE sqlstmt USING :B1,
:B2,
:B3,
:B4,
:B5;
strcpy(sqlstmt.arr,
"SELECT package1.procedure2(:p1, "
":p2, "
":p3, "
":p4, "
":p5) "
"FROM dual");
sqlstmt.len = strlen(sqlstmt.arr);
/*EXEC SQL PREPARE S FROM :sqlstmt;*/
EXEC SQL EXECUTE sqlstmt USING :B1,
:B2,
:B3,
:B4,
:B5;
ASKER
I did that but now get warnings :
char retval [100];
EXEC SQL EXECUTE
BEGIN
:retval := package1.procedure2(:p1, :p2, :p3, :p4, :p5);
END;
END-EXEC;
"prog.c", line 1502.11: 1506-280 (W) Function argument assignment between types "char*" and "char" is not allowed.
"prog.c", line 1503.11: 1506-280 (W) Function argument assignment between types "char*" and "char" is not allowed.
"prog.c", line 1504.11: 1506-280 (W) Function argument assignment between types "char*" and "char" is not allowed.
"prog.c", line 1505.11: 1506-280 (W) Function argument assignment between types "char*" and "char" is not allowed.
"prog.c", line 1506.11: 1506-280 (W) Function argument assignment between types "char*" and "char" is not allowed.
char retval [100];
EXEC SQL EXECUTE
BEGIN
:retval := package1.procedure2(:p1, :p2, :p3, :p4, :p5);
END;
END-EXEC;
"prog.c", line 1502.11: 1506-280 (W) Function argument assignment between types "char*" and "char" is not allowed.
"prog.c", line 1503.11: 1506-280 (W) Function argument assignment between types "char*" and "char" is not allowed.
"prog.c", line 1504.11: 1506-280 (W) Function argument assignment between types "char*" and "char" is not allowed.
"prog.c", line 1505.11: 1506-280 (W) Function argument assignment between types "char*" and "char" is not allowed.
"prog.c", line 1506.11: 1506-280 (W) Function argument assignment between types "char*" and "char" is not allowed.
what's the definition of the stored procedure, and how are p1 through p5 defined ?
ASKER
it's a function
FUNCTION abcd(
p1 IN VARCHAR2,
p2 IN VARCHAR2,
p3 IN VARCHAR2,
p4 IN VARCHAR2,
p5 IN VARCHAR2
) RETURN VARCHAR2 IS
in pro c they as:
char p1;
char p2;
char p3;
char p4;
char p5;
FUNCTION abcd(
p1 IN VARCHAR2,
p2 IN VARCHAR2,
p3 IN VARCHAR2,
p4 IN VARCHAR2,
p5 IN VARCHAR2
) RETURN VARCHAR2 IS
in pro c they as:
char p1;
char p2;
char p3;
char p4;
char p5;
You defined p1 through p5 as chars, and they need to be strings. Define them as VARCHAR2's in a SQL DECLARE block.
ASKER
I was not able to define as VARCHAR2 but define them VARCHAR but got errors
>> but got errors
What errors ? And what's your code now ?
What errors ? And what's your code now ?
ASKER
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR sqlstmt[400];
int cid;
VARCHAR cName[100];
VARCHAR b1[100];
VARCHAR b2[100];
VARCHAR b3[100];
VARCHAR b4[100];
VARCHAR b5[100];
EXEC SQL END DECLARE SECTION;
tData Data; /* is a structuer*/
(GetName(&Data.techId, &Data.Name));
strncpy(b1,Data.Name.B1,8) ;
strncpy(b2,Data.Name.B2,8) ;
strncpy(b3,Data.Name.B3,8) ;
strncpy(b4,Data.Name.B4,8) ;
strncpy(b5,Data.Name.B5,8) ;
EXEC SQL EXECUTE
BEGIN
:cName := package.procedure(:b1
,:b2
,:b3
,:b4
,:b5);
END;
END-EXEC;
"user.c", line 1517.11: 1506-280 (S) Function argument assignment between types "char*" and "struct {...}" is not allowed.
"user.c", line 1518.11: 1506-280 (S) Function argument assignment between types "char*" and "struct {...}" is not allowed.
"user.c", line 1519.11: 1506-280 (S) Function argument assignment between types "char*" and "struct {...}" is not allowed.
"user.c", line 1520.11: 1506-280 (S) Function argument assignment between types "char*" and "struct {...}" is not allowed.
"user.c", line 1521.11: 1506-280 (S) Function argument assignment between types "char*" and "struct {...}" is not allowed.
VARCHAR sqlstmt[400];
int cid;
VARCHAR cName[100];
VARCHAR b1[100];
VARCHAR b2[100];
VARCHAR b3[100];
VARCHAR b4[100];
VARCHAR b5[100];
EXEC SQL END DECLARE SECTION;
tData Data; /* is a structuer*/
(GetName(&Data.techId, &Data.Name));
strncpy(b1,Data.Name.B1,8)
strncpy(b2,Data.Name.B2,8)
strncpy(b3,Data.Name.B3,8)
strncpy(b4,Data.Name.B4,8)
strncpy(b5,Data.Name.B5,8)
EXEC SQL EXECUTE
BEGIN
:cName := package.procedure(:b1
,:b2
,:b3
,:b4
,:b5);
END;
END-EXEC;
"user.c", line 1517.11: 1506-280 (S) Function argument assignment between types "char*" and "struct {...}" is not allowed.
"user.c", line 1518.11: 1506-280 (S) Function argument assignment between types "char*" and "struct {...}" is not allowed.
"user.c", line 1519.11: 1506-280 (S) Function argument assignment between types "char*" and "struct {...}" is not allowed.
"user.c", line 1520.11: 1506-280 (S) Function argument assignment between types "char*" and "struct {...}" is not allowed.
"user.c", line 1521.11: 1506-280 (S) Function argument assignment between types "char*" and "struct {...}" is not allowed.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Now, I am getting below if I chnage them char[]
"user.c", line 1495.9: 1506-131 (S) Explicit dimension specification or initializer required for an auto or static array.
"user.c", line 1496.9: 1506-131 (S) Explicit dimension specification or initializer required for an auto or static array.
"user.c", line 1497.9: 1506-131 (S) Explicit dimension specification or initializer required for an auto or static array.
"user.c", line 1498.9: 1506-131 (S) Explicit dimension specification or initializer required for an auto or static array.
"user.c", line 1499.9: 1506-131 (S) Explicit dimension specification or initializer required for an auto or static array.
"user.c", line 1500.9: 1506-131 (S) Explicit dimension specification or initializer required for an auto or static array.
"user.c", line 1495.9: 1506-131 (S) Explicit dimension specification or initializer required for an auto or static array.
"user.c", line 1496.9: 1506-131 (S) Explicit dimension specification or initializer required for an auto or static array.
"user.c", line 1497.9: 1506-131 (S) Explicit dimension specification or initializer required for an auto or static array.
"user.c", line 1498.9: 1506-131 (S) Explicit dimension specification or initializer required for an auto or static array.
"user.c", line 1499.9: 1506-131 (S) Explicit dimension specification or initializer required for an auto or static array.
"user.c", line 1500.9: 1506-131 (S) Explicit dimension specification or initializer required for an auto or static array.
Well, you need to specify the length of the char array ...
EXEC SQL EXECUTE
BEGIN
:retval := package1.procedure2(:p1, :p2, :p3, :p4, :p5);
END;
EXEC-SQL;