Two columns must be UNIQUE if the second is not NULL.

Two columns must be UNIQUE if the second is not NULL. If the second is NULL, the first has no need to be UNIQUE.

CREATE TABLE Moo
(
Prima        INT PRIMARY KEY,
Secunda    INT NOT NULL,
Tertia        VARCHAR2(1)
);

CREATE UNIQUE INDEX Cow ON Moo(Secunda, NVL(Tertia, TO_CHAR(Prima)));

INSERT INTO Moo(Prima, Secunda, Tertia)
SELECT 1, 1, NULL FROM Dual UNION ALL
SELECT 2, 1, NULL FROM Dual;

DROP TABLE Moo;

Is there another way to do it?

Added 'SINGLE '.

I had a little trouble at matches your description to your example, but if you want to apply the uniqueness on (secunda, tertia) only for lines where tertia is not null, then the following should work:

create an index unique xxx on moo)

cases when is not null, then end of secunda, tertia

Tertia

);

Concerning

Jonathan Lewis

P.S. When do a quick test of the best way to define this index, I found what seems to be a bug in 11.2.0.4 (and maybe other versions) with the expression:

Tertia case if no then cast (null as an int) to another end secunda

Update: now blog at: Easy & #8211; Oops. | Notebook of the Oracle

Tags: Database

Similar Questions

  • For the second time in two months, all my messages in the Inbox are not there. Only the SUBJECT and the FROM is left. Tried to 'fix this folder' and lost ALL

    For the second time in two months, all my messages in the Inbox are not there. Only the SUBJECT and the FROM is left.

    Tried to 'fix this folder' and ALL - lost ALL the Inbox.

    The file is still there and works well...

    How can I stop it and what are the causes?

    Thank you all, Gabe

    If you have the file somewhere on your hard drive, export and import tools it will be important back to Thunderbird.

    https://addons.Mozilla.org/en-us/Thunderbird/addon/ImportExportTools/

    Instructions http://chrisramsden.vfast.co.uk/3_How_to_install_Add-ons_in_Thunderbird.html

  • The procedure of procurement of the game Clash of Clans first two payments $9.99 $4.44 and the second did not gems continued with the developer of the game and they told me to resolve this ongoing problem with Apple's iTunes... help me solve

    The procedure of procurement of the game Clash of Clans first two payments $9.99 $4.44 and the second did not gems continued with the developer of the game and they told me to solve this problem continue with Apple iTunes... help solve me this problem and the compensatory jewelry

    Double-see your message, my first response to this topic tells you how to contact iTunes Support (we are fellow users): Re: the procurement process of the Clash game Clans the amount was deducted from the iTunes account and do not have t...

  • Is possible to write the INSERT statement that fills two columns: 'word' and 'sense' of the file text with multiple lines - in each line is followed word that is the meaning?

    Is possible to write the INSERT statement that fills two columns: 'word' and 'sense' of the file text with multiple lines - in each line is followed word that is the meaning?

    Hello

    2796614 wrote:

    Is possible to write the INSERT statement that fills two columns: 'word' and 'sense' of the file text with multiple lines - in each line is followed word that is the meaning?

    Of course, it is possible.  According to what the text file looks like to, you can create an external table that treats the text file as if it were a table.  Otherwise, you can always read the file in PL/SQL, using the utl_file package and INSERT of PL/SQL commands.

    You have problems whatever you wantt?  If so, your zip code and explain what the problem is.

    Whenever you have any questions, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the exact results you want from these data, so that people who want to help you can recreate the problem and test their ideas.  In this case, also post a small sample of the text involved file.

    If you ask about a DML operation, such as INSERT, then INSERT statements, you post should show what looks like the tables before the DML, and the results will be the content of the table changed after the DML.

    Explain, using specific examples, how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: Re: 2. How can I ask a question on the forums?

  • Is it possible to display a pop-up for 1 time when the recordset is not null

    I heard that it is difficult to pass the PHP variables in javascript, as I can't possibly write javascript in php tags.

    The pseudo-code is like this:

    If the recordset of the query is not null, then popup a window, to get the results of the recordset object.

    The code looks something like this, but I know it is not possible to put js(in bold) in the php. The idea is sort of like this:

    <? PHP

    ......

    $today = date("Y-m-d"); today's date

    @mysql_select_db ($database_myconnection2, $myconnection2);

    $query_Recordset5 = sprintf ("" SELECT * FROM temp WHERE the dev_expdate < %s ", GetSQLValueString ($today,"text")");

    $Recordset5 = mysql_query ($query_Recordset5, $myconnection2) or die (mysql_error ());

    $row_Recordset5 = mysql_fetch_assoc ($Recordset5);

    $totalRows_Recordset5 = mysql_num_rows ($Recordset5);


    < script type = "text/javascript" >

    If ($row_Recordset5! = Null)

    {window.open ();


    }

    < /script >

    ? >

    <>

    ......

    $today = date("Y-m-d"); today's date

    @mysql_select_db ($database_myconnection2, $myconnection2);

    $query_Recordset5 = sprintf ("SELECT * FROM temp WHERE dev_expdate")< %s"="" ,getsqlvaluestring($today,="">

    $Recordset5 = mysql_query ($query_Recordset5, $myconnection2) or die (mysql_error ());

    $row_Recordset5 = mysql_fetch_assoc ($Recordset5);

    $totalRows_Recordset5 = mysql_num_rows ($Recordset5);

    f I($row_Recordset5! = "") {? >}

  • My printer is connected to two computers. I find that the second computer does not print unless the first computer is also on. Can I get every computer to print without the two be on?

    the printer has been first on windows 7 and second on windows xp, because that's the way I was told iy had to be done. But I thought that each computer can print separeately withou t windows 7 being on.

    Hello

    1. How is the printer connected? This printer is on a network?
    2. this configuration was already working before?

    You must configure a print server. If your printer is a network printer, you can connect it to a router, and all computers connected to this router can use the printer individually. If the printer is not a network printer, you can buy the equipment to turn it into one.

    See the articles below for more information:
    http://support.Microsoft.com/kb/308028
    http://TechNet.Microsoft.com/en-us/library/bb457001.aspx

    I hope this helps.

  • If you have two hard drives, can you wipe the second and just use it as a storage device?

    If you have two HARD drives in a PC Windows 7, can you remove everything (including the System 32, Windows users, literally everything) in the second and still use his computer? All my programs on the first HDD would remain on my PC, but all the files of the second being scratched? I'm running out of space on my first HARD drive and need to know if I can keep the second as storage just pure.

    Thank you.

    Hey Elliot,

    Thanks for posting your query in the Microsoft Community Forums.

    According to the description, it seems that you want to delete all the data on the secondary hard drive without affecting the first hard drive operating system files.

    I'll be happy to help you with this.

    If the operating system (Windows 7) is installed on the first hard drive, it has nothing to do with the second hard disk. You can go ahead and delete all data without hesitation.

    Note: Make sure that you remove the data from the hard drive where Windows 7 is installed.

    If you want to reduce the number of unnecessary files on your hard disk to free up disk space and help your computer run faster, use disk cleanup.

    For more information, see the link.

    Delete files using disk cleanup

    If you have any other questions, feel free to let us know. We will be happy to help you.

  • Concatenate two columns and store it in the existing column

    Hi all

    I created a form based interactive report and need help on that. In the report, I want to display a column with label the CANDIDATE's FULL NAME by concatenating the existing columns in the same table.

    Am mentioning the details and the following questions:

    Table name: CANDIDATE_DETAILS

    Column 1: CANDIDATE_FNAME (first name) Data Type: CHAR (50)

    Column 2: CANDIDATE_LNAME (family name) the data type: CHAR (50)

    Column 3: CANDIDATE_FULLNAME (full name) Data Type: CHAR (100)

    If in the case of column 3 that is, CANDIDATE_FULLNAME is not created in the database, I could have written in query to create one using the concatenation of columns 1 and 2 of the column

    ALTER TABLE CANDIDATE_DETAILS ADD CANDIDATE_FULLNAME TANK (100 CHAR)

    AS (CANDIDATE_FNAME |) ' ' || ( CANDIDATE_LNAME)

    Since then, I have already created CANDIDATE_FULLNAME column, I just change or simply store the concatenation of Column1 and Column2. I tried to use under request, but his does not work:

    ALTER TABLE CANDIDATE_DETAILS

    CHANGE CANDIDATE_FULLNAME ACE (CANDIDATE_FNAME |) ' ' || CANDIDATE_LNAME)

    Also I'm checking the code under SQL Workshop-> SQL commands by entering the query below and his works fine.

    Select CANDIDATE_FNAME. ' ' || CANDIDATE_LNAME

    of 'CANDIDATE_DETAILS '.

    but do not know where to enter this code in "The Page Creator" that without creating an additional column in the database my needs can be met.

    Please let me know if you need more information and really appreciate any assistance.

    Thank you

    Verhasselt

    Hello

    If the requirement is to display the columns and their contents concatenated in a third, you can try this:

    1. create a new column in the report by adding code to the selection of the report:

    Select CANDIDATE_FNAME, CANDIDATE_LNAME, "'"CANDIDATE_FULLNAME"'CANDIDATE_DETAILS'"

    2. in the page editor, select the "CANDIDATE_FULLNAME" column and his correspondents "formatting of column" > "HTML Expression" describe what you like:

    #CANDIDATE_FNAME # #CANDIDATE_LNAME #.

  • Column Salary to come in the form $ does not time?

    Trying to get this works, but can't. Help, please. You will need to get the column Salary to come in the form $ instead of the time. Whenever it is multiplied by 12, it ends by multiplying by time and not by $12. So I'll take 48 h 0 m instead of $48. There are some pictures of what I am trying to accomplish. There's a picture of what is happening and another pic of my formula before you enter the time in time and get the product duration under treatment. Help, please. Thank you

    E SALVATION '

    You multiply at a range of a number. The result is lasting. That makes sense, if you do 15 minutes (duration) of exercise every day for five days (number) you have made 1.25 hours (duration) of exercise.

    For a numeric result, you need to multiply a number (hours) by a number of $ / hour. Your friend here is DUR2HOURS, which converts a duration in a number representing the number of hours:

    Kind regards

    Barry

  • Choose the value is not null in my database using report 6i

    Hello world
    I have 2 fields in my database and I want to put in my report that the data that is not empty.
    I have the following code example, but I don't know where to put in my report and how to use it:
    Can someone help me please?
    SELECT column1
          ,column2
          ,DECODE (GRADE_Num,NULL, GRADE_Letter,GRADE_NUM) AS grade
    FROM ....

    Hello..

    Depends on what you want to do...
    What is your main query, your column of formulas or perhaps within a function, or a procedure... .so depends on your needs place you only
    And the decode line will always search results if this value is null. .because you tell if grade_num is null then show the note by letter... otherwise (way grade_num is not null), you will see the grade_num...
    This can be achieved using the NVL function also...
    instead of decoding you could write NVL (grade_name, grade_letter)...
    NVL function works as follows: If the first argument is null then subititute as the second argument.

    If your goal is to extract the lines where a certain column is not NULL only, you can then you can also say something like that...

    SELECT column1, Column2
    From table_name
    where (Column1 is not null) AND (column2 is not null);

  • How to effectively check if a field in the form is not null

    Hello

    I'm guessing there's a way to programmatically check if a field has been entered during the loading of the form.  A sort of loop should do the trick...

    I tried to use the following code (from dohanlon for another purpose) which must run through all fields in the form, but I can't plug it in an if/else statement or even check for any value non-zero.

    xfa.resolveNodes (' form1... #field [*] "" ');

    Conceptually, here is how I like to do:

    If (xfa.resolveNodes ("form1... #field [*------]".rawValue!)) = null) {}

    Do it

    }

    Basically, I'm just checking if any field is not null, then I can "do something".  I know that I can't use it to check .rawValue but I can't think of anything.

    I'd appreciate any help (as always).


    Hello

    I prefer loops, because you can build in a little management as well as errors.

    See an example here: http://assure.ly/H1ksGR.

    Hope that helps,

    Niall

  • If var! = NULL or if the variable is not NULL which is more correct?

    Hello Experts

    Which of the following is better?


    Also when assign us a variable (type nvarchar) null including notation should we use?

    new_address = NULL;

    or

    new_address = ";

    declare
    new_address ADDRESS. ADDRESS TYPE %;
    Start

    new_address: = 'a ';
    If new_address! = NULL then
    dbms_output.put_line(new_address||) e DO ');
    end if;

    end;

    declare
    new_address ADDRESS. ADDRESS TYPE %;
    Start

    new_address: = 'a ';
    If new_address is not NULL then
    dbms_output.put_line(new_address||) e DO ');
    end if;

    end;

    Thank you

    NULL is unknown.

    NULL = false NULL

    NULL! = NULL also false

    ----

    Ramin Hashimzade

  • How to know the history have not null value

    Hi all

    I want to find records that have prior LOG_REVIEW_STAGE = "HHH" have (DT_LOG_BEGIN is not null and DT_LOG_END IS NULL and LOG_STATUS = pending)
    based on the identification number

    Thanks in advance
    For Example my Ouput should be 
    
    ID     SORT_ORDER     LOG_STATUS     LOG_REVIEW_STAGE     DT_LOG_BEGIN     DT_LOG_END
    -----------------------------------------------------------------------------------------------
    20     700          Pending          FFF               1/26/2004     
    ID     SORT_ORDER     LOG_STATUS     LOG_REVIEW_STAGE     DT_LOG_BEGIN     DT_LOG_END
    -----------------------------------------------------------------------------------------------
    10     100          Complete     AAA               1/13/2004     1/13/2004
    10     200          Complete     BBB               1/23/2004     1/23/2004
    10     300          Pending          CCC               1/23/2004     
    10     400                    DDD          
    10     601                    EEE          
    10     700                    FFF          
    10     800                    GGG          
    10     900                    HHH         ---------------------->>>>>>>>>
    10     1000                    JJJ          
    10     1100                    KKK          
    20     100          Complete     AAA               1/13/2004     1/13/2004
    20     200          Complete     BBB               1/23/2004     1/23/2004
    20     300          Complete     CCC               1/23/2004     1/23/2004
    20     400          Complete     DDD               1/24/2004     1/24/2004
    20     601          Complete     EEE               1/25/2004     1/25/2004
    20     700          Pending          FFF               1/26/2004     
    20     900                    HHH          ---------------------->>>>>>>>>
    20     1000                    JJJ          
    20     1100                    KKK          
    create table TEMP_TABLE
    (
      id               NUMBER(2),
      sort_order       NUMBER(10),
      log_status       VARCHAR2(50),
      log_review_stage VARCHAR2(50),
      dt_log_begin     DATE,
      dt_log_end       DATE
    )
    ;
    
    
    
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (10, 100, 'Complete', 'AAA', to_date('13-01-2004', 'dd-mm-yyyy'), to_date('13-01-2004', 'dd-mm-yyyy'));
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (10, 200, 'Complete', 'BBB', to_date('23-01-2004', 'dd-mm-yyyy'), to_date('23-01-2004', 'dd-mm-yyyy'));
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (10, 300, 'Pending', 'CCC', to_date('23-01-2004', 'dd-mm-yyyy'), null);
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (10, 400, null, 'DDD', null, null);
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (10, 601, null, 'EEE', null, null);
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (10, 700, null, 'FFF', null, null);
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (10, 800, null, 'GGG', null, null);
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (10, 900, null, 'HHH', null, null);
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (10, 1000, null, 'JJJ', null, null);
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (10, 1100, null, 'KKK', null, null);
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (20, 100, 'Complete', 'AAA', to_date('13-01-2004', 'dd-mm-yyyy'), to_date('13-01-2004', 'dd-mm-yyyy'));
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (20, 200, 'Complete', 'BBB', to_date('23-01-2004', 'dd-mm-yyyy'), to_date('23-01-2004', 'dd-mm-yyyy'));
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (20, 300, 'Complete', 'CCC', to_date('23-01-2004', 'dd-mm-yyyy'), to_date('23-01-2004', 'dd-mm-yyyy'));
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (20, 400, 'Complete', 'DDD', to_date('24-01-2004', 'dd-mm-yyyy'), to_date('24-01-2004', 'dd-mm-yyyy'));
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (20, 601, 'Complete', 'EEE', to_date('25-01-2004', 'dd-mm-yyyy'), to_date('25-01-2004', 'dd-mm-yyyy'));
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (20, 700, 'Complete', 'FFF', to_date('26-01-2004', 'dd-mm-yyyy'), to_date('26-01-2004', 'dd-mm-yyyy'));
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (20, 800, 'Pending', 'GGG', to_date('27-01-2004', 'dd-mm-yyyy'), null);
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (20, 900, null, 'HHH', null, null);
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (20, 1000, null, 'JJJ', null, null);
    insert into TEMP_TABLE(id, sort_order, log_status, log_review_stage, dt_log_begin, dt_log_end)
    values (20, 1100, null, 'KKK', null, null);
    commit;

    Please provide examples of data, as well as an explanation of your logic. It is very useful!

    I think that's what you want:

    SELECT id
         , sort_order
         , log_status
         , log_review_stage
         , dt_log_begin
         , dt_log_end
    FROM
    (
            SELECT id
                 , sort_order
                 , log_status
                 , log_review_stage
                 , dt_log_begin
                 , dt_log_end
                 , LEAD(log_review_stage) OVER (PARTITION BY id ORDER BY sort_order) AS next_log_review_stage
            FROM   temp_table
    )
    WHERE  log_status            = 'Pending'
    AND    dt_log_begin          IS NOT NULL
    AND    dt_log_end            IS NULL
    AND    next_log_review_stage = 'HHH'
    ;
    

    When run on your dataset, it returns:

                      ID           SORT_ORDER LOG_STATUS      LOG_REVIEW_STAGE                                   DT_LOG_BEGIN        DT_LOG_END
    -------------------- -------------------- --------------- -------------------------------------------------- ------------------- -------------------
                      20                  800 Pending         GGG                                                01/27/2004 00:00:00
    

    If this is incorrect, please explain why.

    Thank you!

  • Two actions to one button - delaying the second action

    Hi all

    I have a menu on my site - this menu does two things when you click each button - they charge two separate sovereign wealth funds in video clips already on the scene.

    I want to do is delay one of the actions of a few seconds so that the file always starts loading before the other (one is a background, it is a foreground)

    any suggestions?

    my site: www.ponch.biz/portfolio (still much to do in detail but comments on what is happening here are welcome)

    Thank you very much

    Ponch

    David,

    Thank you very much, who did it!

    see you soon

    Ponch

  • Error running columns must be updated in the error table

    Hi all

    I deliver, in my process when execution time if I got an error, that it would be updaed in my error log table, is there any special function is there for that?

    Hello

    For any error that occurs in your trapping interface use the package step.

    Go to step 1 to step 2 by KO trail

    in step 2, you can use a variable with a refresh of query ' select SUBSTR)< %="odiRef.getPrevStepLog" ("message")="" %="" >,="" 1,="" 4000)="" du="" double="" '="" faire="" passer="" votre="" message="" d’erreur...="" de="" cette="" façon,="" vous="" pouvez="" gérer="" vos="">
    Also, as mentioned in a previous post, you can easily change your variable as refresh query

    *'select SUBSTR (< %="odiRef.getPrevStepLog" ("message")="" %="" >,="" 1,="" 3000)="" || »=""><->' |)< %="odiRef.getPrevStepLog" (« step_name »)="" %="" >="" du="" double="" '="" *="" d’inscrire="" le="" nom="" de="" l’étape="" afin="" que="" vous="" sachiez="" où="" cette="" erreur="" s’est="">
    Now, you can use this variable to insert this value into a table of error log using a procedure of ODI step (do the next step).

    Solve your problem?

    Published by: 922636 on 13 Sep 2012 06:58

Maybe you are looking for

  • Impossible to install the operating system using the product on Satellite 1110 recovery CD

    I had to replace my hard drive after the failure, but impossible to install Windows XP Home (Home) from the recovery CD. I followed the instructions on the CD case, but nothing happens, just a cursor flashing at the top left of the screen. If I try t

  • Satellite L650 - how to change the language of the BIOS?

    HelloI had received as a gift a portable Toshiba L650, and I see that the BIOS is in a language other than English.The OS is in English, so no problem.The BIOS is in Swedish, because a friend gave me her laptop. * How can I change the BIOS language?

  • I have to ask Microsoft Outlook on my computer for programs to run correctly?

    Should it be part of my Microsoft Outlook e-mail system?  I don't use it at all, but when I try to download from Yahoo mail, it takes me straight to Microsoft Outlook - wants me to run the wizard.  Can you help me?

  • Windows Live Movie Maker Music Sync problem

    I use Windows Live Movie Maker on Vista.  I think I'm having a problem syncing music with photos.  I have a slideshow that I add music. Finally, I want to make a DVD. No problem initially adding pieces to the photo show.   When I start at the beginni

  • Reset windows password

    I would like to place a "Forgot password" option to the windows logon screen and point to a script that connects to the AD and reset the password, so that the user can reset the password itself with some security checks. I could build the script, but