Existing table: Add a field that must be unique or null, is - permit?

Hello

I'm working on Oracle Utilities applications. I'm not a guru on the development of the database.

There is an existing table with the following fields:

  1. DocVersion
  2. UIDContract
  3. StartTime
  4. StopTime
  5. Volume

The first 3 fields are used to the PK.

The function of this table to follow how much volume is linked to a Doc version and now with the change of the volume associated with the new SelNumber field.

Now I have to make a change and I want to add a new field: SelNumber.

There are two situations when a record is written to this table:

  1. existing situation is always necessary: then the SelNumber field is not filled in = NULL
  2. The new situation has added: the SelNumber field is not NULL.

What's not now, it is that, in the new situation, the first free fields have the same value, only the SelNumber is different. So the first time a record is added to the table. But the next this record is replaced with the new value.

I can't add the SelNumber field to the PK because in the first situation is NULL and a field of pharmacokinetics cannot be null, or...?

So how can I resolve that I can add a record to the table the PK fields have the same value, but the value SelNumber is different, and in the situation, the SelNumber is null? Is it possible to make a unique constraint on the SelNumber field that has the value null or a unique number? Or is it a stupid thought?


The alternative is I think, to create a new table, but on the other hand, I think that it should be possible!

Please can someone help me with this problem I am facing in?

Nico

Hello

I don't think you can do what you want with a Primary Key constraint.

You can, however, create an index based on a single function, where the index values are all NULL when SelNumber is set to NULL:

CREATE UNIQUE INDEX table_x_uk

ON table_x

(NVL2 (SelNumber, Docversion, NULL)

NVL2 (SelNumber, UIDContract, NULL)

NVL2 (SelNumber, StartTime, NULL)

SelNumber

);

It will not not no constraint on the lines where SelNumber is set to NULL, but, if SelNumber is not null, then the combination of all 4 columns must be unique.

Sorry, I can't test it now.

Tags: Database

Similar Questions

  • Add the constraint not NULL in the existing table that has null values

    Hello

    I want to add a constraint not null to and an existing table, but the table already contains values null in this column.

    EMP

    Emp_id name

    1 axada

    2

    3 sdkdd

    Here is already the data IE 2 empid is Null as name. I must add a fool of constraint not null which new values will not be null, but I don't want to change the data of exisitng alreadt which is null.

    Hello

    "The opposite": NOVALIDATE does not validate the data that is ALREADY in the table, but do not allow the insertion of a NULL value.

    Have you tried my sample code?

    CREATE TABLE MaTable (x NUMBER PRIMARY KEY, y NUMBER);

    INSERT INTO myTable VALUES (1, 123);

    INSERT INTO myTable VALUES ( 2, NULL );

    INSERT INTO myTable VALUES (3, 456);

    ALTER TABLE mytable MODIFY (y NOT NULL NOVALIDATE );

    INSERT INTO myTable VALUES (4, 678);

    INSERT INTO myTable VALUES ( 5, NULL );

    SELECT * FROM MyTable;

    '2' line was inserted with null before the creation of the NOT NULL constraint, this line remains "as what" at the end of the trial.

    '5' line trying to insert a NULL value after creating the NOT NULL constraint, which is denied.

    Best regards

    Bruno.

  • I can cause a ticking a box to add 1 to a calculated field?  I have a field that summarizes the numbers entered in several previous fields and must be able to add '1' If a checkbox is enabled as well.

    I can cause a ticking a box to add 1 to a calculated field?  I have a field that summarizes the numbers entered in several previous fields and must be able to add '1' If a checkbox is enabled as well.

    My first sample: If all the checked Checkbox event.value wins 1

    My next sample: If one of the boxes is enabled event.value wins 1

    Event.Value =

    this.getField ("Check Box16") .isBoxChecked (0) |

    this.getField ("Check Box17") .isBoxChecked (0) |

    this.getField ("Check Box18") .isBoxChecked (0) |

    this.getField ("Check Box19") .isBoxChecked (0) |

    this.getField ("Check Box20") .isBoxChecked (0)

  • Add the sequence to an existing table

    How can I add a sequence to an existing table in a new field called the User_Id? I use Oracle SQL Developer 3.0.04 version, and it provides an option to create a sequence that I did, called Log_Seq. So, I need to put this sequence in the Final_Log table under a column named User_Id. I'm stuck at this part. I'd appreciate any help I can get!

    Hello
    what you can do is to add a trigger on the table that make it work for you.

    For example:
    http://www.razorsql.com/features/oracle_add_sequence_trigger.html

    concerning
    Peter

  • Add the cluster to an existing table in oracle

    Is it possible to add the cluster of an existing table? For example...

    I have a table:

    CREATE TABLE table_name)

    t_id number PRIMARY KEY,

    t_name varchar2 (50));

    Cluster:

    CLUSTER to CREATE my_cluster

    (c_id NUMBER) SIZE 100;

    Y at - it a command such as: ALTER TABLE t_name add CLUSTER my_cluster (t_id); or something like that?

    Because I want to table to look like this:

    CREATE TABLE table_name)

    t_id number PRIMARY KEY,

    t_name varchar2 (50))

    My_cluster (t_id) CLUSTER;

    And drop all the tables isn't really what I want to do.

    Thank you

    No,

    It is the reverse:

    A table can be stored as a segment of memory (the common way) or in a cluster.

    Will not be part of the table "in the cluster", but other parts outside.

    Please create a new table in the cluster and insert your data here.

    Sorry,

    Martin

  • How can I add data file to an existing table on Oracle RAC ASM with no OMF? Thank you!

    How can I add data file to an existing table on Oracle RAC ASM with no OMF? Thank you!

    Hello

    So I guess you have some files in ASM, see your first existing file structure

    Select file_name

    from dba_data_files;

    and to add to an existing table, the example below (even if you're better sticking with OMFs!)-is that what you are looking for?

    SQL > create tablespace TEST1

    2 datafile '+ DATA' size 1 M;

    Created tablespace.

    SQL > select file_name in dba_data_files;

    FILE_NAME

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

    +Data/orcl2/datafile/users.259.859820983

    +Data/orcl2/datafile/undotbs1.258.859820983

    +Data/orcl2/datafile/SYSAUX.257.859820983

    +Data/orcl2/datafile/system.256.859820981

    +Data/orcl2/datafile/example.269.859821049

    +Data/orcl2/datafile/Test1.271.859843053

    6 selected lines.

    SQL > alter tablespace TEST1

    2 Add datafile ' + DATA / mynewfile01.dbf ' size 2 m;

    Tablespace altered.

    SQL > select file_name in dba_data_files;

    FILE_NAME

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

    +Data/orcl2/datafile/users.259.859820983

    +Data/orcl2/datafile/undotbs1.258.859820983

    +Data/orcl2/datafile/SYSAUX.257.859820983

    +Data/orcl2/datafile/system.256.859820981

    +Data/orcl2/datafile/example.269.859821049

    +Data/orcl2/datafile/Test1.271.859843053

    + DATA / mynewfile01.dbf

    Thank you

  • How add us partition on an existing table?

    Hi gurus,

    What would be the best way to add a partition to an existing table?

    Is there a simple documentation for example?

    Thank you

    What would be the best way to add a partition to an existing table?

    Is there a simple documentation for example?

    Was it something you were ask in an interview?

    You cannot add a partition to a table unless this table is a partitioned table.

    The table is already partitioned? If so, after the DDL.

    The Oracle documentation has examples of adding partitions to a table that is already partitioned

    Partition management

    Adding Partitions

    This section explains how to manually add partitions of a partitioned table and explains why partitions can be added specifically for partitioned more indexes.

    Adding a Partition to a partitioned Table range

    Use of the ALTER TABLE ... ADD PARTITION statement to add a new partition at the end 'high' (the point after the last existing partition). To add a partition at the beginning or in the middle of a table, use the SPLIT PARTITION clause.

  • Cannot add the partition to an existing table.

    Hello

    I don't add the partition to an existing table that is not partitioned, get the error as a type of data not valid, then I'm not find syntax errors.

    ALTER TABLE MESSAGEX_XCHANGE

    ADD THE PARTITION OF RANGE (LAST_MODIFY_TIMESTAMP)

    (

    PARTITION old_data VALUES LESS THAN (To_TIMESTAMP('27/02/2014','DD/MM/YYYY')),

    You see for VALUES LESS THAN (To_TIMESTAMP('28/02/2014','DD/MM/YYYY')) of the PARTITION

    );

    Error report:

    SQL error: ORA-00902: invalid data type

    1. 00000 - "invalid data type".

    * Cause:

    * Action:

    Thank you

    Manon...

    You get this error because your edit statement has an invalid syntax. In addition, you cannot partition a table that is not already configured for partitioning!

    You have to physically re-create the partitioned table in order to add new partitions to it.

  • Add the column to an existing table-based user-defined type

    Hello guys,.
    I am compiling my function that returns a type defined by the user based on an existing table. Throughout the process of initialization so my query returns an additional column - SCORE (1). Here is my package:

    create or replace
    PACKAGE STAFF_AGENCY_PKG AS

    TYPE TYPE_SEEKER_TABLE IS TABLE OF THE DRAW. SEEKER % ROWTYPE;
    FUNCTION GET_SEEKERS (IN_KEYWORD IN VARCHAR2)
    TYPE_SEEKER_TABLE RETURN PIPELINE;

    END STAFF_AGENCY_PKG;
    -------

    create or replace
    STAFF_AGENCY_PKG PACKAGE BODY
    AS

    FUNCTION GET_SEEKERS (IN_KEYWORD IN VARCHAR2)
    TYPE_SEEKER_TABLE RETURN PIPELINE
    IS
    R_TBL TYPE_SEEKER_TABLE; -to return
    BEGIN
    FOR R IN)
    SELECT Seeker.SEEKER_ID,
    Seeker.FIRSTNAME,
    Seeker.LASTNAME,
    Seeker.NATIONALITY,
    Seeker.ISELIGIBLE,
    Seeker.BIRTHDATE,
    Seeker.ISRECIEVEEMAILS,
    Seeker.HIGHESTDEGREE,
    Seeker.ETHNICITY,
    Seeker.GENDER,
    Seeker.ISDISABILITY,
    Seeker.DISABILITY,
    Seeker.CV,
    Seeker.PASSWORD,
    Seeker.PREFFERED_CITY,
    SEEKER. E-mail
    SEEKER. JOB_PREFERENCES_ID,
    SCORE (1)
    THE APPLICANT Seeker
    WHERE CONTAINS (CV, ' < query >)
    < textquery lang 'grammar' = 'context' = > ' |
    GET_RELATED_CATEGORIES (IN_KEYWORD) |
    ' < / textquery >
    < score datatype = "INTEGER" / >
    (< / query > ', 1) > 0
    )
    LOOP
    PIPE ROW (R); -Error (38,10): PLS-00382: expression is of the wrong type
    END LOOP;
    RETURN;

    END GET_SEEKERS;
    END STAFF_AGENCY_PKG;

    How do I change my user type to be sufficient?

    Oracle version 11.2.0.1.0
    Thanks in advance!

    >
    How do I change my user type to be sufficient?
    >
    You will need to create two new TYPEs. The one who has all the columns of the draw. The REQUESTOR table and the new column SCORE, then a TYPE which is an array of the first type.

    See example 12-22 using a Pipelined Table function for a Transformation in the PL/SQl language reference

    http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/tuning.htm#i53120

    Here's the first part

    -- Define the ref cursor types and function
    CREATE OR REPLACE PACKAGE refcur_pkg IS
      TYPE refcur_t IS REF CURSOR RETURN employees%ROWTYPE;
      TYPE outrec_typ IS RECORD (
        var_num    NUMBER(6),
        var_char1  VARCHAR2(30),
        var_char2  VARCHAR2(30));
      TYPE outrecset IS TABLE OF outrec_typ;
     FUNCTION f_trans(p refcur_t)
          RETURN outrecset PIPELINED;
    END refcur_pkg;
    /
    
    CREATE OR REPLACE PACKAGE BODY refcur_pkg IS
      FUNCTION f_trans(p refcur_t)
       RETURN outrecset PIPELINED IS
        out_rec outrec_typ;
        in_rec  p%ROWTYPE;
      BEGIN
    

    Change

      TYPE outrec_typ IS RECORD (
        var_num    NUMBER(6),
        var_char1  VARCHAR2(30),
        var_char2  VARCHAR2(30));
      TYPE outrecset IS TABLE OF outrec_typ;
    

    to include all the columns you need. Unfortunately, you have to manually list all the columns in the draw. The REQUESTOR table. If you think you need this same structure in other places you must create them as SQL types instead of PL/SQL types.

    This example should be enough to show you how to modify your code to do something similar.

  • to add more fields to a report just below existing fields

    Hello
    there is report in which the following fields are displayed
    
    jobnumber   customername  rig              well  
     124             abc                 r-90            w-10
    
    
    the requiremnt is to add more fields  and place them just below the above fields
    this enitre thing is in  a main frame  say M_GP
    the job number ,customer name is in another main frame  say M_HD
    and the data 124 etc is in a  repeating frame R_date
    
    ie M_GP encloses M_HD and R_date
    
    kindly guide as to how to include the remaining fields just below these fields so tht the 
    output looks like this
    
    jobnumber   customername  rig              well  
     124             abc                 r-90            w-10
    
    contract    material SIR service_SIR     Service_or_num
    12455         48878        9909090           28278
    
    all these fields r part of the same query and same table
    
    
         select OPN_JOB_DESC  "Job Number",
    ENTRY_DATE "Date",
    RIG "Rig",
    WELL "Well"
    ,JOB || '-'  || JOB_TYPE  "Job Type",
    CUSTOMER_NAME "Customer",
    SERVICE_ORDER_NUM "Service Order No:",
    MATERIAL_SEQ   "Material SIR",
    SERVICE_SEQ      "Service SIR",
    CONTRACT           "Contract"
    from xxnp_opn_joblog_001
     where OPN_JOB_DESC =:P_JOB_NUMBER
    kindly Guide

    thanking in advance

    Hello
    Keep the labels and fields both repeating frame and define the position that you have demonstrated.

    -Clément

  • I can add a column to an existing table with the data.

    Hello

    I'm working on
    The Version of database: Oracle 9i

    I can add a column to an existing table that already has data with below given command.

    ALTER TABLE table_name
    ADD the definition of the column_name column;

    Kind regards
    John

    Add to that:

    If your new column is NOT "null", you need the task in 3 steps:

    1. Add the column without a NOT NULL constraint
    2. the default value of the new column added.
    3. Add the NOT NULL constraint in the new column.

    concerning
    AJ

  • Windows mail. When sending a new email, I want to use the BCC field, that I can not select because it is not on the new Message. __How make CCB to come when I create a new message? This something __Is I can add tools please?

    Windows mail. When sending a new email, I want to use the BCC field, that I can not select because it is not on the new Message.
    How can I get the future BCC when I create a new message?
    Can I add tools please?

    Thanks for the reply Bruce Hagen. I am very grateful.

    Dave.

    In a new message window: view | All the headers. Check it out. Or, simply click on the button to easily add to your contacts list to: To, CC, or BCC.

    Bruce Hagen ~ MS - MVP [Mail]

  • ADOBE Acrobat Pro DC - add lines to an existing table

    Hello. I have an existing table, I need to add lines.  Is this possible? Thanks in advance.

    It is very difficult to do something like this in a PDF file (unless it was created using LiveCycle Designer).

    You will be better off by changing the original file, and then creating a new PDF from it.

  • How to add the new column in existing table to our desired location?

    How to add the new column in existing table to our desired location?

    For example, I have to add the new column 'course' before the salary column in the emp table.

    I think the best way is to add the column at the end of the table and create a new view with the order of the columns...

    Another option...

    places the data into a temporary table and recreate the table with the correct order of the columns, and then insert data to the table from the temporary table

    Refer

    Add column (from table) in the desired position

    Example:

    CREATE TABLE temp_my_user LIKE)

    SELECT * FROM password);

    DROP TABLE password;

    (Password) CREATE TABLE

    userID NUMBER

    , first name VARCAHR2 (25)

    , middleInitial VARCHAR2 (1)

    (, name VARCHAR2 (25));

    INSERT INTO password (userID, firstName, lastName)

    (SELECT username

    first name

    lastName

    OF temp_my_user);

    DROP TABLE temp_user;

  • How to connect to an Adobe Javascript(Folder Level Script) SAP Web Service and retrieve the response in a table of the Adobe Javascript/AcroJS. Could you please it explain with an example. I have two required input parameters that must be filled.

    How to connect to an Adobe Javascript(Folder Level Script) SAP Web Service and retrieve the response in a table of the Adobe Javascript/AcroJS. Could you please it explain with an example. I have two required input parameters that must be filled.

    I s generic SOAP example/tutorial on my blog: get a serial number in a form using SOAP - KHKonsulting LLC

    The web service uses only a single parameter, but you should be able to adapt the code to two arguments without problems.

Maybe you are looking for

  • Can you switch from activity between kilojoules and calories

    prefer the use of calories on kilojoule, is there a way to change this to Active

  • What is obvious: Interface of Skype on Mac sucks

    I came here for almost the same reasons to see if I could fix my problems of interface of Skype, but I see now everyone has the same problems. I was going to ask how I could increase the width of the columns so that when I reduce the size of the wind

  • my windows will not stop

    Windows continues to close when I go to shut down the computer

  • How to disable windows 7 AUTORUN

    I have Windows 7 Home Edition. I want to COMPLETELY disable the Autorun feature. I would use the "gpedit" basic tool but it is not available on home edition (it is very sad!) I tried the config of auto in the Control Panel/hardware and audio playing,

  • Gzip request to the web application server Java

    Hi experts, My first post here. I am building a Java for Blackberry application that needs to send data relatively large (in the hundreds of kb/s) on a web server. Since the mobile internet connection is not fast enough transfer a lot of data will ta