Handle two different queries with one ref cursor

516 Views Asked by At

I have two select queries and i wanted to open cursor for both of them ?


v_str1:='SELECT ROWID FROM ' || p_tblname|| 'WHERE '|| p_cname||'='''||
       p_cvalue || '''';

v_str2:='SELECT COUNT ( * ) INTO v_cnt FROM ' || p_tblname|| 'WHERE '|| p_cname||' = '''||p_cvalue||'''';

.....

OPEN ref_cur_name FOR v_str1 LOOP

  IF v_cnt = 1
  THEN
     EXIT;
  ELSE

    EXECUTE IMMEDIATE 'DELETE FROM '||  p_tblname||
           'WHERE   ROWID = REC.ROWID';
  END IF;

  v_cnt := v_cnt - 1;

END LOOP;

First query is a select statement and other just puts the count into v_cnt . Now i need to execute both of these queries . now is there a way to use both these queries ?

Also there is a syntax error after OPEN statement i.e . at LOOP.

1

There are 1 best solutions below

0
On

Use Execute immediate

EXECUTE IMMEDIATE 'SELECT   COUNT ( * )
 INTO   v_cnt
 FROM  '                                                                                                            ||
  p_tblname||
'WHERE  '|| p_cname||' = '''||p_cvalue||'''';