Arbitrary ordering?

Querying dba_constraints, I might finish with an 'order by constraint_type'. But this now means that unique constraints are listed after foreign keys because 'R' sorts before 'U'. If I'm running the query to generate the SQL to re-create the constraints, I'll get a lot of failures because the foreign keys are supposed to reference primary or uniquely-constrained columns, and the unique constraints won't have been created yet. It's no good me ordering by constraint_type desc, either, because then I'll be trying to create foreign keys before the primary keys get created, because 'R' would sort before 'P'. What I really need is all the primary constraints, then all the uniques and all the foreign keys bringing up the rear.
So my question: is there a way of ordering by a column in an arbitrary, user-defined way? Where you say, for example, "order by constraint_type ('P','U','C','R')".
A bit like list partitioning, where you get to define what "constrains" a record to a partitcular partition, only this time, you get to define your ordering sequence.
As another example, I want to sort the EMP table in department number order, but the ordering I want is "20, then 10, then 40 and then 30", for whatever weird business reason you might think up.
Do-able in a simple (or not-so simple) query? I can see how four separate union queries could do it... am wondering if there's anything more elegant and that could extend easily to lots more than 4 distinct ordering values.

Decode the constraint type and order by the decoded column.  In SQLPlus, you can even NOPRINT the ordering column.
SQL> create table hkc_test_90 (table_name varchar2(30), col_name varchar2(30), constraint_type varchar2(1));
Table created.
SQL> insert into hkc_test_90 values ('T_A','C_1','P');
1 row created.
SQL> insert into hkc_test_90 values ('T_A','C_3','U');
1 row created.
SQL> insert into hkc_test_90 values ('T_B','C_1','P');
1 row created.
SQL> insert into hkc_test_90 values ('T_B','C_2','R');
1 row created.
SQL> insert into hkc_test_90 values ('T_C','C_1','P');
1 row created.
SQL> insert into hkc_test_90 values ('T_C','C_4','R');
1 row created.
SQL> commit;
Commit complete.
SQL>
SQL> select table_name, col_name, constraint_type, decode(constraint_type,'P',1,'U',2,'C',3,'R',4) ctype_no
  2  from hkc_test_90
  3  order by ctype_no, table_name;
TABLE_NAME                     COL_NAME                       C   CTYPE_NO
T_A                            C_1                            P          1
T_B                            C_1                            P          1
T_C                            C_1                            P          1
T_A                            C_3                            U          2
T_B                            C_2                            R          4
T_C                            C_4                            R          4
6 rows selected.
SQL> col ctype_no noprint
SQL> select table_name, col_name, constraint_type, decode(constraint_type,'P',1,'U',2,'C',3,'R',4) ctype_no
  2  from hkc_test_90
  3  order by ctype_no, table_name;
TABLE_NAME                     COL_NAME                       C
T_A                            C_1                            P
T_B                            C_1                            P
T_C                            C_1                            P
T_A                            C_3                            U
T_B                            C_2                            R
T_C                            C_4                            R
6 rows selected.
SQL>
Hemant K Chitale

Similar Messages

  • Animate table row-wise in arbitrary order

    Dear all,
    I would like to animate a table such that the content appear row-wise, but e.g. first row 1, then row 3 and then row 2.
    How to do that?
    I failed, when tried to define the animate for each element separately, since I was not able to move row 3 before row 2.
    Any suggestions?
    Thanks,
    Thomas

    It doesn't appear to be a way to do this automatically, so what you probably have to do is duplicate the chart for as many times as you have rows and then set them to build in in the order you wish. Would be a pain in the butt, but should work.

  • Draw a smooth shape out of point array where points are in arbitrary order

    hi folks,
    I got a little problem I just can't get figured out:
    - there's an array of points (x,y)
    - the points inside this array are arbitrary
    - now I need to find out which points define the outermost shape
    - all other points that are inside this outermost shape may not be used
    - and finally the shape should be smooth...
    a picture of what I mean is to see here:
    http://www.student-zw.fh-kl.de/~chgr0001/tmp/shape.htm
    I wonder if there's a method in Java2D to do this?!
    thanks for your help!

    well,
    it's about a class that draws an area based on coordinates out of a database.
    These coordinates are originally from a GPS device and hold information about public WLANs. If someone walked around with his GPS and found WLAN data, this data together with the according GPS coordinates is stored in certain fractions of time.
    Now my problem is that I want to present the areas, where you can get a WLAN link, on a map. To do so, I want to draw the outermost shape of a "walkaround with my GPS" session and colorize it with the average link quality.
    Furthermore I like to have that shape smooth.
    I would appreciate any hints on how to proceed and which methods of which classes are useful to do so.

  • IPhone sync playlist to arbitrary order

    I can't for the life of me get playlists to the iPhone in the order they are listed in the iTunes playlists. All playlists on the iPhone are always listed in Artist order from A to Z. How do I change it?

    Connect the phone to iTunes and then sync your phone and everything that you have checked will be synced.  You need to click on the Music section of iTunes once you have clicked on your phone when it becomes visible in iTunes and ensure that you have checked/put a tick against the Playlist that you want, otherwise it will not be synced.

  • Order of execution in Function Main

    I have two separate transfers in one mapping, which results in creation of two separate load functions when I generate the mapping. The function calls in function Main are in arbitrary order but I want to control in what order the functions are called. How do I do that?
    I'm using version 9.2.0.2.8.
    Thanks.

    Currently there is no explicit way to control order of load processes within one mapping if targets are completely independent, i.e. does not participate in some other transformations later in the same mapping. (But actually, if targets are really independent you should not bother).
    Implicitly the order of loading is determined by the order you have dropped targets on the mapping editor. Unfortunately you couldn’t rely heavily on this approach.
    If targets within flow are interrelated (for example, after loading one table you are using it in loading second table) OWB correctly determine dependencies and build mapping package with loading process parts properly ordered. Your may want to actually employ this feature (together with loading dummy tables).
    But again, I don’t think you really need this. Instead, consider using having independent mappings for these tables and use Workflow to explicitly control execution order of mappings. For example, perform really parallel loading of these two tables - by forking two mappings for parallel execution (if hardware allows).

  • Ordering photos in Web Gallery

    I would like to impose an arbitrary order on a Web Photo Gallery. What is the recommended practice for doing this? Add a metadata attribute and sort on it? Rename the photos including an order field in the name?
    I tried simply dragging and dropping. That does not appear to work as the dragged photo always bounces back to its original position.
    I'm on a Mac if that matters.

    Make a collection of your selected images and then drag & drop (from the center of the images) into the order you want. Then take that Collection to the Web Module. The Web Module remebers what ever Web Preset you save/use for that Collection.
    Don
    Don Ricklin, MacBook 1.83Ghz Duo 2 Core running 10.4.9 & Win XP, Pentax *ist D
    http://donricklin.blogspot.com/

  • 30gb video iPod is playing songs out of order.

    I have a 30gb Video iPod (4 or 5 years old).  It has suddenly started playing album tracks in the wrong order.  When I look at the album track listing, the songs are the correct order, but it won't play them that way.  It's always in a different, arbitrary order.  Please help!  Thanks in advance.

    First, try doing a Reset to restart the iPod
    http://support.apple.com/kb/HT1320
    If that does not help, and this problem only affects ONE album, and this album's songs are seen as having the correct Track # information in iTunes, what I would do is delete just this album from the iPod.  Then, add it back.  If there is some corrupted data on the iPod related to the album's song order, this should fix it.
    If it's happened to all albums (or many albums) on the iPod, I would do a Restore on the iPod using iTunes.  Select the iPod in the iTunes sidebar, under DEVICES.  Over to the right, go to the Summary tab.  Click the Restore button.  This will erase the iPod, reinstall its software, and set it to default settings.

  • OSB Console - Order by num messages not ordering correctly

    I am a consultant with experience in SOA Suite 11g, but I don't know much about OSB.
    I have a customer who is complaining that in OSB console he cannot sort by the number of messages received. There is a view with a table in the admin console webapp where you can click on the column header to sort by values in the column, the messages column which shows the number of message received seems to do some arbitrary ordering, but it is not in increasing or decreasing order. One theory the customer had is that numbers are displayed in an "American way", i.e. a thousand is written 1,000 instead of 1000. I am not sure if this is the problem, and he has checked the logs to see that the value is in fact stored as 1000. Customer's linux machine has US regional settings but customer is in non-English speaking country.
    Has anybody encountered anything like this, or does anybody have any tips on what we could try to fix this? Customer needs to be able to order by num messages.
    Location of issue is in OSB admin console, "service health" tab. OSB 11g

    I am a consultant with experience in SOA Suite 11g, but I don't know much about OSB.
    I have a customer who is complaining that in OSB console he cannot sort by the number of messages received. There is a view with a table in the admin console webapp where you can click on the column header to sort by values in the column, the messages column which shows the number of message received seems to do some arbitrary ordering, but it is not in increasing or decreasing order. One theory the customer had is that numbers are displayed in an "American way", i.e. a thousand is written 1,000 instead of 1000. I am not sure if this is the problem, and he has checked the logs to see that the value is in fact stored as 1000. Customer's linux machine has US regional settings but customer is in non-English speaking country.
    Has anybody encountered anything like this, or does anybody have any tips on what we could try to fix this? Customer needs to be able to order by num messages.
    Location of issue is in OSB admin console, "service health" tab. OSB 11g

  • IPad doesn't synch iPhoto events in chronologic order.. what to do? I'm on MacBook Pro, OS X Yosemite 10.10.1 with iPhoto 9.6 - Solution anyone?... Thanks!

    iPad doesn't synch iPhoto events in chronologic order.. what to do? I'm on MacBook Pro, OS X Yosemite 10.10.1 with iPhoto 9.6 - Solution anyone?... Thanks!

    Solution anyone?...
    Wait for an iOS update and send feedback to Apple. Many have reported that problem here - synced events and faces in arbitrary order, but there is no known solution.  You cannot arrange the synced events, albums, and faces on your iOS devices in any way.
    You can use this feedback form to submit a feature request:  http://www.apple.com/feedback/iphoto.html

  • Default Order of trigger execution

    If a table has two or more triggers(of same type like both "before insert") defined on it then what is the default order of executing of the triggers.
    Thanks in advance.

    Prior to 11g, there is none. Two triggers with identical specs (i.e. two row-level before insert triggers) will fire in an arbitrary order. And that order may change between calls. If you have code that depends on a particular order, you're much better off creating a single trigger that makes calls to two different procedures that do whatever the two triggers are doing in an appropriate order.
    In 11g, you gain the ability to force triggers to run in a particular order, but I would generally advise against any architecture that would require this sort of thing.
    Justin

  • Sorting order for Highlights, Shadows, Whites and Blacks controls.

    I absolutely love the new set of controls as compared to the similar options in LR3.  With just these 6 controls and a few seconds I can get my image looking great.  One thing is making me crazy though, the four controls are logically sorted "Whites, Highlights, Shadows, Blacks" in terms of the range that they impact.  If the controsl were sorted as I suggested, I would be able to think through the problem of fixing a particular image more efficiently.
    Has this been discussed or considered?

    tomalphin wrote:
    I should add, with only four items in question, putting the two you are most likely to use slightly closer together will result in little gained efficiency.  Having them sorted in a manner that is easier to teach, learn and internalize will likely lead to better results for a larger percentage of users. 
    Further, if they were sorted in the manner I suggest, it would be possible to further strengthen the understanding of how the features work by showing a color curve overlay on the histogram.  This would make it even easier for folks to understand how these six abstract controls affect the image.
    It sounds like there is a mix of rational and reactive pushback to this approach from the vocal audience on this forum.  I would be very interested to see how the two compared in blind lab studies with participants of comparable experience.  (Including new  and existing users... I would like to think that Adobe is saavy enough to realize that it is important to court new users if they want to grow their customer base and profit opportunity.)
    If there's one thing we can pull from this whole discussion, it's that there's no way for Adobe to make everyone happy on this issue.  There just isn't.  Some people absolutely hate that the sliders are ordered as the are in LR4b, others seem to think it makes perfect sense.  Both are adamant in their stance.  So now it becomes this whole over-blown issue of," What percentage of users like it this way compared to that way."  I'm sorry, but I just don't understand why it's such a big deal.  Is it that hard to use the controls in the order that Adobe placed them in LR4b.  Really?  Is it?  Is it really that slow for you high-volume photographers out there?  Is it really something that you won't completely get used to in all of a few hours of using LR4?
    The current sort order of the sliders in LR4b is not necessarily just an order-of-operations that is being thrust upon Lightroom users.  The rationale is that the controls follow an order which, in most cases for most photographs, flows from the most global adjustments to the most specific.  It's more than just an arbitrary ordering based on "what Adobe says we ought to do first".
    The truth is, while I understand Adobe's reasoning here, I really don't care what order the sliders end up in.  Why?  Because it really doesn't matter all that much, at all.  I mean, think about it.  Let's say that the current order of the sliders in LR4b makes it to the final version.  Are users going to keep using Lightroom 3 in protest?  No.  Are users going to keep all their photos in PV2010 expressly because they simply can't handle the order of the sliders in PV2012?  No.  The reason that nobody will go to such lengths is that it's reallly just not that important.  This is an exceptionally minor issue of personal preference that has less weight and importance than the hard drive space at Adobe used to store all of the threads that have popped up in complaint of the slider order.
    I know that everyone vehemently arguing against the current slider order will whole-heartedly disagree... but I simply had to put in my two-cents.  The issue of slider order is so miniscule that I cannot fathom why so much has already been written about it.
    EDIT*****
    An afterthought...
    Really?  "Blind lab studies" to scientifically determine what order to put LR4 sliders in?  C'mon guys... you've got to be kidding me...

  • Playlist synching out of order

    My playlists are out of order on my iPad and iPhone.  In iTunes the playlist shows the way I want it (sorted by date added...last added shows first).  However when I open the playlist in either my iPad or iPhone they playlist order is completely messed up.  In fact, I can't figure out what the order is as it isn't date added, alphabetical, artist, etc.
    I have the latest software on all devices and I use iCloud synching and iCloud matching but noticed this problem before I used iCloud but after I had upgrade to iOS5 and OSX 10.7.2.  Also, I have right moused clicked on the playlist in iTunes and selected "Copy To Play Order".
    Does anyone know what to do?
    Thanks

    Me too, on my ipod Touch only (correct on iTunes and correct on iPod Classic).  So irritating!  It's ALMOST in reverse order (least recent at the top, rather than most recent the way I want it), but then within an artist, it's in arbitrary order.    No fixes found yet.

  • Row Insert order

    Is it possible to know for sure the order in which rows were inserted in a table?
    I donot have any time stamp columns in the table. But I want to know which row was the last inserted one, which one was prior to that and like that.
    Thanks in advance.

    No. Unless you have a data column that can identify an order, there is no way to determine this. "SELECT * FROM myTable" will return rows in an arbitrary order.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Sorting alphabetically

    I have two classes:
    1.class Record
    -Constructor Summary
    Record(String artist, String name, String category)
    -Methods
    String getArtist()
    String getCategory()
    String getName()
    2.class CDRack
    This is a part of it:
    /** Class CDRack represents collections of compact discs. Discs are
    located in the rack in slots numbered from zero upwards. The discs are
    represented by Record objects and empty slots by null values. */
    public class CDRack extends Object {
      private Record[] mRecords;
      private int size;
    /**Creates a new, empty CD rack.
    Parameters:
    size - the size of the new rack, i.e. the number of slots it has */
          public CDRack(int size) {
              mRecords = new Record[size];
              this.size = size;
    /** "Organizes" the discs in the rack so that they will be located in
    consecutive slots starting at slot number zero, and any and all empty
    slots will be at the "end of the rack". After calling this method, the
    discs are in an undefined (i.e. arbitrary) order - the only thing this
    method guarantees is that there aren't any empty slots in between full
    ones.
          public void organize() {
              // Turn array into a list - more flexible
              List l = Arrays.asList(aanilevyt);
              // Remove all nulls from a copy of the list which supports  removal.
              l = new ArrayList(l);
              while (l.remove(null)) /*do nothing*/;
              // Clear the original array.
              for (int i = 0; i < mRecords.length; i++){
                   mRecords<i> = null;
              } // Put the non-nulls back.
              l.toArray(mRecords);
    /**"Organizes" the discs in the rack to the beginning of the rack (see
    the method organize) and sorts them in alphabetical order. Recordings
    by the same artist are placed in alphabetical order by disc name. */
        public void sortAlphabetically() {
    I have thought and thought..
    I can't use Collections.sort(). Class Record doesn't implement Comparable(and I can't change it).
    One suggestion is that I could make my own class which implements Comparator.
    import java.util.*;
    public class AlphabeticComparator
    implements Comparator{
      public int compare(Object o1, Object o2) {
        String s1 = (String)o1;
        String s2 = (String)o2;
        return s1.toLowerCase().compareTo(
          s2.toLowerCase());
    }      But how can I "tell" to CDRack class that it would
    use the class AlphabeticComparator?
    All methods except the sortAlphabetically() works.
    And how to capture "l.toArray(mRecords)" from organize() so that I could use it also in sortAlphabetically()?
    I hope somebody would like to help.
    Merry Christmas

    The problem is now solved, 14 methods done. I'm so happy!
    Now I can stop coding and start eating Christmas food and chocolate. :)
    With Woelfchen's help in another group I got the program run.
    Thanks for your help too! Good tips!
         *****   *Merry Chistmas*
        *******    greetings
       *********   Maria from Finland
          **

  • Java.lang.ClassCastException

    My class CDRack is almost ready, but in the last method
    sortAlphabetically() there
    comes java.lang.ClassCastException. I found in the net
    http://java.sun.com/docs/books/tutorial/collections/algorithms/
    that with method Collections.sort(l) I can sort alphabetically.
    The code compiles, but when I run it with a tester program, it stops
    to ClassCastException in the almost last row.
    Something is wrong with Collections.sort(l) ?
    /** Class CDRack represents collections of compact discs. Discs are
    located in the rack in slots numbered from zero upwards. The discs are
    represented by Record objects and empty slots by null values. */
    public class CDRack extends Object {
      private Record[] mRecords;
      private int size;
    /**Creates a new, empty CD rack.
    Parameters:
    size - the size of the new rack, i.e. the number of slots it has */
          public CDRack(int size) {
              mRecords = new Record[size];
              this.size = size;
    /** "Organizes" the discs in the rack so that they will be located in
    consecutive slots starting at slot number zero, and any and all empty
    slots will be at the "end of the rack". After calling this method, the
    discs are in an undefined (i.e. arbitrary) order - the only thing this
    method guarantees is that there aren't any empty slots in between full
    ones.
          public void organize() {
              // Turn array into a list - more flexible
              List l = Arrays.asList(aanilevyt);
              // Remove all nulls from a copy of the list which supports  removal.
              l = new ArrayList(l);
              while (l.remove(null)) /*do nothing*/;
              // Clear the original array.
              for (int i = 0; i < mRecords.length; i++){
                   mRecords[i] = null;
              } // Put the non-nulls back.
              l.toArray(mRecords);
    /**"Organizes" the discs in the rack to the beginning of the rack (see
    the method organize) and sorts them in alphabetical order. Recordings
    by the same artist are placed in alphabetical order by disc name. */
        public void sortAlphabetically() {
              // Turn array into a list - more flexible
              List l = Arrays.asList(aanilevyt);
              // Remove all nulls from a copy of the list which supports  removal.
              l = new ArrayList(l);
              while (l.remove(null)) /*do nothing*/;
              // Clear the original array.
              for (int i = 0; i < mRecords.length; i++){
                   mRecords[i] = null;
              } // Put the non-nulls back.
              l.toArray(mRecords);
              Collections.sort(l);   // alphabetical order. THERE IS CLASSCASTEXCEPTION 
    }

    I have thought and thought but the sorting alphabetically doesnt work.
    I can't use Collections.sort and class Record doesnt implement Comparable(and I can't change it).
    One suggestion was that I could make my own class which implements Comparator. Could it be like this
    import java.util.*;
    public class AlphabeticComparator
    implements Comparator{
      public int compare(Object o1, Object o2) {
        String s1 = (String)o1;
        String s2 = (String)o2;
        return s1.toLowerCase().compareTo(
          s2.toLowerCase());
    }      But how an earth can I tell to CDRack class that it would
    use the class AlphabeticComparator?
    Somebody please save my Christmas!
    /** Class CDRack represents collections of compact discs. Discs are
    located in the rack in slots numbered from zero upwards. The discs are
    represented by Record objects and empty slots by null values. */
    public class CDRack extends Object {
      private Record[] mRecords;
      private int size;
    /**Creates a new, empty CD rack.
    Parameters:
    size - the size of the new rack, i.e. the number of slots it has */
          public CDRack(int size) {
              mRecords = new Record[size];
              this.size = size;
    /** "Organizes" the discs in the rack so that they will be located in
    consecutive slots starting at slot number zero, and any and all empty
    slots will be at the "end of the rack". After calling this method, the
    discs are in an undefined (i.e. arbitrary) order - the only thing this
    method guarantees is that there aren't any empty slots in between full
    ones.
          public void organize() {
              // Turn array into a list - more flexible
              List l = Arrays.asList(aanilevyt);
              // Remove all nulls from a copy of the list which supports  removal.
              l = new ArrayList(l);
              while (l.remove(null)) /*do nothing*/;
              // Clear the original array.
              for (int i = 0; i < mRecords.length; i++){
                   mRecords<i> = null;
              } // Put the non-nulls back.
              l.toArray(mRecords);
    /**"Organizes" the discs in the rack to the beginning of the rack (see
    the method organize) and sorts them in alphabetical order. Recordings
    by the same artist are placed in alphabetical order by disc name. */
        public void sortAlphabetically() {

Maybe you are looking for