one code for two tables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Julia Sats

    one code for two tables

    Can I do something like it:

    if i = 0 then
    for cur_var in (select * from t0) loop
    else
    for cur_var in (select * from t1) loop

    /*
    a lot of lines here
    */

    end loop;



    even if I would try to do like it:

    v_refcursor refcursor;
    v_rec0 t0%rowtype;
    v_rec1 t1%rowtype;

    BEGIN
    if i = 0 then
    OPEN v_refcursor FOR SELECT * FROM t0
    else
    OPEN v_refcursor FOR SELECT * FROM t1
    end if;

    I need to use different record_variable s for FETCH and repeat my /* a lot of
    lines here */ couples time for different record variables.

    Any idea how to do code only once ?

    Thanks



  • sybrandb@yahoo.com

    #2
    Re: one code for two tables

    "Julia Sats" <julia.sats@sym patico.cawrote in message news:<mr7ab.695 4$hF3.915423@ne ws20.bellglobal .com>...
    Can I do something like it:
    >
    if i = 0 then
    for cur_var in (select * from t0) loop
    else
    for cur_var in (select * from t1) loop
    >
    /*
    a lot of lines here
    */
    >
    end loop;
    >
    >
    >
    even if I would try to do like it:
    >
    v_refcursor refcursor;
    v_rec0 t0%rowtype;
    v_rec1 t1%rowtype;
    >
    BEGIN
    if i = 0 then
    OPEN v_refcursor FOR SELECT * FROM t0
    else
    OPEN v_refcursor FOR SELECT * FROM t1
    end if;
    >
    I need to use different record_variable s for FETCH and repeat my /* a lot of
    lines here */ couples time for different record variables.
    >
    Any idea how to do code only once ?
    >
    Thanks
    Redesign your database (recommended) and get rid of this mess
    or use dynamic sql (not recommended, as you will end up with an
    unscalable application).
    Instead of hacking yourself out, like you seem to do consistently,
    please try to *learn* and use approved practices, *design* your
    programs and stop creating spaghetti.

    Sybrand Bakker
    Senior Oracle DBA

    Comment

    Working...