-1

I have a procedure like that:

CREATE PROCEDURE   PROCEDURE1 (var1 type1)
INSERT INTO TEMP
select * from table1 where Huge_Expression1 AND  condition1 
select * from table1 where Huge_Expression1 AND  condition2  
select * from table1 where Huge_Expression1 AND  condition3
.. 
select * from table1 where Huge_Expression2 AND  condition1 
select * from table1 where Huge_Expression2 AND  condition2  
select * from table1 where Huge_Expression2 AND  condition3
..
select * from table1 where Huge_Expression3 AND  condition1 
select * from table1 where Huge_Expression3 AND  condition2  
select * from table1 where Huge_Expression3 AND  condition3
END   PROCEDURE

The problem is that the procedure is very bulky and difficult to debug.

My effort was as follows:

#!/bin/bash
# file name is script1

condH[1]="Huge_Expression1"
condH[2]="Huge_Expression2"
condH[3]="Huge_Expression3"

Run_Proc() {
    dbaccess $dbname << EOF

   CREATE PROCEDURE   PROCEDURE (var1 type1)

   INSERT INTO TEMP

   FOR i = 1 TO 3
    select * from table1 where ${condH[i]} AND  condition1
    select * from table1 where ${condH[i]} AND  condition2
    select * from table1 where ${condH[i]} AND  condition3
    ..
   END fOR

   END PROCEDURE
   ---
   execute procedure PROCEDURE1(var1)
   EOF
   }
   
   Run_Proc $dbname
   #
   #Which is executed in the shell in this way
   ./script1 database1

Unfortunately, the term read from the array i.e. ${} is not interpreted inside the procedure

I also tried to solve the problem by making two procedures and calling one of them and arguing the condition, but the condition was not in the form of a boolean but in the form of a string ,Like defining an array inside a procedure.

can anybody help?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.