Sort and select in database..

hi All...
i write a coding that store data in database, that i have two column rule and weight. after that, i want to display the data with weight sorting ascending and select distinct rule.
but it's not working. nothings error but it don't do nothing.
is it wrong with my sql statement?
public void insertDatabase(Vector rule, double weight){
           try{
                 String sqlInsert = "INSERT INTO Sheet2 ( Rule, Weight ) " +
                      "VALUES ( '"+ rule +"', '" + weight + "' )";
                 int row = myStatement.executeUpdate(sqlInsert);                             myResultSetDisplay = myStatement.executeQuery("Select * from Sheet2");
                 myResultSetSort = myStatement.executeQuery("SELECT * FROM Sheet2 ORDER by Pemberat ASC");
                 myResultSetDistinct = myStatement.executeQuery("SELECT DISTINCT Petua FROM Sheet2");
            catch(SQLException e){
                        System.out.println(e.getMessage());
           }//catch
       }

how to use admin tool I was talking about the admin tool of the database.
or debugger?If you're using an IDE, like Eclpise, you can use the built-in debugger to execute the code step by step.
and i got error that
[Microsoft][ODBC Microsoft Access Driver]Attribute
cannot be set nowThe message is clear. It's too late to set the attribute. You already have issued some actions on the connection. Rearrange your logic.

Similar Messages

  • Browsing and selecting through database link to fill in a form item

    Hi
    I have created a database link named in my application
    dblink_3
    I have a form and report in my application. On the from I have an item called P6_USER_ for which I would like to access a table (trk_user) through the database link I created so that I can fill in the text field or select list with a user from the table.
    can I browse by a select list somehow? or do I need to create a button that takes me to a report with a list of the data in the table and select that way.
    Please steer me in the right direction,
    Thanks,
    Kirk

    Hi Kirk,
    The fact that the data is on an external table shouldn't make any difference. You can do:
    SELECT field1 d, field2 r FROM trk_user@dblink_3 ORDER BY 1
    and that will give you your select list

  • URGENT !! Capture the insert and select on database

    Hi,
    I need to capture the inserts and selects on the database.
    What are the options available on 9i?
    Thanks in advance!

    I don;t know how many times I've had to say this, but since I've had to say it to my boss, it bears repeating here:
    The SPFILE makes absolutely zero, null, nought difference to whether or not something is changeable dynamically or not. Not one bit, one whit or one iota.
    Parameters are as static or as dynamic as they were when init.oras rules the roost. Check in V$PARAMETER: if the thing says ISSYSMODIFIABLE is TRUE, then the parameter can be altered with an alter system command -and that's true whether you're using an init.ora or an spfile. If it says ISSYSMODIFIABLE=FALSE, then the parameter CANNOT be altered with an alter system command, and that's true whether you're using an init.ora or an spfile.
    Now comes the subtlety: if you add SCOPE=SPFILE to your alter system command then you aren't actually altering the system at all. All you're doing is asking the instance to edit the spfile. So an alter system set db_block_size=67238 scope=spfile will work, because you're not actually asking to alter the current block size at all. You're merely asking the instance to do what you would otherwise have done with notepad or gedit to a traditional init.ora.
    Only if you SCOPE=MEMORY is your alter system command actually trying to change the currently running instance.
    Of course, the trouble starts when you miss off a SCOPE clause, because then you get SCOPE=BOTH, which means MEMORY+SPFILE. But try that on a parameter which is SYSMODIFIABLE=FALSE: it won't work, because the MEMORY bit trips over the fact that the parameter is not system (dynamically) modifiable. Which just goes to prove that the existence of an SPFILE changes ABSOLUTELY NOTHING about whether a parameter can be dynamically modified or not.
    So no, the sentence "my database is using spfile and I have option to use alter system command" makes zero sense if, by it, you mean "I'm using an spfile so can I change things dynamically which I wouldn't be allowed to if I was stuck using a boring old init.ora"
    The answer is always and forever, "NO"!
    I blame a certain bouffant-haired so-called expert for first promulgating this myth that all parameters suddenly became dynamic in the presence of an spfile. It was never true when he wrote it. It isn't true now. It never will be true. It just happens to be the case that "alter system..scope=spfile" is Oracle's equivalent of "vi init.ora" as far as spfiles are concerned.

  • Sorting and selecting songs

    A recent  update to iTunes changed the way a sort list is presented.  In the past yopu entered a key word and all playlists, artist,or songs with the string was displayed and then you could select a group of them by highlighting the one that you want and putting them into a playlist.  I just keyed in the word Chester  (an old American song) and the resulta are shown below in an attachment.  I would like to make a playlist of the first six entries, but can only display one song at a time. 
    There must be a beter way of selecting all six at one time 
    Thanks
    Danny

    Click the magnifying glass in the search windows and untick Search entire library to restore the old search behaviour (filtering instead of results displayed in an overlay). Pressing enter after typing your search term should also have the same effect, but you get the overlay results as you type in the meantime.
    tt2

  • Insertion sorts and comparable

    HI guys. I need to refresh my memory for these two things, Insertion sorts and comparable.
    I don't quite understand what is the different between insertion sorts and selection sorts.
    And secondary, comparable. What is it for? How does it work? Here is the sample code. All I see is the use of it to call the compareTo method.
    public static void main (Comparable[] objects)
    for(int index=1; index < objects.length; index++)
    Comparable key = objects[index];
    int position = index;
    //shift larger values to the right
    while (position > 0 && objects[position-1].compareTo(key)>0)
    objects[position] = objects[position-1];
    position--;
    }//end while
    objects[] = key;
    }//end for
    Thanks a lot.

    HI guys. I need to refresh my memory for these two
    things, Insertion sorts and comparable.
    I don't quite understand what is the different between
    insertion sorts and selection sorts. They are different sorting algorithms.
    (As you understand, I don't remember much either :) )
    You're probably best off by finding a book about it.
    And secondary, comparable. What is it for? How does it
    work? Here is the sample code. All I see is the use of
    it to call the compareTo method.Comparable is an interface that declares the compareTo-method. By using that general method you can write a general sorting method that are independent on what objects are being sorted and how they are being sorted, as long as they implement Comparable.

  • Regarding Logical database and  select statement..

    Hi
    Experts.
    i would  like to  know the  diff b/w logical data base & select statement  while using report.
    wt is the use of logical databases in R/3. is there   any   advantage  used in the  reports.
    Thanks & Regards..
    Spandana.

    Dear Spandana,
      Go through the below description of LDB. I hope you wil get a fair amount of idea.
    SAP comes loaded with all the extras. Among the extras that are most helpful to IT managers are all the access routines needed to pull any business object that managers can think of out of SAP databases. However, SAP has not thought of everything where your particular applications are concerned. SAP organizes its standard database tables to service business units based on conventional business applications. Itu2019s likely your business requires something new, perhaps even something exotic. In that case, you will need to create a new database, using information from different places. Basically, you need a logical database. You need to create a virtual business data object repository consisting of a new kind of record or table that suits your purposes. In addition, the repository should be composed of information that is actually stored in a number of different locations, none of them necessarily logically associated with one another. Letu2019s take a closer look at creating logical databases.
    A case for a logical database
    Suppose my company manufactures widgets of the most obscure variety, and they are components of other widgets. I sell my widgets as raw material for the more sophisticated widgets built by others, but in some cases I actually partner with other manufacturers in creating yet another class of widget. Now, in my world, I consequently have customers who are also partners. I sell to them and I partner with them in manufacturing and distribution. Also, I need an application that uses both of these dual-use relationships.
    Essentially, I have a customer database and a partner database. Neither contains records that are structured to contain the identifying particulars of the other. Thus, I need a hybrid database that gives me tables detailing these hybrid relationships. What can I do? I can go the long way around and write a new database, pulling information from both and creating new objects with a customized program that I write by hand. However, this process is cumbersome and contains maintenance issues. On the other hand, I can use SAPu2019s logical database facility, create my logical database in a couple of minutes, and have no maintenance issues at all.
    Logical database structures
    There are three defining entities in an SAP logical database. You must be clear on all three in order to create and use one.
    u2022     Table structure: Your logical database includes data from specified tables in SAP. There is a hierarchy among these tables defined by their foreign keys (all known to SAP), and you are going to define a customized relationship between select tables. This structure is unique and must be defined and saved.
    u2022     Data selection: You may not want or need every item in the referenced tables that contributes to your customized database. There is a selection screen that permits you to pick and choose.
    u2022     Database access programming: Once youu2019ve defined your logical database, SAP will generate the access subroutines needed to pull the data in the way you want it pulled.
    Creating your own logical database
    ABAP/4 (Advanced Business Application Programming language, version 4) is the language created by SAP for implementation and customization of its R/3 system. ABAP/4 comes loaded with many predefined logical databases that can construct and table just about any conventional business objects you might need in any canned SAP application. However, you can also create your own logical databases to construct any custom objects you care to define, as your application requires in ABAP/4. Hereu2019s a step-by-step guide:
    1.     Call up transaction SLDB (or transaction SE36). The path you want is Tools | ABAP Workbench | Development | Programming Environment | Logical Databases. This screen is called Logical Database Builder.
    2.     Enter an appropriate name in the logical database name field. You have three options on this screen: Create, Display, and Change. Choose Create.
    3.     Youu2019ll be prompted for a short text description of your new logical database. Enter one. Youu2019ll then be prompted to specify a development class.
    4.     Now comes the fun part! You must specify a root node, or a parent table, as the basis of your logical database structure. You can now place subsequent tables under the root table as needed to assemble the data object you want. You can access this tree from this point forward, to add additional tables, by selecting that root node and following the path Edit | Node | Create. Once youu2019ve saved the structure you define in this step, the system will generate the programming necessary to access your logical database. The best part is you donu2019t have to write a single line of code.
    Watch out!
    The use of very large tables will degrade the performance of a logical database, so be aware of that trade-off. Remember that some tables in SAP are very complex, so they will be problematic in any user-defined logical database.
    Declaring a logical database
    Hereu2019s another surprising feature of logical databases: You do not assign them in your ABAP/4 Code. Instead, the system requires that you specify logical databases as attributes. So when you are creating a report, have your logical database identifier (the name you gave it) on hand when you are defining its attributes on the Program Attributes screen. The Attributes section of the screen (the lower half) will include a Logical database field, where you can declare your logical database.
    Logical databases for increasing efficiency
    Why else would you want to create a logical database? Consider that the logical databases already available to you begin with a root node and proceed downward from there. If the data object you wish to construct consists of items that are all below the root node, you can use an existing logical database program to extract the data, then trim away what you donu2019t want using SELECT statementsu2014or you can increase the speed of the logical database program considerably by redefining the logical database for your object and starting with a table down in the chain. Either way, youu2019ll eliminate a great deal of overhead.
    Regards
    Arindam

  • Sorting and filtering by select-multi person or group field in the list in SharePoint 2013

    Hi everybody,
    In SharePoint 2013, I have defined a column as "Person or Group" field, which you allow for multiple selections. when I try to sort/filter it by this field in the list. The field doesn't show up in the dropdown. If I changed "Allow multiple
    selections" option to "No" by clicking the column name to edit it in "List Settings", the field can show up sort in the dropdown.
    How about support sorting and filter by select-multiple "Person or Group" field in sharepoint 2013?
    BTW, in SharePoint 2010, it can support this issue no matter what the "Allow multiple selections" option the request is.
    Any help would be great!
    Thanks,
    Jodie

    Hi Jodie,
    Can you please give this as a try.
    To fix the Filter Issue on Assigned To Column. We need to run the following scripts.
    The field which allows more than one values or which allows multiple selections. The multi-valued fileds are non-sortable,
    non-filterable. Multi-valued fields cannot be indexed
    $web=Get-SPWeb
    $list=$web.Lists[] $field=$list.Fields[ColumnName] $strSchema=$field.SchemaXml $str=Schema$strSchema.Replace("Sortable=`"FALSE`"","Sortable=`"true`"")
    $field.SchemaXml = $strSchema
    Krishana Kumar http://www.mosstechnet-kk.com
    Thanks for your reply, I have tried to run the scripts, but it still cannot work. The following is my scripts:
    $web=Get-SPWeb 'http://cst-server-01'
    $list=$.web.Lists["Product Request"]
    $field=$list.Fields["Applicant"]
    $strSchema=$field.SchemaXml
    $str=Schema$strSchema.Replace("Sortable='"FALSE'"", "Sortable='"True'"")
    $field.SchemaXml = $strSchema

  • Diff b/w select single * .... and select....up to 1 row

    Hi Abapers,
    What is the diff b/w Select single * from.... and select * ...up to 1 row.
    Thanks in advance.
    Subbu.

    Select SINGLE...
    SINGLE
    The result of the selection should be a single entry. If it is not possible to identify a unique entry, the system uses the first line of the selection. If you use the FOR UPDATE addition, the selected entry is protected against parallel updates from other transactions until the next database commit (see LUW and database lock mechanism). If the database system identifies a deadlock, a runtime error occurs.
    ... UP TO n ROWS
    Effect
    The set of results is restricted to a maximum of nrows.
    Example
    To output a list of the 3 business customers with the greatest discount:
    DATA WA_SCUSTOM TYPE SCUSTOM.
    SELECT * FROM SCUSTOM INTO WA_SCUSTOM UP TO 3 ROWS
             WHERE CUSTTYPE = 'B'
             ORDER BY DISCOUNT DESCENDING.
      WRITE: / WA_SCUSTOM-ID, WA_SCUSTOM-NAME, WA_SCUSTOM-DISCOUNT.
    ENDSELECT.
    Notes
    If you use an UP TO n ROWS addition in an ORDER-BY clause , the lines read are sorted into the correct order. The first n lines are then displayed. The system may need to read more than n lines from the database to be able to do this.
    If n = 0, all selected lines are displayed.
    n < 0 results in a runtime error.
    <b>Knowing when to use SELECT SINGLE or SELECT ... UP TO 1 ROWS</b>
    A lot of people use the SELECT SINGLE statement to check for the existence of a value in a database. Other people prefer to use the 'UP TO 1 ROWS' variant of the SELECT statement.
    <b>So what's the difference between using 'SELECT SINGLE' statement as against a 'SELECT .... UP TO 1 ROWS' statement ?</b>
    If you're considering the statements
    SELECT SINGLE field INTO w_field FROM table.
    and
    SELECT field INTO w_field FROM table UP TO 1 ROWS. ENDSELECT.
    then looking at the result, not much apart from the extra ENDSELECT statement. Look at the run time and memory usage and they may be worlds apart.
    Why is this ?? The answer is simple.
    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.
    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.
    Get the difference ??
    If not, here is a good example, credit for this example goes to Richard Harper, a friend of mine on sapfans.com :
    Create a Ztable called ZDifference with 2 fields in it, MANDT of type MANDT and POSNR of type POSNR. Make sure both of these are keys. Also create a table maintenance dialog for it (SE11->Utilities->Table Maintenance Generator). Fill the table with ten rows 000001-000010.
    Then run the program shown below:
    Report Z_Difference
           Message-id 38
           Line-Size  80
           Line-Count 0
           No Standard Page Heading.
    Start-Of-Selection.
      Data: w_Single type Posnr,
            t_Rows   type standard table of Posnr
                     initial size 0
                     with header line.
      Select single Posnr
        from zDifference
        into w_Single.
      Select Posnr
        into table t_Rows
        from zDifference
       up to 1 rows
       order by Posnr descending.
       Write :/ 'Select single:', w_Single.
       Skip 1.
       Write :/ 'Up to 1 rows :'.
       Loop at t_Rows.
            Write t_Rows.
       EndLoop.
    You should see the output:
    Select single: 000001
    Up to 1 rows : 000010
    The first 'SELECT' statement selected the first record in the database according to any selection criterion in the 'WHERE' clause. This is what a 'SELECT SINGLE' does. The second 'SELECT' has asked the database to reverse the order of the records before returning the first row of the result.
    In order to be able to do this the database has read the entire table, sort it and then return the first record. If there was no ORDER BY clause then the results would have been identical (ie both '000001') but the second select if given a big enough table to look at would be far slower.
    Note that this causes a problem in the Extended Program Check if the full key is not specified in a 'SELECT SINGLE'. Replacing the 'SELECT SINGLE' by an "UP TO 1 ROWS" will give the same exact results without any warning but the program will run slower and consume more memory. This is a good example of a warning that we should ignore... considering you are sure of what you are doing !!
    Message was edited by:
            Judith Jessie Selvi

  • Basic query regarding work-area and select query

    hi
    dear sdn members,
    thanks too all for solving all my query's up till now
    i am stuck in a problem need help
    1)  why basically work-area has been used ? the sole purpose
    2)  different types of select query ? only coding examples
    note: no links pls
    regards,
    virus

    hi,
    Work Area
    Description for a data object that is particularly useful when working with internal tables or database tables as a source for changing operations or a target for reading operations.
    WORKAREA is a structure that can hold only one record at a time. It is a collection of fields. We use workarea as we cannot directly read from a table. In order to interact with a table we need workarea. When a Select Statement is executed on a table then the first record is read and put into the header of the table and from there put into the header or the workarea(of the same structure as that of the table)of the internal table and then transferred top the body of the internal table or directly displayed from the workarea.
    Each row in a table is a record and each column is a field.
    While adding or retrieving records to / from internal table we have to keep the record temporarily.
    The area where this record is kept is called as work area for the internal table. The area must have the same structure as that of internal table. An internal table consists of a body and an optional header line.
    Header line is a implicit work area for the internal table. It depends on how the internal table is declared that the itab will have the header line or not.
    .g.
    data: begin of itab occurs 10,
    ab type c,
    cd type i,
    end of itab. " this table will have the header line.
    data: wa_itab like itab. " explicit work area for itab
    data: itab1 like itab occurs 10. " table is without header line.
    The header line is a field string with the same structure as a row of the body, but it can only hold a single row.
    It is a buffer used to hold each record before it is added or each record as it is retrieved from the internal table. It is the default work area for the internal table.
    With header line
    SELECT.
    Put the curson on that word and press F1 . You can see the whole documentation for select statements.
    select statements :
    SELECT result
    FROM source
    INTO|APPENDING target
    [[FOR ALL ENTRIES IN itab] WHERE sql_cond]
    Effect
    SELECT is an Open-SQL-statement for reading data from one or several database tables into data objects.
    The select statement reads a result set (whose structure is determined in result ) from the database tables specified in source, and assigns the data from the result set to the data objects specified in target. You can restrict the result set using the WHERE addition. The addition GROUP BY compresses several database rows into a single row of the result set. The addition HAVING restricts the compressed rows. The addition ORDER BY sorts the result set.
    The data objects specified in target must match the result set result. This means that the result set is either assigned to the data objects in one step, or by row, or by packets of rows. In the second and third case, the SELECT statement opens a loop, which which must be closed using ENDSELECT. For every loop pass, the SELECT-statement assigns a row or a packet of rows to the data objects specified in target. If the last row was assigned or if the result set is empty, then SELECT branches to ENDSELECT . A database cursor is opened implicitly to process a SELECT-loop, and is closed again when the loop is ended. You can end the loop using the statements from section leave loops.
    Up to the INTO resp. APPENDING addition, the entries in the SELECTstatement define which data should be read by the database in which form. This requirement is translated in the database interface for the database system´s programming interface and is then passed to the database system. The data are read in packets by the database and are transported to the application server by the database server. On the application server, the data are transferred to the ABAP program´s data objects in accordance with the data specified in the INTO and APPENDING additions.
    System Fields
    The SELECT statement sets the values of the system fields sy-subrc and sy-dbcnt.
    sy-subrc Relevance
    0 The SELECT statement sets sy-subrc to 0 for every pass by value to an ABAP data object. The ENDSELECT statement sets sy-subrc to 0 if at least one row was transferred in the SELECT loop.
    4 The SELECT statement sets sy-subrc to 4 if the result set is empty, that is, if no data was found in the database.
    8 The SELECT statement sets sy-subrc to 8 if the FOR UPDATE addition is used in result, without the primary key being specified fully after WHERE.
    After every value that is transferred to an ABAP data object, the SELECT statement sets sy-dbcnt to the number of rows that were transferred. If the result set is empty, sy-dbcnt is set to 0.
    Notes
    Outside classes, you do not need to specify the target area with INTO or APPENDING if a single database table or a single view is specified statically after FROM, and a table work area dbtab was declared with the TABLES statement for the corresponding database table or view. In this case, the system supplements the SELECT-statement implicitly with the addition INTO dbtab.
    Although the WHERE-condition is optional, you should always specify it for performance reasons, and the result set should not be restricted on the application server.
    SELECT-loops can be nested. For performance reasons, you should check whether a join or a sub-query would be more effective.
    Within a SELECT-loop you cannot execute any statements that lead to a database commit and consequently cause the corresponding database cursor to close.
    SELECT - result
    Syntax
    ... lines columns ... .
    Effect
    The data in result defines whether the resulting set consists of multiple rows (table-like structure) or a single row ( flat structure). It specifies the columns to be read and defines their names in the resulting set. Note that column names from the database table can be changed. For single columns, aggregate expressions can be used to specify aggregates. Identical rows in the resulting set can be excluded, and individual rows can be protected from parallel changes by another program.
    The data in result consists of data for the rows lines and for the columns columns.
    SELECT - lines
    Syntax
    ... { SINGLE }
    | { { } } ... .
    Alternatives:
    1. ... SINGLE
    2. ... { }
    Effect
    The data in lines specifies that the resulting set has either multiple lines or a single line.
    Alternative 1
    ... SINGLE
    Effect
    If SINGLE is specified, the resulting set has a single line. If the remaining additions to the SELECT command select more than one line from the database, the first line that is found is entered into the resulting set. The data objects specified after INTO may not be internal tables, and the APPENDING addition may not be used.
    An exclusive lock can be set for this line using the FOR UPDATE addition when a single line is being read with SINGLE. The SELECT command is used in this case only if all primary key fields in logical expressions linked by AND are checked to make sure they are the same in the WHERE condition. Otherwise, the resulting set is empty and sy-subrc is set to 8. If the lock causes a deadlock, an exception occurs. If the FOR UPDATE addition is used, the SELECT command circumvents SAP buffering.
    Note
    When SINGLE is being specified, the lines to be read should be clearly specified in the WHERE condition, for the sake of efficiency. When the data is read from a database table, the system does this by specifying comparison values for the primary key.
    Alternative 2
    Effect
    If SINGLE is not specified and if columns does not contain only aggregate expressions, the resulting set has multiple lines. All database lines that are selected by the remaining additions of the SELECT command are included in the resulting list. If the ORDER BY addition is not used, the order of the lines in the resulting list is not defined and, if the same SELECT command is executed multiple times, the order may be different each time. A data object specified after INTO can be an internal table and the APPENDING addition can be used. If no internal table is specified after INTO or APPENDING, the SELECT command triggers a loop that has to be closed using ENDSELECT.
    If multiple lines are read without SINGLE, the DISTINCT addition can be used to exclude duplicate lines from the resulting list. If DISTINCT is used, the SELECT command circumvents SAP buffering. DISTINCT cannot be used in the following situations:
    If a column specified in columns has the type STRING, RAWSTRING, LCHAR or LRAW
    If the system tries to access pool or cluster tables and single columns are specified in columns.
    Note
    When specifying DISTINCT, note that you have to carry out sort operations in the database system for this.
    SELECT - columns
    Syntax
    | { {col1|aggregate( col1 )}
    {col2|aggregate( col2 )} ... }
    | (column_syntax) ... .
    Alternatives:
    1. ... *
    2. ... {col1|aggregate( col1 )}
    {col2|aggregate( col2 )} ...
    3. ... (column_syntax)
    Effect
    The input in columns determines which columns are used to build the resulting set.
    Alternative 1
    Effect
    If * is specified, the resulting set is built based on all columns in the database tables or views specified after FROM, in the order given there. The columns in the resulting set take on the name and data type from the database tables or views. Only one data object can be specified after INTO.
    Note
    If multiple database tables are specified after FROM, you cannot prevent multiple columns from getting the same name when you specify *.
    Alternative 2
    ... {col1|aggregate( col1 )}
    {col2|aggregate( col2 )} ...
    Effect
    A list of column labels col1 col2 ... is specified in order to build the resulting list from individual columns. An individual column can be specified directly or as an argument of an aggregate function aggregate. The order in which the column labels are specified is up to you and defines the order of the columns in the resulting list. Only if a column of the type LCHAR or LRAW is listed does the corresponding length field also have to be specified directly before it. An individual column can be specified multiple times.
    The addition AS can be used to define an alternative column name a1 a2 ... with a maximum of fourteen digits in the resulting set for every column label col1 col2 .... The system uses the alternative column name in the additions INTO|APPENDING CORRESPONDING FIELDS and ORDER BY. .
    Column labels
    The following column labels are possible:
    If only a single database table or a single view is specified after FROM, the column labels in the database table - that is, the names of the components comp1 comp2... - can be specified directly for col1 col2 ... in the structure of the ABAP Dictionary.
    If the name of the component occurs in multiple database tables of the FROM addition, but the desired database table or the view dbtab is only specified once after FROM, the names dbtab~comp1 dbtab~comp2 ... have to be specified for col1 col2 .... comp1 comp2 ... are the names of the components in the structure of the ABAP Dictionary.
    If the desired database table or view occurs multiple times after FROM, the names tabalias~comp1 tabalias~comp2 ... have to be specified for col1 col2 .... tabalias is the alternative table name of the database table or view defined after FROM, and comp1 comp2 ... are the names of the components in the structure of the ABAP Dictionary.
    The data type of a single column in the resulting list is the datatype of the corresponding component in the ABAP Dictionary. The corresponding data object after INTO or APPENDING has to be selected accordingly.
    Note
    If multiple database tables are specified after FROM, you can use alternative names when specifying single columns to avoid having multiple columns with the same name.
    Example
    Read specific columns of a single row.
    DATA wa TYPE spfli.
    SELECT SINGLE carrid connid cityfrom cityto
    INTO CORRESPONDING FIELDS OF wa
    FROM spfli
    WHERE carrid EQ 'LH' AND connid EQ '0400'.
    IF sy-subrc EQ 0.
    WRITE: / wa-carrid, wa-connid, wa-cityfrom, wa-cityto.
    ENDIF.
    Alternative 3
    ... (column_syntax)
    Effect
    Instead of static data, a data object column_syntax in brackets can be specified, which, when the command is executed, either contains the syntax shown with the static data, or is initial. The data object column_syntax can be a character-type data object or an internal table with a character-type data type. The syntax in column_syntax, like in the ABAP editor, is not case-sensitive. When specifying an internal table, you can distribute the syntax over multiple rows.
    If column_syntax is initial when the command is executed, columns is implicitly set to * and all columns are read.
    If columns are specificied dynamically without the SINGLE addition, the resulting set is always regarded as having multiple rows.
    Notes
    Before Release 6.10, you could only specify an internal table with a flat character-type row type for column_syntax with a maximum of 72 characters. Also, before Release 6.10, if you used the DISTINCT addition for dynamic access to pool tables or cluster tables, this was ignored, but since release 6.10, this causes a known exception.
    If column_syntax is an internal table with header line, the table body and not the header line is evaluated.
    Example
    Read out how many flights go to and from a city. The SELECT command is implemented only once in a sub-program. The column data, including aggregate function and the data after GROUP BY, is dynamic. Instead of adding the column data to an internal l_columns table, you could just as easily concatenate it in a character-type l_columns field.
    PERFORM my_select USING `CITYFROM`.
    ULINE.
    PERFORM my_select USING `CITYTO`.
    FORM my_select USING l_group TYPE string.
    DATA: l_columns TYPE TABLE OF string,
    l_container TYPE string,
    l_count TYPE i.
    APPEND l_group TO l_columns.
    APPEND `count( * )` TO l_columns.
    SELECT (l_columns)
    FROM spfli
    INTO (l_container, l_count)
    GROUP BY (l_group).
    WRITE: / l_count, l_container.
    ENDSELECT.
    ENDFORM.
    SELECT - aggregate
    Syntax
    ... { MAX( col )
    | MIN( col )
    | AVG( col )
    | SUM( col )
    | COUNT( DISTINCT col )
    | COUNT( * )
    | count(*) } ... .
    Effect
    As many of the specified column labels as you like can be listed in the SELECT command as arguments of the above aggregate expression. In aggregate expressions, a single value is calculated from the values of multiple rows in a column as follows (note that the addition DISTINCT excludes double values from the calculation):
    MAX( col ) Determines the maximum value of the value in the column col in the resulting set or in the current group.
    MIN( col ) Determines the minimum value of the content of the column col in the resulting set or in the current group.
    AVG( col ) Determines the average value of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical.
    SUM( col ) Determines the sum of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical.
    COUNT( DISTINCT col ) Determines the number of different values in the column col in the resulting set or in the current group.
    COUNT( * ) (or count(*)) Determines the number of rows in the resulting set or in the current group. No column label is specified in this case.
    If you are using aggregate expressions, all column labels that are not listed as an argument of an aggregate function are listed after the addition GROUP BY. The aggregate functions evaluate the content of the groups defined by GROUP BY in the database system and transfer the result to the combined rows of the resulting set.
    The data type of aggregate expressions with the function MAX, MIN or SUM is the data type of the corresponding column in the ABAP Dictionary. Aggregate expressions with the function AVG have the data type FLTP, and those with COUNT have the data type INT4. The corresponding data object after INTO or APPENDING has to be selected accordingly.
    Note the following points when using aggregate expressions:
    If the addition FOR ALL ENTRIES is used in front of WHERE, or if cluster or pool tables are listed after FROM, no other aggregate expressions apart from COUNT( * ) can be used.
    Columns of the type STRING or RAWSTRING cannot be used with aggregate functions.
    When aggregate expressions are used, the SELECT command makes it unnecessary to use SAP buffering.
    Null values are not included in the calculation for the aggregate functions. The result is a null value only if all the rows in the column in question contain the null value.
    If only aggregate expressions are used after SELECT, the results set has one row and the addition GROUP BY is not necessary. If a non-table type target area is specified after INTO, the command ENDSELECT cannot be used together with the addition SINGLE. If the aggregate expression count( * ) is not being used, an internal table can be specified after INTO, and the first row of this table is filled.
    If aggregate functions are used without GROUP BY being specified at the same time, the resulting set also contains a row if no data is found in the database. If count( * ) is used, the column in question contains the value 0. The columns in the other aggregate functions contain initial values. This row is assigned to the data object specified after INTO, and unless count( * ) is being used exclusively, sy-subrc is set to 0 and sy-dbcnt is set to 1. If count( *) is used exclusively, the addition INTO can be omitted and if no data can be found in the database, sy-subrc is set to 4 and sy-dbcnt is set to 0.
    if helpful reward points

  • Sorts and pga_aggregate_target

    Hi All,
    I am on Oracle v11.2.
    I would like to verify my understanding of pga_aggregate_target here.
    Query and plan of the same query shown below
    SQL> select name, value from v$parameter where name like '%area_size' or name like 'pga%';
    NAME                           VALUE
    create_bitmap_area_size        8388608
    bitmap_merge_area_size         1048576
    hash_area_size                 131072
    sort_area_size                 65536
    pga_aggregate_target           2147483648
    5 rows selected.
    Elapsed: 00:00:00.11
    SQL>
    SQL> set autotrace on
    SQL>
    SQL> select * from ( select * from TABLE_A order by ap_first_inserted desc ) where rownum < 11 ;
                                 ..... Output data ..........
    10 rows selected.
    Elapsed: 00:00:55.11
    Execution Plan
    Plan hash value: 712899093
    | Id  | Operation               | Name         | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT        |              |    10 |   870 |       |   823K  (1)| 02:44:37 |
    |*  1 |  COUNT STOPKEY          |              |       |       |       |            |          |
    |   2 |   VIEW                  |              |    50M|  4199M|       |   823K  (1)| 02:44:37 |
    |*  3 |    SORT ORDER BY STOPKEY|              |    50M|  2751M|  3876M|   823K  (1)| 02:44:37 |
    |   4 |     TABLE ACCESS FULL   | TABLE_A      |    50M|  2751M|       |   122K  (1)| 00:24:30 |
    Predicate Information (identified by operation id):
       1 - filter(ROWNUM<11)
       3 - filter(ROWNUM<11)
    Statistics
              1  recursive calls
              0  db block gets
         446865  consistent gets
         446755  physical reads
              0  redo size
           1028  bytes sent via SQL*Net to client
            359  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
             10  rows processedTABLE_A has 50 million records.
    Am I correct in saying that, this query, mainly the SORT operation is completly executed in memory (stats after plan show "0" sorts (disk) ) ?
    In the plan, under columns TempSpc, it shows "3876M". What is this? does that mean 3876 MB of space ? in that case it is much bigger than the 2GB pga_aggregate_target or it is 3876 million bytes (which is still 3 and half GB) ? if the size of data being sorted exceeds 2GB, will Oracle use disk space?
    I checked in DBA_SEGMENTS, the data segment of TABLE_A has taken up about 3.5GB space.
    Thanks in advance.

    Thanks Jonathan.
    So, basically due to the rownum filter, not much memory/disk space was used.
    I ran another query which uses dense_rank function and it produced this stats
    Statistics
           2631  recursive calls
          66486  db block gets
          44394  consistent gets
          54296  physical reads
       61478516  redo size
            775  bytes sent via SQL*Net to client
           4179  bytes received via SQL*Net from client
              4  SQL*Net roundtrips to/from client
              1  sorts (memory)
              1  sorts (disk)
        1006295  rows processedThere was 1 memory sort and 1 disk sort.
    The parameters are like
    SQL> select name, value from v$parameter where name like '%area_size' or name like 'pga%';
    NAME                           VALUE
    create_bitmap_area_size        8388608
    bitmap_merge_area_size         1048576
    hash_area_size                 10485760
    sort_area_size                 10485760
    pga_aggregate_target           0
    5 rows selected.But this is a QA database.
    The production database has parameters
    SQL> select name, value from v$parameter where name like '%area_size' or name like 'pga%';
    NAME                           VALUE
    create_bitmap_area_size        8388608
    bitmap_merge_area_size         1048576
    hash_area_size                 131072
    sort_area_size                 65536
    pga_aggregate_target           2147483648
    5 rows selected.Now, as the documentation says (v11.2), pga_aggregate_target parameter will be in effect in case of the prod database. Am I correct in saying that, if my query gets enough memory allocation from pga_aggregate_target (of 2GB), there should be no need of any disk sorting?

  • Sorting before get logical database

    Hi,
    I would like to know any way to apply sorting before get logical database?
    for e.g.
    GET regup.
       PERFORM extract.
       IF reguh-zbukr NE regup-bukrs.
         tab_uebergreifend-zbukr = reguh-zbukr.
         tab_uebergreifend-vblnr = reguh-vblnr.
         COLLECT tab_uebergreifend.
       ENDIF.
    END-OF-SELECTION.
    I need to sort regup before GET regup which before it trigger for each line.
    Thanks.

    Hi,
    Instead of going for a sort before GET statement, you can move the required fields into an internal table first and sort that table and use it for your processing.
    A small eg:
    GET bkpf.
      MOVE:bkpf-bukrs TO tb_bkpf-bukrs,
                 bkpf-budat TO tb_bkpf-budat,
                 bkpf-belnr TO tb_bkpf-belnr.
          APPEND tb_bkpf.
          CLEAR  tb_bkpf.
    Please revert back for any further queries.
    Regards,
    Chandra.

  • Regarding select single and select upto???

    HI All,
    Cud u pls let me know the differences between select single and select upto??
    and which is the better option?? pls its quite urgent..plss plss
    plss
    Thanx in Advance
    Prasad

    Hi..,
    According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields.
    select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.
    The best way to find out is through sql trace or runtime analysis.
    Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for.
    The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.
    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.
    Mainly:  to read data from
    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.
    Mainly: to check if entries exist.
    Check this example ...
    DATA: gv_vbeln TYPE vbak-vbeln,
    gv_erdat TYPE vbak-erdat.
    SELECT SINGLE vbeln erdat
    FROM vbak
    INTO (gv_vbeln, gv_erdat)
    WHERE erdat = '12/01/2006'.
    SELECT vbeln erdat
    FROM vbak UP TO 1 ROWS
    INTO (gv_vbeln, gv_erdat)
    <b>ORDER BY erdat ASCENDING</b>.
    ENDSELECT.
    *In the example, the select single gets the first record that satisfies the WHERE clause unlike in the UP TO 1 ROWS where it sorts the database records by the earliest date and gets its VBELN.
    <b>Try using the ORDER BY clause in SELECT SINGLE .. It gives an error !! U cannot use that with SELECT SINGLE</b>
    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.
    Hope u understood !!
    reward if it helps u..
    sai ramesh

  • Diff between select single and select upto 1 rows.

    Hello aLL,
    PL tell what is technical diff between select single and select upto 1 rows and how it is affecting the performance.
    Rushikesh

    Hi
    Knowing when to use SELECT SINGLE or SELECT ... UP TO 1 ROWS
    A lot of people use the SELECT SINGLE statement to check for the existence of a value in a database. Other people prefer to use the 'UP TO 1 ROWS' variant of the SELECT statement.
    So what's the difference between using 'SELECT SINGLE' statement as against a 'SELECT .... UP TO 1 ROWS' statement ?
    If you're considering the statements
    SELECT SINGLE field INTO w_field FROM table.
    and
    SELECT field INTO w_field FROM table UP TO 1 ROWS. ENDSELECT.
    then looking at the result, not much apart from the extra ENDSELECT statement. Look at the run time and memory usage and they may be worlds apart.
    Why is this ?? The answer is simple.
    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.
    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.
    Get the difference ??
    If not, here is a good example, credit for this example goes to Richard Harper, a friend of mine on sapfans.com :
    Create a Ztable called ZDifference with 2 fields in it, MANDT of type MANDT and POSNR of type POSNR. Make sure both of these are keys. Also create a table maintenance dialog for it (SE11->Utilities->Table Maintenance Generator). Fill the table with ten rows 000001-000010.
    Then run the program shown below:
    Code:
    Program: Z_Difference
    Purpose: A program that demonstrates the difference
    between SELECT SINGLE and SELECT UP TO n ROWS.
    This program requires the data table Z_DIFFERENCE
    to have been created according to the structure
    outlined in the text above and populated with
    at least 10 records.
    Creation Date: 21/04/2004
    Requested By:
    Reference Doc:
    Author: R Harper
    Modification History:
    Date Reason Transport Who
    Report Z_Difference
    Message-id 38
    Line-Size 80
    Line-Count 0
    No Standard Page Heading.
    Start-Of-Selection.
    Data: w_Single type Posnr,
    t_Rows type standard table of Posnr
    initial size 0
    with header line.
    Select single Posnr
    from zDifference
    into w_Single.
    Select Posnr
    into table t_Rows
    from zDifference
    up to 1 rows
    order by Posnr descending.
    Write :/ 'Select single:', w_Single.
    Skip 1.
    Write :/ 'Up to 1 rows :'.
    Loop at t_Rows.
    Write t_Rows.
    EndLoop.
    You should see the output:
    Select single: 000001
    Up to 1 rows : 000010
    The first 'SELECT' statement selected the first record in the database according to any selection criterion in the 'WHERE' clause. This is what a 'SELECT SINGLE' does. The second 'SELECT' has asked the database to reverse the order of the records before returning the first row of the result.
    In order to be able to do this the database has read the entire table, sort it and then return the first record. If there was no ORDER BY clause then the results would have been identical (ie both '000001') but the second select if given a big enough table to look at would be far slower.
    Note that this causes a problem in the Extended Program Check if the full key is not specified in a 'SELECT SINGLE'. Replacing the 'SELECT SINGLE' by an "UP TO 1 ROWS" will give the same exact results without any warning but the program will run slower and consume more memory. This is a good example of a warning that we should ignore... considering you are sure of what you are doing !!

  • JTable woes (JDK 1.5): Sorting and updating data

    So I've been working on this project for a while here that is essentially the front-end to a database system. The data itself is displayed in a JTable derivative. Column 1 is a JComboBox containing a list of companies, Column 2 is a JComboBox containing a list of employees, and the rest of the columns contain information specific to that employee.
    The data for each row is actually contained within a custom TableRowData object, which is used to assign listeners and such:
        private void initComponents() {
            this.organizations.setSelectedEnum(this.data.getOrganizationNumber());
            organizations.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if("comboBoxChanged".equals(e.getActionCommand())) {
                        clearData();
                        try {                 
                            updateEmployees();
                            fireRowDataChanged();
                        } catch (SQLException ex) {
                            Logger.getLogger(VenosTeammateRow.class.getName()).log(Level.SEVERE, null, ex);
            pocs.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {               
                    if("comboBoxChanged".equals(e.getActionCommand())) {
                        try {
                            data = getEmployeeInformation();
                            fireRowDataChanged();
                        } catch (SQLException ex) {
                            Logger.getLogger(VenosTeammateRow.class.getName()).log(Level.SEVERE, null, ex);
        }Ideally, I would like a change in Column 1 to load the employees for the selected company into Column 2. This is working as expected.
    I would also like a change in Column 2 to load the information specific to the selected employee into the rest of the columns. This is also working as expected.
    The problem I am having arises when the data is sorted and THEN a change is made to either column.
    To sort, I am using a custom comparator that keeps track of the sort direction and current sort column.
    In the JTable derivative class, I have a method, sortByColumn(int col):
    public void sortByColumn(int col) {
            this.getColumnModel().getColumn(col).getCellEditor().cancelCellEditing();
            if(this.getSelectedRow() > 0 && this.getSelectedRow() < this.getRowCount())
                this.removeRowSelectionInterval(this.getSelectedRow(), this.getSelectedRow());
            DefaultTableModel mdl = (DefaultTableModel)this.getModel();
            comp.setSortColumn(col);
            Collections.sort(mdl.getDataVector(), comp);
            // Declare and initialize the header
            JTableHeader header = this.getTableHeader();
            // Reset all headers to their identifier values
            for(int i = 0; i < mdl.getColumnCount(); i++) {
                String identifier = header.getColumnModel().getColumn(i).getIdentifier().toString();
                header.getColumnModel().getColumn(i).setHeaderValue(identifier);
            // Find the sort order (for the sorting indicator)
            int sortOrder = comp.getSortOrder(col);
            // Store the identifier text temporarily
            String headerText = header.getColumnModel().getColumn(col).getIdentifier().toString();
            // Declare and initialize the sort indicator based on the sort order
            String sortIndicator;
            switch(sortOrder) {
                case TableRowComparator.ASCENDING:
                    sortIndicator = "  \u2191";
                    break;
                case TableRowComparator.DECENDING:
                    sortIndicator = "  \u2193";
                    break;
                case TableRowComparator.UNSORTED:
                    sortIndicator = "";
                    break;
                default:
                    sortIndicator = "  \u2193";
                    break;
            /* Set the Header to display the text with the indicator. Since
             * this will automatically set the Identifier to the same value,
             * reset it to the value we stored previously.
            header.getColumnModel().getColumn(col).setHeaderValue(headerText+sortIndicator);
            header.getColumnModel().getColumn(col).setIdentifier(headerText);
            // Make sure all the changes are painted
            header.repaint();
            this.repaint();
        }After the sort, the rows are updated and displayed correctly. However, for example with three rows, if by sorting row 1 and row 3 swap, changing the JComboBox in row 3 also updates the data in row 1.
    I'll be converting my code into a short self-contained program momentarily to post on here for a better understanding of what's going on. However, I decided I would post this just in case there were something painfully obvious I missed.
    Thanks.

    Thanks, you've been really helpful :) However, I realized while trying to copy my code to a smaller, self-contained form to illustrate my problems... I never changed the row number in my TableDataRow! So of course the update information, which was relying on the row number stored in the TableDataRow object (and not the actual row number in the model's data vector) updated according to the old row numbers.
    Basically, I coded myself into a corner :P
    Fixed it by making a new comparator to compare TableDataRow objects, and I stored an array of those objects in my custom table model. So the hard work is done on the TableDataRow objects, the data vector is cleared, and then each TableDataRow is added back as a vector.
    Not sure if this is the most elegant solution, but... it works.
    Edited by: GranoblasticMan on Oct 21, 2008 1:11 PM

  • Selection of database

    Hi,
    I have a task of selecting a database. The project is a stand alone application. we want to develop a database that creates, updates, modifies sales database. SQL server happens to be free of cost but I am not sure if its functionality is as competent as oracle.
    I will appreciate suggestions.
    Thanks!

    You would need to have much more detailed requirements before you could make any sort of decisions about the type of database you would need or want. If you have functional requirements for the project, you can go through each bit of application functionality and find the features of each database that would be most beneficial in addressing the functional requirements of your system. There are a lot of things to consider:
    - What sort of transaction volume do you expect
    - Will you be purging the data periodically? If so, Oracle's partitioning features may be a huge benefit and SQL Server's locking mechanism may be a substantial burden.
    - Is it acceptable for writers to block readers? If you're using SQL Server, it is generally necessary to have a separate reporting database to deal with this sort of issue, which isn't necessary with Oracle.
    - What sort of managability features do you need? Will there be DBA's on site to deal with the database (not sure if you're writing an internal application or a commercial application)?
    - What sort of backup and recovery will be necessary?
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

Maybe you are looking for