SQL - how it is better

Hello

I now have this quite large SQL, and I wish to address to make it much faster. So that's how it is now.

Select

Field1,

Field2,

(select C1.color in the TBL_CARS C1 where C1.ID = P.ID) "color of the car."

field48,

(select

Case C2. TYPE

When's ' then 'Ducati. "

When 'C' then 'Chevrolet '.

else 'Toyota '.

end

C2 TBL_CARS where C2.ID = P.ID) "type of vehicle"

sphere5,

((Select NVL

C3 case. BILL

where 'X' and 'society '.

When's ' then 'Department '.

When 'P', then 'staff '.

another "Unknown".

C3 TBL_CARS where C3.ID = P.ID)

'Free') "car billing.

TBL_PERSON p

and not in P.BADGE (select C.BADGE from TBL_CARS C where C.COND = 'EXCLUDE')

In fact, my TBL_CARS table is used everywhere. As you can see in the extraction of level field (subqueries), it was used many times. Based on it, we can say that "some people have cars, and you need to extract some data from TBL_CARS person has a snack car." Otherwise, it of fine, just extract the other data of the person"

I thought there was a way to make it much faster.

Any suggestions please?

What about

WHERE (C.DATABASE = 'X 2' or C.DATABASE is null)

Tags: Database

Similar Questions

  • Diskmgmt.msc 'frozen' while reducing a partition on an external USB drive... How can I better ensure that no problem has occurred with the drive?

    I tried to shrink a partition on an external HARD drive.  About thirty minutes later I went back and found diskmgmt.msc with circle icon showing that he was always busy.  I shut down the PC, rebooted and it seems that no changes have been made on the external drive, but I wonder how I could better check?

    My little finger tells me to format the drive and start all over with him, but that will involve a lot of resources.

    Any thoughts would be appreciated.

    Thank you!

    My little finger tells me to format the drive and start all over with him, but that will involve a lot of resources.

    I trust is no longer system files on this drive. I delete all existing partitions, and then create new ones and format.

  • SQL: how to display the second string of the function in the Jobs table only if the function has more than one string.

    SQL: how to display the second string of the function in the Jobs table only if the function has more than one string.

    Hello

    You can use REGEXP_SUBSTR Oracle/PLSQL: REGEXP_SUBSTR function

    Select the function double REGEXP_SUBSTR('PUBLIC RELATION REPRESENTATIVE ','[^]+',1,2);

    Do you have any value of the column as no 2nd string?

  • How can we better support extensions distriqt?

    So after almost a year of use Uservoice, so we have realized it is unresponsive to the needs to support our extensions, we wanted to ask for suggestions on how we can better improve the experience and the support we provide. We strive to provide support, but observations of the community seem to indicate that we are not meeting your expectations.

    We are a small team and extensions in no case pay our bills, so what we're looking to improve our use of available tools to better support.

    Our current thoughts are to switch completely to github issues and wiki and start a public forum, perhaps a group on Google groups, but we are very open to suggestions at this point.

    We hope to update within the next month. Any suggestions you have about best software or ways to use github will be welcome even if there is something you feel, we do not well enough at the moment.

    See you soon,.

    Michael

    Hi all

    The new site of extension support and license is now available.

    As promised the new extensions are available on the site, and all had the server check removed. Each of your applications will now be totally independent from our servers.

    To get started with the new site, you should:

    Each extension now has a dedicated area and we plan to extend these areas with the guides get started, screenshots, code snippets, and FAQS. Discover the extension announcements here.

    Get started now http://airnativeextensions.com

  • New Fund certification - how does the beta?

    Hello

    I am interested in taking the new beta review of VCA Office which has just been announced this week.  I have previouslt sat other exams from vmware, but not a beta version review.  How does the beta exam?  I noticed in the action plan there is no set of passmark.  I have to take the exam and then wait for the results that they are assembled?

    If I take the beta exam in version then it will be upgraded to full certification once the beta review of the version?  The review is currently only £50 instead of £110.

    Thank you

    How the BETA exams work generally is you will have more questions than the final exam, this is for feedback on the various issues that VMware had in mind. This can if extend the depth of a subject given to difficult of a given question and you will be able to provide comments on each question, at least that's how it was in the reviews BETA for the VCP, VCAP4-DCA and the VCAP4-DCD, everything that I took part in the BETA program.

    As you have noticed, there is no set of passmark because currently it's unknown yet, which will be determined by VMware after the exam in BETA version in which they finalized a score and select the questions that they feel best fit the content based on feedback. Receive your scores may take up to 2 months and more if it is not more that it has been for most of the BETA exams. If you pass the exam in beta, you pass the real exam, it's just in the BETA version, you get the width of the questions while the final exam, you will see a subset of these questions. The other added benefit is not only the feedback that you provide to VMware, but also a nice discount on the normal price and I hope that you are not required to take any compulsory course which can run up to US $3,000

    Good luck

  • How does the beta program?

    I wonder how to join the beta program, how do you do it on ios 10.02 device?

    Hello

    Just go to apple.com.beta

    Then you just register & follow download information the pofile

    Then you get the updates of the beta software.

    See you soon

    Brian

  • How to write better my query

    Hello

    on 11.2.0.4

    I have two tables:

    creation scripts are attached.

    Capture.PNG

    And I wrote a query to search for the students in which all their friends are in different qualities of themselves. Return the students names and ranks.

    Here's my query and it works fine. But can it be written better? More effectively?

    Select friend f, h1 highschooler, f.id1, h1.name, h1.grade, f.id2, h2.name, h2.grade

    H2 highschooler where h1.id = f.id1 and h2.id = f.id2 and h1.grade <>h2.grade and f.id1 not in

    (by selecting f1.id1 in friend f1, h3 highschooler,

    highschooler h4 where h3.id = f1.id1 and h4.id = f1.id2 and h3.grade = h4.grade)

    Thank you and best regards.

    Step has)

    count(*) over(partition by id1) cnt
    

    It counts how many ID2 are there in each ID1

    Step B)

    count(decode(h.grade, h1.grade, null, 1)) over(partition by id1) f1
    

    This does 2 things

    Step 1

    decode(h.grade, h1.grade, null, 1)
    

    If grade ID1 is equal to the rank of ID2 return NULL otherwise if its different 1 return

    Note: COUNTY does not have the value NULL. This is the reason for return null.

    Step 2

    count() over(partition by id1) f1
    

    This is essentially considered how ID2 can have a different category than for each ID1 ID1

    When we filter for step A is equal to step B, then it will give ID1 which all ID2 are in a different category

  • SQL how to use a variable and use the result as a reference for the name of the table

    Hi all

    I have new in the declaration of Oracle, sorry in advance if something is easy for you all. BTW, I have this scenario:

    I have a table OL structured in this way:

    Date - it contains dates, for example 11/01/2015

    TableName - it contains strings, for example, OL1, OL2, OL3 and so on...

    Then I have a different table, the name of these tables are of the same name in the table of the OL, so I have table table, OL1, OL2, OL3 table and so on. The structure of these tables is the same. And Yes.

    table OL1

    ---------------------------------------------------------------

    ID LAST NAME FIRST NAME PHONE

    ---------------------------------------------------------------

    1 JOHN DOE 12345679

    2 PAUL 111111122 TIBBS

    table OL2

    ---------------------------------------------------------------

    ID LAST NAME FIRST NAME PHONE

    ---------------------------------------------------------------

    1 ANNA KRAIG (NULL)

    NATHAN FRESHMANN 111111133 2

    If the scenario is clear, I would like to retrieve the value (null), research in all the OL * tables by using the value of the OL table (tablename) max.

    If I'm going to do these simple steps, I got the result:

    Select max (TableName) OL

    the result will be OL2

    # I know not how to use the option set to avoid changing the table name in the sql statement all the time.

    set mytable = 'OL2.

    Select Name, family name

    of & mytable

    When the phone is null

    Any idea?

    Thank you very much in advance.

    Hello

    run immediately "select dt.log_id, obj.presentation_name, dl.begin_time

    bulk collect into v_result_set

    of ' | v_ol |' dt join internal ol_object obj on

    DT.object_type_id = obj.object_type_id

    inner join ol_chunk_log dl on

    DT.log_id = DL.log_id

    where dt.data_value is null';

    dbms_output.put_line (v_ol);

    end;

    Correct the code such as:

    run immediately "select dt.log_id, obj.presentation_name, dl.begin_time

    of ' | v_ol |' dt join internal ol_object obj on

    DT.object_type_id = obj.object_type_id

    inner join ol_chunk_log dl on

    DT.log_id = DL.log_id

    where dt.data_value is null' bulk collect into v_result_set;


    for i in v_result_set.first ... v_result_set. Last

    loop

    dbms_output.put_line ('LOG ID: ' | ) ( v_result_set.log_id (i)) ;

    dbms_output.put_line (' NAME CLOSELY: ' |) v_result_set.presentation_name (i));

    dbms_output.put_line (' START TIME: ' |) ( v_result_set.begin_time (i)) ;

    end loop;

    end;

    Kind regards.

  • How can I better make ctx_doc.markup for a lot/set of documents?

    Hello

    I'm working on a system that stores chat messages in a table where the body of the message is stored in a CLOB column. I start to implement a message text using Oracle text search and seeks to use the functionality of ctx_doc.markup to the markup for the search terms. The message table is a bit like:

    (Message) CREATE TABLE

    ID NUMBER (19.0),.

    sender NUMBER (19.0),.

    beneficiary, NUMBER (19.0),.

    received_at TIMESTAMP (6).

    CLOB data,

    )


    and we have an index of text in context on the 'data' column and 'contains' queries against it work very well. When I was looking to add capacity to the markup for the search terms, I was a little surprised that there doesn't seem to be an easy way to markup a range of results.


    What I plan to do is essentially:

    Start

    ctx_doc. Markup (index_name = > 'MESSAGE_DATA_TXT_IDX',)

    textkey = > '2523992',

    text_Query = > "test" ', "

    restab = > "message_search_result_markup"

    query_id = > '4',

    tagset = > 'TEXT_DEFAULT');

    end


    So in my case, a search can lead to hundreds of returned messages. Now in order to tag each one, I have to do a "ctx_doc.markup" for each of them, which is hundreds of times that seems horribly inefficient. Keep in mind that all this is done in a Java web service.


    So my first question is, why "tagging" does not have a list of IDs to be passed to the 'textkey? That would make things much simpler as:

    ctx_doc. Markup (index_name = > 'MESSAGE_DATA_TXT_IDX',)

    textkey = > '2523992,2523993,2523994,2523995',

    text_Query = > "test" ', "

    restab = > "message_search_result_markup"

    query_id = > '4',

    tagset = > 'TEXT_DEFAULT');

    who would then end with 4 rows with query_id 4 in the message_search_result_markup table.


    Then I thought well, since I generate the code SQL in Java, I can add it as a lot of these calls in the begin/end block

    Start

    ctx_doc. Markup (...);

    ctx_doc. Markup (...);

    ctx_doc. Markup (...);

    ctx_doc. Markup (...);

    end

    Basically, one for each message. But now I have the problem of linking a net result towards the actual message from the strong result does not store the primary key of the message that is passed as the 'textkey. If the schema of the table of restab would be something like

    create the table message_search_result_markup (query_id number, varchar2, clob document textkey);


    So I have a unique query_id for each request and be able to easily retrieve all results of markup and return them along with other data of the corresponding messages such as sender, recipient, timestamp, etc..


    So now I think it's for each "textkey' I have, I have to create a unique query_id which is not so simple because everything is multithreaded and multiprocess and different queries can return the same messages, so I couldn't just use the textkey as the query_id.


    Does anyone have any better suggestions/ideas?


    Remember I want to minimize the number of SQL queries, I have to do Java, ideally only have to do 1 query for the message, 1 search query markup messages found and 1 more request for the marked results.

    You can write a function defined by the user to the ctx_doc.markup procedure, so that you can use it in a SQL query.  Please see the demo below.

    Scott@orcl12c >-table data and the index to test:

    Scott@orcl12c > CREATE TABLE message

    2 (id NUMBER (19.0),)

    3 sender NUMBER (19.0),.

    4 recipient NUMBER (19.0),.

    5 received_at TIMESTAMP (6).

    6 CLOB data)

    7.

    Table created.

    Scott@orcl12c > INSERT ALL

    2 IN THE VALUES of the message (id, data)

    3 (1, ' I "m work on a system that stores chat messages in a table where the body of the message)

    4 stored in a CLOB column. I'm starting to implement a message using Oracle's full-text search

    5 text and I want to use the functionality of ctx_doc.markup to the markup for the search terms.

    6 the message table is a bit like :')

    7 IN VALUES message (id, data)

    8 (2, ' and we have a hint of context on queries column text and "contains" "data" against her)

    9 work very well. When I was looking to add capacity to the markup for the search terms, I was a little

    10 surprised that there doesn't seem to be an easy way to markup a range of results. ')

    11 SELECT * FROM DUAL

    12.

    2 rows created.

    Scott@orcl12c > CREATE INDEX message_data_idx message WE (data) INDEXTYPE IS CTXSYS. FRAMEWORK

    2.

    The index is created.

    Scott@orcl12c >-function defined by the user to the ctx_doc.markup procedure:

    Scott@orcl12c > your_markup FUNCTION to CREATE or REPLACE

    2 (p_index_name IN VARCHAR2,

    3 p_textkey in VARCHAR2,

    4 p_text_query IN VARCHAR2,

    5 p_plaintext IN DEFAULT BOOLEANTRUE,

    6 p_starttag IN VARCHAR2 DEFAULT '<>

    7 p_endtag IN VARCHAR2 DEFAULT ' > '.

    8 p_key_type IN VARCHAR2 DEFAULT 'ROWID')

    9 BACK CLOB

    10 AS

    11 v_clob CLOB.

    BEGIN 12

    13 CTX_DOC. SET_KEY_TYPE (p_key_type);

    14 CTX_DOC. MARKUP

    15 (index_name-online p_index_name,

    16 textkey-online p_textkey,

    17 text_query-online p_text_query,

    18 restab-online v_clob,

    19 in clear-online p_plaintext,

    starttag 20-online p_starttag,

    21 endtag-online p_endtag);

    22 RETURN v_clob;

    23 END your_markup;

    24.

    The function is created.

    Scott@orcl12c > SHOW ERRORS

    No errors.

    Scott@orcl12c >-query:

    Scott@orcl12c > kwic FORMAT A60 WORD_WRAPPED COLUMN

    Scott@orcl12c > SELECT id,.

    2 your_markup

    3 ("message_data_idx",

    4 ROWID,

    KWIC 'column' 5)

    Message 6 OF

    7 WHERE CONTAINS (data, "column") > 0

    8.

    ID KWIC

    ---------- ------------------------------------------------------------

    1 I'm working on a system that stores chat messages in a

    table where the body of the message is

    stored in a CLOB >. I started to implement a

    message using Oracle full text search

    Text and I try to use the ctx_doc.markup function for

    the markup for the search terms.

    The message table is a bit like:

    2 and we have an index of text in context on the 'data' >

    and "contains a" queries against it

    work very well. When I was looking to add the ability to

    markup for the search terms, I was a little

    surprised that there doesn't seem to be an easy way to

    tag a range of results.

    2 selected lines.

  • SQL how to interpret?

    What is correct it a SQL or SQL? TX

    Hello

    Indra Budiantho wrote:
    What is correct it a SQL or SQL? TX

    Most people say "suite", perhaps simply because it is easier, but there is nothing bad to say "ess-queue - ELL ', as some people do.

    When SQL is used as an adjective, there may be an article ('a' or 'year', depending on how you choose to pronounce, to 'the'), but when SQL is a noun, it can properly be used with an article. In other words, don't say "The SQL has a bug." It is correct to say "the SQL statement has a bug."

  • How to format better my query for a report?

    I have a shell script to run sql queries for the database information every day.

    However down here, I want some columns to be indented to the right and I also want to format the % column.

    As for column name, under the name of column, there are lines including one very long and longer line, how in a linesize?


    Checking information of State/DataGuard


    time of the error message
    Code CAL INSTALLATION GRAVITY DEST_ID MESSAGE number stamp
    ======================== ============= ========== ========== ========== === ========= ================================================================================================================================================================================================================================================================
    Thank you

    See the link for all the format patterns and items below... etc.

    http://docs.Oracle.com/CD/B19306_01/server.102/b14200/sql_elements004.htm

    Hope this helps,

    Concerning
    http://www.oracleracexpert.com
    Import and export transportable tablespace
    http://www.oracleracexpert.com/2009/09/transportable-tablespace-export-and.html
    Oracle pump export/import data with examples.
    http://www.oracleracexpert.com/2009/08/Oracle-data-pump-exportImport.html

  • How to remove Beta camera profiles

    At some point, I loaded in LR 2.0 beta camera profiles... Now that I have updated to LR 2.5 all camera profiles have been included in the software, but the beta versions are also there... How can I remove the Beta profiles (using LR 2.5 on Windows 7)

    C:\ProgramData\Adobe\CameraRaw\CameraProfiles

  • pl sql - how to set Oracle concurrent Request Status = error

    I registered a custom as a competitor to Oracle pl sql block. I would like to raise an EXCEPTION that will be the end of employment in an error state if a condition is met. How can I do this? Here is a snippet of code that I have:
    EXCEPTION
           WHEN v_nodata THEN
                    <what command can I put here?  I want the concurrent request job to error so that the next pl sql block doesn't get executed.>
          when OTHERS THEN NULL;
    END;
    /
    Thank you!

    You can use RAISE; (when you are already within an exception block and want to raise the same error) or

    RAISE_APPLICATION_ERROR(-20000, 'My error message goes here');
    

    Replace - 20000 for any negative number between - 20000 and-20999 your error code.

    http://download.Oracle.com/docs/CD/E11882_01/AppDev.112/e10472/errors.htm

    Edit:
    If you are talking about registration of an error code to a name, you must use the PRAGMA EXCEPTION INIT.

    DECLARE
      deadlock_detected EXCEPTION;
      PRAGMA EXCEPTION_INIT(deadlock_detected, -60);
    BEGIN
      NULL; -- Some operation that causes an ORA-00060 error
    EXCEPTION
      WHEN deadlock_detected THEN
        NULL; -- handle the error
    END;
    

    Published by: fsitja on December 10, 2009 16:18

  • SQL: How to tell the difference between the numerical value and Alpha numeric

    Pls check the following requirements and let me know how to prepare the SQL:

    1. I want to find the product that begins with Alpha value separately

    2. I want to find the product that starts with the numerical value separately

    data are the following:
    CREATE TABLE prod
        (product_code                   VARCHAR2(4) NOT NULL)
    INSERT INTO prod
    VALUES
    ('L016')
    /
    INSERT INTO prod
    VALUES
    ('A035')
    /
    INSERT INTO prod
    VALUES
    ('B001')
    /
    INSERT INTO prod
    VALUES
    ('1717')
    /
    INSERT INTO prod
    VALUES
    ('7151')
    /
    INSERT INTO prod
    VALUES
    ('7019')
    /
    INSERT INTO prod
    VALUES
    ('0729')
    /
    INSERT INTO prod
    VALUES
    ('0730')
    /
    INSERT INTO prod
    VALUES
    ('L007')
    /
    INSERT INTO prod
    VALUES
    ('C013')
    /
    INSERT INTO prod
    VALUES
    ('D008')
    /
    INSERT INTO prod
    VALUES
    ('L021')
    /
    INSERT INTO prod
    VALUES
    ('0710')
    /
    INSERT INTO prod
    VALUES
    ('0718')
    /
    INSERT INTO prod
    VALUES
    ('L005')
    /
    INSERT INTO prod
    VALUES
    ('0716')
    /
    INSERT INTO prod
    VALUES
    ('0711')
    /
    INSERT INTO prod
    VALUES
    ('0701')
    /
    INSERT INTO prod
    VALUES
    ('0724')
    /
    INSERT INTO prod
    VALUES
    ('0728')
    /
    INSERT INTO prod
    VALUES
    ('0714')
    /
    INSERT INTO prod
    VALUES
    ('0704')
    /
    INSERT INTO prod
    VALUES
    ('7150')
    /
    INSERT INTO prod
    VALUES
    ('L024')
    /
    INSERT INTO prod
    VALUES
    ('L033')
    /
    INSERT INTO prod
    VALUES
    ('0721')
    /
    INSERT INTO prod
    VALUES
    ('0708')
    /
    INSERT INTO prod
    VALUES
    ('0723')
    /
    INSERT INTO prod
    VALUES
    ('L004')
    /
    INSERT INTO prod
    VALUES
    ('L018')
    /
    INSERT INTO prod
    VALUES
    ('0725')
    /
    INSERT INTO prod
    VALUES
    ('0719')
    /
    INSERT INTO prod
    VALUES
    ('0726')
    /
    INSERT INTO prod
    VALUES
    ('0712')
    /
    INSERT INTO prod
    VALUES
    ('0727')
    /
    INSERT INTO prod
    VALUES
    ('0703')
    /
    INSERT INTO prod
    VALUES
    ('TEST')
    /
    Kind regards

    Yamen
    1)select * from prod where translate(substr(product_code,1,1),'#0123456789','#') != '#'
    
    2)select * from prod where translate(substr(product_code,1,1),'#0123456789','#') is null
    

    Ravi Kumar

  • SQL: how to integrate the setting inside the quotes for wildcard character %

    I would like to know how to change a SQL statement to include a parameter within double quotes. I want to use the parameter inside a statement such as: SELECT * table col WHERE AS '%@parm '.

    I can get the query to work without the parameter, but not with her? Is there a workaround for CS3?

    Thank you

    Well, after much trial and error, it seems I had to change the setting itself.

    and from this
    Request.Form ["TextBox1"]:

    for this
    '%' + Request.Form ["TextBox1"] + "%";

    Yay!

Maybe you are looking for

  • connection blocked by admin device - I am the admin

    Problem: After I try to login, I get this message: Connection of the user to this computer has been blocked for a period of time by the administrator of the device The only way to open a session is started in safe mode. The message returns to normal

  • Software of blackBerry operating Z10 will not update to the latest version

    I tried all my best to update my device but fail on several opportunity, my WIFI network is poor can not update it. I tried via link BB and the message that I received there was that your blackberry is the latest software available which is not true,

  • AIR-LAP1252AG - without WLC

    Hello, I just got 9 AIR-LAP1252AG with the lightweight operating system by mistake. I do not have a Cisco WLC, I use a BSC1100. Can I use the CLI to configure an SSID and 1252 semi-autonomous work? Or do I have to reload a stand-alone OS? All comment

  • Disqualification external tasks

    HelloI have a stored procedure, and I am the appellant through a Windows File batch (.bat) in the location "edq\oedq.local.home\commandarea".The procedure is completed successfully, but the external task is not getting out even after that stored proc

  • new to windows 8

    What program to use to open a file of type .xlr?