execute immediate missing right parentheses error

1.3k views Asked by At

I have code like below in my procedure. When I call the procedure, there is missing right parentheses error. When I test it outside the procedure, with no execute immediate clause, it works fine. Would anyone help me pls to eliminate the mistake?

EXECUTE IMMEDIATE '
  INSERT INTO prehledcen
    (id_obchodu
    ,id_obchodu_poradi
    ,smer
    ,typceny
    ,vzdalenost
    ,hodnotaceny
    ,kid)
    SELECT a.id_obchodu
          ,a.id_obchodu_poradi
          ,smer
          ,''PredchoziLast''
          ,predchozi_last_time - datum_obchodu
          ,predchozi_last
          ,kid
        FROM middle_office.f_d_obchody_zmeny_test a
   INNER JOIN (SELECT id_obchodu
                     ,id_obchodu_poradi
                     ,MAX(dwh_insert_process) dwh_insert_process
                     ,MIN(insert_sysdate) insert_sysdate
                 FROM middle_office.f_d_obchody_zmeny_test b
                GROUP BY id_obchodu
                        ,id_obchodu_poradi) b
      ON b.id_obchodu = a.id_obchodu
     AND b.id_obchodu_poradi = a.id_obchodu_poradi
     AND a.dwh_insert_process = b.dwh_insert_process
   WHERE (datum_obchodu >= ' || v_datum_od || ' OR
         (datum_obchodu < ' || v_datum_od || ' AND  b.insert_sysdate >= ' || v_datum_od || '))';
1

There are 1 answers

0
Wernfried Domscheit On BEST ANSWER

I assume you have bad values for v_datum_od. Try this one:

EXECUTE IMMEDIATE '
  INSERT INTO prehledcen
  ...
   WHERE (datum_obchodu >= :d1 OR (datum_obchodu < :d2 AND b.insert_sysdate >= :d3))' 
USING v_datum_od, v_datum_od, v_datum_od;