SQL Constraints

Hi,
I have got a small query ( using oracle 10g)
I would like to create constraints as shown in the below table between first and second colum( id & item). Is this possible using constraints
id     item     Qty
1     Apple     10
2     Orange     40
3     Kiwi     10
3     Kiwi     5
2     Apple     8
2     Orange     50  ======> not allowed ( id 2 should be Orange)
1     Mango     20  ======>  not allowed ( id 1 should be Apple)
4     Mango 10
Help in this regard is very much appreciated.
Thanks
YG

Hi,
user8268619 wrote:
Hi,
I have got a small query ( using oracle 10g)
I would like to create constraints as shown in the below table between first and second colum( id & item). Is this possible using constraints
id     item     Qty
1     Apple     10
2     Orange     40
3     Kiwi     10
3     Kiwi     5
2     Apple     8
2     Orange     50  ======> not allowed ( id 2 should be Orange)
1     Mango     20  ======>  not allowed ( id 1 should be Apple)
4     Mango 10
Help in this regard is very much appreciated.
Thanks
YG
Sorry, it's not clear what you want.
When you say "id 2 should be Orange", do you mean item should be 'Orange' whenever id=2?  If so, what's wrong with the row
2     Orange     50  ======> not allowed ( id 2 should be Orange)
You may need to have 2 tables; the table you mentioned above, and another table with the allowed (id, item) combinations, with a foreign key constraint.

Similar Messages

  • SQL constraint (Is this allowed)?!

    Dear all,
    I'm designing a database at the moment. I have a table called Student. In this table I have the following fields:
    Student ID, Name, Grant ID*, Fund ID*
    The Grant ID* and Fund ID* are foreign keys referencing a grant table and a fund table.
    In a normal situation, the student has a grant OR typical fund such as self funding or scholarship etc.
    the question is : can I have a constraint to force the table entry to one column only but not the other and vise versa.So the student will only have a grant OR typical fund?
    I don't know the name of this constraint, I have searched for a long time but without knowing what I am searching for Its like searching for a needle in a hay stack.

    Something like this perhaps
    SCOTT @ jcave102 Local> ed
    Wrote file afiedt.buf
      1  create table a (
      2    col1 number,
      3    col2 number,
      4    constraint chk_a1 check( (col1 is not null and col2 is null) or
      5                             (col2 is not null and col1 is null))
      6* )
    SCOTT @ jcave102 Local> /
    Table created.
    Elapsed: 00:00:00.01
    SCOTT @ jcave102 Local> insert into a values( 1, null );
    1 row created.
    Elapsed: 00:00:00.01
    SCOTT @ jcave102 Local> insert into a values( null, 1 );
    1 row created.
    Elapsed: 00:00:00.01
    SCOTT @ jcave102 Local> insert into a values( 1, 1 );
    insert into a values( 1, 1 )
    ERROR at line 1:
    ORA-02290: check constraint (SCOTT.CHK_A1) violated
    Elapsed: 00:00:00.07
    SCOTT @ jcave102 Local> insert into a values( null, null );
    insert into a values( null, null )
    ERROR at line 1:
    ORA-02290: check constraint (SCOTT.CHK_A1) violated
    Elapsed: 00:00:00.01Justin

  • Accepting input in PL/SQL

    My requirement is Accepting Input from KeyBoard in the LOOP PL/SQL Block.
    Becasue of PL/SQL constraints I am not able to accept value in the loop
    except the first time. Please advice me is there any other options in PL/SQL
    to accept input from the keyboard in the loop.

    I'm not sure how you can do this, perhaps someone else does.
    I suggest writing a Shell Script or Batch file which accepts the input and then runs SQL*Plus and your script with arguments.
    Good Luck,
    Eric Kamradt

  • Block with more than one table type agurment -  Update Procedure for Block

    Hi,
    I have one form with 3 Block. First Block is single row block, and other 2 are details block . The details balocks are based on the Procedure datasource, because of the complex query conditions. Now my requirement is When Inserting / Updating the Master Block (Single Row Block), I need to get the values in the two details block , because I need to update some other tables also based on these values. I created a procedure with two Table Type parameters (for each details block) , but when I using this procedure as the Update Procedure Name in the block, I am getting the error Only One table type arguement is allowed. Is there any other method to implement this.
    Thanks in advance.

    Rizly,
    A quick summary to make sure I understand your requirements. You have a single row base table master block with two detail blocks that are based on Procedures. When you update the single row base table master block, you need all of the data in the two procedure based detail blocks as there are updates that you have to perform to other tables that use this data. You have created a stored procedure that take two PL/SQL tables as parameters, but you are getting the error that only 1 table parameter is allowed.
    I need to ask you a few questions first. What is your Forms version? The stored procedure you created; are you using this procedure in the "On-Insert, On-Update, On-Delete" triggers or do you call the procedure in one of the Base Table block ("Key-Commit, When-Button-Pressed" or other trigger)? When you modify or add a new Master block record are you adding values to the detail blocks or using values from the previous Master block record?
    If you are using your procedure in the On-Insert, On-Update or On-Delete trigger(s), then based on your description, the error you are receiving is correct. The "On-..." triggers are constrained in that their procedures expect only a single PL/SQL table, Table of Records or Ref Cursor as a parameter. This is a Forms constraint - not a PL/SQL constraint as Forms is expecting you to only perform actions on the block where the "On-..." Trigger is located.
    Perhaps you should consider creating a database Package that has two package specification constructs (Ref Cursor, Table of Records, etc) you can populate from Forms and then simply call the package procedure that will use the Ref Cursors to perform the needed update or inserts.
    Hope this helps.
    Craig...
    If mine or someone elses response was helpful, please mark it accordingly

  • Changing NP User ID UDF in business One

    Hey All,
    We have a client who had all of their netpoint userids created automatically by netpoin. (numeric ids). They want to change some user ids to sensible user ids for their users. If they change the netpoint user UDF in business one the synch runs and starts getting SQL constraint errors because it is trying to link the  same contact more then once. Surely there is a way for them to rename a userid through the interface?
    Any help would be appreciated.
    Thanks.

    I would try to rename the userid in netpoint, then before synchronization, change th NPUserid in B1, so that when it synchs the Userid exists, and it should still be linked to orders, etc

  • User_tab_cols - nullable column?

    Dear All,
    check the workflow:
    C:\>sqlplus scott/tiger
    SQL*Plus: Release 10.2.0.1.0 - Production on Fri Apr 4 16:20:48 2008
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> CREATE TABLE TEST
    2 (ID NUMBER(*,0))
    3 /
    Table created.
    SQL>
    SQL> ALTER TABLE TEST ADD (CONSTRAINT TEST_ID_NOT_NULL CHECK (ID IS NOT NULL) EN
    ABLE)
    2 /
    Table altered.
    SQL>
    SQL> DESC TEST
    Name Null? Type
    ID NUMBER(38)
    SQL>
    SQL> -- Null? -> NULL
    SQL>
    SQL> SELECT TABLE_NAME
    2 ,NULLABLE
    3 FROM USER_TAB_COLS
    4 WHERE TABLE_NAME = 'TEST'
    5 /
    TABLE_NAME N
    TEST Y
    SQL>
    SQL> -- Nullable? Since when? I've declared a constraint on it. Ok, let's try:
    SQL>
    SQL> INSERT INTO TEST (ID) VALUES (NULL)
    2 /
    INSERT INTO TEST (ID) VALUES (NULL)
    ERROR at line 1:
    ORA-02290: check constraint (SCOTT.TEST_ID_NOT_NULL) violated
    SQL>
    SQL> -- True, I have a check constraint on the ID.
    SQL> -- But why is the column nullable if I check the user_tab_cols?
    SQL> -- I don't see the difference between forcing Oracle to add
    SQL> -- constraints automatically at creation time
    SQL> -- (create table test (id number not null)) and
    SQL> -- adding constraints manually... It will use constraints
    SQL> -- anyway...
    SQL>
    SQL> -- Don't forget to clean up!
    SQL> DROP TABLE TEST CASCADE CONSTRAINTS
    2 /
    Table dropped.
    SQL>
    Any thoughts?
    Thanks,
    Franky

    Franky,
    Oracle has worked this way for as long as I can remember. Observe
    UT1 > create table t1 (col1   varchar2(10)  not null);
    Table created.
    UT1 > desc t1
    Name                                      Null?    Type
    COL1                                      NOT NULL VARCHAR2(10)
    UT1 > select search_condition from dba_constraints where table_name = 'T1';
    SEARCH_CONDITION
    "COL1" IS NOT NULL
    UT1 > drop table t1
      2  /
    Table dropped.
    UT1 > create table t1 (col1 varchar2(10) );
    Table created.
    UT1 > desc t1
    Name                                      Null?    Type
    COL1                                               VARCHAR2(10)
      1* alter table t1 add (Constraint t1col1 check (col1 is not null))
    UT1 > /
    Table altered.
    UT1 > desc t1
    Name                                      Null?    Type
    COL1                                               VARCHAR2(10)
      1* select search_condition from dba_constraints where table_name = 'T1'
    UT1 > /
    SEARCH_CONDITION
    col1 is not nullUsing the "not null" keywords in the create table results in Oracle setting a switch as being turned on. It is this setting that describe reads for the table not null column. But in both cases dba_constraints will show a check constraint.
    It is just the way it is. I suggest using the "not null" key words on the table create rather than setting explicit column level constraints for the columns.
    I just noticed that in the first case that the column name is in double quotes in the search condition and is the second it is not.
    HTH -- Mark D Powell --

  • Create synta error. right parenthisis missing (SUPER SIMPLE)

    hi guys im having a problem with this create statement its probably because i have looked at it too much now im just not seeing the problem can anyone point out my mistake thanks
    this is my first time using auto_increment so its probably somthing to do with that
    SQL> CREATE TABLE BOOK_INFO (
    2 BOOK_CN_NUM AUTO_INCREMENT(3),
    3 BOOK_ISBN VARCHAR2(9),
    4 BOOK_TITLE VARCHAR2(100),
    5 BOOK_AUTHOR_NAME VARCHAR(30),
    6 BOOK_STATUS VARCHAR2(4) DEFAULT 'IN',
    7 CONSTRAINT BOOK_CN PRIMARY KEY (SUBSTR(BOOK_TITLE(1,2), SUBSTR(BOOK_AUTHOR_NAME(1,2), BOOK_CN_N
    UM)
    8 ) ENABLE CONSTRAINT BOOK_CN
    9
    SQL>
    SQL> /
    BOOK_CN_NUM AUTO_INCREMENT(3),
    ERROR at line 2:
    ORA-00907: missing right parenthesis
    much appreciated
    RMMO

    im about to give up with this..... another error.....
    SQL> ed
    Wrote file afiedt.buf
    1 CREATE TABLE BOOK_INFO(
    2 BOOK_CN VARCHAR2(9),
    3 BOOK_CN_NUM NUMBER(3),
    4 BOOK_ISBN VARCHAR2(9),
    5 BOOK_TITLE VARCHAR2(100),
    6 BOOK_AUTHOR_NAME VARCHAR(30),
    7 BOOK_STATUS VARCHAR2(4) DEFAULT 'IN',
    8 CONSTRAINT BOOK_CN PRIMARY KEY)
    9* ENABLE CONSTRAINT BOOK_CN
    SQL> /
    CONSTRAINT BOOK_CN PRIMARY KEY)
    ERROR at line 8:
    ORA-00906: missing left parenthesis
    thanks for being sooooo patient!

  • Define infix operators for Object types

    Hi,
    Is it possible to define infix operators for object types?
    Example:
    CREATE TYPE BODY Complex AS
       MEMBER operator + (x Complex) RETURN Complex IS
       BEGIN
          RETURN Complex(rpart + x.rpart, ipart + x.ipart);
       END plus;
    Usage:
      given a table E (C1 Complex, C2 Complex)
    Select C1+C2 from E;
    Kind regards
    Taouik

    An "object type" is nothing but a an o-o class. Can you create SQL constraints on o-o classes? Usually not. Oracle is no different.
    Where do you create constraints in Oracle? On tables. And yes, an o-o class (object type) can be used to create a table (aka an object table). That table can have any of the standard SQL constraints supported by Oracle.

  • MDMGX Hierarchies Filter

    Hi Experts,
    I am executing standard MDMGX for reconsilation accounts (Hierarchy table based on company code) which is using MDM_ERP_MULTI_HIERARCHIES_EXTR as Function Module XML.
    I want to get compnay starts with ' 7%' for reconsilation accounts. I have tried adding the following 2 statements in SQL Constraint column
    CompanyCode LIKE '7%' 
    BUKRS like '7%'
    But,XML file getting all company codes. Filter is not working as expected.
    How to achieve this?

    Hi Ramu,
    You need to dig out the table name and field name which is being used in function module XML MDM_ERP_MULTI_HIERARCHIES_EXTR and then try using in WHERE CLAUSE. Since you are not using directly table here (as you are using function module), so you need to check whether it actually work for you or not after finding table and field name and write it down as syntax in Where Clause as shown on page [8/15|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f0740b31-a934-2b10-2e95-af2252991baa?quicklink=index&overridelayout=true].
    Otherwise you can achieve it using MDM workflow where you can create records in MDM Data Manager based on validation to filter out values starting with 7.
    Kindly revert with result.
    Regards,
    Mandeep Saini

  • MDMGX error while Transporting entries

    Hi Guru's
    I Have created a port call LT_Promotions in SAP t-code MDMGX and trying to transport this in test sytem ,while i try to save the transport it errors with message
    "Key entry for table MDMGXC1 may only be generic"
    Dont know what this is ..
    Will you Please let me know how can i go around this..
    Regards
    Vikrant M Kelkar

    Hi Vikranth,
       This error happens if there are wrong entries in MDMGXC1 table. go to this table and maintain the ports and check tables.
    Ports would be the ports of MDM where you want the data to be present. check tables are the tables from where you want to extract the data.
    Mandatory  details to be entered in MDMGXC1 are as below
    Remote System Type  - Remote system type in which the generic  extractor is used.
    Object Type -Object type for which you want to extract reference data.
    Port Name - Code of the target MDM port.
    Table Name - Name of a table.
    Language - Independent Fields -Field names of language-independent fields to be extracted.
    SQL Constraint - SQL constraint or selection criteria for selecting data from the table
    The syntax to be followed is as below
    Table Name - Name of a table.
          Example
          T005
    Language - Independent Fields
        Syntax
       <Fld in R/3> = <Fld in MDM>, <Fld in R/3> = <Fld in MDM>,u2026
         Example
         LAND1=Country_key,INTCA3=Legacy_Code.
    SQL Constraint
           TableName~FieldName = u2018Eu2019
          Example
            T005T~SPRAS = 'Eu2018
    Note : Maintain the above values instead of uploading.
    Hope it resolves the issue
    Kindly award points
    Regards

  • Constraint table in sql server7

    i have a database in sql server7 and i want to see all the constraints that are applied on that table manually i.e. through sql query.please tell me what is the sql query that i can use to see all the constraints applied on the table.
    same thing i want to do with ms-access ,tell me if i can use any query to see the constraints on ms-access table.

    Hi, this is Oracle Forum, you must go to Microsoft Forum for add this Post, please take the next reference.
    http://forums.microsoft.com/
    Regards.

  • SQL 2012 and later will fail to publish a database for any tables with a default constraint that references a user defined function.

    Script will create database, 3 database objects and publish. 
    The error is due to the generation script to create the conflict tables that is not stripping out default constraints that reference a UDF. 
    As you can see below, the failure is on the generation script for the conflict table.
    The conflict table should be a bucket table that shouldn’t enforce data integrity. 
    See how the default constraints for the columns someint and somestring were stripped out of the generation logic however the default constraint that utilizes a UDF persist and uses the same object name that was used on the production table (The
    bold line) , this occurs if I explicitly name the constraint or let the system generate the name for me like in the example posted. 
      The only way I could see getting around this right now is to drop all default constraints in the system that uses a UDF, publish then add the constraints back which is vulnerable to invalid data and a lot of moving
    steps.  This all worked with SQL 2000, 2005, 2008, 2008r2, it’s stopped working in SQL 2012 and continues to not work in SQL 2014. 
    Error messages:
    Message: There is already an object named 'DF__repTable__id__117F9D94' in the database.
    Could not create constraint. See previous errors.
    Command Text: CREATE TABLE [dbo].[MSmerge_conflict_MergeRepFailurePublication_repTable](
            [id] [varchar](8) NULL CONSTRAINT [DF__repTable__id__117F9D94]  DEFAULT ([dbo].[repUDF]()),
            [somedata] [varchar](64) NULL,
            [rowguid] [uniqueidentifier] ROWGUIDCOL  NULL,
            [someint] [int] NULL,
            [somestring] [varchar](64) NULL
    Parameters:
    Stack:    at Microsoft.SqlServer.Replication.AgentCore.ReMapSqlException(SqlException e, SqlCommand command)
       at Microsoft.SqlServer.Replication.AgentCore.AgentExecuteNonQuery(SqlCommand command, Int32 queryTimeout)
       at Microsoft.SqlServer.Replication.AgentCore.ExecuteDiscardResults(CommandSetupDelegate commandSetupDelegate, Int32 queryTimeout)
       at Microsoft.SqlServer.Replication.Snapshot.YukonMergeConflictTableScriptingManager.ApplyBaseConflictTableScriptToPublisherIfNeeded(String strConflictScriptPath)
       at Microsoft.SqlServer.Replication.Snapshot.BaseMergeConflictTableScriptingManager.DoConflictTableScriptingTransaction(SqlConnection connection)
       at Microsoft.SqlServer.Replication.RetryableSqlServerTransactionManager.ExecuteTransaction(Boolean bLeaveTransactionOpen)
       at Microsoft.SqlServer.Replication.Snapshot.BaseMergeConflictTableScriptingManager.DoConflictTableScripting()
       at Microsoft.SqlServer.Replication.Snapshot.MergeSmoScriptingManager.GenerateTableArticleCftScript(Scripter scripter, BaseArticleWrapper articleWrapper, Table smoTable)
       at Microsoft.SqlServer.Replication.Snapshot.MergeSmoScriptingManager.GenerateTableArticleScripts(ArticleScriptingBundle articleScriptingBundle)
       at Microsoft.SqlServer.Replication.Snapshot.MergeSmoScriptingManager.GenerateArticleScripts(ArticleScriptingBundle articleScriptingBundle)
       at Microsoft.SqlServer.Replication.Snapshot.SmoScriptingManager.GenerateObjectScripts(ArticleScriptingBundle articleScriptingBundle)
       at Microsoft.SqlServer.Replication.Snapshot.SmoScriptingManager.DoScripting()
       at Microsoft.SqlServer.Replication.Snapshot.SqlServerSnapshotProvider.DoScripting()
       at Microsoft.SqlServer.Replication.Snapshot.MergeSnapshotProvider.DoScripting()
       at Microsoft.SqlServer.Replication.Snapshot.SqlServerSnapshotProvider.GenerateSnapshot()
       at Microsoft.SqlServer.Replication.SnapshotGenerationAgent.InternalRun()
       at Microsoft.SqlServer.Replication.AgentCore.Run() (Source: MSSQLServer, Error number: 2714)
    Get help: http://help/2714
    Server COL-PCANINOW540\SQL2012, Level 16, State 0, Procedure , Line 1
    Could not create constraint. See previous errors. (Source: MSSQLServer, Error number: 1750)
    Get help: http://help/1750
    Server COL-PCANINOW540\SQL2012, Level 16, State 0, Procedure , Line 1
    Could not create constraint. See previous errors. (Source: MSSQLServer, Error number: 1750)
    Get help: http://help/1750
    Pauly C
    USE [master]
    GO
    CREATE DATABASE [MergeRepFailure]
    ALTER DATABASE [MergeRepFailure] SET COMPATIBILITY_LEVEL = 110
    GO
    USE [MergeRepFailure]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    create view
    [dbo].[repView] as select right(newid(),8) as id
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE FUNCTION [dbo].[repUDF]()
    RETURNS varchar(8)
    BEGIN
    declare @val varchar(8)
    select top 1 @val = id from [repView]
    return @val
    END
    GO
    create table repTable
    id varchar(8) default([dbo].[repUDF]()),
    somedata varchar(64) null,
    rowguid uniqueidentifier ROWGUIDCOL default(newid()),
    someint int default(1),
    somestring varchar(64) default('somestringvalue')
    GO
    insert into reptable (somedata) values ('whatever1')
    insert into reptable (somedata) values ('whatever2')
    go
    /*test to make sure function is working*/
    select * from reptable
    GO
    /*Publish database*/
    use [MergeRepFailure]
    exec sp_replicationdboption @dbname = N'MergeRepFailure', @optname = N'merge publish', @value = N'true'
    GO
    declare @Descrip nvarchar(128)
    select @Descrip = 'Merge publication of database ''MergeRepFailure'' from Publisher ''' + @@servername +'''.'
    print @Descrip
    -- Adding the merge publication
    use [MergeRepFailure]
    exec sp_addmergepublication @publication = N'MergeRepFailurePublication', @description = N'@Descrip',
    @sync_mode = N'native', @retention = 14, @allow_push = N'true', @allow_pull = N'true', @allow_anonymous = N'true',
    @enabled_for_internet = N'false', @snapshot_in_defaultfolder = N'true', @compress_snapshot = N'false', @ftp_port = 21,
    @ftp_subdirectory = N'ftp', @ftp_login = N'anonymous', @allow_subscription_copy = N'false', @add_to_active_directory = N'false',
    @dynamic_filters = N'false', @conflict_retention = 14, @keep_partition_changes = N'false', @allow_synctoalternate = N'false',
    @max_concurrent_merge = 0, @max_concurrent_dynamic_snapshots = 0, @use_partition_groups = null, @publication_compatibility_level = N'100RTM',
    @replicate_ddl = 1, @allow_subscriber_initiated_snapshot = N'false', @allow_web_synchronization = N'false', @allow_partition_realignment = N'true',
    @retention_period_unit = N'days', @conflict_logging = N'both', @automatic_reinitialization_policy = 0
    GO
    exec sp_addpublication_snapshot @publication = N'MergeRepFailurePublication', @frequency_type = 4, @frequency_interval = 14, @frequency_relative_interval = 1,
    @frequency_recurrence_factor = 0, @frequency_subday = 1, @frequency_subday_interval = 5, @active_start_time_of_day = 500, @active_end_time_of_day = 235959,
    @active_start_date = 0, @active_end_date = 0, @job_login = null, @job_password = null, @publisher_security_mode = 1
    use [MergeRepFailure]
    exec sp_addmergearticle @publication = N'MergeRepFailurePublication', @article = N'repTable', @source_owner = N'dbo', @source_object = N'repTable', @type = N'table',
    @description = null, @creation_script = null, @pre_creation_cmd = N'drop', @schema_option = 0x000000010C034FD1, @identityrangemanagementoption = N'manual',
    @destination_owner = N'dbo', @force_reinit_subscription = 1, @column_tracking = N'false', @subset_filterclause = null, @vertical_partition = N'false',
    @verify_resolver_signature = 1, @allow_interactive_resolver = N'false', @fast_multicol_updateproc = N'true', @check_permissions = 0, @subscriber_upload_options = 0,
    @delete_tracking = N'true', @compensate_for_errors = N'false', @stream_blob_columns = N'false', @partition_options = 0
    GO
    use [MergeRepFailure]
    exec sp_addmergearticle @publication = N'MergeRepFailurePublication', @article = N'repView', @source_owner = N'dbo', @source_object = N'repView',
    @type = N'view schema only', @description = null, @creation_script = null, @pre_creation_cmd = N'drop', @schema_option = 0x0000000008000001,
    @destination_owner = N'dbo', @destination_object = N'repView', @force_reinit_subscription = 1
    GO
    use [MergeRepFailure]
    exec sp_addmergearticle @publication = N'MergeRepFailurePublication', @article = N'repUDF', @source_owner = N'dbo', @source_object = N'repUDF',
    @type = N'func schema only', @description = null, @creation_script = null, @pre_creation_cmd = N'drop', @schema_option = 0x0000000008000001,
    @destination_owner = N'dbo', @destination_object = N'repUDF', @force_reinit_subscription = 1
    GO

    More information, after running a profile trace the following 2 statements, the column with the default on a UDF returns a row while the other default does not.  This might be the cause of this bug.  Is the same logic to generate the object on
    the subscriber used to generate the conflict table?  
    exec sp_executesql N'
    select so.name, schema_name(so.schema_id)
    from sys.sql_dependencies d
    inner join sys.objects so
    on d.referenced_major_id = so.object_id
    where so.type in (''FN'', ''FS'', ''FT'', ''TF'', ''IF'')
    and d.class in (0,1)
    and d.referenced_major_id <> object_id(@base_table, ''U'')
    and d.object_id = object_id(@constraint, ''D'')',N'@base_table nvarchar(517),@constraint nvarchar(517)',@base_table=N'[dbo].[repTable]',@constraint=N'[dbo].[DF__repTable__id__117F9D94]'
    exec sp_executesql N'
    select so.name, schema_name(so.schema_id)
    from sys.sql_dependencies d
    inner join sys.objects so
    on d.referenced_major_id = so.object_id
    where so.type in (''FN'', ''FS'', ''FT'', ''TF'', ''IF'')
    and d.class in (0,1)
    and d.referenced_major_id <> object_id(@base_table, ''U'')
    and d.object_id = object_id(@constraint, ''D'')',N'@base_table nvarchar(517),@constraint nvarchar(517)',@base_table=N'[dbo].[repTable]',@constraint=N'[dbo].[DF__repTable__somein__1367E606]'
    Pauly C

  • SQL*Loader and integrity constraints

    I am running into trouble with integrity constraints in my SQL*Loader script runs. Should I be going up to unix and removing the constraints from sqlplus, then asking the wizard to reinstall them after the data load? Is this documented somewhere? I can't find it. Sorry for asking such a basic question.
    Thanks,
    Ann Cantelow

    Hi,
    Your approach is correct.
    Create tables first
    Move data via the scripts
    Create contraints, indexes, primary keys
    See the User Guide for the ORacle Migration Workbench http://otn.oracle.com/tech/migration/workbench
    Regards
    John

  • I cannot Disable a constraint in SQL Developer

    Here is my issue:
    I have created a table already named practice1.
    Using SQL Developer PL/SQL try to run a loop as following:
    DECLARE
    COUNTER1  NUMBER(2);
    BEGIN
    COUNTER1 := 30;
    ALTER TABLE practice1
    DISABLE  CONSTRAINT PRK1;
    LOOP
    COUNTER1 := 30;
    INSERT INTO PRACTICE1
    VALUES (COUNTER1, 'test7', 8, 9);
    EXIT WHEN  COUNTER1 >26;
    END LOOP;
    END;
    In other words I Insert the COUNTER1 variable value as Primary Key in the tables field1 column.
    I run the script successfully without the ALTER TABLE DISABLE CONTSRAINT.. command.
    Everytime I run it I had to increase the starting value of Variable COUNTER1 so it will not attempt to insert a duplicate pre-existed value in Primary Key.
    Then I decided to insert the command ALTER TABLE DISABLE CONSTRAINT in order to not have to worry to change the starting value.
    I am able to disable the constraint by using the same command in isolation . If I run it as part of the script as above I get the following error:
    Error report:
    ORA-06550: line 5, column 1:
    PLS-00103: Encountered the symbol "ALTER" when expecting one of the following:
       ( begin case declare end exception exit for goto if loop mod
       null pragma raise return select update while with
       <an identifier> <a double-quoted delimited-identifier>
       <a bind variable> << continue close current delete fetch lock
       insert open rollback savepoint set sql execute commit forall
       merge pipe purge
    06550. 00000 -  "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:
    I would appreciate any suggestions.
    Thank you.

    Your question has NOTHING to do with sql developer.
    Mark this question ANSWERED and repost it in the SQL and PL/SQL forum.
    https://forums.oracle.com/community/developer/english/oracle_database/sql_and_pl_sql
    The problem is that you CANNOT execute DDL directly in PL/SQL. You need to use dynamic SQL to execute DDL within PL/SQL.
    EXECUTE IMMEDIATE 'ALTER TABLE . . .';
    If you need more help use the correct forum as shown above.

  • PL/SQL Automatic Constraint Handler(Code)

    For those interested...
    I created the following database code that automatically does the constraint check/return error message for you.
    You could even take this a step further and create your own message repository...
    This guy even grabs/checks for foreign key violations:
    First part of code builds/returns dictionary data constraints for table that you specify.
    It then loads this data into object type.
    This object type will be referenced later in the database trigger that you create for table where you want to validate constraints
    return DbCons_documents_Array
    as
    dbdata DbCons_documents_Array := DbCons_documents_Array();
    i NUMBER := 1;
    begin
    FOR cns_rec IN(select child.child_cons_name clchild_cons_name,
    child.parent_cons_name clparent_cons_name,
    child.child_columns clchild_columns,
    parent.parent_cons_name pparent_cons_name,
    parent.parent_tname pparent_tname,
    child.child_tname clchild_tname,
    CONCAT(CONCAT('"',replace(replace(parent.parent_columns,'"',''),'''','')),'"') pparent_columns,
    child.parent_cons_type pparent_cons_type
    --CONCAT(CONCAT('''',web_form_array(find_web_frm_val).db_col_value),'''');
    FROM (
    select a.table_name child_tname,
    a.constraint_name child_cons_name,
    NVL(b.r_constraint_name,a.constraint_name) parent_cons_name,
    b.constraint_type parent_cons_type,
    max(decode(position, 1, '"'||column_name||'"',NULL)) ||
    max(decode(position, 2,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position, 3,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position, 4,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position, 5,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position, 6,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position, 7,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position, 8,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position, 9,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position,10,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position,11,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position,12,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position,13,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position,14,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position,15,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position,16,', '||'"'||column_name||'"',NULL))
    child_columns
    from user_cons_columns a, user_constraints b
    where a.constraint_name = b.constraint_name
    and b.constraint_type IN ( 'U', 'R' )
    --and nvl(B.r_constraint_name,B.constraint_name) = A.constraint_name
    -- and nvl(a.r_owner,a.owner) = b.owner
    group by a.table_name, a.constraint_name, b.r_constraint_name,b.constraint_type ) child,
    ( select a.constraint_name parent_cons_name,
    a.table_name parent_tname,
    max(decode(position, 1, '"'||column_name||'"',NULL)) ||
    max(decode(position, 2,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position, 3,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position, 4,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position, 5,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position, 6,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position, 7,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position, 8,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position, 9,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position,10,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position,11,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position,12,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position,13,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position,14,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position,15,', '||'"'||column_name||'"',NULL)) ||
    max(decode(position,16,', '||'"'||column_name||'"',NULL))
    parent_columns
    from user_cons_columns a, user_constraints b
    where a.constraint_name = b.constraint_name
    and b.constraint_type in ( 'P', 'U', 'R' )
    group by a.table_name, a.constraint_name ) parent
    where child.parent_cons_name = parent.parent_cons_name
    and child.child_tname = upper('YOUR TABLE NAME HERE')
    LOOP
    dbdata.extend(i);
    dbdata(i) := cdrl5.dbconstraint_documents_rec(cns_rec.pparent_cons_name,cns_rec.clchild_tname,cns_rec.pparent_tname,cns_rec.pparent_columns,cns_rec.pparent_cons_type);
    --dbdata(i) := '';
    -- dbdata(i) := dbconstraint_rec('test','test','test','test');
    --v_sql :=
    -- dbdata(i).constraint_name;
    i := i+1;
    END LOOP;
    FOR d IN 1..dbdata.COUNT
    LOOP
    IF dbdata(d).constraint_name IS NULL
    THEN
    dbdata.delete(d);
    END IF;
    END LOOP;
    -- dbdata.delete;
    return dbdata;
    END;
    Second part is code that is in trigger of table you are inserting into. Note that you have to store the table name/column name(that make up the constraint)/actual form values into pl/sql table:
    DECLARE
    v_sql VARCHAR2(32000);
    v_literal_value VARCHAR2(100);
    v_error_relay VARCHAR2(4000);
    v_db_values NUMBER := 1;
    v_dup_count NUMBER;
    nforeign_key EXCEPTION;
    TYPE DupRecordType IS REF CURSOR;
    dup_rec_cv DupRecordType;
    dbdata DbCons_Documents_Array := DbCons_Documents_Array(cdrl5.dbconstraint_documents_rec(null,null,null,null,null));
    TYPE tokenTableType is TABLE of varchar2(4000) -- table for Stringtoken
    index by binary_integer;
    tokenChar VARCHAR2(4000) := '," ';
    tokens tokenTableType;
    vCnt integer := 1;
    myLine varchar2(4000) := null;
    Line varchar2(4000) := null;
    vPos integer := 1;
    TYPE form_rec IS RECORD
    table_name VARCHAR2(100),
    db_column VARCHAR2(100),
    db_col_value VARCHAR2(1000)
    TYPE form_type IS TABLE OF form_rec
    INDEX BY binary_integer;
    web_form_array form_type;
    BEGIN
    dbdata.DELETE;
    -- IF :new.DOC_ID IS NOT NULL
    -- THEN
    NOTE: Load the below table(with values specified) for each table constraint
    web_form_array(v_db_values).table_name :=
    'YOUR TABLE NAME';
    web_form_array(v_db_values).db_column :=
    'YOUR FIELD NAME';
    web_form_array(v_db_values).db_col_value :=
    :new.;
    v_db_values := v_db_values +1;
    FOR cns_rec IN(select *
    from TABLE ( cast( documents_cons_dml() as DbCons_documents_Array ))
    LOOP
    line :=
    cns_rec.constraint_where;
    v_sql := 'SELECT count(*) FROM '||cns_rec.constraint_column;
    IF INSTR(line,',',1,1) <= 0
    THEN
    FOR find_web_frm_val IN 1..web_form_array.COUNT
    LOOP
    IF cns_rec.table_name = web_form_array(find_web_frm_val).table_name
    AND replace(line,'"','') = web_form_array(find_web_frm_val).db_column
    THEN
    v_literal_value :=
    CONCAT(CONCAT('''',web_form_array(find_web_frm_val).db_col_value),'''');
    v_sql := v_sql||' WHERE '||' '||web_form_array(find_web_frm_val).db_column||' = '||v_literal_value;
    END IF;
    END LOOP;
    ELSE
    while (vPos <= length(line))
    loop
    if (length(replace(tokenChar,substr(line, vPos, 1), '')) = length(tokenChar))
    then
    myLine := myLine || substr(line, vPos, 1);
    elsif (myLine is not NULL) then
    tokens(vCnt) := myLine;
    FOR find_web_frm_val IN 1..v_db_values
    LOOP
    IF cns_rec.table_name = web_form_array(find_web_frm_val).table_name
    AND MYLine = web_form_array(find_web_frm_val).db_column
    THEN
    v_literal_value :=
    CONCAT(CONCAT('''',web_form_array(find_web_frm_val).db_col_value),'''');
    END IF;
    end loop;
    IF vCnt = 1
    THEN
    v_sql := v_sql||' WHERE '||' '||myLine||' = '||v_literal_value;
    ELSE
    v_sql := v_sql||' AND '||' '||myLine||' = '||v_literal_value;
    END IF;
    myLine := null;
    vCnt := vCnt + 1;
    end if;
    vPos := vPos + 1;
    end loop;
    if (myLine is not NULL) then
    tokens(vCnt) := myLine;
    end if;
    vCnt := 1;
    vPos := 1;
    END IF;
    OPEN dup_rec_cv FOR v_sql;
    FETCH dup_rec_cv
    INTO v_dup_count;
    CLOSE dup_rec_cv;
    IF cns_rec.column_position = 'R'
    THEN
    IF v_dup_count <= 0
    THEN
    v_error_relay :=
    'The form field value for Database Column '||' '||line||' '||' that was entered does not exist';
    RAISE nforeign_key;
    END IF;
    ELSIF cns_rec.column_position = 'U'
    THEN
    IF v_dup_count > 0
    THEN
    RAISE DUP_VAL_ON_INDEX;
    END IF;
    END IF;
    -- commit_trans(v_dup_count);
    -- INSERT INTO test
    -- values(line||' '||INSTR(line,',',1,1));
    -- VALUES(cns_rec.constraint_name||' '||cns_rec.table_name||' '||cns_rec.constraint_column||' '||cns_rec.constraint_where);
    -- values(v_sql||' '||vPos||' '||length(line));
    -- VALUES(web_form_array(i).table_name||' '||CONCAT(CONCAT('''',web_form_array(i).db_col_value),'''')||' '||i);
    --commit;
    -- i := i+1;
    END LOOP;
    EXCEPTION
    WHEN DUP_VAL_ON_INDEX
    THEN
    raise_application_error(-20101, 'Attempted to update duplicate. Cannot update '||:new.);
    WHEN nforeign_key
    THEN raise_application_error(-20101, v_error_relay||' '||' YOUR MESSAGE HERE '||:new.);
    END;

    Mark:
    Ordinarily, I not really a critical guy, but that thing is such a mess that I have to comment. I won't mention the complete lack of bind variables (which leads to the shared pool and hard parsing concerns), but as posted it won't even compile. I had some time to kill, so.
    For starters, the big query in your function gets:
    ORA-01467: sort key too long
    on my 9.2.0.6 instance with 16K blocksize, and on my 9.2.0.1 instance with an 8K blocksize. Interestingly, it does work on my 8.1.7.4 instance with 8K blocks. So, I had to limit it to 15 columns.
    You give no function name at all. Based on the trigger code, I assume the function should be documents_cons_dml. I also added a paramter to pass the table name since one could conceivably have more than one table in an application.
    I also took the liberty of fixing your extend problem. In your code, you extend the array by one in the first iteration through the loop, by two in the second and so on. Which is why you need the delete loop at the end.
    There is no definition for the DbCons_documents_Array that the function returns, so I assumed something like:
    SQL> CREATE TYPE dbconstraint_documents_rec AS OBJECT (
      2     constraint_name   VARCHAR2(30),
      3     table_name        VARCHAR2(30),
      4     constraint_column VARCHAR2(30),
      5     constraint_where  VARCHAR2(4000),
      6     column_position   VARCHAR2(1) );
      7  /
    Type created.
    SQL> CREATE TYPE DbCons_documents_Array AS
      2     VARRAY(50) OF dbconstraint_documents_rec;
      3  /
    Type created.I used the names that you used in the trigger, although the names don't seem to match with the column contents, must be code re-use.
    So, now the function looks like:
    SQL> CREATE FUNCTION documents_cons_dml (p_table_name IN VARCHAR2)
      2    RETURN DbCons_documents_Array AS
      3
      4     dbdata DbCons_documents_Array := DbCons_documents_Array();
      5     i NUMBER := 1;
      6  BEGIN
      7     FOR cns_rec IN(SELECT child.child_cons_name clchild_cons_name,
      8                           child.parent_cons_name clparent_cons_name,
      9                           child.child_columns clchild_columns,
    10                           parent.parent_cons_name pparent_cons_name,
    11                           parent.parent_tname pparent_tname,
    12                           child.child_tname clchild_tname,
    13                           CONCAT(CONCAT('"',REPLACE(REPLACE(parent.parent_columns,'"',''),'''','')),'"') pparent_columns,
    14                           child.parent_cons_type pparent_cons_type
    15                    FROM (SELECT a.table_name child_tname,
    16                                 a.constraint_name child_cons_name,
    17                                 NVL(b.r_constraint_name,a.constraint_name) parent_cons_name,
    18                                 b.constraint_type parent_cons_type,
    19                                 MAX(DECODE(position, 1, '"'||column_name||'"',NULL)) ||
    20                                 MAX(DECODE(position, 2,', "'||column_name||'"',NULL)) ||
    21                                 MAX(DECODE(position, 3,', "'||column_name||'"',NULL)) ||
    22                                 MAX(DECODE(position, 4,', "'||column_name||'"',NULL)) ||
    23                                 MAX(DECODE(position, 5,', "'||column_name||'"',NULL)) ||
    24                                 MAX(DECODE(position, 6,', "'||column_name||'"',NULL)) ||
    25                                 MAX(DECODE(position, 7,', "'||column_name||'"',NULL)) ||
    26                                 MAX(DECODE(position, 8,', "'||column_name||'"',NULL)) ||
    27                                 MAX(DECODE(position, 9,', "'||column_name||'"',NULL)) ||
    28                                 MAX(DECODE(position,10,', "'||column_name||'"',NULL)) ||
    29                                 MAX(DECODE(position,11,', "'||column_name||'"',NULL)) ||
    30                                 MAX(DECODE(position,12,', "'||column_name||'"',NULL)) ||
    31                                 MAX(DECODE(position,13,', "'||column_name||'"',NULL)) ||
    32                                 MAX(DECODE(position,14,', "'||column_name||'"',NULL)) ||
    33                                 MAX(DECODE(position,15,', "'||column_name||'"',NULL)) child_columns
    34                          FROM user_cons_columns a, user_constraints b
    35                          WHERE a.constraint_name = b.constraint_name and
    36                                b.constraint_type IN ( 'U', 'R' )
    37                          GROUP BY a.table_name, a.constraint_name,
    38                                   b.r_constraint_name,b.constraint_type ) child,
    39                         (SELECT a.constraint_name parent_cons_name,
    40                                 a.table_name parent_tname,
    41                                 MAX(DECODE(position, 1, '"'||column_name||'"',NULL)) ||
    42                                 MAX(DECODE(position, 2,', "'||column_name||'"',NULL)) ||
    43                                 MAX(DECODE(position, 3,', "'||column_name||'"',NULL)) ||
    44                                 MAX(DECODE(position, 4,', "'||column_name||'"',NULL)) ||
    45                                 MAX(DECODE(position, 5,', "'||column_name||'"',NULL)) ||
    46                                 MAX(DECODE(position, 6,', "'||column_name||'"',NULL)) ||
    47                                 MAX(DECODE(position, 7,', "'||column_name||'"',NULL)) ||
    48                                 MAX(DECODE(position, 8,', "'||column_name||'"',NULL)) ||
    49                                 MAX(DECODE(position, 9,', "'||column_name||'"',NULL)) ||
    50                                 MAX(DECODE(position,10,', "'||column_name||'"',NULL)) ||
    51                                 MAX(DECODE(position,11,', "'||column_name||'"',NULL)) ||
    52                                 MAX(DECODE(position,12,', "'||column_name||'"',NULL)) ||
    53                                 MAX(DECODE(position,13,', "'||column_name||'"',NULL)) ||
    54                                 MAX(DECODE(position,14,', "'||column_name||'"',NULL)) ||
    55                                 MAX(DECODE(position,15,', "'||column_name||'"',NULL)) parent_columns
    56                          FROM user_cons_columns a, user_constraints b
    57                          WHERE a.constraint_name = b.constraint_name and
    58                                b.constraint_type IN ( 'P', 'U', 'R' )
    59                          GROUP BY a.table_name, a.constraint_name ) parent
    60                    WHERE child.parent_cons_name = parent.parent_cons_name and
    61                          child.child_tname = upper(p_table_name)) LOOP
    62        dbdata.extend;
    63        dbdata(i) := dbconstraint_documents_rec(cns_rec.pparent_cons_name,
    64                                                cns_rec.clchild_tname,
    65                                                cns_rec.pparent_tname,
    66                                                cns_rec.pparent_columns,
    67                                                cns_rec.pparent_cons_type);
    68        i := i+1;
    69     END LOOP;
    70     RETURN dbdata;
    71  END;
    72  /
    Function created.
    SQL> CREATE TABLE t (ID NUMBER PRIMARY KEY, descr VARCHAR2(10));
    Table created.
    SQL> CREATE TABLE t1 (idt1 NUMBER PRIMARY KEY, descr VARCHAR2(10));
    Table created.
    SQL> ALTER TABLE t ADD CONSTRAINT t_fk
      2  FOREIGN KEY (id) REFERENCES t1 (idt1);
    Table altered.Now for the trigger. Once I got rid of the schema owner cdrl5 in the dbconstraint_documents_rec call it actually compiled first time. So, my trigger looks like:
    SQL> CREATE OR REPLACE TRIGGER t_bi
      2  BEFORE INSERT ON t
      3  FOR EACH ROW
      4  DECLARE
      5     v_sql VARCHAR2(32000);
      6     v_literal_value VARCHAR2(100);
      7     v_error_relay VARCHAR2(4000);
      8     v_db_values NUMBER := 1;
      9     v_dup_count NUMBER;
    10     nforeign_key EXCEPTION;
    11
    12     TYPE DupRecordType IS REF CURSOR;
    13     dup_rec_cv DupRecordType;
    14
    15     dbdata DbCons_Documents_Array := DbCons_Documents_Array(dbconstraint_documents_rec(null,null,null,null,null));
    16
    17     TYPE tokenTableType IS TABLE OF VARCHAR2(4000) INDEX BY BINARY_INTEGER;
    18     tokenChar VARCHAR2(4000) := '," ';
    19     tokens tokenTableType;
    20     vCnt INTEGER := 1;
    21     myLine VARCHAR2(4000) := NULL;
    22     Line VARCHAR2(4000) := NULL;
    23     vPos INTEGER := 1;
    24
    25     TYPE form_rec IS RECORD (
    26        table_name VARCHAR2(100),
    27        db_column VARCHAR2(100),
    28        db_col_value VARCHAR2(1000));
    29
    30     TYPE form_type IS TABLE OF form_rec INDEX BY BINARY_INTEGER;
    31     web_form_array form_type;
    32
    33  BEGIN
    34     dbdata.DELETE;
    35  -- NOTE: Load the below table(with values specified) for each table constraint
    36
    37     web_form_array(v_db_values).table_name := 'T';
    38     web_form_array(v_db_values).db_column := 'ID';
    39     web_form_array(v_db_values).db_col_value := :new.ID;
    40     v_db_values := v_db_values +1;
    41
    42     FOR cns_rec IN(SELECT *
    43                    FROM TABLE ( CAST(documents_cons_dml('T') AS DbCons_documents_Array ))) LOOP
    44        line := cns_rec.constraint_where;
    45        v_sql := 'SELECT count(*) FROM '||cns_rec.constraint_column;
    46        IF INSTR(line,',',1,1) <= 0 THEN
    47           FOR find_web_frm_val IN 1 .. web_form_array.COUNT LOOP
    48              IF cns_rec.table_name = web_form_array(find_web_frm_val).table_name AND
    49                 REPLACE(line,'"','') = web_form_array(find_web_frm_val).db_column THEN
    50
    51                 v_literal_value :=CONCAT(CONCAT('''',web_form_array(find_web_frm_val).db_col_value),'''');
    52                 v_sql := v_sql||' WHERE '||' '||web_form_array(find_web_frm_val).db_column||' = '||v_literal_value;
    53              END IF;
    54           END LOOP;
    55        ELSE
    56           WHILE (vPos <= LENGTH(line)) LOOP
    57              IF (LENGTH(REPLACE(tokenChar,substr(line, vPos, 1), '')) = LENGTH(tokenChar)) THEN
    58                 myLine := myLine || substr(line, vPos, 1);
    59              ELSIF (myLine IS NOT NULL) THEN
    60                 tokens(vCnt) := myLine;
    61                 FOR find_web_frm_val IN 1 .. v_db_values LOOP
    62                    IF cns_rec.table_name = web_form_array(find_web_frm_val).table_name AND
    63                          MYLine = web_form_array(find_web_frm_val).db_column THEN
    64                       v_literal_value := CONCAT(CONCAT('''',web_form_array(find_web_frm_val).db_col_value),'''');
    65                    END IF;
    66                 END LOOP;
    67                 IF vCnt = 1 THEN
    68                    v_sql := v_sql||' WHERE '||' '||myLine||' = '||v_literal_value;
    69                 ELSE
    70                    v_sql := v_sql||' AND '||' '||myLine||' = '||v_literal_value;
    71                 END IF;
    72                 myLine := null;
    73                 vCnt := vCnt + 1;
    74              END IF;
    75              vPos := vPos + 1;
    76           END LOOP;
    77
    78           IF (myLine IS NOT NULL) THEN
    79              tokens(vCnt) := myLine;
    80           END IF;
    81           vCnt := 1;
    82           vPos := 1;
    83        END IF;
    84
    85        OPEN dup_rec_cv FOR v_sql;
    86        FETCH dup_rec_cv INTO v_dup_count;
    87        CLOSE dup_rec_cv;
    88        IF cns_rec.column_position = 'R' THEN
    89           IF v_dup_count <= 0 THEN
    90              v_error_relay := 'The form field value for Database Column '||' '||line||' '||' that was entered does not exist';
    91              RAISE nforeign_key;
    92           END IF;
    93        ELSIF cns_rec.column_position = 'U' THEN
    94           IF v_dup_count > 0 THEN
    95              RAISE DUP_VAL_ON_INDEX;
    96           END IF;
    97        END IF;
    98     END LOOP;
    99  EXCEPTION
    100     WHEN DUP_VAL_ON_INDEX THEN
    101        raise_application_error(-20101, 'Attempted to update duplicate. Cannot update '||:new.ID);
    102     WHEN nforeign_key THEN
    103        raise_application_error(-20101, v_error_relay||' '||' YOUR MESSAGE HERE '||:new.ID);
    104  END;
    105  /
    Trigger created.So, lets try this puppy out.
    SQL> INSERT INTO t1 VALUES (1, 'T1 ONE');
    1 row created.
    SQL> COMMIT;
    Commit complete.I want at least one valid value to make sure I can actually insert something without dying on the trigger.
    SQL> INSERT INTO t VALUES (1, 'T One');
    1 row created.
    SQL> COMMIT;
    Commit complete.Which we can. Now lets test the Primary Key.
    SQL> INSERT INTO t VALUES (1, 'T One');
    INSERT INTO t VALUES (1, 'T One')
    ERROR at line 1:
    ORA-00001: unique constraint (OPS$ORACLE.SYS_C0027113) violatedOOPS, that's Oracle's message. Well, maybe it's because you are only checking cns_rec.column_position for R or U and my constraint is a P, and by the way, your function does not return the Primary Key for the table passed at all.
    So, lets try the foreign key:
    SQL> INSERT INTO t VALUES (2, 'T Two');
    INSERT INTO t VALUES (2, 'T Two')
    ERROR at line 1:
    ORA-02291: integrity constraint (OPS$ORACLE.T_FK) violated - parent key not foundOOPS. So, for every valid insert I am doing a huge amount of extra work, and I still get Oracle's errors when it's wrong. If I have screwed something up in the set-up, please feel free to post a working example exactly as I did here.
    John

Maybe you are looking for

  • Split PO Line into multiple shipments

    Hi , I have following situation on our PO. We create a PO with line info as ITEM DATE PRICE QTY ABC 1-JUN-08 100 1000 we provide this to supplier and after their assesment after a week or so supplier gives back tentive ship date 1-JUN-08 300 3-JUN-08

  • Why I can't sync firefox after using "restart with Addons disabled"? Why It's showing account not found?

    I'm using firefox sync with multiple desktop and laptop, even with Linux and windows environments since long, without any problem. Recently, I've used "Restart with addons disabled" option. Since then I can't setup sync. It's showing account or usena

  • Quality Lost On Preview/Edit

    I have captured several scenes and saved them as avi files. These files play perfectly in Windows Media Player. However as soon as I preview these files within PE the quality of the video degrades significantly. When paused the shot looks fine, howev

  • Query on EO Object

    Hello Gurus.. I have a requirement. I have a EO - "InsertDeviceDetailsEO"; VO - "InsertDeviceDetailsEOView" and AM - "DeviceDetailsAM" I have a Page DeviceDetails with a button "CreateDevice". When user clicks on this button a new page is open for en

  • Lightroom export - relative subdirectory

    Hi, this question is pretty much what I want to ask (http://forums.adobe.com/message/1461872#1461872) but the answer is not clear to me. I want to create export pre-sets in LR 2.4 and keep them in relative subdirectories. Say I attend an event I want