DYNAMIC SQL SELECTION QUESTION

Ask a Question related to Oracle Server, Design and Development.

  1. #1

    Default DYNAMIC SQL SELECTION QUESTION

    I posted a question earlier but that did not help me.

    I need to insert data from joined files A - B into C

    The tables are joined by the fields: SUN_DB & ACCOUNT_NR

    BUT!!!!

    The name of file B's is partial "variable" and comes out of file A
    field: SUN_DB

    Example:
    Row of File A: field SUN_DB = "ZZZ" so File A has to be joined
    with Table: "B_ZZZ" by the fields SUN_DB & ACCOUNT_NR

    Row of File A: field SUN_DB= "YYY" so File A has to be joined
    with Table: "B_YYY" by the fields SUN_DB & ACCOUNT_NR

    There are +- 700 SUN_DB codes and so 700 TABLES TO JOIN WITH
    IN SHORT I need to run +-700 joines between Table A and variable Table
    Name B named: SALFLDG'||SUN_DB||'

    Do I make myself clear?

    I use the following script but some say it is far too complex for I
    try to achieve. For me this script is working fine but it is ignoring
    the following conditions "AND ACCNT_TYPE <> 'P' AND ANAL_A0 LIKE
    'ABNA%'; "
    Can anyone explain me why?

    DECLARE retval INTEGER; CURSOR obj_cur IS

    SELECT DISTINCT 'INSERT INTO C_SPIN (SUN_DB, ACCNT_CODE, TRANS_DATE,
    AMOUNT, ANAL_A0, ANAL_T0)

    SELECT SSRFACC.SUN_DB,SRFACC.ACCNT_CODE,TRANS_DATE,
    AMOUNT,SSRFACC.ANAL_A0, ANAL_T0 FROM SSRFACC,SALFLDG'||SUN_DB||'

    WHERE SSRFACC.ACCNT_CODE = SALFLDG'||SUN_DB||'.ACCNT_CODE AND
    SSRFACC.SUN_DB ='''||SUN_DB||''' ' CMDSQL
    FROM SSRFACC

    WHERE SUN_DB LIKE 'B%' AND ACCNT_TYPE <> 'P' AND ANAL_A0 LIKE
    'ABNA%';

    drop_cursor INTEGER;
    out_str VARCHAR2(1000);
    BEGIN FOR obj_rec IN obj_cur LOOP drop_cursor :=
    DBMS_SQL.OPEN_CURSOR;
    out_str := obj_rec.cmdsql;
    DBMS_SQL.PARSE (drop_cursor, out_str,
    DBMS_SQL.NATIVE);
    retval := dbms_sql.EXECUTE(drop_cursor);
    DBMS_SQL.CLOSE_CURSOR (drop_cursor);
    END LOOP;
    END;


    ITAPORT06 Guest

  2. Similar Questions and Discussions

    1. Taking Action on Dynamic Menu Selection
      :embarrassment; How do i get an action to take place when a menu item is selected from a dynamic menu? I want to move to a specific record item in...
    2. Dynamic selection of RadioButton
      Hi All, I have a requirement wherein I need to dynamically select a RadioButton of mxml form on page load. The database would be queried on page...
    3. Dynamic Drop Down Dependent on another Selection
      FORM has 2 List/Menu elements First is ParentCategory Second is SubCategory How can the SubCategory list be populated by only those...
    4. Dynamic font selection
      Hi I am looking into ways of producing a system that allows users to input a line of text then select from a list of fonts and then see the...
    5. Dynamic selection with php/mysql/javascript?
      On Tue, 29 Jul 2003 17:48:54 -0500, Roger Lin wrote: sorry for this useless post...but ... have you tried google??? some usefull links:...
  3. #2

    Default Re: DYNAMIC SQL SELECTION QUESTION

    ITAPORT06 wrote:
    [...]
    >
    > Example:
    > Row of File A: field SUN_DB = "ZZZ" so File A has to be joined
    > with Table: "B_ZZZ" by the fields SUN_DB & ACCOUNT_NR
    >
    > Row of File A: field SUN_DB= "YYY" so File A has to be joined
    > with Table: "B_YYY" by the fields SUN_DB & ACCOUNT_NR
    >
    > There are +- 700 SUN_DB codes and so 700 TABLES TO JOIN WITH
    > IN SHORT I need to run +-700 joines between Table A and variable Table
    > Name B named: SALFLDG'||SUN_DB||'
    >
    Hello ITAPORT06,
    maybe it's worth to rethink your database design. What about putting all
    700 tables into one adding a column sun_db so that you can join on this
    column? This would eliminate the need for dynamic SQL altogether.
    > Do I make myself clear?
    >
    > I use the following script but some say it is far too complex for I
    > try to achieve. For me this script is working fine but it is ignoring
    > the following conditions "AND ACCNT_TYPE <> 'P' AND ANAL_A0 LIKE
    > 'ABNA%'; "
    > Can anyone explain me why?
    >
    > DECLARE retval INTEGER; CURSOR obj_cur IS
    >
    > SELECT DISTINCT 'INSERT INTO C_SPIN (SUN_DB, ACCNT_CODE, TRANS_DATE,
    > AMOUNT, ANAL_A0, ANAL_T0)
    >
    > SELECT SSRFACC.SUN_DB,SRFACC.ACCNT_CODE,TRANS_DATE,
    > AMOUNT,SSRFACC.ANAL_A0, ANAL_T0 FROM SSRFACC,SALFLDG'||SUN_DB||'
    >
    > WHERE SSRFACC.ACCNT_CODE = SALFLDG'||SUN_DB||'.ACCNT_CODE AND
    > SSRFACC.SUN_DB ='''||SUN_DB||''' ' CMDSQL
    > FROM SSRFACC
    >
    > WHERE SUN_DB LIKE 'B%' AND ACCNT_TYPE <> 'P' AND ANAL_A0 LIKE
    > 'ABNA%';
    >
    > drop_cursor INTEGER;
    > out_str VARCHAR2(1000);
    > BEGIN FOR obj_rec IN obj_cur LOOP drop_cursor :=
    > DBMS_SQL.OPEN_CURSOR;
    > out_str := obj_rec.cmdsql;
    > DBMS_SQL.PARSE (drop_cursor, out_str,
    > DBMS_SQL.NATIVE);
    > retval := dbms_sql.EXECUTE(drop_cursor);
    > DBMS_SQL.CLOSE_CURSOR (drop_cursor);
    > END LOOP;
    > END;
    >
    I don't see why the where condition is not executed but there is
    something that you can improve:
    I would put the dbms_sql.open_cursor and dbms_sql.close_cursor out of
    the loop. A SQL cursor can be used for more than one SQL. You can reuse
    it just by parsing a new SQL.
    Maybe it would help to output the SQLs using dbms_output to see what's
    wrong.
    Eventually, you might have a look at the execute immediate feature of
    Oracle 8i and up. This is a bit easier to handle and according to the
    docs it is more performant.

    Hope that helps,
    Lothar
    --
    Lothar Armbrüster | [email]la@oktagramm.de[/email]
    Hauptstr. 26 | [email]la@heptagramm.de[/email]
    D-65346 Eltville | [email]lothar.armbruester@t-online.de[/email]
    Lothar Armbruester Guest

  4. #3

    Default Re: DYNAMIC SQL SELECTION QUESTION

    Lothar & Paul thank your for yor contribution but my prblem is still
    not solved.

    Paul: Yes the application I want to extract data from is Systems
    Union Sun. So you are aware of the database structure. The dynamic sql
    statement underneath works fine BUT I only have one problem is the
    statement almost at the end of the script:
    >WHERE SUN_DB LIKE 'B%' AND ACCNT_TYPE <> 'P' AND ANAL_A0 LIKE
    >'ABNA%';
    It does NOT ignore SUN_DB Like B% BUT is does ignore ACCNT_TYPE <>
    'P' AND ANAL_A0 LIKE 'ABNA%'

    It does not select records on the last 2 argument
    Why is that and how can Isolve this?
    Thanks



    On Tue, 01 Jul 2003 23:06:24 +0200, ITAPORT06 <mokat67@hotmail.com>
    wrote:
    >I posted a question earlier but that did not help me.
    >
    >I need to insert data from joined files A - B into C
    >
    >The tables are joined by the fields: SUN_DB & ACCOUNT_NR
    >
    >BUT!!!!
    >
    >The name of file B's is partial "variable" and comes out of file A
    >field: SUN_DB
    >
    >Example:
    >Row of File A: field SUN_DB = "ZZZ" so File A has to be joined
    >with Table: "B_ZZZ" by the fields SUN_DB & ACCOUNT_NR
    >
    >Row of File A: field SUN_DB= "YYY" so File A has to be joined
    >with Table: "B_YYY" by the fields SUN_DB & ACCOUNT_NR
    >
    >There are +- 700 SUN_DB codes and so 700 TABLES TO JOIN WITH
    >IN SHORT I need to run +-700 joines between Table A and variable Table
    >Name B named: SALFLDG'||SUN_DB||'
    >
    >Do I make myself clear?
    >
    >I use the following script but some say it is far too complex for I
    >try to achieve. For me this script is working fine but it is ignoring
    >the following conditions "AND ACCNT_TYPE <> 'P' AND ANAL_A0 LIKE
    >'ABNA%'; "
    >Can anyone explain me why?
    >
    >DECLARE retval INTEGER; CURSOR obj_cur IS
    >
    >SELECT DISTINCT 'INSERT INTO C_SPIN (SUN_DB, ACCNT_CODE, TRANS_DATE,
    >AMOUNT, ANAL_A0, ANAL_T0)
    >
    >SELECT SSRFACC.SUN_DB,SRFACC.ACCNT_CODE,TRANS_DATE,
    >AMOUNT,SSRFACC.ANAL_A0, ANAL_T0 FROM SSRFACC,SALFLDG'||SUN_DB||'
    >
    >WHERE SSRFACC.ACCNT_CODE = SALFLDG'||SUN_DB||'.ACCNT_CODE AND
    >SSRFACC.SUN_DB ='''||SUN_DB||''' ' CMDSQL
    >FROM SSRFACC
    >
    > >>>>>>>>>>>>>>>>>>>>>>>>>>WHERE SUN_DB LIKE 'B%' AND ACCNT_TYPE <> 'P' AND ANAL_A0 LIKE
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'ABNA%';
    >
    >drop_cursor INTEGER;
    >out_str VARCHAR2(1000);
    >BEGIN FOR obj_rec IN obj_cur LOOP drop_cursor :=
    >DBMS_SQL.OPEN_CURSOR;
    >out_str := obj_rec.cmdsql;
    >DBMS_SQL.PARSE (drop_cursor, out_str,
    >DBMS_SQL.NATIVE);
    >retval := dbms_sql.EXECUTE(drop_cursor);
    >DBMS_SQL.CLOSE_CURSOR (drop_cursor);
    >END LOOP;
    >END;
    >
    ITAPORT06 Guest

  5. #4

    Default Re: DYNAMIC SQL SELECTION QUESTION

    "ITAPORT06" <mokat67@hotmail.com> wrote in message
    news:m37ggv4qq86sg5q3v970bhjet1ran14ui7@4ax.com...
    > Lothar & Paul thank your for yor contribution but my prblem is still
    > not solved.
    >
    > Paul: Yes the application I want to extract data from is Systems
    > Union Sun. So you are aware of the database structure. The dynamic sql
    > statement underneath works fine BUT I only have one problem is the
    > statement almost at the end of the script:
    >
    Sorry, I didn't really check the original SQL; I responded to the
    'Redesign!' comment.
    As to the original problem, is it an issue with nulls?

    Regards,
    Paul



    Paul Brewer Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139