We help IT Professionals succeed at work.

How to call store procedure in pro c

khanzada19
khanzada19 asked
on
830 Views
Last Modified: 2013-12-07
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;
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2009

Commented:
Usually, you call a stored procedure something like this :

EXEC SQL EXECUTE
BEGIN
    :retval := package1.procedure2(:p1, :p2, :p3, :p4, :p5);
END;
EXEC-SQL;

Author

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.
CERTIFIED EXPERT
Top Expert 2009

Commented:
what's the definition of the stored procedure, and how are p1 through p5 defined ?

Author

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;
CERTIFIED EXPERT
Top Expert 2009

Commented:
You defined p1 through p5 as chars, and they need to be strings. Define them as VARCHAR2's in a SQL DECLARE block.

Author

Commented:
I was not able to define as VARCHAR2 but define them VARCHAR but got errors
CERTIFIED EXPERT
Top Expert 2009

Commented:
>> but got errors

What errors ? And what's your code now ?

Author

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.

CERTIFIED EXPERT
Top Expert 2009
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

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.
CERTIFIED EXPERT
Top Expert 2009

Commented:
Well, you need to specify the length of the char array ...

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.