using indexes on varchar confusion with pl/sql collections

Hi, I seek to learn the mechanics behind the collections and have done ok so far until I came across you try using the index of varchar.

I use the following code: -.
declare
  type address_lines_tab is table of varchar2(50)
    index by pls_integer;

  type address_tab is table of address_lines_tab
    index by varchar(40);

  type student_rec is record(
    first     varchar2(40),
    last      varchar2(40),
    address   address_tab
  );

  type student_tab is table of student_rec
    index by pls_integer;

  student   student_tab;
  i         number       := 0;
  v         varchar2(20);
  x         number       := 0;
begin
  student(1).first := 'mike';
  student(1).last := 'jones';
  student(1).address('home')(1) := 'the manor';
  student(1).address('home')(2) := 'london';
  student(1).address('home')(3) := 'w12 4kf';
  student(1).address('term')(1) := '5 university';
  student(1).address('term')(2) := 'plymouth';
  student(1).address('term')(3) := 'pl22da';
  student(2).first := 'helen';
  student(2).last := 'roots';
  student(2).address('home')(1) := '1 little lane';
  student(2).address('home')(2) := 'hull';
  student(2).address('home')(3) := 'h45 4fd';
  student(2).address('term')(1) := '3 university';
  student(2).address('term')(2) := 'plymouth';
  student(2).address('term')(3) := 'pl22da';

  for student_no in student.first .. student.last
  loop
    dbms_output.put_line(   'STUDNET NAME:'
                         || student(student_no).first
                         || ' '
                         || student(student_no).last);

    for add_type in
      student(student_no).address.first .. student(student_no).address.last
    loop
      dbms_output.put_line(student(student_no).address);
      for add_line in
        student(student_no).address(add_type).first .. student(student_no).address(add_type).last
      loop
        dbms_output.put_line(student(student_no).address(add_type)(add_line));
      end loop;
    end loop;
  end loop;
end;
the problem I have is in the second loop when trying to display 2 different types of address (IE home and term).

because its indexed by a varchar, I get the following error: -.
ORA-06502: PL/SQL: digital or value error: character of number conversion error

How can I get around that, when a loop in the associative arrays that are indexed by varchar?

Thank you very much

It's the exit, I expect to see:-
STUDNET NAME:mike jones
HOME
the manor
london
w12 4kf
TERM
5 university
plymouth
pl22da
STUDNET NAME:helen roots
HOME
1 little lane
hull
h45 4fd
TERM
3 university
plymouth
pl22da

Hello..

The problem is tat you can not use a "student (student_no).address.first" and "student (student_no).address.last" in a loop; because they are varchar2 index...

Yo can use, something like that...

    nuStudent := student(student_no).address.count;
    for add_type in 1 ..nuStudent 

Tags: Database

Similar Questions

  • run immediately with bind sql collection

    Hi, I'm working on an implementation immediate execution where to use a binding that is to an SQL array type. The type of table is produced by be transmitted from an array of Java.

    So it looks like:

    execute immediate mystatement using myarray;

    "mystatement" contains a forall command. I thought that it wouldn't work, because of limitations in the use of tables to link with dynamic sql, but it does. Also, I see in the Oracle documentation that allows dynamic sql to binds to SQL collection types. Am I so I read the documentation correctly, please, that this is a correct use of the immediate execution with a SQL collection?

    I tested on 10.2 and 11 g

    Thank you

    David

    979394 wrote:
    Hi, I'm working on an implementation immediate execution where to use a binding that is to an SQL array type. The type of table is produced by be transmitted from an array of Java.

    So it looks like:

    execute immediate mystatement using myarray;

    "mystatement" contains a forall command. I thought that it wouldn't work, because of limitations in the use of tables to link with dynamic sql, but it does. Also, I see in the Oracle documentation that allows dynamic sql to binds to SQL collection types. Am I so I read the documentation correctly, please, that this is a correct use of the immediate execution with a SQL collection?

    I tested on 10.2 and 11 g

    Thank you

    David

    Welcome to the Forum!
    Here is a small demonstration to what Solomon said: (not the best of examples I would say, but should provide an indication)

    drop table depts;
    drop table emps;
    drop type type_depts;
    
    create table depts (dept_no   number, dept_name varchar2(25), loc varchar2(10));
    
    create table emps (empno  number, name varchar2(25), dept_no  number, salary number);
    
    create or replace type type_depts is table of number;
    
    insert into depts values (10, 'ABC', '111');
    insert into depts values (20, 'ABC1', '111');
    insert into depts values (30, 'ABC2', '111');
    insert into depts values (40, 'ABC3', '111');
    insert into depts values (50, 'ABC4', '111');
    
    insert into emps values (1, 'PQR', 10, 100);
    insert into emps values (2, 'PQR1', 20, 100);
    insert into emps values (3, 'PQR2', 30, 100);
    insert into emps values (4, 'PQR3', 10, 100);
    insert into emps values (5, 'PQR4', 30, 100);
    insert into emps values (6, 'PQR5', 10, 100);
    insert into emps values (7, 'PQR6', 40, 100);
    insert into emps values (8, 'PQR7', 80, 100);
    
    commit;
    
    /* Block to find a DEPT_NO in EMP that does not exist in DEPT table */
    set serveroutput on;
    declare
      dept    type_depts;
    
      type type_emp is table of pls_integer index by pls_integer;
      emp     type_emp;
    
      idx     pls_integer;
    begin
      select dept_no
        bulk collect into dept
        from depts;
    
      execute immediate 'select empno from emps where dept_no not in (select column_value from table(:1))' bulk collect into emp using dept;
    
      for i in emp.first..emp.last loop
        dbms_output.put_line('Emp No:- ' || emp(i));
      end loop;
    end;
    
    anonymous block completed
    Emp No:- 8
    

    As you say, the 'mystatement"contains the FORALL statement; Is the name of the Table known at runtime, or it is passed as an additional parameter? If the Table name is known, then, IMO, there is no any dynamic SQL. A FORALL statement should be enough.

    Please provide details. In addition, please read {message identifier: = 9360002}.

  • Using index z is compatible with fluid Grid Layout CS6?

    Hello

    I imagine that because you cannot use absolute positioning grid to fluid, index Z is not an option?

    I tried all the different variations anyway, but couldn't do my 3 divs to stack it with success.

    There are some occasions where they stack, but it ruined other elements of the page.

    What do you say?

    Thank you very much.

    Absolute positioning can still be used in a design responsive, but be careful because it can destroy the design if not done correctly.

    Judging from your description, the problem could be something else. Please give us a link to the site so that we can have a look.

  • Confusion with a SQL

    I want to know about these sales_code that are present in tb_ken_payout but it lacks tb_payout_ken_xls. I wrote the following query to get the data:

    SELECT sales_code
    OF tb_ken_payout
    WHERE sales_code NOT IN
    (SELECT lgsalescode
    OF tb_payout_ken_xls);

    He did return no rows. However, when I re-writes the SQL code, he returned number of rows.

    SELECT sales_code,
    lgsalescode
    Tb_ken_payout a.,
    tb_payout_ken_xls b
    WHERE sales_code = lgsalescode (+)
    AND lgsalescode IS NULL;

    I think that the two SQLs output should be same. Who is correct, one that is bad and why?

    Hello

    Operatiors logical (such as = and IN) can return three different values:
    TRUE
    FAKE
    UNKNOWN

    The result of

    x = y
    

    is UNKNOWN if x or NULL.

    The results of

    x IN ( SELECT  y
           FROM    table_z
         )
    

    will be set to TRUE if x = y for one of the lines is found; Otherwise, IN will return FALSE only when x! = y for all lines. IN return UNKNOWN if x = y for any of the lines, but there IS NULL for at least one. It is usually normal, because

    WHERE   x IN ( SELECT  y
                   FROM    table_z
                 )
    

    means "choose this line if IN returns TRUE. The line is not levied if IN return FALSE or UNKNOWN.
    The logic to three values is important when you do NOT, because "NOT UNKNOWN" itself is UNKNOWN. It's

    WHERE   x NOT IN ( SELECT  y
                       FROM    table_z
                     )
    

    Let's get the line only if IN returns FALSE (and, therefore, NOT IN returns TRUE). If IN returns UNKNOWN, then the whole State is UNKNOWN, and the line is not drawn.

    It is therefore always if ensure a NOT IN subquery will return all the lines with NULL value, like this:

    WHERE   x NOT IN ( SELECT  y
                       FROM    table_z
                       WHERE   y  IS NOT NULL
                     )
    

    If you do NOT use, then the additional condition 'IS NOT NULL' will not change the results of a subquery IN. In other words, you could say:

    WHERE   x IN ( SELECT  y
                   FROM    table_z
                   WHERE   y IS NOT NULL
                 )
    

    but do not, and it is less effective.

  • PL/SQL collection headaches

    Hello guys,.

    Thought maybe you could help simple here, I write a procedure to validate a Tin CAN.

    Basic rules are

    A Tin CAN has exactly eleven digits.
    Among the ten first exactly two digits are the same (the others are all different).
    -And then some - check digit - check module.

    The control module that brings me to put all the numbers in a table. So far so good.
    Then, I need to check "exactly two. Now that I have them in a table, I had in my mind that I could use this table. But I'm NOT in good terms with PL/SQL collections ;)

    I've been watching of multiset, but doesn't seem not that it is, or?

    So far I did it in SQL, but which seems to repeat what I just did, so I thought if a solution using the table. (I know how to do these two things in a single SQL, but I fear that no one here will understand)

    This is my procedure (please do not pay attention to the management of exceptions)
    SQL> CREATE OR REPLACE PROCEDURE validate_otn (in_tin VARCHAR2) IS
      TYPE tin_t IS VARRAY (11) OF PLS_INTEGER NOT NULL;
    
      v_digits       tin_t := tin_t (0);
      v_count        NUMBER;
      v_count_dist   NUMBER;
    BEGIN
      --
      -- Verify that we have numeric, non-null input
      --
      IF TO_NUMBER (in_tin) IS NULL THEN
        RETURN;
      END IF;
    
      ---------
      -- Verify that we have exactly the right number of digits
      ---------
      IF LENGTH (in_tin) != v_digits.LIMIT THEN
        RAISE VALUE_ERROR;
      END IF;
    
      ---------
      -- Put all digits into array
      ---------
      SELECT     SUBSTR (in_tin,
                         LEVEL,
                         1
                        )
                   x
      BULK       COLLECT INTO v_digits
      FROM       DUAL
      CONNECT BY LEVEL <= LENGTH (in_tin);
    
      ---------
      -- Verify exactly one digit used twice, among first ten
      ---------
      SELECT COUNT (x),
             COUNT (DISTINCT x)
      INTO   v_count,
             v_count_dist
      FROM   (SELECT     SUBSTR (in_tin,
                                 LEVEL,
                                 1
                                )
                           x
              FROM       DUAL
              CONNECT BY LEVEL <= LENGTH (in_tin) - 1);
    
      IF v_count - v_count_dist != 1 THEN
        RAISE VALUE_ERROR;
      END IF;
    --
    -- Lots more to come, including some modulo checks, etc
    --
    EXCEPTION
      WHEN OTHERS THEN
        DBMS_OUTPUT.put_line (SQLERRM);
        RAISE VALUE_ERROR;
    END validate_otn;
    /
    Procedure created.
    
    SQL> show errors
    No errors.
    
    SQL> select banner from v$version;
    
    BANNER                                                          
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production                          
    CORE     10.2.0.3.0     Production                                      
    TNS for Linux: Version 10.2.0.3.0 - Production                  
    NLSRTL Version 10.2.0.3.0 - Production                          
    
    5 rows selected.
    I'm looking to replace it with Collection/full year:
      SELECT COUNT (x),
             COUNT (DISTINCT x)
      INTO   v_count,
             v_count_dist
      FROM   (SELECT     SUBSTR (in_tin,
                                 LEVEL,
                                 1
                                )
                           x
              FROM       DUAL
              CONNECT BY LEVEL <= LENGTH (in_tin) - 1);
    Any ideas?


    I don't want to follow during a casting of hours - commuting.


    Best regards
    Peter

    Returns The VALUE of distinct values, for example:

    DECLARE
       p_tin CONSTANT sys.ku$_objnumset := sys.ku$_objnumset(1,2,2,3,4,5,6,7,8,9,10);
    BEGIN
       DBMS_OUTPUT.PUT_LINE(p_tin.count || ' elements');
       DBMS_OUTPUT.PUT_LINE(SET(p_tin).count || ' distinct elements');
    END;
    
    11 elements
    10 distinct elements
    

    You can probably use it somehow.

    Note that it needs correct nested table collections, not varrays.

  • [SQL] Tuning why he can't use indexes?

    Here's a SQL that cannot use indexes

    SELECT T.FID FID,

    t.cfsignState SIGNSTATE,

    T.FNUMBER WBNUMBER,

    T1. CFCUSTOMERTRANSNUMBER CUNUMBER,

    T2. CFCOMPANYNAME CUSTOMERNAME,

    T.CFATTACHMENTFILE ATTFILE,

    T.CFATTACHMENT ATT

    OF CT_OPE_SIGNBILL T

    LEFT OUTER JOIN CT_OPE_WAYBILL T1

    ON T1. FID = T.CFWAYBILLID

    LEFT OUTER JOIN T2 CT_MAR_CUSTOMER

    ON T2. FID = T1. CFCUSTOMERID

    WHERE ((T.FNUMBER ('1410582816' N)) OR (T1.) CFCUSTOMERTRANSNUMBER (N '1410582816')));

    Elapsed time: 00:00:12.15

    Execution plan

    ----------------------------------------------------------

    Hash value of plan: 2925502694

    ------------------------------------------------------------------------------------------------------------------------

    | ID | Operation | Name | Lines | Bytes | TempSpc | Cost (% CPU). Time | Pstart. Pstop |

    ------------------------------------------------------------------------------------------------------------------------

    |   0 | SELECT STATEMENT |                 |     2.   420.       | 48996 (3) | 00:01:16 |       |       |

    |   1.  NESTED EXTERNAL LOOPS |                 |     2.   420.       | 48996 (3) | 00:01:16 |       |       |

    |*  2 |   FILTER |                 |       |       |       |            |          |       |       |

    |*  3 |    EXTERNAL RIGHT HASH JOIN |                 |     2.   310.    67 M | 48995 (3) | 00:01:16 |       |       |

    |   4.     RANGE OF PARTITION ALL THE |                 |  1241K |    53 M |       | 36422 (3) | 00:00:57 |     1.    63.

    |   5.      TABLE ACCESS FULL | CT_OPE_WAYBILL |  1241K |    53 M |       | 36422 (3) | 00:00:57 |     1.    63.

    |   6.     TABLE ACCESS FULL | CT_OPE_SIGNBILL |   907K |    95 M |       |  8217 (5) | 00:00:13 |       |       |

    |   7.   TABLE ACCESS BY INDEX ROWID | CT_MAR_CUSTOMER |     1.    55.       |     1 (0) | 00:00:01 |       |       |

    |*  8 |    INDEX UNIQUE SCAN | PK_MAR_CUSTOMER |     1.       |       |     1 (0) | 00:00:01 |       |       |

    ------------------------------------------------------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):

    ---------------------------------------------------

    2 - filter("T".") FNUMBER ' = U ' 1410582816 "OR 'T1'. '. CFCUSTOMERTRANSNUMBER '= U '1410582816')

    3 - access("T1".") IDF"(+) ="T ". ("' CFWAYBILLID")

    8 - access("T2".") IDF"(+) ="T1 ". ("' CFCUSTOMERID")

    Statistics

    ----------------------------------------------------------

    1 recursive calls

    19 db block Gets

    234698 compatible Gets

    191546 physical reads

    0 redo size

    1035 bytes sent via SQL * Net to client

    524 bytes received via SQL * Net from client

    2 SQL * Net back and forth to and from the client

    0 sorts (memory)

    0 sorts (disk)

    1 rows processed

    but, if I rewrite it as below, it can use indexes

    SELECT T.FID FID,

    t.cfsignState SIGNSTATE,

    T.FNUMBER WBNUMBER,

    T1. CFCUSTOMERTRANSNUMBER CUNUMBER,

    T2. CFCOMPANYNAME CUSTOMERNAME,

    T.CFATTACHMENTFILE ATTFILE,

    T.CFATTACHMENT ATT

    OF CT_OPE_SIGNBILL T

    LEFT OUTER JOIN CT_OPE_WAYBILL T1

    ON T1. FID = T.CFWAYBILLID

    LEFT OUTER JOIN T2 CT_MAR_CUSTOMER

    ON T2. FID = T1. CFCUSTOMERID

    WHERE ((T.FNUMBER (N '1410582816')))

    Union

    SELECT T.FID FID,

    t.cfsignState SIGNSTATE,

    T.FNUMBER WBNUMBER,

    T1. CFCUSTOMERTRANSNUMBER CUNUMBER,

    T2. CFCOMPANYNAME CUSTOMERNAME,

    T.CFATTACHMENTFILE ATTFILE,

    T.CFATTACHMENT ATT

    OF CT_OPE_SIGNBILL T

    LEFT OUTER JOIN CT_OPE_WAYBILL T1

    ON T1. FID = T.CFWAYBILLID

    LEFT OUTER JOIN T2 CT_MAR_CUSTOMER

    ON T2. FID = T1. CFCUSTOMERID

    WHERE ((T1. CFCUSTOMERTRANSNUMBER (N '1410582816')));

    Elapsed time: 00:00:00.02

    Execution plan

    ----------------------------------------------------------

    Hash value of plan: 2215743926

    -----------------------------------------------------------------------------------------------------------------------------------

    | ID | Operation | Name                     | Lines | Bytes | Cost (% CPU). Time | Pstart. Pstop |

    -----------------------------------------------------------------------------------------------------------------------------------

    |   0 | SELECT STATEMENT |                          |     2.   420.    11 (64) | 00:00:01 |       |       |

    |   1.  UNIQUE FATE |                          |     2.   420.    11 (64) | 00:00:01 |       |       |

    |   2.   UNION-ALL |                          |       |       |            |          |       |       |

    |   3.    NESTED EXTERNAL LOOPS |                          |     1.   210 |     4 (0) | 00:00:01 |       |       |

    |   4.     NESTED EXTERNAL LOOPS |                          |     1.   155.     3 (0) | 00:00:01 |       |       |

    |   5.      TABLE ACCESS BY INDEX ROWID | CT_OPE_SIGNBILL |     1.   110.     2 (0) | 00:00:01 |       |       |

    |*  6 |       INDEX RANGE SCAN | IDX_CT_OPE_SIGNBILL_IT01 |     1.       |     1 (0) | 00:00:01 |       |       |

    |   7.      TABLE ACCESS BY INDEX ROWID | CT_OPE_WAYBILL |  1241K |    53 M |     1 (0) | 00:00:01 | ROWID | ROWID |

    |*  8 |       INDEX UNIQUE SCAN | CPK_OPE_WAYBILLBP7 |     1.       |     1 (0) | 00:00:01 |       |       |

    |   9.     TABLE ACCESS BY INDEX ROWID | CT_MAR_CUSTOMER | 25598 |  1374K |     1 (0) | 00:00:01 |       |       |

    | * 10 |      INDEX UNIQUE SCAN | PK_MAR_CUSTOMER |     1.       |     1 (0) | 00:00:01 |       |       |

    |  11.    NESTED LOOPS |                          |     1.   210 |     5 (0) | 00:00:01 |       |       |

    |  12.     NESTED EXTERNAL LOOPS |                          |     1.   100.     4 (0) | 00:00:01 |       |       |

    |  13.      TABLE ACCESS BY INDEX ROWID | CT_OPE_WAYBILL |     1.    45.     3 (0) | 00:00:01 | ROWID | ROWID |

    | * 14 |       INDEX RANGE SCAN | IDX$ $_47CB0003 |     1.       |     2 (0) | 00:00:01 |       |       |

    |  15.      TABLE ACCESS BY INDEX ROWID | CT_MAR_CUSTOMER |     1.    55.     1 (0) | 00:00:01 |       |       |

    | * 16.       INDEX UNIQUE SCAN | PK_MAR_CUSTOMER |     1.       |     1 (0) | 00:00:01 |       |       |

    |  17.     TABLE ACCESS BY INDEX ROWID | CT_OPE_SIGNBILL |     1.   110.     2 (0) | 00:00:01 |       |       |

    | * 18.      INDEX RANGE SCAN | IDX$ $_47C30001 |     1.       |     1 (0) | 00:00:01 |       |       |

    -----------------------------------------------------------------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):

    ---------------------------------------------------

    6 - access("T".") FNUMBER "= U '1410582816')

    8 - access("T1".") IDF"(+) ="T ". ("' CFWAYBILLID")

    10 - access("T2".") IDF"(+) ="T1 ". ("' CFCUSTOMERID")

    14 - access("T1".") CFCUSTOMERTRANSNUMBER '= U '1410582816')

    16 - access("T2".") IDF"(+) ="T1 ". ("' CFCUSTOMERID")

    18 - access("T1".") IDF '=' T '. ("' CFWAYBILLID")

    Statistics

    ----------------------------------------------------------

    1 recursive calls

    0 db block Gets

    Gets 11 coherent

    0 physical reads

    0 redo size

    1035 bytes sent via SQL * Net to client

    524 bytes received via SQL * Net from client

    2 SQL * Net back and forth to and from the client

    1 sorts (memory)

    0 sorts (disk)

    1 rows processed

    SQL >

    My Question is why the first statement cannot use indexes? What is its mechanism?

    as Maria Colgan explains in his commentary on https://blogs.oracle.com/optimizer/entry/or_expansion_transformation: "since OR expansion is a transformation focused on costs, it cannot always take place." It cannot take place, then it can be forced by using the indicator, USE_CONCAT. "Fundamentally OR expansion is

    a transformation that can be used to optimize the disjunctive queries (queries that contain clauses of GOLD). The basic idea of in the expansion of the GOLD is to transform a query containing the disjunctions in the form of a query UNION ALL of two or more branches. This is done by dividing the disjunction in components and by associating each component with a branch of a query UNION all.

    So, you can use the USE_CONCAT flag to check if OR expansion is an option at all for the optimizer in your example. The strategy itself is quite old and mentioned by Tom Kyte in https://asktom.oracle.com/pls/apex/f?p=100:11:0:P11_QUESTION_ID:921229345078.

  • Digital / use of the Index of Varchar BINARY not

    Hello

    We had recently on our system a table with an index of Varchar2, who was not used and causing the queries to do a full table scan.

    The user used for querying is the user used by the ETL, and in order to avoid the distinction of uppercase / lowercase, this user has a trigger to change the Dutch NLS settings.

    User settings are:
    NLS_LANGUAGE = DUTCH
    NLS_SORT = DUTCH_CI
    NLS_COMP = ANSI

    As far as I know, when NLS_COMP is set to ANSI, it uses the NLS_SORT setting.
    That is why in this case, we use not BINARY.

    I also know that do not use the BINARY is supposed to so that the user not to use indexes, they are created by default in BINARY format.

    However, until today almost all our used queries index properly.
    Which is a bit suspicious, that we did not use the BINARY parameters.

    It's why I did some checking, and what I concluded was the following:
    * When you have a numeric index (Number type), the index is used, even when the user uses no BINARY file
    * When the index is a character (type varchar2), the index is not used when the user is not BINARY, however it will be used when parameters NLS_SORT = BINARY.

    I couldn't find anywhere on the internet a explanation on the difference between a number and the type Varchar index and whether they should act differently with the BINARY sort.

    Please could someone explain this behavior, it would be an interesting lesson for me.


    Kind regards

    Yaron

    NLS_COMP and NLS_SORT are only relevant for character data, it is related to the internal digital representation of characters. Binary number compared with the linguistic characteristics do not, they are always sorted pure 'mathematically '.

    Werner

  • I just got an iphone and am confused with itunes.  I the have not used in years.  I can I sync my music from itunes to iphone.

    I just got an iphone and am confused with itunes.  I the have not used in years.  I can I sync my music from itunes to iPhone.

    You need a computer that is running the latest iTunes version to either a Mac or Windows operating system.

    Mac

    1. Open iTunes.
    2. In the MenuBar at the top of your computer screen, choose iTunes > check for the updates.
    3. Follow the prompts to install the latest version.

    Windows

    1. Open iTunes.
    2. In the MenuBar at the top of the iTunes window, choose Help > check for updates. Learn what to do If you see not the menu bar.
    3. Follow the prompts to install the latest version.

    Instructions for syncing your iPhone here > synchronize your iPhone, iPad or iPod touch with iTunes on your computer via a USB - Apple Support

  • SQL not using indexes at runtime, but by using the index in "explain plan".

    Hi all

    I am facing a problem here that I don't get to think.

    I have a SQL that makes a FULL ACCESS of TABLE into two tables and its costs are very high, but it occurs only when I run it in my program (I saw it in the session trace). If I do a "explain plan" sqlplus (SQL Navigator or PLSQL Developer) it shows that he use indexes and have a low cost. I already checked the statistics from both tables, and they are up to date.

    Did someone never facing a similar problem or knows something I can do to find my problem?

    Thank you all very much.

    Hello

    As far as I KNOW, optimizer Oracle never guarantees that an Index scan in query explain plan will be necessarily used during query execution.

    ORACLE-BASE - DBMS_XPLAN: Oracle display execution Plans

    Could you please read the above, run the query, as described and check the execution using DBMS_XPLAN plan. The cursor cache DISPLAY_CURSOR and not PLAN_TABLEs.

  • Using XQuery with PL/SQL, link the Variable

    I am only able to find an example of use of xquery with pl/sql.

    [http://www.comp.dit.ie/btierney/oracle11gdoc/appdev.111/b28369/xdb_xquery.htm#CBAEEJDE]

    Why is what they show only using bind variables? It's the only way it should be used, it provides a performance gain more simply by using the crossing clause and a passing beam a PL/SQL variable? I'm looking to implement a solution for my company using Xquery in PL/SQL. I am concerned that these procedures will be called during a flow of the user interface and performance it must be as soon as possible.

    A PL/SQL variable, column, or the output of another operation would be all be equivalent to a connection variable that PL/SQL compilation is concerned. Which would be bad practice would be to build in XQuery with the predicate hardcoded in the XQuery operation whenever the XQuery query has been run.

  • Tables created in a stored procedure cannot be used with dynamic SQL? The impact?

    There is a thread on the forum which explains how to create tables within a stored procedure (How to create a table in a stored procedure , however, it does create a table as such, but not how to use it (insert, select, update, etc.) the table in the stored procedure.) Looking around and in the light of the tests, it seems that you need to use dynamic SQL statements to execute ddl in a stored procedure in Oracle DB. In addition, it also seems that you cannot use dynamic SQL statements for reuse (insert, select, update, etc.) the table that was created in the stored procedure? Is this really the case?

    If this is the case, I am afraid that if tables cannot be 'created and used"in a stored procedure using the dynamic SQL, as is the case with most of the servers of DB dynamic SQL is not a part of the implementation plan and, therefore, is quite expensive (slow). This is the case with Oracle, and if yes what is the performance impact? (Apparently, with Informix, yield loss is about 3 - 4 times, MS SQL - 4 - 5 times and so on).

    In summary, tables created within a stored procedure cannot be 'used' with dynamic SQL, and if so, what is the impact of performance as such?

    Thank you and best regards,
    Amedeo.

    Published by: AGF on March 17, 2009 10:51

    AGF says:
    Hi, Frank.

    Thank you for your response. I understand that the dynamic SQL is required in this context.

    Unfortunately, I am yet to discover "that seeks to" using temporary tables inside stored procedures. I'm helping a migration from MySQL to Oracle DB, and this was one of the dilemmas encountered. I'll post what is the attempt, when more.

    In Oracle, we use [global temporary Tables | http://www.psoug.org/reference/OLD/gtt.html?PHPSESSID=67b3adaeaf970906c5e037b23ed380c2] aka TWG these tables need only be created once everything like a normal table, but they act differently when they are used. The data inserted in TWG will be visible at the session that inserted data, allowing you to use the table for their own temporary needs while not collide with them of all sessions. The data of the TWG will be automatically deleted (if not deleted programmatically) when a) a commit is issued or b) the session ends according to the parameter that is used during the creation of the TWG. There is no real need in Oracle to create tables dynamically in code.

    I noticed that many people say that the "Creation of the tables within a stored procedure" is not a good idea, but nobody seems necessarily explain why? Think you could elaborate a little bit? Would be appreciated.

    The main reason is that when you come to compile PL/SQL code on the database, all explicit references to tables in the code must correspond to an existing table, otherwise a djab error will occur. This is necessary so that Oracle can validate the columns that are referenced, the data types of those columns etc.. These compilation controls are an important element to ensure that the compiled code is as error free as possible (there is no accounting for the logic of programmers though ;)).

    If you start to create tables dynamically in your PL/SQL code, so any time you want to reference this table you must ensure that you write your SQL queries dynamically too. Once you start doing this, then Oracle will not be able to validate your SQL syntax, check the types of data or SQL logic. This makes your code more difficult to write and harder to debug, because inevitably it contains errors. It also means that for example if you want to write a simple query to get that one out in a variable value (which would take a single line of SQL with static tables), you end up writing a dynamic slider all for her. Very heavy and very messy. You also get the situation in which, if you create tables dynamically in the code, you are also likely to drop tables dynamically in code. If it is a fixed table name, then in an environment multi-user, you get in a mess well when different user sessions are trying to determine if the table exists already or is the last one to use so they can drop etc. What headache! If you create tables with table names, then variable Dynamics not only make you a lot end up creating (and falling) of objects on the database, which can cause an overload on the update of the data dictionary, but how can ensure you that you clean the tables, if your code has an exception any. Indeed, you'll find yourself with redundant tables lying around on your database, may contain sensitive data that should be removed.

    With the TWG, you have none of these issues.

    Also, what is the impact on the performance of the dynamic SQL statements in Oracle? I read some contrasting opinions, some indicating that it is not a lot of difference between static SQL and SQL dynamic in more recent versions of Oracle DB (Re: why dynamic sql is slower than static sql is this true?)

    When the query runs on the database, there will be no difference in performance because it is just a request for enforcement in the SQL engine. Performance problems may occur if your dynamic query is not binding variable in the query correctly (because this would cause difficult analysis of the query rather than sweet), and also the extra time, to dynamically write the query running.

    Another risk of dynamic query is SQL injection which may result in a security risk on the database.

    Good programming will have little need for the tables of dynamically created dynamically or SQL.

  • need help in the associative arrays indexed by varchar

    Hi, I wanted to fill an associative array that is indexed by varchar, but I'm confused by incrementing the pointer so that the next lines gets inserted into the next available place.
    sample data:
    type ty_tb_tab_acc is record (account varchar2 (30));
    type ty_tb_indx_acct is table of index ty_tb_tab_acc by varchar2 (35);

    cursor sampls_cursor is
    Select an account in sam_tab where the clause goes in here

    say that my cursor returns 20 accounts. now, I want these 20 accounts will be inserted in the table associative ty_tb_indx_acct
    How should I buckle and incrment table?

    Please share your ideas

    user13710379 wrote:
    If this isn't the case, associatve tables approach I should use.
    My requirement:
    1.i will be 2 sliders who choose (type varchar2) account number according to diff where clause.
    2. then, I need to compare these two cusrsor account number and fill out a folder or a collection, if the two account numbers are the same.

    This must be done using SQL. Not the tables or collections or associative arrays.

    SQL is the MOST powerful language, that you have in the Oracle RDBMS. It is faster than PL/SQL, when it comes to crunch data. It is more scalable.

    So why then pull data SQL in PL/SQL (expensive) memory? And then shoot some more SQL data in memory of PL/SQL (expensive)? And then use PL/SQL loop processing to compare the two sets of data?

    SQL can do that very quickly and very efficiently - as it was designed for this specific purpose.

    See the JOIN, INTERSECT , and LESS SQL operations to compare data sets.

  • Error message: this isn't a problem with intellectual property. Board of Directors, but rather with your SQL Server when you visit a Web site.

    Original title: an error occurred in SQL server?

    Hello, I just wanted to go to this site, but this error pops up: error SQL

    An error occurred in SQL server:

    This isn't a problem with intellectual property. Board of Directors, but rather with your SQL Server. Please contact your host and copy the above message.

    «Back to index »

    Please help me, I just moved my computer so I had to disconnect from the internet, but now he has problems.

    Is the site I tried to go to: http://www.minecraftforum.net/topic/227822-166-millenaire-npc-village-076c-duplicate-villager-fix/

    Hey Brainiac,

    1. are you encounter problems with this site?

    2. are you able to connect to this site from a different computer?

    3. were you able to connect to this website before?

    4. you remember to make changes to the computer before this problem?

    The problem seems to be, with the site that you are visiting. You can check if you can access the site from another computer.

    Hope this information is useful.

  • Why the feature multiple column indexes using index skip scan?

    Hi all

    I have just been hired by a new company and I explored its database infrastructure. Interestingly, I see several function based indexed column used for all the tables. I found it strange, but they said ' we use Axapta to connect Axapta with Oracle, function index according to should be used to improve performance. Therefore, our DBAs create several indexes of feature based for each table in the database. "Unfortunately, I can not judge their business logic.

    My question is, I just created similar to my local database tables in order to understand the behavior of the function index according to several columns. In order to create indexes of based function (substr and nls_lower), I have to declare the columns as varchars2. Because in my business our DBAs had created a number of columns as a varchar2 data type. I created two excatly same table for my experience. I create miltiple function according to index on the my_first table, and then I create several normal index on the my_sec table. The interesting thing is, index skip scan cannot be performed on more than one basic function index (table my_first). However, it can be performed to normal several index on my_sec table. I hope that I have to express myself clearly.

    Note: I also ask the logic of the rule function based index, they said when they index a column they don't ((column length) * 2 + 1) formula. For example, I want to create indexes on the zip code column, column data type VARCHAR2 (3), so I have to use 3 * 2 + 1 = 7, (substr (nls_lower (areacode), 1, 7). substr (nls_lower ()) notation is used nested for any function function index. I know that these things are very illogical, but they told me, they use this type of implementation for Axapta.

    Anyway, in this thread, my question is reletad to function function with index index skip scan, not logical bussiness, because I can not change the business logic.

    Also, can you please give hints or clues for multiple function based indexes?

    Thanks for your help.


    SQL > create table my_first as select '201' codeZone, to_char (100 + rownum) account_num, dbms_random.st
    Ring name ('A', 10) from dual connect by level < = 5000;

    Table created.

    SQL > create table my_sec as select '201' codeZone, to_char (100 + rownum) account_num, dbms_random.st

    Ring name ('A', 10) from dual connect by level < = 5000;

    Table created.

    SQL > alter table my_first change account_num varchar2 (12);

    Modified table.


    SQL > alter table my_sec change account_num varchar2 (12);

    Modified table.

    SQL > alter table my_first change codeZone VARCHAR2 (3);

    Modified table.

    SQL > alter table my_sec change codeZone VARCHAR2 (3);

    Modified table.

    SQL > create index my_first_i on my_first (substr (nls_lower (areacode), 1, 7), substr (nls_lower (account_num), 1, 15));

    The index is created.

    SQL > create index my_sec_i on my_sec (area code, account_num);

    The index is created.

    SQL > analyze table my_first computing statistics for all columns indexed for all indexes.

    Parsed table.

    SQL > analyze table my_sec computing statistics for all columns indexed for all indexes.

    Parsed table.

    SQL > exec dbms_stats.gather_table_stats (USER, 'MY_FIRST');

    PL/SQL procedure successfully completed.

    SQL > exec dbms_stats.gather_table_stats (USER, 'MY_SEC');

    PL/SQL procedure successfully completed.

    SQL > my_first desc;
    Name                                      Null?    Type
    ----------------------------------------- -------- ----------------------------
    CODEZONE VARCHAR2 (3)
    ACCOUNT_NUM VARCHAR2 (12)
    NAME VARCHAR2 (4000)

    SQL > desc my_sec
    Name                                      Null?    Type
    ----------------------------------------- -------- ----------------------------
    CODEZONE VARCHAR2 (3)
    ACCOUNT_NUM VARCHAR2 (12)
    NAME VARCHAR2 (4000)

    SQL > select * from my_sec where account_num = '4000';


    Execution plan
    ----------------------------------------------------------
    Hash value of plan: 1838048852

    --------------------------------------------------------------------------------
    --------

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). TI
    me |

    --------------------------------------------------------------------------------
    --------

    |   0 | SELECT STATEMENT |          |     1.    19.     3 (0) | 00
    : 00:01 |

    |   1.  TABLE ACCESS BY INDEX ROWID | MY_SEC |     1.    19.     3 (0) | 00
    : 00:01 |

    |*  2 |   INDEX SKIP SCAN | MY_SEC_I |     1.       |     2 (0) | 00
    : 00:01 |

    --------------------------------------------------------------------------------
    --------


    Information of predicates (identified by the operation identity card):
    ---------------------------------------------------

    2 - access ("ACCOUNT_NUM" = '4000')
    Filter ("ACCOUNT_NUM" = '4000')


    Statistics
    ----------------------------------------------------------
    1 recursive calls
    0 db block Gets
    Gets 7 compatible
    0 physical reads
    0 redo size
    543 bytes sent via SQL * Net to client
    384 bytes received via SQL * Net from client
    2 SQL * Net back and forth to and from the client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed

    SQL > select * from my_first where substr (nls_lower (account_num), 1: 25) = '4000';


    Execution plan
    ----------------------------------------------------------
    Hash value of plan: 1110109060

    ------------------------------------------------------------------------------
    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
    ------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT |          |     1.    20.     9 (12) | 00:00:01 |
    |*  1 |  TABLE ACCESS FULL | MY_FIRST |     1.    20.     9 (12) | 00:00:01 |
    ------------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):
    ---------------------------------------------------

    1 Filter (SUBSTR (NLS_LOWER ("MY_FIRST". "" "" ACCOUNT_NUM")(, 1, 15) ="4000"
    AND SUBSTR (NLS_LOWER ("ACCOUNT_NUM"), 1, 25) = '4000')


    Statistics
    ----------------------------------------------------------
    15 recursive calls
    0 db block Gets
    Gets 26 consistent
    0 physical reads
    0 redo size
    543 bytes sent via SQL * Net to client
    384 bytes received via SQL * Net from client
    2 SQL * Net back and forth to and from the client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed

    SQL > Select / * + INDEX_SS (MY_FIRST) * / * from my_first where substr (nls_lower (account_num), 1: 25) = '4000';


    Execution plan
    ----------------------------------------------------------
    Hash value of plan: 2466066660

    --------------------------------------------------------------------------------
    ----------

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU).
    Time |

    --------------------------------------------------------------------------------
    ----------

    |   0 | SELECT STATEMENT |            |     1.    20.    17 (6) |
    00:00:01 |

    |*  1 |  TABLE ACCESS BY INDEX ROWID | MY_FIRST |     1.    20.    17 (6) |
    00:00:01 |

    |*  2 |   INDEX SCAN FULL | MY_FIRST_I |     1.       |    16 (7) |
    00:00:01 |

    --------------------------------------------------------------------------------
    ----------


    Information of predicates (identified by the operation identity card):
    ---------------------------------------------------

    1 - filter (SUBSTR (NLS_LOWER ("ACCOUNT_NUM"), 1, 25) = '4000')
    2 - access (SUBSTR (NLS_LOWER ("ACCOUNT_NUM"), 1, 15) = '4000')
    Filter (substr (NLS_LOWER ("ACCOUNT_NUM"), 1, 15) = '4000')


    Statistics
    ----------------------------------------------------------
    15 recursive calls
    0 db block Gets
    857 consistent gets
    0 physical reads
    0 redo size
    543 bytes sent via SQL * Net to client
    384 bytes received via SQL * Net from client
    2 SQL * Net back and forth to and from the client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed

    Check MoS for a bug with the FBI and Skip Scan - it sounds like it could be a bug.

    On 11.2.0.4 with your sample code 10053 trace shows the optimizer whereas an index FULL scan to the point where she should consider an index SKIP scan for "unique table path".

    A person with 12.1.0.1 practice would like to run your test and see if it's fixed in this version.

    Concerning

    Jonathan Lewis

  • Need help with PL/SQL so and then select

    Hello guys, I am new to the PL/SQl programming (only Java experience) and I'm pretty stuck to my task. It would be great if you could help me. I am in programming with Oracle SQL * Plus Version 10.2.0.3.0

    Whenever a user logs on to the server a database entry is created with information about the logged-on user. I need to create a PL/SQL command that selects all the information from last month. Unfortunately, the date_stamp column has a certain weird format: 1131210 for December 10, 2013


    My idea so far:


    DECLARE

    v_today NUMBER;

    BEGIN

    v_today: = TO_NUMBER (TO_CHAR (SYSDATE, 'MM'));       -Save the number of the month (e.g.12) in v_today

    IF v_today = 01 THEN

    SELECT * from audittrl

    WHERE the date_stamp between 1131201 AND the 1131231;

    ELSIF v_today = 02 THEN

    SELECT * from audittrl

    WHERE the date_stamp between the 1130131 AND 1130101;

    .......

    END IF;

    END;

    /

    Error code: "an INTO clause in this SELECT statement.

    I do not want to save the result to select a variable, hope you can help me. Thanks in advance.

    Hello

    6a4d1bcd-c00e-4dac-AB64-9b6bdb1652d1 wrote:

    Thanks, I'll try that, if still get caught once, I'll be back. Anway I'm not sure of the solution of Chris227, because I can't test it right now. From my point of view it gives you information the current month (e.g., December) and not the month previous (-online November), or have I missed something. ?

    You are right.  In addition, it does not for a given year.  If you have data from several years in the table, it will select lines for the month of December 2012, 2011, 2010,... but also of 2013.

    Here's a way to get around that:

    DECLARE

    prev_month_start PLS_INTEGER: = TO_NUMBER (TO_CHAR (ADD_MONTHS (SYSDATE-1)

    , "YYMM"1' "01"

    )

    );

    this_month_start PLS_INTEGER: = TO_NUMBER (TO_CHAR (SYSDATE

    , "YYMM"1' "01"

    )

    );

    BEGIN
    FOR (IN) rec
    SELECT *.
    Of audittrl
    WHERE the date_stamp > = prev_month_start
    AND date_stamp< >
    ORDER BY user_id, date_stamp - or other

    )
    LOOP
    dbms_output.put_line (rec.date_stamp);
    dbms_output.put_line (rec.event);
    dbms_output.put_line (rec.user_id)
    dbms_output.put_line (rec.host_name);
    END LOOP;
    END;

    This should also be more effective, because it will allow the optimizer to use an index on date_stamp.  Even if there is no index, it will be more effective because it avoids calling any function (for example, SUBSTR) on each line of the table.

    You needn't PL/SQL to get these results.  Just use SQL, you might say:

    SELECT event, host_name, user_id and date_stamp
    Of audittrl
    WHERE the date_stamp > = TO_NUMBER (TO_CHAR (ADD_MONTHS (SYSDATE-1)
    , "YYMM"1' "01"
    )
    )
    AND date_stamp<  to_number="" (="" to_char="" (="" sysdate="" to_number="" (="" to_char="" (="">


    , "YYMM"1' "01"
    )
    )

    ORDER BY user_id, date_stamp - or other

    ;

    Your front end will provide column headers and touch the data so that the columns line up.  It can also set the output to a file.  (For example, if your front-end is SQL * Plus, you can use the command of the COIL.)

    I guess date_stamp is a NUMBER.  If it is a string, the solutions above can be simplified a bit.

    This problem (and many other problems) would be so much simpler if date_stamp was a DATE column.  Using numbers or strings to store the date information is simply asking for trouble.

Maybe you are looking for

  • Trouble turninig off Satellite L40 with connected AC

    I have trouble with my laptop; I can not turn off/put into hibernation / sleep my computer when the AC adapter is connected. After I finished my work on my computer I have im trying to turn on the computer in hibernation mode. After all the computer

  • OR 9403: Digital Input/Output slows timed loop?

    Hi all I use a loop timed sample of 7 current channels (NI 9023), 3-channel (NI 9025) voltage at 1000 Hz in scan mode and it works fine. However, when I add for 8 output channels of the input/output module digital module NI 9403 for timed loop, CAPAS

  • Weird problem, copy files don't mix well with the background change...?

    It is a small thing, but when I try to copy a new version of a file on the desktop, a window opens, asking me if I want to replace the old version. I already knew that, is not a problem. However, I also put my wallpaper to change every few seconds (c

  • Register for window 7 with wrong email.

    I registered window 7 with wrong email. How can I change?

  • Incorrect availability alerts

    I am currently tracking 15 platforms, 1 Linux which is the HQ 12 Windows Server 2003 and Windows 2000 Server 2 agents. I have when the Exchange availability alerts configured for Windows platforms.He works well for about two months, but over the last