Creating a view with a primary key

I want to create a view with a defined primary key. I understand
the view is created within a select statement, but do not
understand how you would define a particular field as a primary
key in the view. Also if your select statement attempts to build
the view and has duplicate keys in the select result set, what
would happen when the duplicate key is found? Would it just not
include the duplicate key in the view?
Thanks in advance for your help.
-Pat

I have a rather difficult problem with duplicate invoice numbers
contained in unique records. In other words I have many records
that appear as follows:
3593, 0004009090, CUSTOMER, TAX, 20000117,014011976-01
4411, 0004009090, CUSTOMER, TAX, 20000718,014011976-01
The last field is invoice number '014011976-01' In my case I am
building a flat file using UTL_FILE for loading into SAP
Business Warehouse. In SAP I need to have Invoice number as a
key in which case I can't have duplicate invoice numbers. All
the SQL I have tried to date returns a large amount of records
similar to the above records. I am selecting these records from
4 different schemas which represent 4 different companies. I
realize the data is the problem and that the vendor of the
product I am working with should not allow records with
duplicate invoice numbers, but I have to get the data loaded as
that is what they want and are paying for. So back to my View. I
was hoping to create a view and be able to work in the view to
remove duplicate records prior to writing them to a file. Any
suggestions are welcomed.
Thanks
-Pat

Similar Messages

  • Creating Materialized View with the Distinct key word

    Hi
    I need help to create Materialized View with the Distinct key word.
    my query is
    select distinct col1, col2 from t1;
    is there any alternate of DISTINCT because I can not refresh the MV as fast on demand if I am using it and Fast on Demand is a must for me.

    hi
    check out this link
    http://download-west.oracle.com/docs/cd/B12037_01/server.101/b10736/basicmv.htm#i1007299
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/intro.htm#sthref183
    hope this helps
    CHeers

  • EF beta - views with no primary key

    When importing views into the entity framework designer, it often gives this error (in the edmx file only; no error is shown in the UI):
    warning 6013: The table/view '[view name]' does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity, you will need to review your schema, add the correct keys, and uncomment it.
    I don't want to cloud the issue by going into the details of the views in question; there will always be views where no PK can be inferred automatically, for many reasons. And I am quite happy to define the key fields myself after import. The problem is that it can't be imported at all. So my question to the ODP.NET developers is: can you just import it, and leave me to define the PK?
    The workaround I am using is:
    1) define a temp table of the same structure
    2) temporarily recreate the view as "select * from [temp table]"
    3) update the model from database
    3) recreate the proper view
    But it's a pain. I have to remember to do that every time I update the model from the database. If I forget, it wipes the mapping, and I have to redefine it manually, field by field.

    Unfortunately there is still a problem, in a minority of cases:
    Error 75: Key Part: '[field name]' for type [view name] is not valid. All parts of the key must be non nullable.
    This happens when the view field is not marked "not null". Generally it flows through from the underlying table field. But one of my views involves a "union all". The underlying table fields are marked "not null" but it doesn't make it through the "union all". The view has a primary key, but still the error.
    I would rather it just trust me that primary key fields will never be null.

  • Create edit form based on view with multiple column key

    Hi
    I have a requirement to create a form to update some tables columns based on a view.
    The problem is that the view has a primary key of 4 columns.
    I have tried to create a rowid key based on one underlying table but this does not work.
    I am calling the form from an interactive report but can only pass 3 keys to the form, so only get 3 fields populated.
    Is there some way i can create the form manually as the wizards cannot cope with this requirement?
    My view is here:
    CREATE OR REPLACE FORCE VIEW "DMOADMIN"."MO_STATUS_LOG_VIEW" ("MONEY_ORD_NO", "STATUS_CODE", "DESCRIP", "STATUS_DATE_TIME", "TXN_DATE_TIME", "LLOG_ID", "LINE_SEQ_NO", "CANCEL_IND", "PROCESS_ID", "PBU_ID", "TXN_SEQ_NO", "CANCEL_REASON", "CONDITION_ID", "ADMIN_DATE_TIME", "ADMIN_LLOG_ID") AS
    SELECT a.money_ord_no,
    b.status_code,
    b.descrip,
    a.status_date_time,
    c.txn_date_time,
    c.llog_id,
    c.line_seq_no,
    c.cancel_ind,
    c.process_id,
    c.pbu_id,
    c.txn_seq_no,
    c.cancel_reason,
    c.condition_id,
    d.txn_date_time admin_date_time,
    d.llog_id admin_llog_id
    FROM mo_status a,
    mo_status_desc b,
    host_txn_log c,
    host_admin_log d
    WHERE a.status_desc_id = b.id
    AND a.money_ord_no = c.money_ord_no(+)
    AND a.status_date_time = c.txn_date_time(+)
    AND a.money_ord_no = d.money_ord_no(+)
    AND a.status_date_time = d.txn_date_time(+)
    WITH CHECK OPTION;
    I have tried to populate the data using with an on load process using a plsql query but it is not working. I get no data found error message. Help!

    Hi Erwin,
    I have a similar situation.
    Tabular form based on a view. The view contains a table in a another instance via dblink and everything works fine.
    The only one difference between my and your view is that my "instead of" view is only for UPDATE. You must to have "intead of" trigger only for UPDATE. Insert and delete works fine withoust "instead of" trigger.
    So, try to delete INSERT and DELETE words from your "INSTEADOFBUBA" trigger.
    hope it helps,
    Mzz

  • Insert values of form on a table with compound primary keys in APEX

    Good evening,
    I have a table with compoud primay keys. On ER model I had a many to many relation and when I coverted to relational model I've got a table with the primary keys of the two entities.
    My problem now is that I am trying to build an APEX application with a Form/Report and I want to insert a tuple both on the "entity" and on the table with two primary keys.
    I created a trigger with
    CREATE OR REPLACE TRIGGER ins_key_elem
    INSTEAD OF INSERT
    ON v_key_elem
    REFERENCING NEW AS NEW
    FOR EACH ROW
    BEGIN
    INSERT INTO elem_type (elem_key, type_key)
    VALUES (:NEW.elem_key, :NEW.type_key);
    INSERT INTO elem(elem_key, name)
    VALUES (:NEW.elem_key, :NEW.name);
    END;
    Is that ok? If it is, now how I can use that trigger to do what I need? i.e. insert the tuple on the two tables when I use the create button of the form
    Edited by: 934530 on May 15, 2012 2:36 PM

    Nevermind...figured it out. Was able to set the value on the Report Attributes page.

  • DBMS_CDC find only the columns that are changed along with the primary key in the table

    Hello,
    We are having a requirement to find the change data in the production environment.
    We are planning to use the DBMS_CDC utility.
    But for  example in the create change table 1 picked emp_id,ename, address, salary,dob.
    I have a sample data of
    empid
    ename
    address
    salary
    DOB
    1
    test1
    24 test street
    2000
    20-Jan-98
    2
    test2
    25 test street
    2500
    15-Aug-97
    if ename for empid 1 is changed to test1_test3 from test1.
    My CDC is capturing  the values in the old and new values in the 5 columns.
    But i need to get only the empid (primary key of the source table) and the ename column as only that's been updated not the rest of the 3 columns.
    Can i accomplish this.
    Please advice.

    Hello,
    Thanks for the information.
    but if i change the change table  then i will miss the other columns right?
    I want to get the columns( empid and ename) only if ename is changed. i.e when ever any column in emp table changes i need to get all the columns where the data is changed along with the primary key columns empid.
    Is there any way i can tweak the parameters so that i can achieve this or is there any other way using the cdc i can get this data.
    Thanks

  • How to Work with Composite Primary Key

    Hi All,
    I'm working with Toplink JPA. Here I have A problem with inserting into database table which have composite Primary Key.
    What I'm doing is, I have two tables. to maintain many to many relation between these two tables I created another intermediate table which consists of foreign Keys (reference) of above two tables.
    Now these two foreign Keys in the Intermediate table made as composite Primary Keys.
    When I'm trying to the data in the Intermediate table I'm getting the foreign Keys values are null..
    could anyone suggest me how to work with composite Primary Keys
    Thanks,
    Satish

    I have the same problem, I have 3 tables with a join table joining them all. I have created an intermediate table entity. When I go to create a an entry, it says that I cannot enter null into "ID". Here is the SQl toplink generates:
    INSERT INTO Z_AUTH_USER_AUTHORIZATION (CONTEXT_ID, AUTHORIZATION_ID, USER_ID) VALUES (?, ?, ?)
    bind => [null, null, null]
    Here are the classes:
    -----------------------Join Table-----------------------------------------------
    @Entity()
    @Table(name = "Z_AUTH_USER_AUTHORIZATION")
    public class AuthUserAuthorization implements Serializable{
    @EmbeddedId
    private AuthUserAuthorizationPK compId;
    // bi-directional many-to-one association to AuthAuthorization
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "AUTHORIZATION_ID", referencedColumnName = "ID", nullable = false, insertable = false, updatable = false)
    private AuthAuthorization authAuthorization;
    // bi-directional many-to-one association to AuthContext
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "CONTEXT_ID", referencedColumnName = "ID", nullable = false, insertable = false, updatable = false)
    private AuthContext authContext;
    // bi-directional many-to-one association to AuthUser
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "USER_ID", referencedColumnName = "ID", nullable = false, insertable = false, updatable = false)
    private AuthUser authUser;
    ---------------------------------------User table--------------------------------------------------------------
    @Entity()
    @Table(name = "Z_AUTH_USER")
    public class AuthUser implements Serializable, IUser{
    @Id()
    @SequenceGenerator(name = "AUTH_USER_ID_SEQ", sequenceName = "Z_AUTH_USER_ID_SEQ")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AUTH_USER_ID_SEQ")
    @Column(name = "ID", unique = true, nullable = false, precision = 10)
    private Integer id;
    // bi-directional many-to-one association to AuthUserAuthorization
    @OneToMany(mappedBy = "authUser", fetch = FetchType.EAGER)
    private java.util.Set<AuthUserAuthorization> authUserAuthorizations;
    -----------------------------------Context table-----------------------------------------------------------------
    @Entity()
    @Table(name = "Z_AUTH_CONTEXT")
    public class AuthContext implements Serializable, IContext{
    @Id()
    @SequenceGenerator(name = "AUTH_CONTEXT_ID_SEQ", sequenceName = "Z_AUTH_CONTEXT_ID_SEQ")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AUTH_CONTEXT_ID_SEQ")
    @Column(name = "ID", unique = true, nullable = false, precision = 8)
    private Integer id;
    // bi-directional many-to-one association to AuthUserAuthorization
    @OneToMany(mappedBy = "authContext", fetch = FetchType.EAGER)
    private java.util.Set<AuthUserAuthorization> authUserAuthorizations;
    ----------------------------Authorization table-------------------------------------------------
    @Entity()
    @Table(name = "Z_AUTH_AUTHORIZATION")
    public class AuthAuthorization implements Serializable, IAuthorization{
    @Id()
    @SequenceGenerator(name = "AUTH_AUTHORIZATION_ID_SEQ", sequenceName = "Z_AUTH_AUTHORIZATION_ID_SEQ")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AUTH_AUTHORIZATION_ID_SEQ")
    @Column(name = "ID", unique = true, nullable = false, precision = 8)
    private Integer id;
    // bi-directional many-to-one association to AuthUserAuthorization
    @OneToMany(mappedBy = "authAuthorization", fetch = FetchType.EAGER)
    private java.util.Set<AuthUserAuthorization> authUserAuthorizations;
    I have tried to create the new entity several ways. I have tried to create one with the default constructor then set this entity on each of the other entities, I have also tried to pass in the entities to the join entity and set them there, but this doesn't work. Any help would be very appreciated!
    Thanks,
    Bill

  • Problem with Sting Primary Key

    I have probleme with Sting Primary Key
    when i create new row
    System.out.println("is new:" + acct.getEntityState());
    show 1 - this row is not new
    why?

    Hi,
    I was unable to reproduce this behavior on OWM 10.1.0.8. It appears that you have a SR open for this issue, so I would suggest to continue with that process.
    Regards,
    Ben

  • Problem with varchar2 primary key..

    OWM version 10.1.0.8
    When I am trying to add a column in a version enable table with varchar2 primary key, it fails.
    If primary key is numeric it works.
    See below the test case.
    -- CASE 1. When primary key is number.
    SQL> create table wmtab
    ( wmtab_id number,
    price number,
    title varchar2(80),
    AUTHOR VARCHAR2(10)
    Table created.
    SQL> ALTER TABLE wmtab add (CONSTRAINT PK_kontakt PRIMARY KEY (wmtab_id));
    Table altered.
    SQL> EXECUTE DBMS_WM.EnableVersioning('WMTAB');
    PL/SQL procedure successfully completed.
    SQL> CALL DBMS_WM.BEGINDDL('WMTAB');
    Call completed.
    SQL> ALTER TABLE wmtab_lts add ( FREIGEGEBEN varchar2(1));
    Table altered.
    SQL> CALL DBMS_WM.commitDDL('WMTAB');
    Call completed.
    -- CASE 2. When primary key is varchar2.
    SQL> create table wmtab
    (wmtab_id varchar2(10) constraint wmtab_pk primary key,
    price number,
    title varchar2(80),
    AUTHOR VARCHAR2(10)
    Table created.
    SQL> EXECUTE DBMS_WM.EnableVersioning('WMTAB');
    PL/SQL procedure successfully completed.
    SQL> CALL DBMS_WM.BEGINDDL('WMTAB');
    Call completed.
    SQL> ALTER TABLE wmtab_lts add ( FREIGEGEBEN varchar2(1));
    Table altered.
    SQL> call DBMS_WM.CommitDDL('wmtab');
    call DBMS_WM.CommitDDL('wmtab')
    ERROR at line 1:
    ORA-20199: primary key columns cannot be added/dropped/modified/reordered for
    version enabled tables
    ORA-06512: at "SYS.OWM_DDL_PKG", line 6196
    ORA-06512: at "SYS.LT", line 11930
    ORA-06512: at line 1
    Same problem is reprosucible on OWM 10.2.0.1.
    But its working fine with varchar2 primary key On OWM 10.2.0.4.2/3
    Is there any workaround or we can get patch for 10.1.x.x?

    Hi,
    I was unable to reproduce this behavior on OWM 10.1.0.8. It appears that you have a SR open for this issue, so I would suggest to continue with that process.
    Regards,
    Ben

  • FindByKey with Composit Primary key

    Hi
    View Object based on Entity Object. Database table defined with Composit Primary Key.
    I have to query ViewObject using findByKey().
    Can any one help me how to use findByKey() using a composit primary key in ADF 11g.
    Thanks

    Hi,
    this is covered in the developer guide here:
    38.1.7 Understanding When You Can Use Partial Keys with findByKey()
    http://download.oracle.com/docs/cd/E12839_01/web.1111/b31974/bcadvvo.htm#ADFFD1189
    The key thing is to have your object types casted correctly or else null for your composite key.
    Brenden

  • How to do hibernate mapping for table or view without a primary key

    Hi,
    Anyone knows how to do hibernate mapping for table or view without a primary key?
    thanks.
    cc

    or you can make all column primary key .Anybody seriously considering that as a good idea should understand the implications:
    1. this requires that each row be unique - that's a minor issue normally, but can be a significant problem in some cases
    2. in practically all databases, a primary key constraint creates a unique index - this has many implications:
    a) in most databases, the index stores a copy of the column data that is indexed - this suggestion therefore more than doubles the data storage required for the data
    b) whenever an indexed column is changed, the index has to be maintained - this suggestion then more than doubles the work that each UPDATE statement has to do, since both the table and the index have to be maintained for any UPDATE at all
    This might work OK for toy projects, but it doesn't scale well at all...

  • How can i create a view with jdevlopper 10132

    hi,
    i want to know how to create a view with JDeveloper 10132.
    thanks

    Sorry, but I had to jump in here.
    7rouz - you've certainly violated the 10 commandments for posting here...
    Do you want to:
    1). Create a database view directly in the database
    2). Model a database view using the database modeller
    3). Create an ADF BC View Object
    4). Create some type of visual object (web page, Swing panel)
    5). something else.
    Your question is too ambiguous to yield an answer, unless by luck.
    Regards,
    John

  • How to create a view with parameter?

    who can tell me hwo to create a view with
    parameters just like a cursor?

    Hi,
    This is not possible in Oracle. What u can do is create the view without the where clasue and supply the where clause at runtime.
    Hope this helps...
    Regards,
    Ganesh R

  • Need help in creating a view with Encryption for hiding the code used by the multiple users

    Hi,
    Can anyone help me out in creating view with encryption data to hide the stored procedure logic with other users.
    I have create a stored procedure with encryted view but while running this manually temporary views are getting created, therefore the problem is if there are 500 entries then 500 temp views will get created.
    Any solution to aviod creating temporary views, please refer my code below
    USE [etl_validation]
    GO
    /****** Object:  StoredProcedure [dbo].[Pr_DBAccess_mod]    Script Date: 05/23/2014 12:53:22 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[Pr_DBAccess_mod](@ETL_CONFIG_ID INT)
    AS
    BEGIN
    DECLARE @openquery NVARCHAR(MAX),
     @DATABASENAME NVARCHAR(100),
     @HIERNAME NVARCHAR(100),
     @TABLENAME NVARCHAR(100),
     @SERVERTYPE NVARCHAR(100),
     @SERVERNAME NVARCHAR(100),
     @USERNAME NVARCHAR(100),
     @PASSWORD NVARCHAR(100),
     @ETL_CONFIG_IDN NVARCHAR(100);
     SET @ETL_CONFIG_IDN=CAST(@ETL_CONFIG_ID AS NVARCHAR);
     SET @TABLENAME='Department';
     SET @SERVERTYPE='SQL';
     SET @SERVERNAME ='192.168.31.176';
     SET @DATABASENAME='AdventureWorks2008R2';
     SET @HIERNAME = 'HumanResources';
     IF @SERVERTYPE='SQL'
     BEGIN
    /*SET @openquery= 'SELECT * INTO ##TestTable
                     FROM OPENROWSET(''SQLNCLI'',''server=192.168.31.176;Trusted_Connection=yes;'','''+@query+''')'
    SET @openquery=  'CREATE VIEW '+@TABLENAME+@ETL_CONFIG_IDN+
                     ' WITH ENCRYPTION AS SELECT * FROM OPENROWSET(''SQLNCLI'',''SERVER='+@SERVERNAME+';TRUSTED_CONNECTION=YES;'',''SELECT * FROM '+@DATABASENAME+'.'+@HIERNAME+'.'+@TABLENAME+''')'
    SELECT @openquery
    END
    EXECUTE sp_executesql @openquery
    END

    Hi aa_rif,
    According to your description and code message, you execute the sp_executesql statement in your stored procedure, it indeed create many views with a tablename and ETL_CONFIG_ID named. If you need not to use these temporary views, you can delete them when
    it contains the tablename in one view name.  
    In addition, if you want to create view with encryption in SQL Server, you can use directly the ENCRYPTION option to encrypt the T-SQL of a view in create view commands, for more information, see:
    http://learnsqlserver.in/4/Create-View-With-Encryption.aspx. if not, you can descript more detail about requriements, so that more forum members can involve into the thread and help you
    out. 
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • Duplicate record with same primary key in Fact table

    Hi all,
       Can the fact table have duplicate record with same primary key . When i checked a cube i could see records with same primary key combination but the key figure values are different. My cube has 6 dimentions (Including Time,Unit and DP) and 2 key figures. So 6 fields combined to form the composite primary key of the fact table. When i checked the records in se16 i could see duplicate records with same primary key. Ther are no parallel loading happening for the cube.
    BW system version is 3.1
    Data base is : Oracle 10.2
    I am not sure how is this possible.
    Regards,
    PM

    Hi Krish,
       I checked the datapacket dimention also. Both the record have same dimention id (141). Except the Keyfigure value there is no other change in the Fact table record.  I know this is against the basic DBMS primary key rule. But i have records like this in the cube.
    Can this situation arise when same records is there in different data packet of same request.
    Thx,
    PM
    null

Maybe you are looking for

  • Close a PO so that no further postings hit it

    Help, I am interested in knowing how to close a PO so that no further invoices and goods receipts may be entered. Even when we have marked Final Invoice and Delivery complete boxes, we can still enter another invoice against that PO. We are using SRM

  • Mapping of transmission line in SAP PM

    Hi Friends, I have a scenario to map in SAP PM. I have to map electrical transmission lines of client into SAP for their maintenance. The transmission lines are like 50-60 km long and they pass through different Area office(Considered as Plant). Main

  • Xclock - solaris 8

    Not sure this is really the right forum for this, but I couldn't see where else to post it. My customer wants to use xclock to have a permanently displayed clock on the screen for the user. The system is a network monitoring one, so they need to be a

  • Elements and Premiere stopped working

    Last week I purchased Elements 8.0 and Premiere (Windows 7), the install went perfect but suddenly both programs only show the tutorials after start-up. There is no option to stop the tutorial, and both programs are greyed out. Probably a re-install

  • No connection 6610i

    Despite having downloaded the Nokia PC Suite and purchased the right (CA-42) cable for my mobile, I remain unconnected during the initial wazard connection process! - My USB ports all work successfully when using other removeable devices. It just see