Dodgy Order By detection

Hi all
Just found an annoying bug in Oracle.
(perhaps I should say that the bug is most likely more in Oracle clients, like TOAD and APEX).
I'm not sure if this has been pointed out already, but it's really quite poor.
Say you have a query, like this:
select member_name, member_points
from member_tableIn TOAD or APEX you can then sort the columns however you want (not using an order by, but by using their in-built sort functions).
Now, if you include an order by...
select member_name, member_points
from member_table
order by member_pointsYou can no longer do a column sort in TOAD or APEX.
This seems to make sense, given the results are already sorted.
And the only method used to detect if results can be sorted or not is by the presence or absence of the "order by" clause.
Now, normally that would be fine - if your query orders it's results, then you probably don't want to sort them, right?
The problem?
Instead of analysing the query properly, all that's done is that the exact string "order by" (not case-sensitive) is checked.
If this string is in your query, you cannot sort your results.
Example:
If you have the following query:
select member_name "Member Name", member_points "Order By"
from member_tableYou cannot sort your results.
This is obviously completely stupid, as the "order by" string is only being used as a title!!
In fact, the detection is so bad that while this won't work...
select member_name, member_points
from member_table
order by member_pointsThis will...
select member_name, member_points
from member_table
order
by member_pointsor this...
select member_name, member_points
from member_table
order  by member_points(2 spaces between "order" and "by")
Buggy!
Anyone else encountered this problem?
So far it happens in TOAD and APEX.

Not an Oracle RDBMS bug, but an APEX bug. (and no, I do not give a damn for TOAD ;-) ).
The problem as you've identified is caused by APEX scanning the SQL, detecting an "ORDER BY" clause, and then assuming the results are already sorted and not allowing you enable APEX's column sort feature on the results.
I ran into it using analytical SQL. My work around is to simply add gunk in between the ORDER and BY tokens.. e.g. (actual snippet from an APEX report query)
row_number() over (order /*--*/ by SUM(bytes) desc) as ORDER_BY_BYTES,
This results in the APEX parser not thinking that the result set is sorted.
You should however raise this issue on the APEX forum here - not really applicable to PL/SQL or SQL or the Oracle RDBMS at all.

Similar Messages

  • Bad Order By Detection

    Hello all
    This thread is the follow-through from another:
    Dodgy Order By detection
    There is a problem in APEX to do with it's detection of the "order by" clause.
    If an SQL query has the string "order by" (case-insensitive) in it, then APEX will not allow you to use column sorts in reports.
    Example of a query that you CAN use column sorts with:
    select name, points
    from tableExample of a query that you CANNOT use column sorts with:
    select name, points
    from table
    order by pointsThat makes sense, as you shouldn't be able to sort an already sorted result set.
    What doesn't make sense is this...
    Example of a query that you CAN (but SHOULDN'T) use columns sorts with:
    select name, points
    from table
    order
    by points(line break between order and by)
    or
    select name, points
    from table
    order  by points(2 spaces between order and by)
    APEX is simply checking for the presence of the string "order<space>by".
    This is, obviously, incorrect.
    Example of a problem case:
    A query that has...
    select row_number() OVER (order by q.value desc) rank, q.*You should be able to sort this, but you cannot...
    Unless you put 2 spaces between the order and by words.
    Bug :)

    A way around this is to create a view:
    create or replace view vw_your_table as
    select row_number() OVER (order by q.value desc) rank, q.*
      from your_table qand select from the view.
    Mike

  • I was looking at the "Find my iPhone" app and I have a doubt regarding how it works for the macbook. In order to detect the location, the macbook should remain signed into iCloud. What if the thief logs out of iCloud. Would we able to locate the macbook?

    I was looking at the "Find my iPhone" app and I have a doubt regarding how it works for the macbook. In order to detect the location, the macbook should remain signed into iCloud. What if the person who has stolen my macbook logs out of iCloud.
    It should work fine for iPhone/iPad because we can enable "Restrictions" to prevent the user from signing out of iCloud. Do we have simialr settings for the macbook?
    Thanks,

    If it's not on the device list, it indicates that someone has gone to Find My iPhone on icloud.com and manually deleted it from the device list (as explained here: http://help.apple.com/icloud/#mmfc0eeddd), and it has not gone back online since (which would cause it to reappear on the device list; Find My iPhone has been turned of in settings on the device; the iClolud account has been deleted from the device; or the entire devices has been erased and restored.
    Unfortunately, there's no other way to track the phone other than through Find My iPhone.  You could call your carrier and see if they would blackliste it so at least the theif couldn't use it.

  • Ipone or ipod is not detected by itunes unless itunes is updated to a newer version. however whenever i restart my computer it seems itunes uninstalls itself or something. in order to sync anything to my phone i have to reinstall itunes. help please

    both my iphone or ipod is not detected by itunes unless itunes is updated/reinstalled. however whenever i restart my computer it seems itunes uninstalls itself or something and in order to detect my phone it needs to be reinstalled all over again. why is itunes uninstalling itself on my mac when it is restarted?

    snow leopard.
    Okay. In that case try the following document:
    Mac OS X v10.6: iOS device not recognized in iTunes after restart

  • Detect potential duplicate vendor master records

    Hi all,
    Our external auditor has the following comment:
    'Match codes and message control can be used to help identify duplicate vendor records. Fields such as “Name”, “Address” and “Country” can be set as searchable fields in order to detect potential duplicate vendor records.  The message control (with identifier “144”) in SAP can give a message prompt when duplicate vendors are identified.
    We noted that your system had not been configured to display a warning message if the name or address, etc of a new record is identical to an existing vendor record.'
    Any idea to implement this?
    I searched for message 144 and found that there is a similar message in message class F2: 'Vendors found with same address; check', but I cannot find where to trigger this error message.
    Please help.
    Best Regards,
    Chris.

    Goto SPRO-Financial accounting-Accounts Receivable and Accounts Payable
    -vendro account-master data- Preparations for Creating Vendor Master Data 
    - Change Message Control for Vendor Master Data
    here you can maekk the messge 144 to Error

  • Detect customers without credit limit

    Hi,
    in my firm we use credit control for customers in the EXP market.
    In SE16N when I go to table KNKK I can pull a list of all customers with credit limits -- they have value "EXP" in field KKBER or no. of credit (equal to customer no.) in field KNKLI.
    However I noted that were several customers in table KNA1 that belonged to account group (field KTOKD) no. 0001 or 0003 and technically are part of EXP market, hence should have credit limit, but I cannot find them in table KNKK.
    Why is that? When master record is set up it's another process to set credit control for the customer?
    Also, I'd like to pull a list of all customers from table KNA1 that belong to EXP market and cross-match them to table KNKK in order to detect if they do not exist in KNKK, i.e. do not have credit control.
    How can I do it?
    Would appreciate your response. Regards

    Hi,
    Try the T-Code F.32
    In this T-code you will get the list of all the customers whose credit limit is not maintained in FD32.
    Thanks and regards,
    Amitesh Anand

  • How to detect wi-fi segnal strenght?

    Hi,
    i was wandering if there is an AIR API in order to detect how many wi-fi segnals mobile phone's detecting, and how much strenght they are.
    Thanks

    I should have mentioned that you can submit and vote for features at http://ideas.adobe.com

  • Purchase Orders replicated in BE with wrong number

    Hello,
    Recently we've observed that in our dev system Purchase Orders are being replicated from SRM to R/3 System with numbers used for POs created in R/3,
    Let say, for example,  that in SRM the PO number starts with 33 and once the PO is replicated it's created with a number that starts with 45.
    Once POs are replicated, there are no links between this PO and the one in SRM shown in bbp_pd.
    So we want to know what checks (transactions) we must check in order to detect what could the reason for this behaviour.
    Any advice is welcome.

    Dear Elias,
    please check number ranges which was defined in SRM for PO's.
    The number ranges for PO's in SRM should be defined as internal, the same number range should be define as external in R/3.
    The number ranges for PO's in SRM which was defined in SRM already defined in R/3 previously and in use.
    Regards
    vasanth

  • Detecting when exception was thrown using custom class loader

    Hello all,
    I would like to implement the solution described here - http://stackoverflow.com/questions/75218/how-can-i-detect-when-an-exceptions-been-thrown-globally-in-java - that uses custom class loader in order to detect when an Exeption thrown somewhere in the JVM hosting my app, please note that exceptions might be thrown from 3rd party jars the app is using. So, thanks to help I got from another post, I've managed to code the custom class loader. My question is how can the class loader wrap the original exception, as the methods in ClassLoader deals with classes, not instances. So where should I set the original exception?
    Thanks!
    Edited by: user9355666 on Sep 28, 2010 10:48 PM

    user9355666 wrote:
    I think I'm missing something fundumental, forgive me for being slow...
    This is what I did so far. For the exception wrapper I made a simple class extens Exception that recieve Exception in its ctor and store it. I also subclassed ClassLoader and override its loadClass(). I've registered it as the system classloader. My thinking was to check in that point that if the requested class is instance of Exception and if yes, returning my wrapper class wrapping this exception. But, since loadClass() return class, how can I set in the wrapper the original exception?
    In addition, let's say 2 different places in the code throws NPE, to my understanding the classloader will load NPE only once, so how throwing the NPE in the second time can be detected?you are missing a key point. you should creating a custom implementation of the NPE class which hooks into your detection code in its constructor. from that point forward, anytime any NPE (which is your custom class) is constructed, you can detect it.

  • CreateStatement() doesn't detect conn reset by peer

    Hi to all. Well... it's almost explained in the subject. I am trying to recycle bad connections in a connection pool, so I use createStaement() in order to detect if the connection is valid (I previously tried with isClosed(), but it catches even less bad connections). The problem is that eventually the createStatement() doesn't fail while testing, although the connection is closed, so wen I try to use it... boom. This occurs (sometimes, not always) after the database is shut down and restarted by night for maintainance purposes. But notice that when the db is shutting down, or restarting, then I receive the corresponding SQLException, but it seems that when it is working again, createStatement() is ok (I check it every 60 seconds), but some condition may have occur that makes the connection JUST OPENED by the pool to be bad. The error I receive when using the conn is Connection reset by peer. I guess that the error is related to communications, but can't identify it, because it seems to be random.
    Anybody can help me?
    Thanks in advance
    PS: I know there are other topics in the forum related to Connection reset by peer error, but I have not found my problem.

    A blast-from-the-past thread...
    I have my own connection pool implementation; I don't know how easy this is to add on to an existing pool. (Which is a big reason why I have my own pool code.) You'll need some way to get each connection from the pool in turn; a basic pool may not support that. You'll need to be suitably careful to synchronize so that you don't ping the connection while another thread is using the same connection.
    I have a background thread ("PoolManager") which does in pseudocode:
        while (true) {
            sleep 10 minutes;
            foreach pool {
                log pool statistics, e.g. pool size, number of open connections, number of fetched connections;
                foreach connection in the pool {
                    synchronize (connection) {
                        log connection's last use time, how many times used, etc;
                        if (connection not currently in use) {
                            if (auto-close old connections configured &&
                                now > last use time + 20 minutes) {
                                 close connection;
                                 continue;
                            if (now > last use time + 10 minutes)
                                // To make auto-close work, this  execute doesn't update the last use time.
                                // Exceptions during this close the connection.
                                execute "select 42 from dual" on the connection;
       }"long last_use_time" is stored for each connection, and set to currentTimeMillis() when the connection is fetched from the pool. The "10 minutes" etc times are configurable, and the dummy ping statement is per-pool configurable.

  • Detecting OCI disconnect

    What is the best way to detect if your OCI database connection has been lost.
    I guess that I could create a thread that runs repeated "select * from dual" or something like that in the background in order to detect a disconnect but I was hoping that there is some better way do this.
    Something more like OCIRegisterCallbackfunc(OCI_ATTR_TYPE_DISCONNECTNOTIFY,CallbackFunc).
    regards
    /N

    But theese functionalities requires that the listener works ok?! If the database machine, for instance, had an power outage and rebooted then I wont get any notification?
    Register for database startup: I assume that you mean a controlled startup of hte instance, not a startup after a reboot of the db-machine. Am I correct?
    Regards
    /I

  • Edge detection using IMAQ Find Edge/IMAQ Edge Tool 3

    Hi,
    I have several images with useless background around a rectangular ROI (coordinates unknown!). So I tried using the two VIs mentioned above in order to detect these edges so that I can remove them. Regretfully, this does not work as planned.
    IMAQ Find Edge usually finds an edge, but not where it should be. The edge detection is earlier than I want it to be.
    IMAQ Edge Tool 3 sometimes does not find an edge at all, sometimes it finds the edge perfectly. Here I use the 'get best edge' option, which delivers the best results with all the images I tested it with.
    All the other options are also not changed while running the VI with the images I have.
    Does anyone have intimate knowledge of these VIs' algorithms, how they work, how they can be manipulated, ... ?

    Hi,
    Can you upload an example image?
    That would clarify what you're trying to do?
    Most of the time a change of mindset solves the problem.
    Kind regards,
    - Bjorn -
    Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's
    LabVIEW 5.1 - LabVIEW 2012

  • Detect uncommitted yet posted data in my forms session?

    In our application it is common practice to use the Forms POST built-in.
    Since we have our own exit-function with the application-wide look and feel we would like to catch the alert-box asking whether to save any changes.
    Is there a way to either adapt the alert-box to our own look and feel or an attribute that could be utilised in order to detect uncommitted data?
    We would rather not want to omit the POST logic nor log any footstep of the user.
    Any hint would be appreciated.

    Use parameters , set their values to 'false' for example before posting changes , and then check the status of all of the blocks in your form. Change the value of a particular parameter to true if the status of a certain block is CHANGED. To prevent from being confused name your parameters according to the block name.
    And in your exit functionality test if one of the parameters is 'true' and you show your alert.

  • Fraud/Anomalie detection in the behaviour of the transactions

    Hello,
    I need to detect anomalies in transaction and I have a concept problem.
    In fact my anomalies concern not a transaction but a group/cluster of transactions.
    This transactions are:
    - of a low amount
    - and very close to each other in the time (between 1 sec and 1 minute of interval).
    (A transaction with a low amount is not a problem in itself)
    I need to detect them and to give for each transaction an anomalie probability. Bigger is the time interval and the amount, lower is the anomalie probability.
    One big problem in this case is that the interval between the transaction is not fixed. I said between 1 sec and 1 min
    but sometimes you can get transactions with an interval of 1 min and 1 sec or of 2 min.
    To detect them, I have thought to:
    - an anomalie detection model by third (such as customers of suppliers)
    - a cluster model to detect and group the transactions
    I don't have implemented the first solution (an anomalie detection model) because I understood that you have to create one case table and one model by third. And as I have a lot of third, it's not easy to implement.
    I have try the second solution (cluster detection) but:
    - the algorithm treat the date time (a number in my case table) as a value and not as a scale time.
    - the number of (group|cluster) is limited of must be given in the algorithm setting.
    Then my questions:
    - Is data mining a tool that can help in this kind of detection
    - If yes, what is the right approach.
    I don't ask for a lot of detail in the implementation of the solution but much more to get the right direction in order to detect this kind of transaction behaviours.
    Thanks for any clue
    Nico

    Hello Anoop
    during our upgrade project we did not have the same problem. I have never heard about a similar problem. May be check OSS (SAP marketplace). Depending on the release you started may be you missed yome customizing to be done (if you started with SAP enterprise 4.7 Ext 1.1 the change is "dramatic"; if you started with SAP enterprise 4.7 Ext 2.0 changes should only be minor; in case of ECC 5.0: I believe there is no change.
    a.) Do you have activated Enhancement Packages?
    b.) do you use the "exit" to prepare "dynamic phrase sets"?
    With best regards
    C.B.

  • I can't get album tracks in the correct order

    Hello
    The tracks in my 'favourite worst nightmare' album by arctic monkeys are in the wrong order and i can't fix it. All my other albums are fine.
    The tracks are all in the correct order in windows explorer, but in itunes, they are listed 4,5,2,3,6,7,8,9,10,11,12,1
    They are all by same artist, same year, same album, same genre.
    When i search for the album and get it on its own, i am able to put it in correct order, but as soon as i cancel the search and view the full library, the songs go back into this dodgy order.
    Any suggestions ?
    thanks

    I am having a similar problem with my Goo Goo Dolls album, Let Love In - I've had it for months and it has been fine but the other day it started to lose the correct order - it started with only one song but then it spread and it was so random I couldn't listen to the album (I am very particular about the order of albums) - Now it seems to only be the first song that is out of place, it is at the end BUT I have no control over changing the order anymore, something that has changed because I used to be able to do that - I haven't updated because of all the trouble everyone had with 7.2 so I have 7.1.1.5 - I HOPE that someone can help me here because I can't listen to that album anymore and I Love the Goo Goo Dolls...

Maybe you are looking for