• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 769
  • Last Modified:

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;
0
khanzada19
Asked:
khanzada19
  • 6
  • 5
1 Solution
 
Infinity08Commented:
Usually, you call a stored procedure something like this :

EXEC SQL EXECUTE
BEGIN
    :retval := package1.procedure2(:p1, :p2, :p3, :p4, :p5);
END;
EXEC-SQL;
0
 
khanzada19Author Commented:
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.
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
Infinity08Commented:
what's the definition of the stored procedure, and how are p1 through p5 defined ?
0
 
khanzada19Author Commented:
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;
0
 
Infinity08Commented:
You defined p1 through p5 as chars, and they need to be strings. Define them as VARCHAR2's in a SQL DECLARE block.
0
 
khanzada19Author Commented:
I was not able to define as VARCHAR2 but define them VARCHAR but got errors
0
 
Infinity08Commented:
>> but got errors

What errors ? And what's your code now ?
0
 
khanzada19Author Commented:
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.

0
 
Infinity08Commented:
Try defining them simply as char[] instead of VARCHAR[]
0
 
khanzada19Author Commented:
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.
0
 
Infinity08Commented:
Well, you need to specify the length of the char array ...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now