Tunning PL/SQL  with sql dynamic returning cursor

Hi
How can I to tunning a Stored Procedure with Dynamic Cursor that return a Cursor (resultset to VB), is very slow

1. Run your app (or better yet your PL/SQL procedure) with SQL_TRACE=TRUE and analyze trace file (TKPROF report e.g.)
2. Tune SQL executed by PL/SQL procedure directly. Copy the SQL from the procedure, run it in SQL*Plus [with SET AUTOTRACE ON] and analyze exec plan, statistics etc.
3. profile your procedure to figure out which part of it takes what (time, resources etc.)

Similar Messages

  • Learning PL/SQL with SQL plus

    I'm looking to teach myself PL/SQL with SQL Plus, it's a works pc so I can not use any other software than SQL plus.
    When starting SQL plus I'm asked for a username, password and host string.
    I'm taking it the host string is the db I want to connect to and obviously supply the username and password for level of access?
    Also what I ideally need is a sample db on my local machine to connect to with SQL plus to learn that way.
    Can anyone point me in the right direction please. Any help is greatly appreciated.

    Use the net8 configuration assistant preferably as it'll get the syntax correct.
    Otherwise you copy the sample one up one folder and edit that.
    Connection information (SID, Server/IP, port number) you'll have to get off your DBA.
    The name at the start of a tnsnames entry is the name that you want to reference the database as, so you can call it FRED if you like.
    e.g.
    FRED =
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS =
            (PROTOCOL = TCP)
            (HOST = <server name or ip address>)
            (PORT = <port>) -- usually 1521 but can differ if more than one instance on the server
        (CONNECT_DATA =
          (SID = <database SID>) -- the name of the database on the server.
      )Once that's set up you can then log onto the database in the following way:
    sqlplus <user>/<password>@fred
    What happens is that the TNS Listener service (that should be running on your PC) will look up "fred" in the tnsnames.ora file and then use the information from that to make the connection to the server on the correct port and connect you to the actual database on there.
    After that.... it's up to you.
    :)

  • TimesTen SQL with group by returning multiple rows

    I have a Active-Standby TimesTen nodes.
    Using group by with or without having clause:
    Whenever I do a group by query on table1 table with or without having clause, SQL returns multiple rows. This looks very strange to me. Each time it gives different count
    Command> select count(*) from table1 group by pname having pname='pool';
    < 390400 >
    1 row found.
    Command> select count(*) from table1 group by pname having pname='pool';
    < 390608 >
    < 32639 >
    2 rows found.
    Command> select count(*) from table1 group by pname having pname='pool';
    < 2394 >
    < 351057 >
    2 rows found.
    Command> select count(*) from table1 group by pname having pname='pool';
    < 305732 >
    1 row found.
    Command> select count(*) from table1 group by pname having pname='pool';
    < 420783 >
    1 row found.
    Command> select count(*),pool_name from root.rms_address_pools group by pool_name order by pool_name;
    < *435473, pool* >
    < *32313, pool* >
    < 453, smvG3 >
    < *28980, pool* >
    < 3786, smvG4 >
    < *26025, pool* >
    < 236120, smvG6 >
    < 131455, smcG3 >
    < *65150, pool* >
    < 23, snt1G1 >
    < 510, snt2G1 >
    < 510, snt2G2 >
    Using where clause:
    Command> select count(*) from table1 where pname='pool';
    < *442354* >
    1 row found.
    Command> select count(*) from table1 where pname='pool';
    < 442354 >
    1 row found.
    Table description:
    Command> desc table1;
    Table table1:
    Columns:
    *IP_ADDRESS                      BIGINT NOT NULL
    PNAME CHAR (32) NOT NULL
    SITEID TINYINT NOT NULL
    1 table found.
    ttVersion:
    bash-3.00# ./ttVersion
    TimesTen Release *7.0.3.1.0 (64 bit Solaris)* (tt70:17001) 2007-10-30T22:17:07Z
    Instance admin: root
    Instance home directory: /TimesTen/tt70
    Daemon home directory: /var/TimesTen/tt70
    bash-3.00#
    Could any one suggest what is wrong with my SQL? or is it a bug with TimesTen?
    Many thanks in advance.
    Br,
    Brij

    Hi Gena,
    When i execute the query with where clause, it gives me the output with more than one pool:
    Command> select pname, count (*) from table1 where pname='pool' group by pname ;
    < smcG3 , 18836 >
    < pool , 423527 >
    2 rows found.
    Command> select pname, count (*) from table1 where pname='pool' group by pname ;
    < intG302 , 17202 >
    < pool , 425159 >
    2 rows found.
    While if give use the having clause it gives me multiple rows for one pool only ( sometimes) :
    select pname, count (*) from table1 group by pname having pname='pool';
    < pool , 32686 >
    < pool , 420445 >
    2 rows found.
    select pname, count (*) from table1 group by pname having pname='pool';
    < pool , 393574 >
    < pool , 5838 >
    < pool , 110943 >
    3 rows found.
    Command> select pname, count (*) from table1 group by pname having pname='pool';
    < pool , 414590 >
    < pool , 8395 >
    2 rows found.
    Please suggest what can be done in this case, need i open a case with Oracle for this.
    Regards, Brij

  • Problem in SQL with CURSOR( ) ,Why the CURSOR did not work?

    hi All:
    I have a problem in SQL with CURSOR.
    The data is as the attachments.
    Here is the SQL statement as follow:
    SELECT A.WADCTO,A.WADOCO,B.IGCOST,CURSOR (SELECT X.IGLITM
    FROM F3102 X
    WHERE X.IGDOCO=A.WADOCO
    AND X.IGCOST IN ('B1','D1','C3')) AS DETAIL
    FROM F4801 A INNER JOIN F3102 B ON A.WADOCO=B.IGDOCO AND A.WADCTO=B.IGDCTO AND B.IGCOST>' '
    WHERE A.WADOCO='10004'
    The statement above returns records as follow:
    WADC WADOCO IGCOST DETAIL
    WO 10004 A1 CURSOR STATEMENT : 4
    CURSOR STATEMENT : 4
    IGLITM
    1KV90CPG2
    1KV90CPG2
    1KV90CPG2
    But, after I add one statement in the subquery, there is no record returned from CURSOR.
    Here is the SQL statement:
    SELECT A.WADCTO,A.WADOCO,B.IGCOST,CURSOR (SELECT X.IGLITM
    FROM F3102 X
    WHERE X.IGDOCO=A.WADOCO
    AND X.IGCOST=B.IGCOST
    AND X.IGCOST IN ('B1','D1','C3')) AS DETAIL
    FROM F4801 A INNER JOIN F3102 B ON A.WADOCO=B.IGDOCO AND A.WADCTO=B.IGDCTO AND B.IGCOST>' '
    WHERE A.WADOCO='10004'
    The statement above returns records as follow:
    WADC WADOCO IGCOST DETAIL
    WO 10004 A1 CURSOR STATEMENT : 4
    CURSOR STATEMENT : 4
    no rows selected
    Why the CURSOR did not work?
    The database version is Oracle Database 10g Release 10.2.0.4.0 - 64bit Production.
    F3102 DATA:
    IGDOCO     IGDCTO     IGLITM     IGCOST
    10004     WO     1KV90CPG2      A1
    10004     WO     1KV90CPG2      B1
    10004     WO     1KV90CPG2      C3
    10004     WO     1KV90CPG2      D1
    F4801 DATA:
    WADCTO     WADOCO
    WO     10004
    Edited by: user2319139 on 2010/3/2 上午 1:17
    Edited by: user2319139 on 2010/3/2 上午 1:20

    Why this structure and not a join?
    The cursor() function returns a cursor handle that needs to be processed - in other words, the client needs to fetch data from it. The Oracle® Database SQL Reference+ (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/expressions005.htm#i1035107) describes it as being equivalent to a ref cursor handle.
    Thus why are you creating ref cursor handles as a column in a SQL projection - where each row will have a "+nested+" ref cursor handle to process. What problem are you attempting to hack solve this way?

  • Function returning pl/sql table of dynamic structure

    Hi,
    I use oracle11g/windows platform.
    I have a requirement to be coded like this:
    A function to return pl/sql table(cant use ref cursor) whose columns varies everytime it runs i.e.,
    means
    type pl_tab_type is object(col1 varchar2(1000), col2 varchar2(1000))
    type pl_tab is table of pl_tab_type
    func f return pl_tab
    as
    end;
    note : pl_tab_type will vary for each run of function f
    i.e.,for example, pl_tab_type can be changd to as follows:
    type pl_tab_type is object(col1 varchar2(1000), col2 varchar2(1000),col3 varchar2(1000))
    how to return pl/sql table of dynamic type from func, thanks for help in advance.

    WRONG FORUM!
    Please mark this question ANSWERED and repost it in the SQL and PL/SQL forum.
    PL/SQL

  • Using database link  with a dynamic SQL in Forms 5

    I have a Form 5 application where a database link is specified in a client version of dynamic SQL. The function that the application is designed to perform is to access data in a table in a remote database and use it to populate another table in a local database with the same structure as the source table. Dynamic SQL is used because the name of the table can only be resolved during run time.
    The problem is that it gives error with code 'ORA-03113' and text 'End-of-file on communication channel' when you try to run it.
    Is it not possible to use a database link with a dynamic SQL? What can I do to overcome the problem ?

    Try to create a local view based ao the remote table and use the view.

  • Help with using dynamic sql logic in a view please?

    Greetings,
    I want to create a dynamic union using all the databases on server. The following works:
    declare @sqlvarchar(max)
    select
    @sql=IsNull(@sql+'union
    all ','')+'select
    * from  '+name+'.[dbo].[A]''
    inner join '+name+'.[dbo].[B]'' on
    a.f1=b.f1'
    from
    sys.databases
    where
    name
    in(select
    name
    from
    sys.databases)
    exec
    (@sql)
    The problem is I need something tangible, like a view, to query using SSAS later. I've tried to use SELECT into to load a new table with a resulting dataset. It gives me a syntax error - the dynamic part can't be combined with static. I can't use OPENQUERY
    because it all happens on the same server. Assistance would be appreciated. Thanks

    Well, you could regenerate the view each time a database is created or dropped.
    Or you can define your cube using an empty view and load the cube using SSIS, eg with
    Dimension Processing Destination.
    Or you can use something like a CLR TVF inside your view.
    David
    David http://blogs.msdn.com/b/dbrowne/

  • What is the problem with native dynamic sql when counting rows in all table

    what is the problem with native dynamic sql when counting rows in all table?Giving an error "table or view does not exist". Thanks.
    DECLARE
    v_sql_string varchar2(1000);
    v_no_of_rows number;
    BEGIN
    for i in ( select table_name from all_tables )
    loop
    v_sql_string := ' select count(1) from ' || i.table_name;
    dbms_output.put_line( v_sql_string );
    --execute immediate v_sql_string into v_no_of_rows;
    end loop;
    END;

    Usually your problem can be described with 'Who cares'. I mean, for what reason do you do this? I doubt that there's a business need to get 100 % accurate answers for this. Normally such things are used to get a picture about the growth of data.
    Personally I would prefer to have up-to-date statistics for all tables and just query the number of rows from there. Sufficient for me in < 99 % of all cases.
    Just my $ .02...

  • Strange Behavior with SQL/XML

    Our University have had for quite some time now a rather difficult situation with a very significant course handbook web site that creates HTML based on database XSL transformation of XML content generated with SQL/XML. The database is 10.2.0.2.0. The HTML is passed via a distributed database link to an Oracle Portal dynamic portlet for display. Some of the derived XML originates from XML Schema registered instance documents and some from relational storage.
    Let me explain. Occasionally after a period of operating (could be one week, sometimes even less) we will experience a problem whereby our derived XML content (just prior to PL/SQL database XSL transformation) will develop a parsing problem. Once this happens to one XSL transform of a course then subsequently it happens for every course viewed/transformed there-after.
    Recently I experienced the problem and then added the XMLNS argument to the extract function. That seemed to fix things and I thought I had it licked.
    Today we started to get the same problem again. The error reported was:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00242: invalid use of ampersand ('&') character (use &amp;)
    Error at line 1
    Now this might have been reasonable for one course. But every course reported the same problem there-after without fail. I managed to fix the issue but in a way that really doesn't seem to make sense. What I did was to alter the SQL/XML statement by adding in an extra XMLEMENT and then to recompile the function that returns an XMLTYPE based on the execution of the SQL statement. After compiling the function everything returned to normal.
    This doesn't seem to make sense.
    I am pretty desperate for help on this. I really don't know how to progress the solution. I don't get much joy from Oracle Support as our application covers too many high tech areas. This is really shaking confidence in our organization's use of Oracle technology.

    Hi Mark.
    We've isolated the problem a bit more now and there is a support SR (6089662.994). At this stage we are unable to reproduce - I am testing out an export though. The problem only occurs when a certain condition has been reached. Once that happens then extraneous characters are produced in the XMLTYPE feed returned by a function. We are not at all sure about how to make this condition occur. This doesn't just happen with one SQL/XML cursor - I've seen it happen with 3 different cursors. All are located in the same function that returns an XMLTYPE.
    We are convinced the problem lies with one or more SQL/XML cursors located in the same function. Once one of these cursors malfunctions it will produce XML that is not well formed OR on occasion has content omitted but is well formed (there often seem to be extraneous characters). When the XML content is not well formed then the parsing stage (dbms_xmlparser.parseclob(myparser, xml_clob)) of XSL transformation crashes. This error then propagates to the dynamic portlet in Oracle Portal thus removing the content on the page. This happens for every execution of the cursor while the condition manifests, the only difference between calls being bind variables.
    The interesting thing is that the error if left to itself will eventually stop. The cursor seems to right itself eventually. On the last occurrence, the problem commenced at 4.30am and went for 3.5 hrs and then seemed to right itself.

  • Dynamic REF Cursor with Dynamic Fetch - Urgent

    i have a pl/sql package with generates dynamic SQL statments. my problem is i want to open this SQL statment dynamically and fetch data in dynamic variable.
    declare
    type type_temp is REF CURSOR;
    cur_temp type_temp;
    mv_sql varchar2(4000);
    begin
    -- this will be dunamically generated and
    -- hence could have any no. of columns.
    mv_sql := select f1, f2, f3, f4 from table_temp;
    open cur_temp for mv_sql;
    fetch cur_temp into c1, c2, c3, c4;
    close cur_temp;
    end;
    problem is my sql statment will have N no. of columns how can i fetch this N no. of columns.

    Very hard problem, because ref cursors do not (directly) support description!
    Se mine (non-ideal) solution (it may be doable, but it isn't very practical
    or easily maintainable):
    1. "Generic" package
    CREATE OR REPLACE PACKAGE dyn_fetch IS
    TYPE ref_cur_t IS REF CURSOR;
    g_query VARCHAR2 (32000);
    g_count NUMBER;
    g_desc_tab DBMS_SQL.DESC_TAB;
    varchar2_type CONSTANT PLS_INTEGER := 1;
    number_type CONSTANT PLS_INTEGER := 2;
    date_type CONSTANT PLS_INTEGER := 12;
    rowid_type CONSTANT PLS_INTEGER := 11;
    char_type CONSTANT PLS_INTEGER := 96;
    long_type CONSTANT PLS_INTEGER := 8;
    raw_type CONSTANT PLS_INTEGER := 23;
    mlslabel_type CONSTANT PLS_INTEGER := 106;
    clob_type CONSTANT PLS_INTEGER := 112;
    blob_type CONSTANT PLS_INTEGER := 113;
    bfile_type CONSTANT PLS_INTEGER := 114;
    PROCEDURE describe_columns;
    FUNCTION record_def RETURN VARCHAR2;
    END;
    CREATE OR REPLACE PACKAGE BODY dyn_fetch IS
    PROCEDURE describe_columns IS
    l_cur INTEGER;
    BEGIN
    l_cur := DBMS_SQL.OPEN_CURSOR;
    DBMS_SQL.PARSE (l_cur, g_query, DBMS_SQL.NATIVE);
    DBMS_SQL.DESCRIBE_COLUMNS (l_cur, g_count, g_desc_tab);
    DBMS_SQL.CLOSE_CURSOR (l_cur);
    EXCEPTION
    WHEN OTHERS THEN
    IF DBMS_SQL.IS_OPEN (l_cur) THEN
    DBMS_SQL.CLOSE_CURSOR (l_cur);
    END IF;
    RAISE;
    END;
    FUNCTION record_def RETURN VARCHAR2 IS
    l_record_def VARCHAR2 (32000);
    l_type VARCHAR2 (100);
    l_col_type PLS_INTEGER;
    l_col_max_len PLS_INTEGER;
    l_col_precision PLS_INTEGER;
    l_col_scale PLS_INTEGER;
    BEGIN
    FOR i IN 1..g_count LOOP
    l_col_type := g_desc_tab(i).col_type;
    l_col_max_len := g_desc_tab(i).col_max_len;
    l_col_precision := g_desc_tab(i).col_precision;
    l_col_scale := g_desc_tab(i).col_scale;
    IF l_col_type = varchar2_type THEN
    l_type := 'VARCHAR2(' || l_col_max_len || ')';
    ELSIF l_col_type = number_type THEN
    l_type := 'NUMBER(' || l_col_precision || ',' || l_col_scale || ')';
    ELSIF l_col_type = date_type THEN
    l_type := 'DATE';
    ELSIF l_col_type = rowid_type THEN
    l_type := 'ROWID';
    ELSIF l_col_type = char_type THEN
    l_type := 'CHAR(' || l_col_max_len || ')';
    -- ELSIF l_col_type = ...
    -- long_type, raw_type ...
    END IF;
    l_record_def := l_record_def || ' col_' || i || ' ' || l_type || ',';
    END LOOP;
    l_record_def := RTRIM (l_record_def, ',');
    RETURN l_record_def;
    END;
    END;
    Note that procedure "record_def" creates columns names as col_1 (col_2 ...)
    because SELECT clause in your query can be without aliases, for example
    "SELECT deptno || dname FROM dept".
    2. Your package which returns query nad ref cursor
    CREATE OR REPLACE PACKAGE test IS
    PROCEDURE set_query (p_query VARCHAR2 := NULL);
    FUNCTION ref_cur RETURN dyn_fetch.ref_cur_t;
    END;
    CREATE OR REPLACE PACKAGE BODY test IS
    PROCEDURE set_query (p_query VARCHAR2 := NULL) IS
    l_query VARCHAR2 (32000) :=
    ' SELECT e.empno, e.ename,' ||
    ' e.deptno, d.dname' ||
    ' FROM emp e,' ||
    ' dept d' ||
    ' WHERE e.deptno = d.deptno';
    BEGIN
    IF p_query IS NULL THEN
    dyn_fetch.g_query := l_query;
    ELSE
    dyn_fetch.g_query := p_query;
    END IF;
    END;
    FUNCTION ref_cur RETURN dyn_fetch.ref_cur_t IS
    l_ref_cur dyn_fetch.ref_cur_t;
    BEGIN
    OPEN l_ref_cur FOR dyn_fetch.g_query;
    RETURN l_ref_cur;
    END;
    END;
    Why we need two separate procedures (functions) in your package ?
    a) Receiving program must use dynamic SQL, but in dynamic block we can access
    only PL/SQL code elements that have global scope (standalone functions and procedures,
    and elements defined in the specification of a package).
    Unfortunately, cursor variables cannot be defined in the specification of a package
    (cannot be global variables).
    b) Receiving program must get the column list before ref cursor.
    So, we have two options: call (in receiving program) the same function two times
    (once to get the column list and once to return a ref cursor)
    or use one procedure (or function) for returning query (to get the column list)
    and second function for returning a ref cursor.
    3. Your receiving program
    CREATE OR REPLACE PROCEDURE test_fetch_ref_cur (p_query VARCHAR2 := NULL) IS
    l_statement VARCHAR2 (32000);
    FUNCTION process_def RETURN VARCHAR2 IS
    l_process_def VARCHAR2 (32000);
    BEGIN
    l_process_def := 'DBMS_OUTPUT.PUT_LINE (';
    FOR i IN 1 .. dyn_fetch.g_count LOOP
    l_process_def := l_process_def || ' l_record.col_' || i || ' || ''>>'' || ';
    END LOOP;
    l_process_def := RTRIM (l_process_def, ' || ''>>'' || ') || ');';
    RETURN l_process_def;
    END;
    BEGIN
    test.set_query (p_query);
    dyn_fetch.describe_columns;
    l_statement :=
    ' DECLARE' ||
    ' TYPE record_t IS RECORD (' ||
    dyn_fetch.record_def || ');' ||
    ' l_record record_t;' ||
    ' l_ref_cur dyn_fetch.ref_cur_t;' ||
    ' BEGIN' ||
    ' l_ref_cur := test.ref_cur;' ||
    ' LOOP' ||
    ' FETCH l_ref_cur INTO l_record;' ||
    ' EXIT WHEN l_ref_cur%NOTFOUND;' ||
    process_def ||
    ' END LOOP;' ||
    ' CLOSE l_ref_cur;' ||
    ' END;';
    EXECUTE IMMEDIATE l_statement;
    END;
    You can test this with:
    SET SERVEROUTPUT ON;
    EXECUTE test_fetch_ref_cur;
    Note that we can try to use more generic solution:
    CREATE OR REPLACE PACKAGE dyn_fetch IS
    -- SAME AS BEFORE, PLUS:
    PROCEDURE fetch_ref_cur (
    p_function_ref_cur VARCHAR2,
    p_process_def VARCHAR2);
    END;
    CREATE OR REPLACE PACKAGE BODY dyn_fetch IS
    -- SAME AS BEFORE, PLUS:
    PROCEDURE fetch_ref_cur (
    p_function_ref_cur VARCHAR2,
    p_process_def VARCHAR2)
    IS
    l_statement VARCHAR2 (32000);
    BEGIN
    l_statement :=
    ' DECLARE' ||
    ' TYPE record_t IS RECORD (' ||
    record_def || ');' ||
    ' l_record record_t;' ||
    ' l_ref_cur dyn_fetch.ref_cur_t;' ||
    ' BEGIN' ||
    ' l_ref_cur := ' ||
    p_function_ref_cur || ';' ||
    ' LOOP' ||
    ' FETCH l_ref_cur INTO l_record;' ||
    ' EXIT WHEN l_ref_cur%NOTFOUND;' ||
    p_process_def ||
    ' END LOOP;' ||
    ' CLOSE l_ref_cur;' ||
    ' END;';
    EXECUTE IMMEDIATE l_statement;
    END;
    END;
    CREATE OR REPLACE PROCEDURE test_fetch_ref_cur (p_query VARCHAR2 := NULL) IS
    FUNCTION process_def RETURN VARCHAR2 IS
    -- SAME AS BEFORE
    END;
    BEGIN
    test.set_query (p_query);
    dyn_fetch.describe_columns;
    dyn_fetch.fetch_ref_cur (
    p_function_ref_cur => 'test.ref_cur',
    p_process_def => process_def);
    END;
    Regards,
    Zlatko Sirotic

  • Performance between SQL Statement and Dynamic SQL

    Select emp_id
    into id_val
    from emp
    where emp_id = 100
    EXECUTE IMMEDIATE
    'Select '|| t_emp_id ||
    'from emp '
    'where emp_id = 100'
    into id_valWill there be more impact in performance while using Dynamic SQL?

    CP wrote:
    Will there be more impact in performance while using Dynamic SQL?All SQLs are parsed and executed as SQL cursors.
    The 2 SQLs (dynamic and static) results in the exact same SQL cursor. So both methods will use an identical cursor. There are therefore no performance differences ito of how fast that SQL cursor will be.
    If an identical SQL cursor is not found (a soft parse), the SQL engine needs to compile the SQL source code supplied, into a SQL cursor (a hard parse).
    Hard parsing burns a lot of CPU cycles. Soft parsing burns less CPU cycles and is therefore better. However, no parsing at all is the best.
    To explain: if the code creates a cursor (e.g. INSERT INTO tab VALUES( :1, :2, :3 ) for inserting data), it can do it as follows:
    while More Data Found loop
      parse INSERT cursor
      bind variables to INSERT cursor
      execute INSERT cursor
      close INSERT cursor
    end loopIf that INSERT cursor does not yet exists, it will be hard parsed and a cursor created. Each subsequent loop iteration will result in a soft parse.
    However, the code will be far more optimal as follows:
    parse INSERT cursor
    while More Data Found loop
      bind variables to INSERT cursor
      execute INSERT cursor
    end loop
    close INSERT cursorWith this approach the cursor is parsed (hard or soft), once only. The cursor handle is then used again and again. And when the application is done inserting data, the cursor handle is released.
    With dynamic SQL in PL/SQL, you cannot really follow the optimal approach - unless you use DBMS_SQL (a complex cursor interface). With static SQL, the PL/SQL's optimiser can kick in and it can optimise its access to the cursors your code create and minimise parsing all together.
    This is however not the only consideration when using dynamic SQL. Dynamic SQL makes coding a lot more complex. The SQL code can now only be checked at execution time and not at development time. There is the issue of creating shareable SQL cursors using bind variables. There is the risk of SQL injection. Etc.
    So dynamic SQL is seldom a good idea. And IMO, the vast majority of people that post problems here relating to dynamic SQL, are using dynamic SQL unnecessary. For no justified and logical reasons. Creating unstable code, insecure code and non-performing code.

  • How to resolve most of the Oracle SQL , PL/SQL Performance issues with help of quick Checklist/guidelines ?

    Please go thru below important checklist/guidelines to identify issue in any Perforamnce issue and resolution in no time.
    Checklist for Quick Performance  problem Resolution
    ·         get trace, code and other information for given PE case
              - Latest Code from Production env
              - Trace (sql queries, statistics, row source operations with row count, explain plan, all wait events)
              - Program parameters & their frequently used values
              - Run Frequency of the program
              - existing Run-time/response time in Production
              - Business Purpose
    ·         Identify most time consuming SQL taking more than 60 % of program time using Trace & Code analysis
    ·         Check all mandatory parameters/bind variables are directly mapped to index columns of large transaction tables without any functions
    ·         Identify most time consuming operation(s) using Row Source Operation section
    ·         Study program parameter input directly mapped to SQL
    ·         Identify all Input bind parameters being used to SQL
    ·         Is SQL query returning large records for given inputs
    ·         what are the large tables and their respective columns being used to mapped with input parameters
    ·         which operation is scanning highest number of records in Row Source operation/Explain Plan
    ·         Is Oracle Cost Based Optimizer using right Driving table for given SQL ?
    ·         Check the time consuming index on large table and measure Index Selectivity
    ·         Study Where clause for input parameters mapped to tables and their columns to find the correct/optimal usage of index
    ·         Is correct index being used for all large tables?
    ·         Is there any Full Table Scan on Large tables ?
    ·         Is there any unwanted Table being used in SQL ?
    ·         Evaluate Join condition on Large tables and their columns
    ·         Is FTS on large table b'cos of usage of non index columns
    ·         Is there any implicit or explicit conversion causing index not getting used ?
    ·         Statistics of all large tables are upto date ?
    Quick Resolution tips
    1) Use Bulk Processing feature BULK COLLECT with LIMIT and FOR ALL for DML instead of row by row processing
    2) Use Data Caching Technique/Options to cache static data
    3) Use Pipe Line Table Functions whenever possible
    4) Use Global Temporary Table, Materialized view to process complex records
    5) Try avoiding multiple network trips for every row between two database using dblink, Use Global temporary table or set operator to reduce network trip
    6) Use EXTERNAL Table to build interface rather then creating custom table and program to Load and validate the data
    7) Understand Oracle's Cost based Optimizer and Tune most expensive SQL queries with help of Explain plan
    8) Follow Oracle PL/SQL Best Practices
    9) Review tables and their indexes being used in the SQL queries and avoid unnecessary Table scanning
    10) Avoid costly Full Table Scan on Big Transaction tables with Huge data volume,
    11) Use appropriate filtration condition on index columns of seeded Oracle tables directly mapped to program parameters
    12) Review Join condition on existing query explain plan
    13) Use Oracle hint to guide Oracle Cost based optimizer to choose best plan for your custom queries
    14) Avoid applying SQL functions on index columns
    15) Use appropriate hint to guide Oracle CBO to choose best plan to reduce response time
    Thanks
    Praful

    I understand you were trying to post something helpful to people, but sorry, this list is appalling.
    1) Use Bulk Processing feature BULK COLLECT with LIMIT and FOR ALL for DML instead of row by row processing
    No, use pure SQL.
    2) Use Data Caching Technique/Options to cache static data
    No, use pure SQL, and the database and operating system will handle caching.
    3) Use Pipe Line Table Functions whenever possible
    No, use pure SQL
    4) Use Global Temporary Table, Materialized view to process complex records
    No, use pure SQL
    5) Try avoiding multiple network trips for every row between two database using dblink, Use Global temporary table or set operator to reduce network trip
    No, use pure SQL
    6) Use EXTERNAL Table to build interface rather then creating custom table and program to Load and validate the data
    Makes no sense.
    7) Understand Oracle's Cost based Optimizer and Tune most expensive SQL queries with help of Explain plan
    What about using the execution trace?
    8) Follow Oracle PL/SQL Best Practices
    Which are?
    9) Review tables and their indexes being used in the SQL queries and avoid unnecessary Table scanning
    You mean design your database and queries properly?  And table scanning is not always bad.
    10) Avoid costly Full Table Scan on Big Transaction tables with Huge data volume,
    It depends if that is necessary or not.
    11) Use appropriate filtration condition on index columns of seeded Oracle tables directly mapped to program parameters
    No, consider that too many indexes can have an impact on overall performance and can prevent the CBO from picking the best plan.  There's far more to creating indexes than just picking every column that people are likely to search on; you have to consider the cardinality and selectivity of data, as well as the volumes of data being searched and the most common search requirements.
    12) Review Join condition on existing query explain plan
    Well, if you don't have your join conditions right then your query won't work, so that's obvious.
    13) Use Oracle hint to guide Oracle Cost based optimizer to choose best plan for your custom queries
    No.  Oracle recommends you do not use hints for query optimization (it says so in the documentation).  Only certain hints such as APPEND etc. which are more related to certain operations such as inserting data etc. are acceptable in general.  Oracle recommends you use the query optimization tools to help optimize your queries rather than use hints.
    14) Avoid applying SQL functions on index columns
    Why?  If there's a need for a function based index, then it should be used.
    15) Use appropriate hint to guide Oracle CBO to choose best plan to reduce response time
    See 13.
    In short, there are no silver bullets for dealing with performance.  Each situation is different and needs to be evaluated on its own merits.

  • How to Populate the JTable Object programatically with SQL Results

    I'm wondering if someone could help me on how to populate the JTable Object with SQL Results wherein the Row of tjhe JTable object is automatically adjusted depending on how many records you have queried.
    Thanks in advance and God bless! (",)
    * frmMain.java
    * Created on October 4, 2006, 6:15 AM
    package tds;
    import java.io.*;
    import java.awt.Toolkit;
    import javax.swing.JFrame;
    import javax.imageio.*;
    import javax.swing.JFrame;
    import java.sql.*;
    import javax.swing.table.DefaultTableModel;
    * @author Dexter.Carlit
    public class frmMain extends javax.swing.JFrame {
    private Connection connection = null;
    private DefaultTableModel model;
    /** Creates new form frmMain */
    public frmMain() {
    initComponents();
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
    jSplitPane = new javax.swing.JSplitPane();
    jScrollPane1 = new javax.swing.JScrollPane();
    jPanel3 = new javax.swing.JPanel();
    jScrollPane2 = new javax.swing.JScrollPane();
    jTree1 = new javax.swing.JTree();
    jTabbedPane1 = new javax.swing.JTabbedPane();
    jPanel1 = new javax.swing.JPanel();
    jPanel4 = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();
    jTextField2 = new javax.swing.JTextField();
    jLabel3 = new javax.swing.JLabel();
    jTextField3 = new javax.swing.JTextField();
    jLabel4 = new javax.swing.JLabel();
    jTextField4 = new javax.swing.JTextField();
    jPanel5 = new javax.swing.JPanel();
    jScrollPane3 = new javax.swing.JScrollPane();
    jGrid = new javax.swing.JTable();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jProgressBar1 = new javax.swing.JProgressBar();
    jPanel2 = new javax.swing.JPanel();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowOpened(java.awt.event.WindowEvent evt) {
    formWindowOpened(evt);
    getAccessibleContext().setAccessibleName("frmMain");
    jSplitPane.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
    jSplitPane.setDividerLocation(200);
    jSplitPane.setDividerSize(10);
    jScrollPane2.setViewportView(jTree1);
    org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(
    jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel3Layout.createSequentialGroup()
    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 916, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    jPanel3Layout.setVerticalGroup(
    jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)
    jScrollPane1.setViewportView(jPanel3);
    jSplitPane.setLeftComponent(jScrollPane1);
    jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
    jLabel1.setText("First Name:");
    jLabel2.setText("Last Name:");
    jLabel3.setText("Position :");
    jLabel4.setText("Department:");
    jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Search Results"));
    jGrid.setModel(new javax.swing.table.DefaultTableModel(
    new Object [][] {
    new String [] {
    "LName", "FName", "Position", "Department", "Office No", "Local No", "Office Mobile No", "Home No", "MobileNo", "Email Address"
    jGrid.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
    jGrid.setColumnSelectionAllowed(true);
    jGrid.setName("");
    jGrid.setTableHeader(jGrid.getTableHeader());
    jScrollPane3.setViewportView(jGrid);
    jScrollPane3.getAccessibleContext().setAccessibleName("rset");
    org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(jPanel5);
    jPanel5.setLayout(jPanel5Layout);
    jPanel5Layout.setHorizontalGroup(
    jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jScrollPane3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 386, Short.MAX_VALUE)
    jPanel5Layout.setVerticalGroup(
    jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jScrollPane3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
    jButton1.setText("Find");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
    jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(java.awt.event.MouseEvent evt) {
    jButton1MouseClicked(evt);
    jButton2.setText("Clear");
    jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(java.awt.event.MouseEvent evt) {
    jButton2MouseClicked(evt);
    org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
    jPanel4.setLayout(jPanel4Layout);
    jPanel4Layout.setHorizontalGroup(
    jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel4Layout.createSequentialGroup()
    .addContainerGap()
    .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel4Layout.createSequentialGroup()
    .add(jLabel1)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE))
    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel4Layout.createSequentialGroup()
    .add(jLabel2)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(jTextField2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE)
    .add(1, 1, 1))
    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel4Layout.createSequentialGroup()
    .add(jLabel3)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(jTextField3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(jLabel4)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(jTextField4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE))
    .add(jPanel4Layout.createSequentialGroup()
    .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 66, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 66, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
    .addContainerGap())
    jPanel4Layout.linkSize(new java.awt.Component[] {jButton1, jButton2}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
    jPanel4Layout.setVerticalGroup(
    jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel4Layout.createSequentialGroup()
    .addContainerGap()
    .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    .add(jLabel1)
    .add(jTextField1))
    .add(18, 18, 18)
    .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    .add(jLabel2)
    .add(jTextField2))
    .add(16, 16, 16)
    .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    .add(jLabel3)
    .add(jTextField3)
    .add(jLabel4)
    .add(jTextField4))
    .add(14, 14, 14)
    .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    .add(jButton2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .add(jButton1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(jPanel5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
    jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
    .addContainerGap()
    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .add(org.jdesktop.layout.GroupLayout.LEADING, jProgressBar1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE))
    .addContainerGap())
    jPanel1Layout.setVerticalGroup(
    jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
    .addContainerGap()
    .add(jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    .add(jProgressBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    jTabbedPane1.addTab("Search", jPanel1);
    org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
    jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(0, 458, Short.MAX_VALUE)
    jPanel2Layout.setVerticalGroup(
    jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(0, 401, Short.MAX_VALUE)
    jTabbedPane1.addTab("Directory", jPanel2);
    jSplitPane.setRightComponent(jTabbedPane1);
    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jSplitPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 675, Short.MAX_VALUE)
    layout.setVerticalGroup(
    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jSplitPane)
    pack();
    }// </editor-fold>//GEN-END:initComponents
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    }//GEN-LAST:event_jButton1ActionPerformed
    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
    jGrid.setModel(new javax.swing.table.DefaultTableModel(
    new Object [][] {
    {null, null, null, null, null, null, null, null, null, null},
    {null, null, null, null, null, null, null, null, null, null},
    {null, null, null, null, null, null, null, null, null, null},
    {null, null, null, null, null, null, null, null, null, null}
    new String [] {
    "LName", "FName", "Position", "Department", "Office No", "Local No", "Office Mobile No", "Home No", "MobileNo", "Email Address"
    jGrid.updateUI();
    }//GEN-LAST:event_jButton2MouseClicked
    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
    try {
    //Load and register SQL Server driver
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    //Establish a connection
    Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://X.X.X.X:1433","MyAccount","MyPassword");
    //Create a Statement object
    Statement sql_stmt = connection.createStatement();
    //Create a ResultSet object, execute the query and return a
    // resultset
    ResultSet rset = sql_stmt.executeQuery("SELECT * FROM EpxDirectory..Directory Order By LName");
    // Populates a JTABLE Object
    int i=0;
    while (rset.next()){
    String LName = rset.getString(1);
    String FName = rset.getString(2);
    String Position = rset.getString(3);
    String Dept_Code = rset.getString(4);
    String OffPhoneNo = rset.getString(5);
    String LocalNo = rset.getString(6);
    String OffMobileNo = rset.getString(7);
    String HomePhoneNo = rset.getString(8);
    String MobileNo = rset.getString(9);
    String Email = rset.getString(10);
    jGrid.updateUI();
    jGrid.setValueAt(rset.getString(1).trim(),i,0);
    jGrid.setValueAt(rset.getString(2).trim(),i,1);
    jGrid.setValueAt(rset.getString(3).trim(),i,2);
    jGrid.setValueAt(rset.getString(4).trim(),i,3);
    jGrid.setValueAt(rset.getString(5).trim(),i,4);
    jGrid.setValueAt(rset.getString(6).trim(),i,5);
    jGrid.setValueAt(rset.getString(7).trim(),i,6);
    jGrid.setValueAt(rset.getString(8).trim(),i,7);
    jGrid.setValueAt(rset.getString(9).trim(),i,8);
    jGrid.setValueAt(rset.getString(10).trim(),i,9);
    i++;
    //Close the ResultSet and Statement
    rset.close();
    sql_stmt.close();
    //Close the database connection
    connection.close();
    System.out.println(Integer.toString(i) + " rows found");
    } catch(Exception e) {
    System.out.println("Failed to connect; Please view Stack Trace");
    e.printStackTrace();
    }//GEN-LAST:event_jButton1MouseClicked
    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
    }//GEN-LAST:event_formWindowOpened
    public static void run(){
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    frmMain frmMain = new frmMain();
    frmMain.setLocationRelativeTo(null); // Center the JFrame on the
    frmMain.setVisible(true);
    private void exitApplication() {
    // try {
    // //gui.putStatus("Closing the connection....please wait.....");
    // if(connection != null) {
    // // connection.close(); //Closing the connection object.
    // } catch(SQLException ex) { //Trap SQLException
    // //gui.putStatus(ex.toString());
    System.exit(0); //Exit the aplication
    * @param args the command line arguments
    public static void main(String args[]) {
    run();
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JTable jGrid;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSplitPane jSplitPane;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTree jTree1;
    // End of variables declaration//GEN-END:variables
    }

    Use code tags.
    Don't mix GUI and JDBC together. Split them out into separate classes.
    You have a good start, but you will need to loop through your resultset and also pull the ResultSet metaData for you column headings

  • Dynamic PL/SQL block vs dynamic SQL SELECT

    Hi there,
    I have a question regarding the optimal way to code a dynamic SELECT INTO statement. Below are the 2 posiibilities I know of:
    _1. Dynamically executing the SELECT statement and making use of the INTO clause of the EXECUTE IMMEDIATE statement_
    CREATE OR REPLACE FUNCTION get_num_of_employees (p_loc VARCHAR2, p_job VARCHAR2)
    RETURN NUMBER
    IS
    v_query_str VARCHAR2(1000);
    v_num_of_employees NUMBER;
    BEGIN
    v_query_str := 'SELECT COUNT(*) FROM emp_'
    || p_loc
    || ' WHERE job = :bind_job';
    EXECUTE IMMEDIATE v_query_str
    INTO v_num_of_employees
    USING p_job;
    RETURN v_num_of_employees;
    END;
    _2. Encapsulating the SELECT INTO statement in a block and dynamically exectuting the block_
    CREATE OR REPLACE FUNCTION get_num_of_employees (p_loc VARCHAR2, p_job VARCHAR2)
    RETURN NUMBER
    IS
    v_query_str VARCHAR2(1000);
    v_num_of_employees NUMBER;
    BEGIN
    v_query_str := 'begin
    SELECT COUNT(*) INTO :into_bind FROM emp_'
    || p_loc
    || ' WHERE job = :bind_job;
    end;';
    EXECUTE IMMEDIATE v_query_str
    USING out v_num_of_employees, p_job;
    RETURN v_num_of_employees;
    END;
    I was just wondering which way would be preferred? I know the second method uses a bind variable for the INTO clause, but does the first one also use bind varialbes (no semi-colon)? Any differences in terms of efficiency or speed?
    Thanks alot
    Edited by: BYS2 on Oct 19, 2011 1:23 AM

    sybrand_b wrote:
    No difference in terms of performance or speed
    Both variants will wreck the primary purpose of PL/SQL: to avoid parsing.
    When I would see a 'developer' do this, I would fire him on the spot.
    Why abuse PL/SQL in such a fashion? Both statements don't require parsing, as there is nothing dynamic in them and indicate a complete lack of understanding of Oracle, or a desire to deliver completely unscalable applications, resulting in end-users desiring to lynch you, and rightly so.
    Remove the dynamic SQL or find another job.
    Sybrand Bakker
    Senior Oracle DBANot dynamic? What if p_loc and p_job were generated dynamically based on user-input? or what if there were potentially thousands of tables that p_loc could refer to? Should I make a CASE statement with a thousand cases?
    In addition, the first example was actually taken directly from the official Oracle Database Application Developer's Guide (version 10.2). http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_dynamic_sql.htm#i1006429 - look under 'Sample Single-Row Query Using Native Dynamic SQL' heading. Therefore, if you have any issues with this alleged 'improper' usage of dynamic SQL, perhaps you should go talk to Oracle directly.
    While I appreciate your response, I don't think it has occurred that you that not everyone is a 'developer'. In fact, I have only very recently (several days ago) taught myself how to use Oracle SQL, PL/SQL and XMLDB by reading several of the official Oracle language and developer's guides. It is more a passing interest to me as I am working on some medical research which may require the use of a database. I am actually in medical school at the moment but have an undergraduate degree in Electrical and Computer engineering so I am generally well-versed in programming.
    Perhaps the next time, you post your rubbish, rude and unhelpful comments, you should stop and think that people come to this forum because they need help and not because they want to be told to 'find another job'. In fact, I am quite certain that I could make you look absolutely stupid in any topic of electrical engineering or medicine.
    Please do us all a favour and stop polluting this forum with your vapid posts. While I understand that your behavior is likely a compensatory mechanism to cope with your inferiority complex, know that help IS available if you need it.
    Edited by: BYS2 on Oct 19, 2011 2:13 AM

  • Returning Cursor using WITH

    Hi
    in my procedure there is a Parameter cursor, How can I to return cursor using WITH
    my cursor is P_cursor
      open p_curosr is
      with my_tab ( select .....  from.....)
      select columns01, columns02,....etc
       from  my_tab,
               others_tabs
       where .....did not work
    How can I to open cursor returning to Client side ?

    did not workwhat is an error?
    probably you forgot to put with my_table AS
    SQL> set serveroutput on;
    SQL>
    SQL> declare
    2   cursor p is
    3   with t as (select 1 num from dual union all
    select 2 from dual)
    4    select * from t;
    5   p1 p%rowtype;
    6   --
    7  begin
    8   open p;
    9    loop
    10      fetch p into p1;
    11      exit when p%notfound;
    12      dbms_output.put_line(p1.num);
    13     end loop;
    14   close p;
    15  end;
    16  /
    1
    2
    PL/SQL procedure successfully completed
    SQL>
    Thanks
    But I need to Open P_cursor without Fetch , P_cursor is is ref cursor passed like parameter
    procedure   my_proc (P_cursor out  out  Typedefined)
       Open P_cursor
        WITH mytable as ( select ......)
      no work

Maybe you are looking for

  • Does voltage output matter when using an adapter with the macbook???????

    i have a generic ac adapter modified with a magsafe plug it works fine on macbook pro i tested it it is 18.5 volts output 85watts will it work ok on macbook???

  • Extra DVI input on my monitor

    I own a  HP Pavillion PC p6631 connected to a HP2010i monitor and would like to have the monitor connected to 2 hard drives but only see one DVI input connector and I believe I need another one.   Can this be done and if so how.  Thank you  This ques

  • How do I set birthday reminders without having to create a separate contact card for each person in a family?

    I'm trying to set birthday reminders in iCal based on the birthday field in Contacts. But in order to create separate birthday entries for individuals in the same family, you have to set up a separate card for each person. Anyway around that?

  • Problems with colour profiles

    Hi, Since I reinstalled Win7 and Photoshop, every time I open a document it is in the "working RGB" colour profile, which makes the document whitish. So I have to assign another profile, namely the one associated with my monitor. But I have to do thi

  • Plug-in not loading - Audition 2.0

    I tried using the ADT plug-in (from http://www.vacuumsound.de/plugins.html) in Audition 2.0.  It's not even recognized when I try to look for it on my plug-ins list.  Other plug-ins from that site seem to load and work fine in Audition.  Tried the AD