Dynamic Query and Collect Statement.

Hi Gurus....
Please explain me how to write dynamic Query,,, Pl. give me with example.
Also would like to know basics of Collect statement and it's use..
Thanks
Ritesh

Hi Ritesh,
COLLECT is used to create unique or compressed datsets. The key fields are the default key fields of the internal table itab . If all non-numeric fields are same in the internal table then it will add numeric fields and maintains a single entry
If you use only COLLECT to fill an internal table, COLLECT makes sure that the internal table does not contain two entries with the same default key fields.
Check this link to know about COLLECT statement
http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/collect.htm
Dynamic query can be built in SAP with the help of () values.
DATA:
V_TABNAME TYPE DDO2L-TABNAME,
V_CONDTION TYPE STRING.
V_TABNAME = 'MARA'.
V_CONDTION = 'MATNR LIKE 'S*'.
SELECT MATNR
  FROM <b>(V_TABNAME)</b>
  INTO TABLE ITAB
WHERE <b>(V_CONDTION)</b>.
Thanks,
Vinay

Similar Messages

  • Dynamic query and Open Cursor fetch into ??

    Hi;
    I think we took the wrong turn some were... because looks like a dead end...
    What I need to do:
    Create a procedure to compare two generic tables in diferente databases and find rows that have diferent data.
    (No restritions on what tables it might compare)
    What I have done:
    CREATE OR REPLACE PROCEDURE COMPARE_TABLES_CONTENT_V3(
    tableName_A IN VARCHAR2, tableName_B IN VARCHAR2, filter IN VARCHAR2) AS
    -- Get all collumns present in [TableName_A]
    -- This is necessary to create a dynamic query
    select column_name bulk collect
    into v_cols1
    from all_tab_columns
    where table_name = v_tab1
    and owner = nvl(v_own1, user)
    order by column_id;
    -- If there is no columns in table A ... them no need to proceed
    if v_cols1.count = 0 then
    dbms_output.put_line('[Error] reading table ' || tableName_A ||
    ' collumns information. Exit...');
    return;
    end if;
    -- Collect Collumns information by ',' separated, for the query
    for i in 1 .. v_cols1.count loop
    compareCollumns := compareCollumns || ',' || v_cols1(i);
    end loop;
    -- Create the query that gives the diferences....
    getDiffQuery := 'select ' || compareCollumns ||
    ' , count(src1) CNT1, count(src2) CNT2 from (select a.*, 1 src1, to_number(null) src2 FROM ' ||
    tableName_A ||
    ' a union all select b.*, to_number(null) src1, 2 src2 from ' ||
    tableName_B || ' b) group by ' || compareCollumns ||
    ' having count(src1) <> count(src2)';
    Whats the problem?
    I'm lost...I can access the query using debugging on the oracle procedure... and run it OK on a new SQL window. No problem here... its perfect.
    But I dont know how to access this information inside the procedure, I need to format the information a bit...
    I try a cursor...
    open vCursor for getDiffQuery;
    fetch vCursor into ??????? -- Into what... query, columns and tables is all dynamic...
    close vCursor;
    Any ideas..

    Making the issue more simple....
    At this point I have a oracle procedure that generates a dynamic sql query, based on the table names passed by parameter.
    getDiffQuery := 'select ' || compareCollumns || (.....)
    end procedure;
    This ''getDiffQuery'' contains a query that gets the diferences in the tables. (Working fine)
    I would like to access this information in the same procedure.
    I cant use cursor because the table, columns... actualy all is dynamic based on the generated query:( !

  • Dynamic Query and default run-time values

    I am trying to build a dynamic query within dreamweaver and
    retain access from the bindings panel.
    here is a simple pseudo-query I want to expand on.
    "SELECT object FROM objects_table WHERE widget_number =
    widgets"
    widgets is set up as a variable with a run-time value that
    relates to $_GET['widgets']
    this works fine but now i want to expand on this so the query
    returns all results if $_GET['widgets'] is undefined. I was hoping
    I could set the default value for widgets to equal widget_number so
    I would get....
    "SELECT object FROM objects_table WHERE widget_number =
    widget_number" but the runtime query is actually
    "SELECT object FROM objects_table WHERE widget_number =
    'widget_number' " which obviously doesn't work.
    I can alter the query manually from the code view but then I
    lose access to the bindings panel as dreamweaver doesn't parse the
    query properly.
    Any pointers?
    Thanks in advance
    - Andrew

    Andy Millne wrote:
    > That will work fine server-side yeah but dreamweaver
    cannot parse the code at
    > design time so by altering the code in this way you lose
    access to the bindings
    > panel and all the server behaviours that depend on the
    recordset have
    > exclamation marks alongside.
    This is simply a question of organizing your workflow. As you
    have
    discovered, Dreamweaver no longer recognizes a recordset if
    you make
    changes to the basic structure of the code. The answer is to
    use
    Dreamweaver to construct your page using an unaltered
    recordset. Once
    the design stage is complete, make the changes required by
    inserting
    your conditional statement. Yes, the fieldnames disappear
    from the
    Bindings panel, and you get exclamation marks in the Server
    Behaviors
    panel, but that's not important. If you need to restore them
    for any
    reason, just wrap the changes in /* */ comments. Remove the
    comments
    when you have finished.
    David Powers, Adobe Community Expert
    Author, "The Essential Guide to Dreamweaver CS3" (friends of
    ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • Dynamic query and parameters

    Hi there,
    I have created a procedure and passing values via parameters but then the sql statement takes it as a string rather than parameters. Could you please let me know what it is that I am doing wrong.
    Code is as follows:
    CREATE OR REPLACE FUNCTION GetTableData(p_vInTname IN VARCHAR2
      ,p_dInLastPubTms IN DATE
    RETURN CLOB
    IS
      vStrSqlQuery VARCHAR2(32767);
      TYPE ref_cursor IS REF CURSOR;
      rc_tablevalues ref_cursor;
      lc_XML CLOB;
    BEGIN
      vStrSqlQuery:= q'[SELECT dbms_xmlgen.getxml('SELECT * FROM p_vInTname ' ||' WHERE record_update_tms >= TO_DATE(p_dInLastPubTMS,'MM/DD/YYYY HH24:MI:SS')) FROM dual]';
      DBMS_OUTPUT.put_line(vStrSqlQuery);
      OPEN rc_tablevalues FOR vStrSqlQuery;
      FETCH rc_tablevalues INTO lc_XML;
      CLOSE rc_tablevalues;
      RETURN lc_XML;
      printClob(lc_XML);
    END GetTableData;
    This compiled successfully.
    Another procedure for printing
    Create or replace PROCEDURE printClob (result IN OUT NOCOPY CLOB) IS
        xmlstr   VARCHAR2 (32767);
        line     VARCHAR2 (2000);
      BEGIN
        xmlstr := DBMS_LOB.SUBSTR (result, 32767);
        LOOP
           EXIT WHEN xmlstr IS NULL;
           line := SUBSTR (xmlstr, 1, INSTR (xmlstr, CHR (10)) - 1);
           DBMS_OUTPUT.put_line ('| ' || line);
           xmlstr := SUBSTR (xmlstr, INSTR (xmlstr, CHR (10)) + 1);
        END LOOP;
      END printClob;
    I am trying to test it to see how it behaves, so created a test procedure which is:
    CREATE OR REPLACE PROCEDURE SANDEEP_TEST_LAMXML
    IS
    lv_x CLOB;
    BEGIN
      lv_x := CTN_PUB_CNTL_EXTRACT_PUBLISH.GetTableData('TRKFCG_SBDVSN',TO_DATE('04/27/2015 19:57:10', 'MM/DD/YYYY HH24:MI:SS'));
    END;
    The above one too compiles successfully. However when I set a break point and then try to pass through the function instead of seeing the parameter in the second part of the query, I am seeing it as:
    SELECT dbms_xmlgen.getxml('SELECT * FROM p_vInTname ' ||' WHERE record_update_tms >= TO_DATE(p_dInLastPubTMS,'MM/DD/YYYY HH24:MI:SS')) FROM dual
    What is that I am doing wrong that I am unable to see the runtime parameters being passed into the variables of the query? Can any one suggest something? I am handling dynamic queries and also a solution such as the above for the first time.
    Thanks in advance.

    There are quite a few errors and here's a working version:
    CREATE OR REPLACE FUNCTION GetTableData(p_vInTname IN VARCHAR2
      ,p_dInLastPubTms IN VARCHAR2
    RETURN CLOB
    IS
      vStrSqlQuery VARCHAR2(32767);
      TYPE ref_cursor IS REF CURSOR;
      rc_tablevalues ref_cursor;
      lc_XML CLOB;
    BEGIN 
      vStrSqlQuery:= q'[SELECT dbms_xmlgen.getxml('SELECT * FROM ]'||p_vInTname||q'[ WHERE record_update_tms >= TO_DATE('']'||p_dInLastPubTMS||q'['',''MM/DD/YYYY HH24:MI:SS'')') FROM dual]';
      DBMS_OUTPUT.put_line(vStrSqlQuery);
      OPEN rc_tablevalues FOR vStrSqlQuery;
      FETCH rc_tablevalues INTO lc_XML;
      CLOSE rc_tablevalues;
      printClob(lc_XML);
      RETURN lc_XML;
    END GetTableData;
    CREATE OR REPLACE PROCEDURE SANDEEP_TEST_LAMXML
    IS
    lv_x CLOB;
    BEGIN
      lv_x := GetTableData('TRKFCG_SBDVSN','04/27/2015 19:57:10');
    END;
    This version will be easier to understand:
    CREATE OR REPLACE FUNCTION GetTableData(p_vInTname IN VARCHAR2 
      ,p_dInLastPubTms IN VARCHAR2 
    RETURN CLOB 
    IS 
      vStrSqlQuery VARCHAR2(32767); 
      TYPE ref_cursor IS REF CURSOR; 
      rc_tablevalues ref_cursor; 
      lc_XML CLOB; 
    BEGIN  
      vStrSqlQuery:= 'SELECT * FROM '||p_vInTname||' WHERE record_update_tms >= TO_DATE('''||p_dInLastPubTMS||''',''MM/DD/YYYY HH24:MI:SS'')';
      DBMS_OUTPUT.put_line(vStrSqlQuery); 
    SELECT dbms_xmlgen.getxml(vStrSqlQuery)
      INTO lc_XML
      FROM dual;
      printClob(lc_XML); 
      RETURN lc_XML; 
    END GetTableData; 

  • Select query and Insert statement performance

    Hi all,
    Can anyone plz guide us on below problem I am facing ?
    1) One of the simple Insert statement runs very slow..What might be the reason? Its simple table without any LOBs ,LONG or so. Everything else in the DB works fine.
    2) one of the SELECT statement runs very slow. It selects all records (around 1000) from a table..How can i improve its performance?
    3)Which columns in the Master and its detail tables should be indexed to improve Query performance on them.
    Many Thanks
    Regards
    sandeep

    To get an answer to your questions you have to post some informations about your system:
    1. operating system
    2. RAM
    3. oracle version
    4. init.ora
    Thomas

  • Dynamic forms and collection.

    Hello,
    In one of your postings you’ve explained that the collections won't work with dynamic forms.  The collection will only "see" the first instance of the subform.  You've provide link to the sample, but it does not longer work  :
    http://my.adobe.acrobat.com/p52549088/. 
    This sample shows how to manually encode data into barcode from a subform that repeats. Can you please provide a working link or sample? Is there any other suggestion on how to link barcodes on dynamic forms?
    Regards,

    Hello Dave,
    I can't say I've seen issue 1 before and would recommend contacting support.
    For item 2 I would suggest wrapping your 'line' of text in a subform then creating a script to use the setInstance method for that subform.
    Let's say you had a subform named "TextLine" (which contained a text field), a numeric field called "NumberOfLines" and a button called "SetLines". You would likely want to have javascript code on the SetLines button click event much like:
    TextLine.instanceManager.setInstances(NumberOfLines,rawValue);
    You will want to save this form as a Dynamic PDF before previewing and you will want to ensure that TextLine allows for more than one occurence (found under Object - Binding, Allow Subform to Repeat when you have that subform selected).
    You may also want to put in some validation against the NumberOfLines field to ensure it has a value.
    I hope that helps.

  • Performance Measure - Select SUM and Collect Statement.

    Dear All,
    I am using YNME_PROCESS_PO_CUST Badi in this i writing some validation Delivery Completion.
    For that i need to calculate GR qty and Delivery quantity based on this i need some validation. But here i confussed which statement i need to use for bast performance.
    Note: In Badi Item Level Data will be process one by one..like item level 10 then 20 then 30......Like that
    Code will like that---
    SELECT  SUM( menge )  FROM ekes
                                INTO  l_delqty
                                WHERE ebeln =  ls_mepoitem-ebeln
                                AND   ebelp =    ls_mepoitem-ebelp.
            SELECT  SUM( dabmg  )  FROM ekes
                             INTO  l_grqty
                             WHERE ebeln =  ls_mepoitem-ebeln
                             AND   ebelp =  ls_mepoitem-ebelp.
            l_delqty1 =  l_grqty - l_delqty.
            IF l_delqty1 NE 0.
              ls_mepoitem-elikz = ''.
              CALL METHOD im_item->set_data( ls_mepoitem ).
            ENDIF.
    I check in SE38 response is better in this code.
    Other code may be like that .. same data will be like upper/
          SELECT * FROM ekes
                     INTO CORRESPONDING FIELDS OF TABLE it_ekes
                     WHERE ebeln =  ls_mepoitem-ebeln
                     AND    ebelp =   ls_mepoitem-ebelp.
          LOOP AT it_ekes.
            MOVE-CORRESPONDING it_ekes TO it_ekes1.
            COLLECT it_ekes1.
            CLEAR  it_ekes.
          ENDLOOP.
          READ TABLE it_ekes1 INDEX 1.
          IF sy-subrc EQ 0.
            l_delqty1 =  it_ekes1-menge - it_ekes1-dabmg.
          ENDIF.
        IF l_delqty1 NE 0.
              ls_mepoitem-elikz = ''.
              CALL METHOD im_item->set_data( ls_mepoitem ).
       ENDIF.
    Can any send me document--
    Regard
    DK

    Hi,
    Single Select statement is certainly better.
    But no need to do select * and using into corresponding fields. These will reduce the performance. Also the loop statment is not absolutely correct. Following could be a sample code.
    TYPES: BEGIN OF gx_ekes,  (maintaining same sequence of fields as in select statement, this way no need of into corresponding fields)
                 ebeln type ebeln,
                 ebelp type ebelp,
                 menge type bbmng,
                 dabmg type dabmg,
                 END OF gx_ekes.
    DATA : lit_ekes TYPE TABLE OF gx_ekes,
                git_ekes TYPE TABLE OF gx_ekes,
                wa_ekes TYPE gx_ekes.
    SELECT ebeln
                  ebelp
                  menge
                  dabmg
    FROM ekes
      INTO TABLE it_ekes
    WHERE ebeln = ls_mepoitem-ebeln
    AND ebelp = ls_mepoitem-ebelp.
    LOOP AT lit_ekes INTO wa_ekes.
    COLECT wa_ekes INTO git_ekes.
    CLEAR: wa_ekes.
    ENDLOOP.
    CLEAR: lit_ekes.
    Now the first record in git_ekes will have the sum as only one line item is being passed in the user exit.
    Regards,
    Pranav.

  • Prallel query and Delete statements

    Hi Gurus, need your help in understanding parallel execution
    We are noticing that delete statements are executing very slowly when parallel query is forced. Is this expected?
    All the literature that I read says that parallel query has no impact on DML statements. Yet, the query plan on the delete statement shows that it will be executed in parallel mode. This could mean that the scan portion is happening in parallel but the delete operation itself is happening in serial, correct?
    I tested in various servers and multiple tables before posting my question here. They all seem to show consistent results. Delete statements are twice slower when parallel query is forced. The same happens when parallel degree is set in table definition.
    For your information, we are running 10g on windows server with 15 million rows in table, 5 million rows being deleted with the statement. There is one index on the table and it doesn’t match the columns in query. Query plan shows full table scan. Table is not portioned.
    Thanks for your help in advance

    Parallel DML is supported by Oracle. Obviously when enabled, it can impact a DML statement.. (what literature have you read that said otherwise?)
    The delete operation itself is done in parallel using rowid ranges (e.g. each PQ slave process does a distinct physical "piece" of the table).
    Parallel DML should typically speed up the process. Why? Because I/O itself has latency. The process needs to wait (idle CPU time) for the I/O operation to complete before continuing.
    So let's assume the process can only do a 100 deletes per second. The actual I/O channel is capable of a 1000 I/O's per second. But due to inherant latency, the "max delete speed limit" for a procces is a 100 I/O's per second. The full capacity of the I/O channel is thus not used (and cannot be used by a single process).
    Parallel Query enables more processes to do I/O in order to utilise this "max speed limit".
    Why would you see a degradation in performance? It could be due to overutilising the I/O channels (attempting to go faster than the speed limit so to say).
    It could be due to some other contention in Oracle or even the o/s. You will need to investigate the wait state and events of the PQ processes to try and determine the probable cause.

  • How to query and revoke Statements Auditing (11g and higher)

    HI,
    When I choose the OS/XML Standard Auditing:
    1) Which views allow me to see what statement auditing have been created?
    For instance: audit all on scott.emp by access.
    2) How to revoke a statement auditing like: audit all on scott by access?
    Thanks and Regards.

    I don't understand... have you tried it?
    07:14:57 SQL> select * from user_obj_audit_opts;
    no rows selected
    Elapsed: 00:00:00.03
    07:14:58 SQL> audit all on junk by access;
    Audit succeeded.
    Elapsed: 00:00:00.03
    07:15:12 SQL> select * from user_obj_audit_opts;
    OBJECT_NAME                    OBJECT_TYPE             ALT       AUD       COM       DEL       GRA       IND       INS       LOC       REN       SEL       UPD       REF EXE       CRE       REA
    WRI       FBK
    JUNK                           TABLE                   A/A       A/A       A/A       A/A       A/A       A/A       A/A       A/A       A/A       A/A       A/A       -/- -/-       -/-       -/-
    -/-       A/A
    1 row selected.
    Elapsed: 00:00:00.12
    07:16:46 SQL> noaudit all on junk;
    Noaudit succeeded.
    Elapsed: 00:00:00.03
    07:16:56 SQL> select * from user_obj_audit_opts;
    no rows selected
    Elapsed: 00:00:00.02
    07:17:03 SQL>
    'ALL' is a shortcut for naming all of the relevant options: ALTER, SELECT, DELETE, etc.

  • Help with MYSQLi Query and WHILE statement

    Hi,
    Not sure what is wrong here but the same record is printed in the while loop 11 times (the amount of records in the table).
    <?php 
    //Main Connection & Query
    //Database Connection & Error
    $con_host = 'X';
    $con_username = 'X';
    $con_password = 'X';
    $con_database = 'X';
    $con = mysqli_connect($con_host, $con_username, $con_password, $con_database);
    ?>
    <?php
    //Query
    $sql = "SELECT * FROM equipment ORDER BY name ASC";
    $query = mysqli_query($con, $sql);
    $row = mysqli_fetch_assoc($query);
    $row_count = mysqli_num_rows($query);
    //Create Variables
    $name = $row['name'];
    $size = $row['size'];
    $quantity = $row['quantity'];
    $protection = $row['protection'];
    $location = $row['location'];
    $sublocation = $row['sublocation'];
    $bc = $row['BC'];
    $id = $row['id'];
    ?>
    <!doctype html>
    <html>
    <link href="stylesheets/main_stylesheet.css" rel="stylesheet" type="text/css">
    <link href='http://fonts.googleapis.com/css?family=Slabo+27px' rel='stylesheet' type='text/css'>
    <!-- Favicon -->
    <link rel="shortcut icon" type="image/png" href="images/icon.png" />
    <style type="text/css">
    </style>
    <head>
    <meta charset="utf-8">
    <title>Print Equipment List</title>
    <link href="stylesheets/print_stylesheet.css" rel="stylesheet" type="text/css">
    <script src="sorttable.js"></script>
    <!--<body onload="window.print()">-->
    </head>
    <body>
    <div class="print_button no-print" onClick="window.print()">Print</div>
    <div class="print_text no-print">Select the sorting of the list by clicking on the table categories and click the print button below</div>
    <div class="print_a4page">
      <div class="print_header">
         <div class="print_header_logo"><img src="images/logo.png" width="306" height="43"></div>
          <div class="print_header_text" id="header_text">Drama Database</div>
          <div class="print_header_info">List printed: <script type="text/javascript">
      var currentTime = new Date();
      var month = currentTime.getMonth() + 1;
      var day = currentTime.getDate();
      var year = currentTime.getFullYear();
      document.write(day + "/" + month + "/" + year);</script>
      <br>
    Total records:
    <?php echo $row_count ?></div>
      </div>
        <div class="print_header_divider">Equipment List</div>
        <div class="print_body">
          <div>
            <form name="users" method="post">
              <div class="table_print">
              <table width="100%" border="0" cellpadding="5" class="sortable">
                <tr class="table_header_print">
                  <th width="15%" scope="col">Name</th>
                  <th width="12%" scope="col">Size</th>
                  <th width="9%" scope="col">Quantity</th>
                  <th width="12%" scope="col">Protection</th>
                  <th width="17%" scope="col">Location</th>
                  <th width="12%" scope="col">Sublocation</th>
                  <th width="11%" scope="col">Barcode</th>
                  <th width="12%" scope="col">Internal ID</th>
                </tr>
                <?php do { ?>
                <tr class="table_body">
                  <td><?php echo $name ?></td>
                  <td><?php echo $size ?></td>
                  <td><?php echo $quantity ?></td>
                  <td><?php echo $protection ?></td>
                  <td><?php echo $location ?></td>
                  <td><?php echo $sublocation ?></td>
                  <td><?php echo $bc ?></td>
                  <td><?php echo $id ?></td>
                </tr>
                <?php } while ($row = mysqli_fetch_assoc($query));?>
              </table>
            </form>
          </div>
        </div>
    </div>
    </body>
    </html>

    Still getting the same issue.
    As I see it, the way you have suggested is just rearanging things right?
    here is a screenshot of the outcome:
    And here is the improved code:
    <?php 
    //Main Connection & Query
    //Database Connection & Error
    $con_host = 'X';
    $con_username = 'X';
    $con_password = 'X';
    $con_database = 'X';
    $con = new mysqli($con_host, $con_username, $con_password, $con_database);
    ?>
    <?php
    //Query
    $sql = "SELECT * FROM equipment ORDER BY name ASC";
    $result = $con->query($sql);
    $row = $result->fetch_assoc();
    $row_count = $result->num_rows;
    //Create Variables
    $name = $row['name'];
    $size = $row['size'];
    $quantity = $row['quantity'];
    $protection = $row['protection'];
    $location = $row['location'];
    $sublocation = $row['sublocation'];
    $bc = $row['BC'];
    $id = $row['id'];
    ?>
    <!doctype html>
    <html>
    <link href="stylesheets/main_stylesheet.css" rel="stylesheet" type="text/css">
    <link href='http://fonts.googleapis.com/css?family=Slabo+27px' rel='stylesheet' type='text/css'>
    <!-- Favicon -->
    <link rel="shortcut icon" type="image/png" href="images/icon.png" />
    <style type="text/css">
    </style>
    <head>
    <meta charset="utf-8">
    <title>Print Equipment List</title>
    <link href="stylesheets/print_stylesheet.css" rel="stylesheet" type="text/css">
    <script src="sorttable.js"></script>
    <!--<body onload="window.print()">-->
    </head>
    <body>
    <div class="print_button no-print" onClick="window.print()">Print</div>
    <div class="print_text no-print">Select the sorting of the list by clicking on the table categories and click the print button below</div>
    <div class="print_a4page">
      <div class="print_header">
         <div class="print_header_logo"><img src="images/logo.png" width="306" height="43"></div>
          <div class="print_header_text" id="header_text">Drama Database</div>
          <div class="print_header_info">List printed: <script type="text/javascript">
      var currentTime = new Date();
      var month = currentTime.getMonth() + 1;
      var day = currentTime.getDate();
      var year = currentTime.getFullYear();
      document.write(day + "/" + month + "/" + year);</script>
      <br>
    Total records:
    <?php echo $row_count ?></div>
      </div>
        <div class="print_header_divider">Equipment List</div>
        <div class="print_body">
          <div>
            <form name="users" method="post">
              <div class="table_print">
              <table width="100%" border="0" cellpadding="5" class="sortable">
                <tr class="table_header_print">
                  <th width="15%" scope="col">Name</th>
                  <th width="12%" scope="col">Size</th>
                  <th width="9%" scope="col">Quantity</th>
                  <th width="12%" scope="col">Protection</th>
                  <th width="17%" scope="col">Location</th>
                  <th width="12%" scope="col">Sublocation</th>
                  <th width="11%" scope="col">Barcode</th>
                  <th width="12%" scope="col">Internal ID</th>
                </tr>
                <?php while ($row = $result->fetch_assoc()) { ?>
                <tr class="table_body">
                  <td><?php echo $name ?></td>
                  <td><?php echo $size ?></td>
                  <td><?php echo $quantity ?></td>
                  <td><?php echo $protection ?></td>
                  <td><?php echo $location ?></td>
                  <td><?php echo $sublocation ?></td>
                  <td><?php echo $bc ?></td>
                  <td><?php echo $id ?></td>
                </tr>
                <?php } ?>
              </table>
            </form>
          </div>
        </div>
    </div>
    </body>
    </html>

  • Dynamic query for delete statement

    Hi friends,
    I have a table hierarchy where suppose i have tables with following hierarchy
    Level1
    level2 (child of level1)
    level3 (child of level2)
    level4 (child of level3)
    Now i want to delete data from lowest level table depending on level one table value which is provided to me.
    I have a requirement where i want to create this delete query dynamically.
    Any help in this concern...
    Thanks,
    Sachin

    Yon can use on delete cascade as satyaki suggested like
    SQL> select * from level1;
            ID DESCRIPTION
             1 L1_1
             2 L1_2
             4 L1_3
             5 L1_4
    4 rows selected.
    SQL> select * from level2;
            ID DESCRIPTION                                                                                           L1_FK
             1 L2_1                                                                                                  1
             2 L2_2                                                                                                  1
             4 L2_3                                                                                                  2
             5 L2_4                                                                                                  2
    4 rows selected.
    SQL> delete from level1 where id =1;
    1 row deleted.
    SQL> select * from level1;
            ID DESCRIPTION
             2 L1_2
             4 L1_3
             5 L1_4
    3 rows selected.
    SQL> select * from level2;
            ID DESCRIPTION                                                                                           L1_FK
             4 L2_3                                                                                                  2
             5 L2_4                                                                                                  2
    2 rows selected.
    SQL>

  • Build dynamic query depending upon selection of table and columns

    Hi ,
    I want your views on following requirement :
    we r doing generic export to excel functionality .
    1.User will select multiple tables and according to tables ,columns on that table will select
    2.There can be multiple table
    3.depending upon column and table selection , we have to build dynamic query and execute .
    Please let me know is it possible .If yes then please tell me how to do above requirement.
    Thanks in advance

    Hi,
    Identifiers cannot be used as bind variables, query are parsed
    before evaluate bind variables. Identifiers like table name.
    For excel you can use some like this:
    SET MARKUP HTML ON ENTMAP ON SPOOL ON PREFORMAT OFF
    SPOOL test_xls.xls
    SELECT colum1||chr(9)||columN FROM tableName;
    or CSV:
    SELECT colum1|| ',' ||columN FROM tableName;
    SPOOL OFF
    SET MARKUP HTML OFF ENTMAP OFF SPOOL OFF PREFORMAT ON
    For construct the query i suggest to read "Dynamic SQL Statements":
    http://www.java2s.com/Tutorial/Oracle/0440__PL-SQL-Statements/0300__Dynamic-SQL.htm
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/dynamic.htm
    http://docs.oracle.com/cd/B10500_01/appdev.920/a96590/adg09dyn.htm
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:227413938857
    --sgc                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Help on performance with dynamic query

    Hi All,
      We are using SQL Server 2008R2. In our one of report we are using Dynamic query and it is taking more time to retrieve the data. to retrieve 32 records it is taking 13-15 secs. In my observation in a table variable, created more than 60 columns. In
    the SP called one more sp with insert statement.
    Please let me know how i can improve performance of the SP.
    I know that i have to provide the SP  for observation but unfortunately I cannot provide the SP. Please guide me how i can achieve this .
    I tried with temp tables by creating indexes on temp tables but i couldn't find improvement in performance. 
    Waiting for valuable replies.

    First of all a "dynamic query" is not "a query" - it is a multitude of them. Some of them may be fast, others may be slow.
    There is of course no way we can give specific suggestions without seeing the code, the table and index definitions etc.
    We can only give the generic suggestions. As for the code, make sure that you are using parameterised SQL and you are not building a complete SQL string with parameters and all. If nothing else, this helps to make the code more readable and maintainable.
    It also protects you against SQL injection. And it also helps to prevent performance issue due to implicit conversion.
    You will need to look at the query plan to see where the bottlenecks may be. You should look at the actual query plan. Note that the thickness of the arrows are more relevant than the percentages you see; the percentages are only estimates, and estimates
    are often off. Next step is to see if you can add indexes to alleviate the situation. You should also analyse if there are problems in the query, for instance indexed columns that are entangled in expression. If you are using views, make sure that you don't
    have views built on top of views etc. This can often result a table appearing multiple times in a query, when one would be enough.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • How to create custom BOL object for dynamic query in CRM 7.0

    Hi,
    Could anyone please explain me with steps that how to create the custom BOL object for dynamic query in CRM 7.0, I did it in previous version but its throwing exception when i try to create the object of my dynamic query class. I just defined the entry of my in crmv_obj_btil to create the dynamic query BOL object. do i need to do any other thing also to make it work?
    Regards,
    Kamesh Bathla
    Edited by: Kamesh Bathla on Jul 6, 2009 5:12 PM

    Hi Justin,
    First of thanks for your reply, and coming to my requirement, I need to report the list of items which are there in the dynamic select statement what am getting from the DB. The select statement number of columns may vary in my example for different countries the select item columns count is different. For US its '15', for UK it may be 10 ...like so, and some of the column value might be a combination or calculation part of other table columns (The select query contains more than one table in the from clause).
    In order to execute the dynamic select statement and return the result i choose to write a function which will parse the cursor for dynamic query and then iterate the values and construct a Type Object and append it to the pipe row.
    Am relatively very new for these sort of things, welcome in case of any suggestions to make it simple (Instead of the function what i thought to work with) also a sample narrating the new procedure will be appreciated.
    Thanks in Advance,
    mallikj2.

  • Dynamic query report problem

    I have followed the tutorial in on dynamic query and created a region where the type is SQL Query (PL/SQL function body returning SQL Query)
    The source is
    declare
    q varchar2(4000);
    teatid NUMBER := :P305_TARGET_ID;
    begin
    wwv_flow.debug('teatid = ' || teatid);
    q:=' select f.id, ';
    q:=q||' f.eat_id ';
    q:=q||' from xmlTransactions f ';
    q:=q||' where f.eat_id = ' || teatid; -- I've also tried putting :P305_TARGET_ID here
    wwv_flow.debug('sql = ' || q);
    return q;
    end;
    I have chosen "Use Generic Column Names...".
    When I run the page, I get NO ROWS FOUND. However, when I cut and paste the SQL statement printed out by the debug statement and run it, it returns rows. Both debug statements print correct values.
    I'm not sure what the problem is here, but basically, I want to do a query where I substitute a value passed into the page from another page.
    In this case the value in P305_TARGET_ID is passed in via a button spawning a popup as in var url = 'f?p=&APP_ID.:305:&APP_SESSION.::::P305_TARGET_ID:' + targetID;
    APEX version is 3.0.1.00.08
    Thank you.
    - JohnW

    Hi, JohnW
    I don't understand why you use a dynamic query for that.
    A "direct" SQL query like this :
    select f.id,f.eat_id from xmlTransactions f where f.eat_id=:P305_TARGET_ID;
    should work.
    Mike

Maybe you are looking for