Implementing Hash tables with chaining.

Hi, I'm in a Java data structures class right now and we have a program to do using hash tables. I've read about hash tables and chaining but does anyone know where i can find some examples of code that implement hash tables using chaining. It's all very confusing to me without seeing how it is used in a program.
To give you an idea of what we're doing, the assignment is to create a word processor that looks thru a file and adds different words to the table and also counts how many of each word there is in that file. Keep in mind I'm not asking for the code to this assignment just for some example of how coding hash tables/chaining works.

Simple and probably not complete overview:
Suppose you have an array in which you will store objects.
You take an object, and find a "hash code" for it. You then restrict the hash code in to the range of your array. This gives you the index where you can store your object.
But what if another object is already present at that index?
Different solutions to this exist - such as re-hashing. One solution is "chaining". Instead of storing the object directly at the hashed index - you store a list of objects which hashed to the same location.
When you do a lookup, you first get your hash. You then look at the corresponding location in the array. If you find a list rather than the required object, you walk along the list until you find the object you are looking for.
Of course, with a small array and bad hash distribution, the performance of this solution can degrade fairly quickly.
BTW, in the real world, just use one of the ready made collections in java.util.

Similar Messages

  • How  to Implement a Chained Hash Table with Linked Lists

    I'm making a migration from C/C++ to Java, and my task is to implement a Chained Hash Table with a Linked List. My problem is to put the strings(in this case names) hashed by the table using de Division Metod (H(k)= k mod N) in to a Linked list that is handling the colisions. My table has an interface implemented(public boolean insert(), public boolean findItem(), public void remove()). Any Help is needed. Thanks for everyone in advance.

    OK. you have your hash table. What you want it to do is keep key/value pairs in linked lists, so that when there is a collision, you add the key/value pair to the linked list rather than searching for free space on the table.
    This means that whenever you add an item, you hash it out, check to see if there is already a linked list and if not, create one and put it in that slot. Then in either case you add the key/value pair to the linked list if the key is not already on the linked list. If it is there you have to decide whether your requirements are to give an error or allow duplicate keys or just keep or modify one or the other (old/new).
    When you are searching for a key, you hash it out once again and check to see if there is a linked list at that slot. If there is one, look for the key and if it's there, return it and if not, or if there was no linked list at that slot, return an error.
    You aren't clear on whether you can simply use the provided linked-list implementations in the Java Collections or whether you have to cobble the linked list yourself. In any case, it's up to you.
    Is this what you're asking?
    Doug

  • Creating hash table with more than two columns

    Hello,
    I tried to search around and can't quite find what I'm trying to do. I know I can make a hash table like:
    $Hash = @{"Texas" = "Hot";"Alaska" = "Cold"}
    But I would like to add a third column, so for the sake of an example have the third one say travel by air and the other travel by car. What's the syntax so I can add more columns than two? Also, how can I change the column header names?

    I think you want something more like this:
    New-Object PSObject -property @{
    State="Texas"
    Temp="Hot"
    Travel="Air"
    If I set $hash to equal that:
    $hash = New-Object PSObject -property @{State="Texas";Temp="Hot";Travel="Air"}
    I get this:
    Travel                                  Temp                                    State
    Air                                     Hot                                    
    Texas
    If I have a master variable
    $hashes = @()
    I can set $hash to the new-object of relevant values each pass of a loop:
    $hash = New-Object PSObject -property @{State="Alaska";Temp="Cold";Travel="Car"}
    And add that to $hashes each time:
    $hashes += $hash
    and add to the collection:
    Travel                                  Temp                                    State
    Air                                     Hot                                    
    Texas
    Car                                     Cold                                    Alaska
    As mjolinor suggested, you really need to understand what you want to do.  I suspect you are just unfamiliar with the terms, because what you're describing is an array of values, which is better suited to a PSObject rather than to a hash table.  
    The method for populating a PSObject I describe above is just one variation of one particular method for doing so, there are others that may be more or less suitable for what you want to do.
    I hope this post has helped!
    Thank you, this is what I was looking for. I've never had to use powershell for this type of task before and did know of this process, and only could find hash tables when I poked around. This will make life much easier! 

  • How to implement fact tables with finest level of detail (fine-grained)?

    Hi,
    Maybe this is basic knowledge what I'm asking here... I don't know, well, here it goes:
    I need to know the way carry my transactional data to a fact table, but keeping the finest level of detail possible (namely, the transactions). I implemented my cubes with MOLAP option for storage (those were the specs that I had to follow) so I can't add a unique constraint to those structures.
    I only seem to be able to load aggregated, precomputed data. If I wanted to load the transactions (after the data has been transformed and clenased) where should I do it?
    I tried to implement a version of the fact tables as ROLAP but got nowhere (I couldn't add a unique constraint or index on that column either).
    I would really, really appreciate your help.
    Best Regards,
    osvaldo.
    [osantos]

    Hi Veeravalli,
    Thanks for your reply :)
    Let me explain the problem in more detail. I have one Date dimension(Date_Code,Month_Code,Quarter_Code,Half_Year_Code,Year_Code). Here Date_Code is the PK.
    In F1---->Date (Using Month_Code key)
    F2-------->Date (Using Date_Code Key)
    Level based hierarchy is there starting from Year to Date.Each level has PK defined and chronological key selected.
    F1 has level set to Month and F2 has level set to Day.
    Now if i am using ago() function on measure of F2 (having day level data) then it's working fine but if i am using ago() function on measure of F1...I am getting an error at Presentation service: Date_code must be projected for time-series functions.
    So the whole issue is with time-series functions. As per my research...I think for time series the tables in the physical model containing the time dimension cannot join to other data sources, except at the most detailed level but here i am joining with F1(using Month_Code which is not the most detailed level).
    So kindly let me know how to achieve this in rpd?

  • Hash Table Extract

    Hi,
    I'm hoping that someone will be able to explain how I extract the first element (in this case the name) from the hashtable in the server code below (case N:).
    import java.net.*;
    import java.io.*;
    import java.util.*;
    public class Server{
      private PrintWriter pw;
      private BufferedReader bf;
      private ServerSocket ss;
      private Socket s;
      //Hashtable used to store test data
      //Set up hash table with test data
      private Hashtable emails;
      public Server() throws Exception{
        emails = new Hashtable();
        emails.put("Ince","[email protected]");
        emails.put("Roberts","[email protected]");
        emails.put("Timms","[email protected]");
        emails.put("Rowlands","[email protected]");
        emails.put("Eustace","[email protected]");
        emails.put("Lord","[email protected]");
          System.out.println("...Setting up server socket");
          ss = new ServerSocket(1200);
          System.out.println("..waiting for connection ");
          s = ss.accept();
          System.out.println("..connection made");
          InputStream is = s.getInputStream();
          bf = new BufferedReader(new InputStreamReader(is));
          OutputStream os = s.getOutputStream();
          pw = new PrintWriter(os, true);
        public void  Run() throws Exception
        boolean cont = true;
        while(cont == true)//server runs while true
          String clientLine = bf.readLine();
          System.out.println( clientLine ); //used to check the connection
          switch(clientLine.charAt(0))
          case'E':
            String Name = "";
            String staffName = null;
            Name = clientLine.substring(1,clientLine.length());
            staffName = (String) emails.get(Name);
            pw.println(staffName);
            break;
          case'N':
            String email = "";
            String emailAddress = null;
            email = clientLine.substring(1,clientLine.length());
            emailAddress = (String) emails.get(email);
            pw.println(emailAddress);
            break;
          case'U':
            String number = (String) emails.get(clientLine);
            if(number == null)
            pw.println(number);
            break;
          case'Q':
            pw.close();
            bf.close();
            s.close();
            cont = false;
          break;
        public static void main(String[]args) throws Exception{
          Server serv = new Server();
          serv.Run();
    }

    1) Use HashMap if possible, rather than Hashtable.
    2) HashMap and Hashtable don't have a "first" element. You can call entrySet(), keySet(), or values() and get the first element from the resulting collection's iteration, but that could be any element from the map--first added, last added, middle. It has no relation to the order added or to any sorting.
    If you want to retrieve in the order added, use LinkeHashMap.
    If you want to retrieve in a sorted order, use a SortedMap, such as TreeMap.
    Make sure you implement equals and hashCode correctly, and if you want to sort, implement Comparable or provide a Comparator.
    http://developer.java.sun.com/developer/Books/effectivejava/Chapter3.pdf
    Making Java Objects Comparable
    http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html
    http://www.javaworld.com/javaworld/jw-12-2002/jw-1227-sort.html

  • URGENT - Sorting Hash Tables

    I am using a hash table with 2 columns. The first one has strings and is the key. The second column has integers.
    I need to sort this table on the first column and print the contents of the table.
    Then i need to sort it on the second column and print the results.
    How do i sort the hastables.
    Please let me know as soon as possible.
    Thanks and Regards,
    Vijay

    You got it all wrong. Hashtables cannot be sorted because then it would not be a hashtable. The content of the Hashtable can be sorted.
    What you want to do is get the key Set (keySet() method) of the Hashtable, wrap it in a List (e.g. LinkedList), sort that (see java.util.Collections for sorting) and then print out the contents of the Hashtable in the order pointed out by the keys in the sorted List.
    Then you can do the same for the values() Collection of the Hashtable.
    Pointers:
    http://java.sun.com/j2se/1.4/docs/api/java/util/Hashtable.html
    http://java.sun.com/j2se/1.4/docs/api/java/util/Set.html
    http://java.sun.com/j2se/1.4/docs/api/java/util/List.html
    http://java.sun.com/j2se/1.4/docs/api/java/util/LinkedList.html
    http://java.sun.com/j2se/1.4/docs/api/java/util/Collections.html

  • Date Object as a key in Hash table

    Hi,
    I'm having a hash table with date object as key , the purpose is I can pick the value which is available in given date range. Consider the below example
    Coffee Powder[Code CODE1] - Effective 21-Jan & Expiry 20-Jun
    Coffee Powder[Code CODE1] - Effective 22-Jun & Expiry 30-Dec
    Meat[Code CODE2] - Effective 21 - Jan & Expiry 1 - Feb
    Meat[Code CODE2] - Effective 2 Feb &  Expiry 6 - Feb
    Currently I'm using the following hashtable & it has the structure Key - Code & Value [ List of objects] ]
    CODE1- List[ Coffe Powder - 21 Jan - 20 Jun , Coffee Powder - 22 Jun - 30 Dec ]
    CODE2- List[ Meat - 21 Jan - 01 Feb, Meat - 02 Feb - 06 Feb ]
    To get the value which is valid for the given date , i need to get the list by passing the code & iterate the list to get the best matched value.
    Example , if I want the Coffee Powder Information which is valid on 1 Feb. I need to get pass the code ( CODE 1 ) which will returns the list of objects. After we need to iterate the list to get the best match.
    Instead of iteration , is there any way to maintain the hashtable & get the results quicker..?
    Thx.

    To get a benefit out of the HashMaps quick access to keys you you'd need an exact match between your search date and a key date.
    Can you cluster your Map-Content? eg.: do you always serch for a complete month?
    Then you could change your Map from Map<Date,Object> to Map<Date,List<Object>> where Date is "normalised" to the first Day in month 00:00 o clock (UTC or local...).
    You could also consider an additional map (Map<Date,List<Date>>) where you group the actual keys of the original Map by the expected search clusters.
    bye
    TPD

  • Comparing String values against a collection of Names in a Hash Table

    Objective:
    Is to make a script that will import a csv file containing two values: "Name" and "Price". This would ideally be stored in a hash table with the key name of "Name" and the value being "Price". The second part would be
    importing a second csv file that has a list of names to compare too. If it finds a similar match to a key name in the hash table and then it will add that to a new array with the price. At the end it would add all the prices and give you a total value.
    The Problem to Solve:
    In the real world people have a tendency to not write names exactly the same way, for example I am looking at a list of books to buy in an eBay auction. In the auction they provide a text list of all the names of books for sale. In my price guide it has all
    the names and dollar values of each book. The wording of the way each book is named could differ from the person who writes it and what is actually in my reference pricing list. An example might be "The Black Sheep" vs "Black Sheep" or
    "Moby-Dick" vs "Moby Dick".
    I've tried making a script and comparing these values using the -like operator and have only had about 70% accuracy. Is there a way to increase that by 
    comparing the characters instead of likeness of words? I'm not really sure how to solve this issue as it's very hard to do quality check on the input when your talking about hundreds of names in the list. Is there a better way to compare values in power-shell
    then the "like" operator? Do I need to use a database instead of a hash table? In the real world I feel like a search engine would know the differences in these variations and still provide the desired results so why not for this type of application?
    In other words, create a bit more intelligence to say well it's not a 100% match but 90% so that is close enough, add it to the array as a match and add the price etc..
    I'd be curious as to any thoughts on this? Maybe a scripting language with better matching for text?

    Have you considered setting up a manual correction process that "learns" as you make corrections, automatically building a look up table of possible spellings of each Name?  If you get an exact match, use it.  If not, go to the look up
    table and see if there's been a previous entry with the same spelling and what it was corrected to.
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • Problems with a hash table

    hi, i have a CountryTable class which i want to implement as a hash table:
    import java.util.*;
    class CountryTable {
         static int count = 0;
         private HashMap table = new HashMap();
         public void addEntry(Colour key, Country country) {
              table.put(key, country);
              count++;
         public Country getCountry(Colour key) {
              return (Country)table.get(key);
         static int getCount() {
              return count;
    The object which are returned from this table is Country:
    class Country {
         //static variables
         static int count = 0;
         //instance variables
         private String name;
         private Colour base;
         //constructor
         Country(String name, Colour base) {
              this.name = name;
              this.base = base;
              count++;
         //return the number of objects created
         static int getCount() {
              return count;
         //return the name
         public String getName() {
              return name;
         public Colour getColour() {
              return base;
    The key for the has table is the class Colour, which includes a hashCode() method:
    class Colour {
         public int rgb;
         Colour(int rgb) {
              this.rgb = rgb;
         public int hashCode() {
              return rgb * -1;
    I implement these classes in a program as follows:
    CountryTable index = new CountryTable();
              Colour colour1 = new Colour(-3473408);
              Country argentina = new Country("Argentina", colour1);
              index.addEntry(colour1, argentina);
              Colour colour2 = new Colour(-131072);
              Country brazil = new Country("Brazil", colour2);
              index.addEntry(colour2, brazil);
                        Colour col = new Colour(or);
                        Country coun = index.getCountry(col);
                        System.out.println(coun.getName());
    I have a list of many countries which i set up, with their relevant countires with which they are associated.
    The variable 'or' contains an RGB value which has been returned elsewhere in the program. The problem that i have is that when a colour is passed into the getCountry() method, nothing is returned and a "nullPointerException" is thrown, even though a colour with which i set up a country was passed in???
    Anyone got any ideas where im going wrong?
    Many thanks Cath

    keeping the other two files same you change the CountryTable to this
    import java.util.*;
    class CountryTable {
    static int count = 0;
    private HashMap table = new HashMap();
    public void addEntry(Colour key, Country country) {
    table.put(key.rgb+"" ,country.getName());
    count++;
    public String getCountry(Colour key) {
    return (String)table.get(key.rgb+"");
    static int getCount() {
    return count;
    public static void main (String args[]){
         CountryTable index = new CountryTable();
    Colour colour1 = new Colour(-3473408);
    Country argentina = new Country("Argentina",colour1);
    index.addEntry(colour1, argentina);
    Colour colour2 = new Colour(-131072);
    Country brazil = new Country("Brazil",colour2);
    index.addEntry(colour2, brazil);
    System.out.println(index.table);
    String coun = index.getCountry(colour2);
    System.out.println(coun);
    }and now try

  • Implementing a threaded Hash Table

    Hiya all,
    Would like to know how to create a threaded hash table. I am making a program that should be able to take in different variables such as string and integers, and be able to store then in a Hash table. Would it be possible to retreive these variables (remove them from the hash map) in a threaded scenario?

    Unlike the new collection implementations, Hashtable
    is synchronized.True, but HashMap is more stable. Its performance stays roughtly the same when it's loaded with different (biased) data sets whereas Hashtable shows much more variation.

  • Hash tables in combination with data references to the line type.

    I'm having an issue with hash tables - in combination with reference variables.
    Consider the following:  (Which is part of a class)  -  it attempts to see if a particular id exists in a table; if not add it; if yes change it.   
      types: BEGIN OF TY_MEASUREMENT,
               perfid      TYPE zgz_perf_metric_id,
               rtime       TYPE zgz_perf_runtime,
               execount    TYPE zgz_perf_execount,
               last_start  TYPE timestampl,
             END OF TY_MEASUREMENT.
    METHOD START.
      DATA:  ls_measurement TYPE REF TO ty_measurement.
      READ TABLE gt_measurements WITH TABLE KEY perfid = i_perfid reference into ls_measurement.
      if sy-subrc <> 0.
        "Didn't find it.
        create data ls_measurement.
        ls_measurement->perfid = i_perfid.
        insert ls_measurement->* into gt_measurements.
      endif.
      GET TIME STAMP FIELD ls_measurements-last_start.
      ls_measurement->execount = ls_measurement->execount + 1.
    ENDMETHOD.
    I get compile errors on the insert statement - either "You cannot use explicit index operations on tables with types HASHED TABLE" or "ANY TABLE".      It is possible that.
    If I don't dereference the type then I get the error  LS_MEASUREMENT cannot be converted to the line type of GT_MEASUREMENTS.
    I'm not looking to solve this with a combination of references and work ares - want a reference solution.   
    Thanks!
    _Ryan
    Moderator message - Moved to the correct forum
    Edited by: Rob Burbank on Apr 22, 2010 4:43 PM

    I think it might work when you change it for
    insert ls_measurement->* into TABLE gt_measurements.
    For hashed table a new line here will be inserted according to given table key.
    Regards
    Marcin

  • How can I implement the equivilent of a temporary table with "on commit delete rows"?

    hi,
    I have triggers on several tables. During a transaction, I need to gather information from all of them, and once one of the triggers has all the information, it creates some data. I Can't rely on the order of the triggers.
    In Oracle and DB2, I'm using temporary tables with "ON COMMIT DELETE ROWS" to gather the information - They fit perfectly to the situation since I don't want any information to be passed between different transactions.
    In SQL Server, there are local temporary tables and global.  Local temp tables don't work for me since apparently they get deleted at the end of the trigger. Global tables keep the data between transactions.
    I could use global tables and add some field that identifies the transaction, and in each access to these tables join by this field, but didn't find how to get some unique identifier for the transaction. @@SPID is the session, and sys.dm_tran_current_transaction
    is not accessible by the user I'm supposed to work with.
    Also with global tables, I can't just wipe data when "operation is done" since at the triggers level I cannot identify when the operation was done, transaction was committed and no other triggers are expected to fire.
    Any idea which construct I could use to acheive the above - passing information between different triggers in the same transaction, while keeping the data visible to the current transaction?
    (I saw similar questions but didn't see an adequate answer, sorry if posting something that was already asked).
    Thanks!

    This is the scenario: If changes (CRUD) happen to both TableA and TableB, then log some info to TableC. Logic looks something like this:
    Create Trigger TableA_C After Insert on TableA {
      If info in temp tables available from TableB
            Write info to TableC
       else
           Write to temp tables info from TableA
    Create Trigger TableB_C After Insert on TableB {
      If info in temp tables available from TableA
            Write info to TableC
       else
           Write to temp tables info from TableB
    So each trigger needs info from the other table, and once everything is available, info to TableC is written. Info is only from the current transaction.
    Order of the triggers is not defined. Also there's no gurantee that both triggers would fire - changes can happen only to TableA / B and in that case I don't want to write anything to TableC.
    The part that gets and sets info to temp table is implemented as temp tables with "on commit delete rows" in DB2 / Oracle.
    What do you think? As I've mentioned, I could use global temp tables with a field that would identify the transaction, but didn't find something like that in SQL Server. And, the lifespan of local temp tables is too short.

  • Row chaining in table with more than 255 columns

    Hi,
    I have a table with 1000 columns.
    I saw the following citation: "Any table with more then 255 columns will have chained
    rows (we break really wide tables up)."
    If I insert a row populated with only the first 3 columns (the others are null), is a row chaining occurred?
    I tried to insert a row described above and no row chaining occurred.
    As I understand, a row chaining occurs in a table with 1000 columns only when the populated data increases
    the block size OR when more than 255 columns are populated. Am I right?
    Thanks
    dyahav

    user10952094 wrote:
    Hi,
    I have a table with 1000 columns.
    I saw the following citation: "Any table with more then 255 columns will have chained
    rows (we break really wide tables up)."
    If I insert a row populated with only the first 3 columns (the others are null), is a row chaining occurred?
    I tried to insert a row described above and no row chaining occurred.
    As I understand, a row chaining occurs in a table with 1000 columns only when the populated data increases
    the block size OR when more than 255 columns are populated. Am I right?
    Thanks
    dyahavYesterday, I stated this on the forum "Tables with more than 255 columns will always have chained rows." My statement needs clarification. It was based on the following:
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28318/schema.htm#i4383
    "Oracle Database can only store 255 columns in a row piece. Thus, if you insert a row into a table that has 1000 columns, then the database creates 4 row pieces, typically chained over multiple blocks."
    And this paraphrase from "Practical Oracle 8i":
    V$SYSSTAT will show increasing values for CONTINUED ROW FETCH as table rows are read for tables containing more than 255 columns.
    Related information may also be found here:
    http://download.oracle.com/docs/cd/B10501_01/server.920/a96524/c11schem.htm
    "When a table has more than 255 columns, rows that have data after the 255th column are likely to be chained within the same block. This is called intra-block chaining. A chained row's pieces are chained together using the rowids of the pieces. With intra-block chaining, users receive all the data in the same block. If the row fits in the block, users do not see an effect in I/O performance, because no extra I/O operation is required to retrieve the rest of the row."
    http://download.oracle.com/docs/html/B14340_01/data.htm
    "For a table with several columns, the key question to consider is the (average) row length, not the number of columns. Having more than 255 columns in a table built with a smaller block size typically results in intrablock chaining.
    Oracle stores multiple row pieces in the same block, but the overhead to maintain the column information is minimal as long as all row pieces fit in a single data block. If the rows don't fit in a single data block, you may consider using a larger database block size (or use multiple block sizes in the same database). "
    Why not a test case?
    Create a test table named T4 with 1000 columns.
    With the table created, insert 1,000 rows into the table, populating the first 257 columns each with a random 3 byte string which should result in an average row length of about 771 bytes.
    SPOOL C:\TESTME.TXT
    SELECT
      SN.NAME,
      MS.VALUE
    FROM
      V$MYSTAT MS,
      V$STATNAME SN
    WHERE
      SN.NAME = 'table fetch continued row'
      AND SN.STATISTIC#=MS.STATISTIC#;
    INSERT INTO T4 (
    COL1,
    COL2,
    COL3,
    COL255,
    COL256,
    COL257)
    SELECT
    DBMS_RANDOM.STRING('A',3),
    DBMS_RANDOM.STRING('A',3),
    DBMS_RANDOM.STRING('A',3),
    DBMS_RANDOM.STRING('A',3)
    FROM
      DUAL
    CONNECT BY
      LEVEL<=1000;
    SELECT
      SN.NAME,
      MS.VALUE
    FROM
      V$MYSTAT MS,
      V$STATNAME SN
    WHERE
      SN.NAME = 'table fetch continued row'
      AND SN.STATISTIC#=MS.STATISTIC#;
    SET AUTOTRACE TRACEONLY STATISTICS
    SELECT
    FROM
      T4;
    SET AUTOTRACE OFF
    SELECT
      SN.NAME,
      SN.STATISTIC#,
      MS.VALUE
    FROM
      V$MYSTAT MS,
      V$STATNAME SN
    WHERE
      SN.NAME = 'table fetch continued row'
      AND SN.STATISTIC#=MS.STATISTIC#;
    SPOOL OFFWhat are the results of the above?
    Before the insert:
    NAME                      VALUE                                                
    table fetch continue        166
    After the insert:
    NAME                      VALUE                                                
    table fetch continue        166                                                
    After the select:
    NAME                 STATISTIC#      VALUE                                     
    table fetch continue        252        332  Another test, this time with an average row length of about 12 bytes:
    DELETE FROM T4;
    COMMIT;
    SPOOL C:\TESTME2.TXT
    SELECT
      SN.NAME,
      MS.VALUE
    FROM
      V$MYSTAT MS,
      V$STATNAME SN
    WHERE
      SN.NAME = 'table fetch continued row'
      AND SN.STATISTIC#=MS.STATISTIC#;
    INSERT INTO T4 (
      COL1,
      COL256,
      COL257,
      COL999)
    SELECT
    DBMS_RANDOM.STRING('A',3),
    DBMS_RANDOM.STRING('A',3),
    DBMS_RANDOM.STRING('A',3),
    DBMS_RANDOM.STRING('A',3)
    FROM
      DUAL
    CONNECT BY
      LEVEL<=100000;
    SELECT
      SN.NAME,
      MS.VALUE
    FROM
      V$MYSTAT MS,
      V$STATNAME SN
    WHERE
      SN.NAME = 'table fetch continued row'
      AND SN.STATISTIC#=MS.STATISTIC#;
    SET AUTOTRACE TRACEONLY STATISTICS
    SELECT
    FROM
      T4;
    SET AUTOTRACE OFF
    SELECT
      SN.NAME,
      SN.STATISTIC#,
      MS.VALUE
    FROM
      V$MYSTAT MS,
      V$STATNAME SN
    WHERE
      SN.NAME = 'table fetch continued row'
      AND SN.STATISTIC#=MS.STATISTIC#;
    SPOOL OFFWith 100,000 rows each containing about 12 bytes, what should the 'table fetch continued row' statistic show?
    Before the insert:
    NAME                      VALUE                                                
    table fetch continue        332 
    After the insert:
    NAME                      VALUE                                                
    table fetch continue        332
    After the select:
    NAME                 STATISTIC#      VALUE                                     
    table fetch continue        252      33695The final test only inserts data into the first 4 columns:
    DELETE FROM T4;
    COMMIT;
    SPOOL C:\TESTME3.TXT
    SELECT
      SN.NAME,
      MS.VALUE
    FROM
      V$MYSTAT MS,
      V$STATNAME SN
    WHERE
      SN.NAME = 'table fetch continued row'
      AND SN.STATISTIC#=MS.STATISTIC#;
    INSERT INTO T4 (
      COL1,
      COL2,
      COL3,
      COL4)
    SELECT
    DBMS_RANDOM.STRING('A',3),
    DBMS_RANDOM.STRING('A',3),
    DBMS_RANDOM.STRING('A',3),
    DBMS_RANDOM.STRING('A',3)
    FROM
      DUAL
    CONNECT BY
      LEVEL<=100000;
    SELECT
      SN.NAME,
      MS.VALUE
    FROM
      V$MYSTAT MS,
      V$STATNAME SN
    WHERE
      SN.NAME = 'table fetch continued row'
      AND SN.STATISTIC#=MS.STATISTIC#;
    SET AUTOTRACE TRACEONLY STATISTICS
    SELECT
    FROM
      T4;
    SET AUTOTRACE OFF
    SELECT
      SN.NAME,
      SN.STATISTIC#,
      MS.VALUE
    FROM
      V$MYSTAT MS,
      V$STATNAME SN
    WHERE
      SN.NAME = 'table fetch continued row'
      AND SN.STATISTIC#=MS.STATISTIC#;
    SPOOL OFFWhat should the 'table fetch continued row' show?
    Before the insert:
    NAME                      VALUE                                                
    table fetch continue      33695
    After the insert:
    NAME                      VALUE                                                
    table fetch continue      33695
    After the select:
    NAME                 STATISTIC#      VALUE                                     
    table fetch continue        252      33695 My statement "Tables with more than 255 columns will always have chained rows." needs to be clarified:
    "Tables with more than 255 columns will always have chained rows +(row pieces)+ if a column beyond column 255 is used, but the 'table fetch continued row' statistic +may+ only increase in value if the remaining row pieces are found in a different block."
    Charles Hooper
    IT Manager/Oracle DBA
    K&M Machine-Fabricating, Inc.
    Edited by: Charles Hooper on Aug 5, 2009 9:52 AM
    Paraphrase misspelled the view name "V$SYSSTAT", corrected a couple minor typos, and changed "will" to "may" in the closing paragraph as this appears to be the behavior based on the test case.

  • Problem  FIELD-SYMBOL with HASHED TABLE

    Hello gurus,
    I have a problem with the following code. It is called in method MB_DOCUMENT_BEFORE_UPDATE of badi MB_DOCUMENT_BADI. I need to read the serial numbers of all items. I tried to do it with a field symbol. The information I need is stored in the hased table (SAPLMIGO)LCL_MIGO_GLOBALS=>KERNEL->PT_GOSERIAL_KERNEL. The systems returns sy-subrc = 4 after the assign. Can anyone help me? Thanks!
    TYPES: BEGIN OF ty_s_goserial,
              selected TYPE xfeld,
              serialno TYPE    gernr,
            END OF ty_s_goserial,
            ty_t_goserial  TYPE STANDARD TABLE OF ty_s_goserial WITH
                                                     NON-UNIQUE DEFAULT KEY.
      TYPES: BEGIN OF ty_s_goserial_kernel,
                global_counter TYPE migo_global_counter,
                t_goserial TYPE ty_t_goserial,
            END OF ty_s_goserial_kernel.
    types: tyt_goserial TYPE HASHED   TABLE OF ty_s_goserial_kernel
                                     WITH UNIQUE KEY global_counter.
        fs_l_serialno = '(SAPLMIGO)LCL_MIGO_GLOBALS=>KERNEL->PT_GOSERIAL_KERNEL'.
        FIELD-SYMBOLS: <fs_serialno> type tyt_goserial.
        ASSIGN (fs_l_serialno) TO <fs_serialno>.
        IF sy-subrc = 4.
          WRITE: / 'Ouch...'.
        ENDIF.

    Hi,
    Try adding body operator..at the end as it is an internal table..
    (SAPLMIGO)LCL_MIGO_GLOBALS=>KERNEL->PT_GOSERIAL_KERNEL[]'.
    Thanks
    Naren

  • Experimenting with hashed table.

    Hello experts,
    I am currently experementing with using hashed table for my report and this is my first time to try this. Below is my code:
    DATA: it_iloa  type hashed TABLE OF t_iloa
           WITH unique KEY iloan.
    Now here is my problem, Originally I am reading it_iloa using its header line. Now, how can I define my hashed table to have a work area/header line?
    Again, thanks guys and have a nice day!

    Hi,
    The SORTED table / HASH table are best used along with a LEY definition of the table, meaning you will declare a key for the internal table.
    So, while declare the table add the WITH UNIQUE KEY column1.
    This will create a HASH index on the column1 and when you are reading the table, make sure you have column1 in the where clause so that HASH index is used and the performance is improved.
    However, unless the table has got huge data you will not be able to see the difference.
    Regards,
    Ravi

Maybe you are looking for

  • How do I share my itunes library with different devices

    I am trying to share my main computers itunes library so it can be accessed by multiple people on their own iphones. It will show up on my own iphone, but my roommates iphones it will not show up. Id like to be able to play music on my iphone from my

  • Can no longer get album artwork

    Just got a new iPhone and wanted album artwork for all the songs I have loaded. Last night I found that some of the older songs I had loaded in my library had no album listed, so I would just find the correct album name, add it into the "Get Info" se

  • Playing albums in a particular order

    Hi all: What is the most efficient way to play albums in a playlist in a particular, user-defined (i.e., not rule-defined) order?

  • EXPLAIN ERROR - E_ADEPT_DOCUMENT_TYPE_UNKNOWN

    I am trying to open a .acsm file in Adobe Digital Editions 2.0.67532 I keep getting the error E_ADEPT_DOCUMENT_TYPE_UNKNOWN I have searched the forum and found this question asked previosuly - but NOT answered. I would like to know what this means an

  • Frames Target Link problem

    I am working on a website and am having trouble with a link that will be clicked in one frame and opened in another frame. For some reason it isn't working. I don't want it to open a new window, I want it to open the page in the bottom frame. I only