There is no sql to find no matching rows

Hi all

I want to optimize the sql where I find the column (junction of two columns) presents in a table (tab1) but not in other (tab2). I tried something like that, but it is showing me no line.

SELECT COL1 | COL2

OF e TAB1

where there is NO

(

Select 1 in TAB2 rd

Join e TAB1 on e.COL1 | e.COL2 = RD. COL1 | RD. COL2

)

When I use the simple sql (which takes a lot of time hell) I get good output: 0

SELECT COL1 | COL2

OF e TAB1

where COL1 | Col2 not in

(

Select COL1 | Col2 from TAB2 rd

)

What is wrong in the query "EXISTS NOT", or suggest me best way to achieve the same thing. Thank you!

Few things

1. do not concatenate columns, and then compare. They can cause an incorrect result. Consider this

tab1.col1 = 'KAR' and tab1.col2 = 'THICK'

and

tab2.col1 = 'KARTHI' and tab2.col2 = 'CK'

Concatenation and join them will result in the return line. But in fact they do not condition.

2. NO EXISTS and NOT IN are not the same. The two manage NULL value very differently. If there is a NULL value in the sub operator NOT IN the entire State query fails.

https://asktom.Oracle.com/pls/asktom/f?p=100:11:0:no:P11_QUESTION_ID:442029737684

Says, try something like this

select t1.*
  from tab1 t1
where not exists
       (
           select null
              from tab2 t2
             where t1.col1 = t2.col1
               and t1.col2 = t2.col2
       )

Tags: Database

Similar Questions

  • SQL to find the grouped rows that have changed their values?

    Hello
    I wonder if it is a pure SQL way do this...?

    I have a table that has a number of columns:
    InsertionDate
    IDENTITY
    Col - has to pass - z - some data.

    the pair (InsertionDate, identity) is unique.

    The lines represent the same values as they change over time, for example:

    Select * from < mytable > by its identity, InsertionDate;
    Balance InsertionDate identity
    10 February 01-1001 - 100
    11 February 01-1001-1
    1001 12 February 01 50
    10 February 01-1002-10
    11 February 01-1002-10
    1002 12 February 01 76


    I want to do the following:

    Select < myTable > from where InsertionDate and the next InsertionDate have a different value for the balance "grouped by" identity and InsertionDate = "10 February 01»;»»
    [I use "grouped by" with great caution - I can't explain in 'Nick sql' without using the misleading grouped by term]

    To produce the output:

    Balance InsertionDate identity
    10 February 01-1001 - 100
    11 February 01-1001-1

    Select < myTable > from where InsertionDate and the next InsertionDate have a different value for the balance "grouped by" identity and InsertionDate = ' 11 February 01»;»»
    Balance InsertionDate identity
    11 February 01-1001-1
    1001 12 February 01 50
    11 February 01-1002-10
    1002 12 February 01 76

    There may be several columns in addition to the balance that should also be checked for changes.

    See you soon,.
    Karl.

    A little misread your reqs:

    with t as (
               select to_date('10-Feb-01','dd-mon-yy') InsertionDate,1001 Identity,-100 Balance from dual union all
               select to_date('11-Feb-01','dd-mon-yy'),1001,1 from dual union all
               select to_date('12-Feb-01','dd-mon-yy'),1001,50 from dual union all
               select to_date('10-Feb-01','dd-mon-yy'),1002,10 from dual union all
               select to_date('11-Feb-01','dd-mon-yy'),1002,10 from dual union all
               select to_date('12-Feb-01','dd-mon-yy'),1002,76 from dual
              )
    select  InsertionDate,
            Identity,
            Balance
      from  (
             select  InsertionDate,
                     Identity,
                     Balance,
                     row_number() over(partition by Identity order by InsertionDate) rn,
                     lead(Balance,1,Balance - 1) over(partition by Identity order by InsertionDate) next_balance
               from  t
            )
      where balance != next_balance
        and rn != 1
      order by Identity,
               InsertionDate
    /
    
    INSERTION   IDENTITY    BALANCE
    --------- ---------- ----------
    11-FEB-01       1001          1
    12-FEB-01       1001         50
    11-FEB-01       1002         10
    12-FEB-01       1002         76
    
    SQL>  
    

    SY.

  • What is happening with the DNS requests that cannot not find a matched host (A) RR in the zone are sent to WINS servers, but there is no WINS server installation?

    What is happening with the DNS requests that cannot not find a matched host (A) RR in the zone are sent to WINS servers, but there is no WINS server installation?

    Hello

    Please repost these questions in the Technet Forums

    http://social.technet.Microsoft.com/forums/en-us/category/WindowsServer

    See you soon.

  • Is there a way I can find the AUTHID set of PL/SQL?

    If I am logged in as A user and I have a query a view that calls a function of authid DEFINER belonging to user B, and it called as a function of the user current authid owned by C that I am not some priivileges of the user whose second service runs under. I think it should be A but y at - it a routine system that I can call that tells me for certain that it is?
    Keith.

    Is there a way I can find the AUTHID set of PL/SQL?

    You can view the current_schema:

    SQL> create or replace procedure p1
       authid definer
    as
    begin
       dbms_output.put_line ('P1 :' || sys_context ('userenv', 'current_schema'));
    end p1;
    /
    Procedure created.
    
    SQL> create or replace procedure p2
       authid current_user
    as
    begin
       dbms_output.put_line ('P2 :' || sys_context ('userenv', 'current_schema'));
    end p2;
    /
    Procedure created.
    
    SQL> grant execute on p1 to scott
    /
    Grant complete.
    
    SQL> grant execute on p2 to scott
    /
    Grant complete.
    
    SQL> connect scott/tiger@oracle
    Connected as SCOTT@oracle
    
    SQL> exec michael.p1
    P1 :MICHAEL
    PL/SQL procedure successfully completed.
    
    SQL> exec michael.p2
    P2 :SCOTT
    PL/SQL procedure successfully completed.
    
  • IS THERE A LIST OF THE DRIVERS THAT MATCH A FAILURE CODE? FOR EXAMPLE (0XDEEDFADE)

    IS THERE A LIST OF THE DRIVERS THAT MATCH A FAILURE CODE?  FOR EXAMPLE (0XDEEDFADE).  «I GET THIS WHEN I TRY TO CONNECT A RECORDER APPLICATION MY PC (WITH CODE SCREEN BLUE DEATH "DRIVER IRQL-NOT-DONOR-BASED EQUALITY).»

    [Moved from comments]

    There is no error like code: 0XDEEDFADE

    Usually due to a bad driver, or a faulty or incompatible hardware or software. Use the general troubleshooting of STOP the Messages above checklist. Technically, this error condition means that a kernel-mode process or driver tried to access a memory location to which it did not have permission, or at a kernel interrupt request level (IRQL) that was too high. (A kernel-mode process can access only other processes that have an IRQL lower or equal to, its own.)

    Make sure you uninstall and reinstall the drivers using the following general method.

    First of all, download the latest driver. Then perform the following steps.

    Click on Start Menu

    Right click on my computer/my computer

    Click on manage the

    Click Device Manager in the list on the left

    Find the device you are trying to uninstall by expanding the game appropriate device (network adapter/IDE ATA / ATAPI controllers)

    Right click on the device

    Click on uninstall (do not click OK in the dialog box that opens after hitting uninstall it)

    Put a check mark to remove software driver for this device (if this option is available, if not, just hit OK) and click OK

    Restart your computer only if Windows asks you to.

    Install the latest driver for the device.

    You can also:

    Sign in as an administrative user.

    First of all, download the latest driver. Then perform the following steps.

    Click on Start Menu

    Click on Control Panel

    Click on hardware and sound

    Click device (the last link under devices and printers) Manager

    Find the device you are trying to uninstall by expanding the game appropriate device (network adapter/IDE ATA / ATAPI controllers)

    Right click on the device

    Click on uninstall (do not click OK in the dialog box that opens after hitting uninstall it)

    Put a check mark to remove software driver for this device (if this option is available, if not, just hit OK) and click OK

    Restart your computer only if Windows asks you to.

    Install the latest driver for the device.

    My system specs

    System manufacturer/model number HP Pavilion e9110t

    Windows 7 Home Premium 64 Bit operating system

    Processor Intel (r) Core (TM) 2 CPU Quad Q9550 @ 2.83 GHz

    Card mother Pegatron IPIEL-A3

    6,00 GB Hundai HMT125U6BFR8C-H9 memory

    Graphics card ATI Radeon HD 4850

    Its Realtek High Definition Audio card / ATI High Definition Audio

    Monitor (s) displays Acer AL2216W

    Screen resolution 1680 x 1050

    Keyboard HP keyboard

    Mouse HP mouse

    Unknown/installed by HP POWER supply

    Generic HP case

    Cooling Stock Intel cooling

    Hitachi HDP725050GLA360 ATA Device 500 GB hard drives

    Internet download speed: 19.15 Mbps Upload: 1.67 Mbps

    Another news network adapter D Realtek RTL8168D/8111 Family PCI - E Gigabit Ethernet NIC (NDIS 6.20) network adapter 802.11n Wireless PCI Express Card LAN Adapter

  • Hello, my phone pulled from my class at school and it has no data on it, so I did not no how to locate without using find my iphone is there another way I could find as soon as possible

    Hello, my phone pulled from my class at school and it has no data on it, so I did not no how to locate without using find my iphone is there another way I could find as soon as possible

    Go to iCloud.com

    Then sign in with your Apple ID and password, then click the Find iPhone.

    If this does not help, see: If find my iPhone is not activated on your missing device > what to do if your iOS device is lost or stolen

  • I already pay for my creative cloud through license and there is no way to find the serial number

    I already pay for my creative cloud through license and there is no way to find the serial number. I have in my account adobe my order number and everything. When I open creative cloud and install the 2 app photo and the Lr, ask me to pay again.

    Who knows something?

    Cloud programs are not serial numbers

    Your subscription to cloud shows correctly on your account page?

    If you have more than one email, you will be sure that you use the right Adobe ID?

    https://www.adobe.com/account.html for subscriptions on your page from Adobe

    .

    If Yes

    Some general information for a subscription of cloud

    Cloud programs don't use serial... numbers you, connect you to your cloud account paying to download & install & activate... you may need to sign out of the cloud and restart your computer and log into the cloud for things to work

    Sign out of your account of cloud... Restart your computer... Connect to your paid account of cloud

    -Connect using http://helpx.adobe.com/x-productkb/policy-pricing/account-password-sign-faq.html

    -http://helpx.adobe.com/creative-cloud/kb/sign-in-out-creative-cloud-desktop-app.html

    -http://helpx.adobe.com/x-productkb/policy-pricing/activation-network-issues.html

    -http://helpx.adobe.com/creative-suite/kb/trial--1-launch.html

    -ID help https://helpx.adobe.com/contact.html?step=ZNA_id-signing_stillNeedHelp

    -http://helpx.adobe.com/creative-cloud/kb/license-this-software.html

    .

    If no

    This is an open forum, Adobe support... you need Adobe personnel to help

    Adobe contact information - http://helpx.adobe.com/contact.html

    Chat/phone: Mon - Fri 05:00-19:00 (US Pacific Time)<=== note="" days="" and="">

    -Select your product and what you need help with

    -Click on the blue box "still need help? Contact us. "

  • Is there an easier way to find images of the iPad/iPhone?

    Is there an easier way to find images of the iPad/iPhone?

    When I sync my iPad or iPhone to my computer, it uses the Photos from Apple, which is terrible.

    Example:

    I turn and go up on iPad #1

    I shoot B-Roll on iPhone (s)

    I have download the XML from the first Clip.

    But I already sync had the phone, the other images are already on my machine somewhere.

    Here's how to find it now, but y at - it an EASIER WAY to get images from iPhone/iPad into a tray of images?

    01_opencontents.jpg

    02_findmasters.jpg

    Heya, heya:

    Have you tried to Capture of Image (Applications > Capture of Image)?

    It's pretty simple.  I usually just drag and drop the files I want.

    If Apple never stops this utility, I think I'm going to cry!

    Although it's _avant_ you synchronize.

    -Warren

  • Search for Windows 7 can't find partial matches - when will it be fixed or is there a workaround?

    Windows (in Windows 7 and Vista) search will find only a partial file name (and the file content I guess) match if the text is the beginning of the string. He won't find a string in a file (the file content?) name. This diminshes greatly the value of research and thought that he would have been treated here.

    Example:

    I have a file named invoicenumber12345.doc
    If I search on invoicenumber file appears in the results. If I look on number12345, 12345 or any other subset of characters that appear in the name I get nothing.

    It is therefore impossible to find files based on partial knowledge.

    Example:

    I know that I have sent a letter to Joe Smith, but I can't because I named the file lettertojoesmith.doc
    Due to the limitation of the search, if I'm not rememer the exact file name (or at least that it starts with "letterto", I couldn't find - then what is research?) Through structure file names so that you know how to find totally defeated RESEARCH capacity.

    Does anyone know when this limitation will be addressed or whether there is a solution?

    You can use wildcards like? and *.
    In your case: search for * 12345 or * joe * smith.

    In fact, it is more flexible that a simple search on partial file names.

  • Using SQL to ensure the matching records are mutually exclusive.

    There are two tables defined in the following way:

    Table A

    Number 1

    Number 2

    Date

    ROWID

    Table B

    Number 1

    Number 2

    Date

    Identifier of the line

    Each table stores a call between number 1 and 2 on a specific date. The goal is to map exactly one entry of table A with exactly the record in table B

    in a mutually exclusive way. So a single call to a table must be associated with exactly one call the other table (the key is here

    A.Number1 is B.Number1 and A.Number2 = B.Number2). Because it is a relationship is many to many (the number of source and destination may be paired multiple)

    (time), I'm not able to build a series of sql statements that will allow me to get a relationship one between pairs of telephone numbers.

    I'm not allowed to develop a PL/SQL procedure, which would easily solve this problem.

    I was able to find a solution using MIN(Number 1) KEEP (DENSE_RANK FIRST ORDER BY Date) to THE (PARTITION BY x) the form x

    using temporary tables, which allows me to reach a breaking successively much many relationships (i.e. three broken bones in a 01:58 after

    an iteration, and after one iteration, I arrive at a one to one relationship). However, I can't break these relations some n number of times because it requires number n

    hard curls. Therefore, I need a sophisticated solution that will allow me to achieve a relationship one by one.

    Example of

    Table A

    Record 1

    Number 1:451923456789

    Number 2:541969432045

    Date: 29/07/2015-09:01

    Worksheet 2

    Number 1: 451923456789

    Number 2: 541969432045

    Date: 29/07/2015-09:03

    Table B

    Record 1

    Number 1: 451923456789

    Number 2: 541969432045

    Date: 29/07/2015-09:04

    Worksheet 2

    Number 1: 451923456789

    Number 2: 541969432045

    Date: 29/07/2015-09:05

    If we unite our table A and B by A.Number1 = B.Number1 and A.Number2 = B.Number2, we have 4 records. I'm looking for exactly two records.

    The criteria is to associate by the minimum of the sum of the date of the table A table B date. Therefore, the final result should match:

    (1) record 1 of table A with record 1 of table B.

    sheet 2) 2 table A with 2 record in table B.

    So we must do something to reduce the 4 records resulting from the join of two records describe as we see above.

    The result of the join:

    1st row: TableA.Record1 with TableB.Record1

    2nd place: TableA.Record1 with TableB.Record2

    Rank 3: TableA.Record2 with TableB.Record1

    4th place: TableA.Record2 with TableB.Record2

    What I'm looking for, which is easily achievable with a slider, but not with SQL:

    1st row: TableA.Record1 with TableB.Record1

    4th place: TableA.Record2 with TableB.Record2

    Note that if the minimum date condition allows us to select the necessary records, we won't get the expected results. In other words, using the minimum date.

    the results will be:

    1st row: TableA.Record1 with TableB.Record1

    Rank 3: TableA.Record2 with TableB.Record1

    (criteria - table a minimum date)

    or

    1st row: TableA.Record1 with TableB.Record1

    2nd place: TableA.Record1 with TableB.Record2

    (criteria - date minimum table B)

    Two of these results to break the rule are mutually exclusive.

    Post edited by: 3000640

    If I understand correctly, something like:

    SQL > with tableA (id, telephone1, telephone2, call_date) as)

    2. Select 1, ' 451923456789 ', ' 541969432045',

    3 to_date (July 29, 2015 09:01 ', 'dd.mm.yyyy hh24')

    4 union double all the

    5. Select 2, ' 451923456789 ', ' 541969432045',

    6 to_date (July 29, 2015 09:03 ', 'dd.mm.yyyy hh24')

    double 7),

    TableB 8 (id, telephone1, telephone2, call_date) as)

    9. Select 1, ' 451923456789 ', ' 541969432045',

    10 to_date (July 29, 2015 09:04 ', 'dd.mm.yyyy hh24')

    11 double Union all the

    12. Select 2, ' 451923456789 ', ' 541969432045',

    13 to_date (July 29, 2015 09:05 ', 'dd.mm.yyyy hh24')

    14 double)

    15 select a.id help, a.phone1 aphone1, a.phone2 aphone2,

    16 a.call_date acall_date, b.id offer, b.phone1 bphone1,

    17 b.phone2 bphone2, b.call_date bcall_date

    18 (select id, telephone1, telephone2, call_date,

    19 row_number() over (partition by numbers1, telephone2

    RN 20 order by call_date)

    tablea 21) a

    22 join (select id, telephone1, telephone2, call_date,

    23 row_number() over (partition by numbers1, telephone2

    RN 24 order by call_date)

    tableb 25) b

    26 on a.phone1 = b.phone1 and

    27 a.phone2 = b.phone2 and

    28 a.rn = b.rn;

    HELP APHONE1 APHONE2 ACALL_DATE BPHONE1 BPHONE2 BCALL_DATE OFFERS

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

    1 451923456789 541969432045 July 29, 2015 09:01 1 451923456789 541969432045 July 29, 2015 09:04

    2 451923456789 541969432045 July 29, 2015 09:03 2 451923456789 541969432045 July 29, 2015 09:05

    John

  • Is there any sample sql dev 4 extensions available yet?

    I just ask the questions first if you do not need to try and find them below. The purpose is explained to half way down.

    Using Jdev 12.1.2 Sql Dev 4.0.2.15.21 and the last Extension SDK

    1. are there available from Oracle Sql Developer 4 sample extensions and the new framework?

    2. ALL the documentation is available on the 'specific to sql dev' ID used for menu and other UI elements?

    3. is there a CURRENT version of the extension.xsd file available?

    Here is the link to an article more than two years, by Jeff Smith, titled "how to create an Extension set of Java".

    https://wikis.Oracle.com/display/oraclesqldeveloper/how+to+create+a+Java+defined+extension

    That was useful as other examples of extension provided.

    The menu structure and IDs for Sql Developer are different from that of the JDeveloper. If some documents (list?) or the programmatic method was necessary to get the ID to use for working with menus.

    The old framework and Sql Dev samples and my own extension used "db_nav" and I was able to get the JDev FirstSample of the ESDK extension to Sql Dev 4. But I don't know any place that even what an 'id' is actually documented.

    The extension.xsd file deployed with JDeveloper and Sql Developer seems to be an older version of what is required in JDeveloper. The "menuType" says that the first element may be a 'label' but JDeveloper gives an error saying that it expects a section element.

    < name XS: complexType "menuType" = >

    < xs:complexContent >

    < xs:extension base = "identifiableType" >

    < xs: Sequence minOccurs = "0" >

    < xs: element name = "label" type = "i18n_string" minOccurs = '0 '.

    maxOccurs = "1" >

    < xs: annotation >

    < intention > the label for the menu. < / intention >

    < / xs: annotation >

    < / xs: element >

    I have reviewed all the last JDeveloper samples in the SDK of Extension for the new extension OSGI framework.

    The goal is to migrate my Sql Dev 3 extension to the new framework. Basically, it adds a submenu and items when you right-click on any item in the database (for example, the DEPT table)

    (1) adding multiple, and/or on several levels, items to a context menu

    (2) the types of node specific filtering / acknowledging

    (3) the execution of the custom actions for new context menu items

    Assuming that this tree in the DB browser

    IDE connections

    Scott-Dev

    Tables

    Dept

    . . .

    Table

    Column

    Forced to
    . . .

    The goal is to add additional menu items to ONLY the lowest level (the show of the elements of FirstSample everywhere).

    Therefore, for a given, for example, table Dept, add Custom1, Custom2, or CustomSubMenu... which then Custom1 and Custom2 submenu items.

    Dept

    . . .

    Table

    Column

    Forced to
    . . .

    CUSTOM1

    CUSTOM2

    CustomSubMenu

    CustomSub1

    CustomSub2

    In the old framework, it has been easy. You need just a hook in the extension.xml file listener

    <>hooks

    "< jdeveloper-crochet xmlns ="http://xmlns.oracle.com/jdeveloper/1013/extension">."

    < context-menu-listeners >

    < site idref = "db_nav" >

    com.any.myContextMenuListener <-listener class >

    < / listener class >

    < / site >

    < / context-menu-listeners >

    < / jdeveloper-crochet >

    . . .

    This class of earphone set in place ContextMenuListener and the controller.

    1. menuWillShow method - build the menu several levels using Java code and add it to the "contextMenu" using the parameter passed. You set the actions and add IdeAction items to the menu. By getting the selection and tests for a ' instanceof ObjectNode (an element datababase) could I do NOT add to the menu unless the user has clicked in a suitable place in the nav tree.

    2. method handleEvent - use "action.getCommandId" to find out who stocks (menus) the user has clicked and shipped to the appropriate code

    Does anyone know any examples of the use of the new framework of the extension to do a similar thing?

    The new mix of actions, controllers, auditors, etc. is quite confused and many examples ESDK use a common extension.xml file that has a bit of everything in it.

    I was also unable to find samples of freeware/shareware extension for the new framework to use as a template.

    The ultimate goal of actually being able to use Sql Developer as a platform target in JDeveloper is on hold because it now uses version 12.1.3 the JDeveloper which has not yet been made public.

    Links to examples would be appreciated.

    Thank you.  I think you have some bad assumptions here.

    (1) If this xsd was not supposed to be public, he would not.  I would never put anything OTN if she was not intended to be used.

    2) there are discrete examples of various things on my blog for 1.x through 3.x.  All these need updates for 4.x with the large OSGI now.  Here are some examples:

    (3) release the thread that has been created for questions of migration of extension<  we="" didn't="" lock="" it="" the="" system="" did="" from="">

    OSGI changed way more that I like for people to extend and it is on my list to get all the samples updated and several of them.

  • Find close matched record

    I have data in the report_date column and dates are met like this:

    report_date
    01/01/1990
    01/03/1990
    01/04/2000
    12/05/2000
    01/01/2010
    01/02/2010

    Now I want to select a date in the table which is < = date provided by the user but the query must return only the single record. For example, if the user provides 01/01/1997 query should return 01/03/1990, which is < = 01/01/1997 and closer to 01/01/1997.

    If I use WHERE the report_date < = 01/01/1997, then the query returns two records. Y at - it a function or a way to find the closest record matching? Similarly, if the user provides on 01/12/1988 and because there is no available record who has report_date < = 1988-12-01, then it must return more closest date of 01/01/1990.

    Published by: skas on sept 17, 2012 16:39


    SELECT MIN (RD) AS REPORT_DATE OF
    (SELECT MAX (REPORT_DATE) AS RD FROM MY_TABLE
    <=>
    UNION ALL
    SELECT MIN (REPORT_DATE) FROM MY_TABLE
    WHERE REPORT_DATE > USER_GIVEN_DATE);

  • sql Update query after matching with the string

    I am trying to reach the query that updates a table column with the value of the other table, after that he finds an exact match.

    So here's the table data and sample to create.
    create table code1 
    (
        codeid number,
        codedesc varchar2(60)
    );
    
    Insert into code1 values ( 1,'R1 CONTRACTS');
    
    Insert into code1 values ( 2,'R2 CONTRACTS');
    
    Insert into code1 values ( 3,'R3 CONTRACTS');
    
    Insert into code1 values ( 4,'R5 CONTRACTS');
    
    Insert into code1 values ( 5,'R9 CONTRACTS');
    
    Insert into code1 values ( 6,'R10 CONTRACTS');
    
    create table table1 
    (   
        tablekey number,
        prefix  varchar2(25),
        codedesc    varchar2(60)
    );
    
    Insert into table1(tablekey,prefix) values (1,'1001PAC');
    
    Insert into table1(tablekey,prefix) values (2,'1001MXT');
    
    Insert into table1(tablekey,prefix) values (3,'1002PAE');
    
    Insert into table1(tablekey,prefix) values (4,'1003PCS');
    
    Insert into table1(tablekey,prefix) values (5,'1004BDX');
    
    Insert into table1(tablekey,prefix) values (6,'1005PAC');
    
    Insert into table1(tablekey,prefix) values (7,'1006PAC');
    
    Insert into table1(tablekey,prefix) values (8,'1007LDR');
    
    Insert into table1(tablekey,prefix) values (9,'1009LCR');
    
    Insert into table1(tablekey,prefix) values (10,'1010LBR');
    
    Insert into table1(tablekey,prefix) values (11,'ABCDEF');
    I'm writing a query that would update the value of column - codedesc (currently Null) of the table1 table: after it is a string of column - table code1 codedesc.

    The logic for the match is, - take - 2nd column of table-codedesc code value and get 2 characters. For example, when the string is - R1 CONTRACTS, the string will be 1. (Select substr ("R1 CONTRACTS, 2, 2) of the double). -Output will be 1.

    Now,.
    Look in table 1 for the 3rd position of the prefix that corresponds to the string returned by the query above. So, if the prefix is '1001PAC', it should look for 2 value of figures from the 3rd position. So, in this case it will be 01. Digitally 01 and 1 are equal, then the match is found for this line in the table1 table, so we will need to update the value of the column codedesc with the "contracts of R1.
        tablekey,    prefix            codedesc    
    ---------- ------------------------------------------------------------
    
          1               1001PAC     R1 CONTRACTS    -- Needs to be update with this value. 
          2               1001MXT     R1 CONTRACTS
          3               1002PAE      R2 CONTRACTS
    ...
          11             ABCDEF                                --Null ( No Need to update when no match found).
    SQL> select * from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Release 10.2.0.4.0 - 64bit Production
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for Linux: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    Appreciate your help.

    Hello

    You want to avoid TO_NUMBER, given that will cause an error if even a line has a number no (except space) in the wrong place.
    Use RTRIM to remove extra spaces at the end of the match_key and LPAD to add '0', if necessary, at the beginning:

    MERGE INTO     table1          dst
    USING   (
              SELECT  LPAD ( RTRIM ( SUBSTR ( codedesc
                                     , 2
                                   , 2
                                   )
                              )
                         , 2
                         , '0'
                         )          AS match_key
              ,     codedesc
              FROM     code1
         )               src
    ON     (src.match_key     = SUBSTR ( dst.prefix
                           , 3
                         , 2
                         )
         )
    WHEN MATCHED THEN UPDATE
         SET     dst.codedesc     = src.codedesc
    ;
    

    Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!

  • SQL query: How to match multiple names strictly with its appropriate values

    Hi all

    Assume there is a table of CODES (with 3 columns) as follows:...
    ------------------------------------------------
    Name ID value
    ------------------------------------------------
    SFO 100 080
    200 NY 044
    300. THE 040
    ------------------------------------------------

    I would need to write a SQL to retrieve the rows that match few of names and values. For example: (1) name = "NY" and value = '044' and (2) name = "LA" and value = "040".

    I wrote this sql...
    SELECT id, name, value of CODES whose name IN ('NY', THE ') and the value IN ('044 ', ' 040')
    This returns 2 rows as expected.

    At the same time, even for the following query, the same 2 rows are returned (which is false)
    SELECT id, name, value of CODES whose name in ('NY', THE ') and value in ('044 ', ' 444')
    -See the code std 444.

    My requirement is that the above query should return to the line for NY.

    My question is: how to match multiple names strictly with its appropriate values... ? That is to say, unless '040' is specified in the part 'value', the corresponding line in 'LA' should not be returned...

    I feel, nor the case AND neither the case of GOLD can be used in Where clause to check these 4 values.

    Any ideas... ? Can you please let me know... ?

    Thank you
    REDA

    as:

    select id, name, value from CODES where (name, value) in (('NY', '044'), ('LA', '040'))
    

    Published by: Lacotte Renaud on February 16, 2010 10:35

  • I "lost" my Apple pencil, is there a way I can find it?

    I went on vacation in Florida recently and I stayed with my grandparents out there and I didn't know it until I got home (Kentucky) I left my pencil here. I know it's in a room there and if I was there I could probably find it but my grandparents can't find it. Is there a way that I could follow it through its serial number or an application following Bluetooth that could help find? Or could I go to the Apple Store and they could follow him? I really want to buy a new one because I know where it is but I don't think I'm going down it any time soon, and I do not trust to find. If anyone knows anyway to help me or find them, it would be much appreciated!

    No, there's really no way to find otherwise to look for. Even if you could follow via BT, it is unlikely that you will get more accurate information that is at your grandparents House. I have a tracker of tile on my keys. It is helpful if I think I might have left my keys work but not so much if I don't know where they are in my house.

Maybe you are looking for