Which statement is better?

I have a statement which i could write in two formats as below,
and I wonder which one is better?
first :
select type, (case type when '01' then 'looking'
                        when '02' then 'for'
                        when '03' then 'help' end case)  as desc
from ( select (case
                        when substr(code, -5, 2)  in ('aa', 'ab') then '01'
                        when substr(code, -5, 2)  in ('ba', 'bb') then '02'
                       when substr(code, -5, 2)  in ('ca', 'cb') then '03'
                  end case ) as type
         from mytable);second:
select (case
                        when substr(code, -5, 2)  in ('aa', 'ab') then '01'
                        when substr(code, -5, 2)  in ('ba', 'bb') then '02'
                       when substr(code, -5, 2)  in ('ca', 'cb') then '03'
                  end case ) as type,
            (case
                        when substr(code, -5, 2)  in ('aa', 'ab') then  'looking'
                        when substr(code, -5, 2)  in ('ba', 'bb') then 'for'
                       when substr(code, -5, 2)  in ('ca', 'cb') then  'help'
                  end case ) as desc,                
         from mytable;this is just an example and in my real statement, there will be 20-30 substr() used.
Thanks

Well you can minimise the number of times you substr to just the once if you want...
select type
      ,decode(type,'01','looking','02','for','03','help') as desc
from (select decode(substr(code, -5, 1),'a','01','b','02','c','03') as type
      from   mytable);
/or
select decode(type,'a','01','b','02','c','03') as type
      ,decode(type,'a','looking','b','for','c','help') as desc
from (select substr(code, -5, 1) as type from mytable);
/... but without more information (like data and expected results) it's difficult to know exactly what would be the best way.

Similar Messages

  • Which solution for better perfomance?

    I'm writing java application based on XML. This application have to store very large XML file into DB (XML file is about 1000MB large). My solution is to divide it into smaller (100MB) parts (because of memory resources) and store it in DB. I have one XMLType table based on object-relational storage (so at the end there will be 10 rows each of 100MB size).
    XML file looks like:
    <students>
    <student id="1">
    ...// 5 nested elements or collections of elements
    </student>
    <student id="2">
    </student>
    <student id="3">
    </student>
    </students>
    </students>
    Now I need to get java object Student which correponds to <student>element. My solution is to select whole <student> element and use JAXB to convert it to Java object. While solving a problem with selecting <student> element (just in case you know a solution for my another problem: How to select specific element from a XML document using JDBC? another question raised in my mind.
    Which solution has better performance when I don't need to select relational data but I'm interested in xml fragment?
    1) Use object-relational storage
    2) Use CLOB storage
    As I figured out object-relational storage is better for selecting data like student name. But is it also better when I need whole xml fragment?
    Isn't my solution completely wrong? I'm quite a newbie in XML DB so it's possible that I missed better solution.
    Thanks for any advice

    I don't know which version you have regarding 11g, but probably in this case I would go for a table with a XMLType Binary XML column. To make xpath and other statements perform use Structured or Unstructured XMLIndexes to support your queries. The following has worked for far smaller XML documents but the millions we used were good for a total of >> 1 TB total storage size...
    CREATE TABLE XMLTEST_DATA
    (    "ID" NUMBER(15,0),
          "DOC" "SYS"."XMLTYPE"
    ) SEGMENT CREATION IMMEDIATE
    NOCOMPRESS NOLOGGING
    TABLESPACE "XML_DATA"
    XMLTYPE COLUMN "DOC" STORE AS SECUREFILE BINARY XML 
    (TABLESPACE "XML_DATA"
      NOCOMPRESS  KEEP_DUPLICATES)
    -- XMLSCHEMA "http://www.XMLTEST.com/Schema1.0.xsd"
    --  ELEMENT "RECORD" 
    DISALLOW NONSCHEMA
    PARTITION BY RANGE(id)
    (PARTITION XMLTEST_DATA_PART_01 VALUES LESS THAN  (100000000) TABLESPACE "XML_DATA" NOCOMPRESS
    ,PARTITION XMLTEST_DATA_PART_02 VALUES LESS THAN  (200000000) TABLESPACE "XML_DATA" NOCOMPRESS
    ,PARTITION XMLTEST_DATA_PART_03 VALUES LESS THAN  (300000000) TABLESPACE "XML_DATA" NOCOMPRESS
    ,PARTITION XMLTEST_DATA_PART_04 VALUES LESS THAN  (400000000) TABLESPACE "XML_DATA" NOCOMPRESS
    ,PARTITION XMLTEST_DATA_PART_05 VALUES LESS THAN  (500000000) TABLESPACE "XML_DATA" NOCOMPRESS
    ,PARTITION XMLTEST_DATA_PART_06 VALUES LESS THAN  (600000000) TABLESPACE "XML_DATA" NOCOMPRESS
    ,PARTITION XMLTEST_DATA_PART_07 VALUES LESS THAN  (700000000) TABLESPACE "XML_DATA" NOCOMPRESS
    ,PARTITION XMLTEST_DATA_PART_08 VALUES LESS THAN  (800000000) TABLESPACE "XML_DATA" NOCOMPRESS
    ,PARTITION XMLTEST_DATA_PART_09 VALUES LESS THAN  (900000000) TABLESPACE "XML_DATA" NOCOMPRESS
    ,PARTITION XMLTEST_DATA_PART_MAX VALUES LESS THAN  (MAXVALUE) TABLESPACE "XML_DATA" NOCOMPRESS
    CREATE INDEX test_xmlindex on XMLTEST_data (doc) indextype is xdb.xmlindex
    LOCAL
    parameters ('GROUP PARENTINFO_GROUP
                 XMLTable test_cnt_tab_ParentInfo
                ''/RECORD/ParentInfo''
                COLUMNS
                 GroupingID01 VARCHAR2(4000) PATH ''Parent/GroupingID'',
                 GroupingID02 VARCHAR2(4000) PATH ''Parent/Parent/GroupingID''
              ');

  • Which is a better performer, the macbook air or the mac mini?

    Which one performs better, the late 2013 macbook air (standard configuration: 4GB RAM, dual core i5 1,3 Ghz CPU) or the mac mini core quad core i7, 4GB RAM with a regular hard disc?

    LowLuster 
    No Air model can be as fast as a Mini with a quad core i7 CPU. Can't happen.
    I didnt solicit your opinion, and it IS a fact, .....skilled users here on this board will and DO TELL other users OFTEN that:
    "outside of processor core use (video/ photo etc.) you will NOT NOTICE ANY DIFFERENCE on X computer vs. slower Y computer"
    I have a 8 month old QUAD core Mac Mini and it is , as I said above "noticeably not ONE BIT" faster than my current 2013 macbook Air with 8gig.
    My quad core came with 4gig of RAM as I recall, I immediately tossed in 16gig.
    Notice the word "noticeably"
    Your subjective hyperbole aside, you are wrong......., those above yourself and myself (point wise,...as Ogel has stated, Clinton has stated, and others) state this fact very often regarding ---"outside of processor core use (video/ photo etc.) you will NOT NOTICE ANY DIFFERENCE on X computer vs. slower Y computer"
    Its not my opinion, its a fact, namely additionally that I stated "noticeably"   - "my quad core mac mini on MOST EVERYTHING (which is most things since 'most things' are NOT photo and video editing) is not "noticeably" ONE BIT faster than my Macbook Air.
    "most things" people do (most people) on their computer does NOT involve photo and video editing (photoshop pro, final cut pro etc etc)
    This is a fact, that AS SUCH most people WILL NOT notice any difference in general computer use between a quad core mac mini (for example) and a entry level macbook Air. (SSD vs. HD speeds aside).       Nobody is going to notice faster youtube, or Word use, or websurfing, Acrobat Pro, Quicktime play, general APPS that havent changed much in 7 years.
    Dont curse on these family boards please, its uncouth.
    Peace

  • Shutdown or Sleep, which one is better??

    I usually use my Mac Mini about 3 hours a day. At the end of the day, should I shutdown the machine or simply put it in sleep mode? Which one is better? What is the difference?
    Mac Mini   Mac OS X (10.4.6)  

    791/3237
    Hi Snawman,
    I agree with the others. In your case, better shut it down for saving energy.
    "Which one is better? What is the difference?":
    - Sleep allows to very quickly resume any task that was running. Leave all applications, documents etc open, they'll just be here at the same place, in the same state, as when you left your computer.
    It's just a matter of quickly going back to work, not having to retype some websites login passwords for example, etc.
    - On the wear and tear point of view, the difference is so small, your Mini will be obsolete and replaced with a newer Mac, far before something breaks down just because of to many cold boots!
    Yes, the most demanding task for a computer's hardware (and probably OS too), is a cold boot.
    Sleep, instead of Shutdown, keeps your computer components from a lot of temperature fluctuations, and the hard disk too just spins down, instead of completely setting itself down, then up again from scratch (and cold).
    Again,
    these differences exist, but they are not so important that you would take them into account and change your energy saving habits.
    - Macs are well designed to cope with many different kinds of users/usages.
    "About running yourself the nightly automatic maintenance":
    In case you didn't know already about this: yes, just open Terminal and paste this command
    sudo periodic daily weekly monthly
    once or twice a month.
    In order to make sure all three maintenance tasks run until the end, after you entered your admin password and hit Return, just leave Terminal open like 15 minutes or so (until you see its prompt again).
    There is no hurry to quit it, as the maintenance runs in the background: Just use your computer in the meanwhile.
    Enjoy your Mac!
    Axl

  • Which tool is better for ETL?

    I want to transfer data from RLDB to Essbase, there are many method and tools, I don't know which tool is better for my case. Now, what I am doing now is:
    1. Create views in Oracle
    2. Export view to falt file
    3. Import flat file to Essbase using rule file and MaxL import script.
    4.The data size: flat file rows 3-4 million, time used: 13 hours
    I want to use more powerful ETL tools, such as: Informatica PowerCenter, OBIEE, FDM, EIS, ..., I have basic knowledge for the above tools, but don't know which tool is better for my case? Please advise?

    First to streamline your existing process, you could get rid of step 2 and add a odbc connection to the server and Sql statement to the load rule to pull directly from your Oracle database. Of course with the number of rows you have, if you use the same extract multiple times, I would create a table to load into from the view and pull from that table.
    As for using an etl (Elt) tool, Informatica is pretty powerful and there is a version of it (although not supported in the future called DIM). I might go the ELT route with ODI(Oracle Data Integrator). In the future I might use OBIEE, but I don't think it fully ready for Essbase until the next version and I don't think it will rank on the same level as a full ETL tool for conversions.
    Edited by: GlennS_2 on Jan 2, 2010 9:58 AM
    As for EIS, I would not use it, but might use Essbase Studio. (It can use OBIEE as a source) again this is not an etl tool, it would just take youe existing views and load them.

  • Which solution is better

    Hi all ,
    I have a table callled preference (usr_id, pref_cd,prod_cd,prod_Fam_cd,updated_date)
    user who logs in to the application will set the preference for a product ..
    Now Java team wants me to create a stored procedure that accepts array of preference objects(each preference object contains all the fields of preference table) and I have to update/insert the preference table .
    I have created the procedure.
    But my question is Is this a good way ? cant java code directly access the table tot do this ? why to make it complex to create a stored procedure and create table types and object types which is additional maintenance.
    Plz suggest which is the better approach?

    raj_fresher wrote:
    now I write a function to perform this and this function will have to return some success code(say 0) to the java program if the inserts and updates are successful else i will have to return some failure code (say 1)1) I assume you really mean that you are creating a stored procedure to do the DML, right? Functions should not do DML.
    2) Why do you need to return a status code? It is generally far preferrable to throw an exception if a procedure fails than to force every caller of the procedure to add code to check the status code after every call.
    Now what condition i have to test for a success or failure when writing a function ?
    I used Merge command to insert a record if it is not present or update the record if it is present.
    Now I will always pass success only right .... what failure condition should i be checking on in the procedure?The condition you have to test for depends on your requirements. What constitutes success? If doing a merge is appropriate, presumably the Java code doesn't care whether rows were inserted or updated. So success may be that the MERGE statement ran without throwing an exception.
    secondly , if it is an oracle error how do i pass on the exception to the java code which is calling this proc?If your procedure throws an exception, that exception will automatically propagate to the Java code. The Java code will get a SQLException with the stack trace and error information.
    Justin

  • Which option is better?

    Hi all,
    I am developing an application which is is CMS.It consists images to upload and display it on web-page.Now here two things comes...
    1 Option: Uplaod the image and store it into the database and then display.
    2 Option: Upload the image store it on server(i.e not in database) store it's associated info in database and then display the image.
    Which option is better and why?
    Expecting kind help ASAP.

    The 2nd option is much better, this way you keep your database just for storing the files information such as the image name, type, tags, gps? and other stats.
    The image file should be stored separately on the server in a well designed folder structure e.g. Author/Date/Filename.jpg
    This makes it easy to use and keeps your data well organised.
    nick

  • Which method is better to the performance?

    Using SQLs at front side or using stored procedures at back side, which method is better to the performance?

    jetq wrote:
    In my view, it maybe have other difference, for example,
    Using stored procedure, you don't need to recompile the script every time to be executed,
    and use the existing execute plan.what if first time procedure is called after DB start?
    PL/SQL does not have EXPLAIN PLAN; only SQL does.
    But using SQL statement from application layer may be different.different than what exactly.
    SQL is SQL & can only be executed by SQL Engine inside the DB.
    SQL statement does not know or care about how it got to the DB.
    DB does not know or care from where SQL originated.

  • Which statement is true?-------------QNo.107

    One of important tables in the USERS tablespace (the USERS tablespace is locally managed and the undo tablespace is managed manually) was dropped and perged from the recyclebin at 9:00am. You noticed this at 11:00am.and you want to perform an incomplete recovery to recover the table.
    Which statement is true?
    A. You must recover all data files to the required system change number.
    B. You must recover all data files,except those that are offline,to the required SCN
    C. You must recover all data files belonging to the USERS tablespace to the required SCN
    D. You cannot recover all data files because segment space management is performed manually for the undo tablespace

    Hi Jaffar,
    There was some threads in the past with more than 20 or 30 questions in one, without any great success to have all answers.
    I don't know if post the original exam question here without his own suggestion and wait the answer is the best method to learn to pass certification.
    Of course, in case of doubt on some point and after reading the associated doc, ask a question would be a better way.
    Nicolas.

  • In SQL Trace how to see which statement getting more time .

    Hi Expart,
    In SQL Trace (T-code ST05) . I am running the standard transaction . how to see which statement
    running more time and less time . suppose one statement running more time so how resolve the
    performance .
    Plz. reply me
    Regards
    Razz

    > The ones in 'RED' color are the statement which are taking a lot of time and you need to
    > optimise the same.
    No, that is incorrect, the red ones show only the ones which need several hundret milliseconds in one execution. This can even be correct for hard tasks. And there are lots of problem, which you will not see
    I have said everything here:
    SQL trace:
    /people/siegfried.boes/blog/2007/09/05/the-sql-trace-st05-150-quick-and-easy
    Go to 'Tracelist' -> Summarize by SQL statements', this is the view which you want to see!
    I summarizes all executions of the same statement.
    There are even the checks explained, the slow ones are the one which need a lot of time per record!
    See MinTime/Rec > 10.000 microseconds.
    Check all number of records, executions, buffer, identicals.
    The SE30 Tipps and Tricks will not help much.
    Siegfried

  • I am going to buy a macbook pro for grade 12, and I need to know wheather I should get a macbook pro or a macbook pro retina. If someone could tell me (in a very simple way) which one is,better for me and why, I would be ever so apprreciative.

    I am going to buy a macbook pro for grade 12, and I need to know wheather I should get a macbook pro or a macbook pro retina. If someone could tell me (in a very simple way) which one is,better for me and why, I would be ever so apprreciative.

    Why do you need a expensive MacBook Pro?
    Your attending high school and unless everyone else is rich also your likely going to be a target by the more poorer students for theft or damage to the machine.
    You could keep it home, but if you need it for class then your exposed again.
    Also at that age your not very careful yet, a MacBook Pro is a expensive and easily damaged machine.
    Unless your made of money and so are others at your school, I would recommned a low profile, just does the job cheap Windows PC.
    If it dies, gets lost, stolen or damaged because of your inexperince handling senstivie electronics then it's no big deal.
    You can buy a Mac later on when your sure you have a need for it, currently there isn't much advantage of owning a Mac compared to a PC, they do just about the same things now, one just looks prettier than the other.
    Since 95% of the world uses Windows PC's your going to have to install Windows on the Mac in order to keep your skills up there or be unemployed, so it's a extra headache and expense.
    good luck

  • I keep getting an error message when downloading a new app which states " Zinio and 5 other apps cannot be purchased at this time" and then it let's me purchase the app that I was looking at? Can anyone explain that?

    I keep getting an error message when downloading a new app which states " Zinio and 5 other apps cannot be purchased at this time" and then it let's me purchase the app that I was looking at? Can anyone explain that?

    apple_master New Delhi, India
    This solved my questionRe: Unable to Purchase 
    Apr 16, 2012 10:22 PM (in response to eight4seven)
    This worked for someone
    I had this problem for about six weeks. I was following this forum but was too unsure of what might happen to try the fixes that were suggested.
    About two weeks ago I decided to delete the downloads.28.sqlitedb file (usingDiskAid(a free program), on a PC running Windows 7). The original downloads.28.sqlitedb was 936 KB. The new one that the system created is 80 Kb., and has stayed at about that size. After about four days I also deleted all the other contents of the Download folder. Ten days later and still no more problems. Downloads are much quicker, nothing greys-out (as was happening frequently before).
    Everything has worked well since with no more error messages.
    I am using an iPod 4G, iOS 5.1 (originally iOS 5.0). I do not have a manifest file, and as far as I know, have not had one. DiskAid can search the whole "hard drive" on the iPod.
    Deleting downloads.28.sqlitedb and the contents of Downloads worked for me.

  • When I try to open my Yahoo mail in safari, I get a message which states:" In order to use Yahoo mail, please turn Private Browsing off. Please go to Settings Safari Private Browsing, and turn off" The problem is my ipad does not a Private Browsing switch

    When I try to open my Yahoo mail in safari, I get a message which states:" In order to use Yahoo mail, please turn Private Browsing off. Please go to Settings>Safari>Private Browsing, and turn off" The problem is, my ipad does not a Private Browsing switchat this location.

    With iOS 7 on the iPad, you turn Private  Browsing on and off by tapping the URL field.  The screen that  opens up has your bookmarks on it.  In the bottom left corner is a hot button marked 'PRIVATE'.  Tap on the word 'PRIVATE' to turn private browsing on or off.  Yeah, there aren't any instructions anywhere that I can find to do this, and if you follow Yahoo's instructions, they don't work.  This doesn't happen with the previous Apple OS, and you can restore your iPad to the older OS. 

  • Which browser is better to use as an option to Safari and how do you download it?

    Which browser is better to use as an option to Safari and how do you safely download it? Thanks

    I use Firefox when a site doesn't work well with Safari. Some people like Google's Chrome, but I find it too instrusive and do not trust Google's security. You can download Firefox from firefox.com.
    Regards.

  • I am looking for macbookpro mid 2010 HDD exact specs so that i can upgrade it to 1TB. PLEASE HELP ME  about OEM apple brand or which one is better.Thanks

    I am looking for macbookpro mid 2010 HDD exact specs so that i can upgrade it to 1TB. PLEASE HELP ME  about OEM apple brand or which one is better?.Thanks

    clintonfrombirmingham Your information is not correct.
    http://kb.sandisk.com/app/answers/detail/a_id/8142/~/difference-between-sata-i,- sata-ii-and-sata-iii
    I have a sata II samsung 5400 rpm and i am only able to transfer at 85 read right speed.
    On my main drive sata III ocz agility 3 ssd i get 120 mb read and 180 write.
    Neither of these come close to the 300 mb promised. So it wont matter if he got sata II or III
    The speed came from Blackmagic Disk Speed Test

Maybe you are looking for