Specify an object in INSERT INTO clause

I need to INSERT or UPDATE specific object attribute.
Example :
CREATE TYPE a AS OBJECT( attr1 varchar2(10), attr2 varchar2(10));
CREATE TYPE b AS OBJECT( attr3 varchar2(10), attr4 a);
CREATE TYPE c AS TABLE OF b;
CREATE TYPE d AS OBJECT( attr5 varchar2(10), attr6 b, attr7 c);
CREATE TABLE d_tab OF d
NESTED TABLE attr7 STORE AS attr7_nest;
It's easy to INSERT an object but how can I insert a specified attribute of an object ?
I try these :
insert into d_tab (attr5, attr6.attr3) values ('TEST2','TEST2'); --> ORA-00904
insert into d_tab (attr5, attr6) values ('TEST2','TEST2'); --> ORA-00932
insert into d_tab (attr5, attr6) values ('TEST2',b('TEST2')); --> ORA-02315
and what about attr7 ???
How insert or update only the attr1 of object b of first row of table_type c of table d_tab ??

Not really of common use, I think, but WITH CHECK OPTION option could be one reason for using that. Let's see an example :
SQL> INSERT INTO
  2  (SELECT empno, ename, deptno FROM emp WHERE deptno < 20)
  3* VALUES (1111, 'Brown', 30)
SQL> /
1 row created.That's the same as
SQL> insert into emp (empno, ename, deptno)
  2  values(1111, 'Brown', 30);But
SQL> INSERT INTO
  2  (SELECT empno, ename, deptno FROM emp WHERE deptno < 20 WITH CHECK OPTION)
  3* VALUES (2222, 'Green', 30)
SQL> /
(SELECT empno, ename, deptno FROM emp WHERE deptno < 20
ERROR at line 2:
ORA-01402: view WITH CHECK OPTION where-clause violation
SQL>Paul

Similar Messages

  • Subquery in insert into clause

    what is the use of using subquery in insert into clause.
    e.g. insert into (select empno from emp)
    values(1234)
    regards
    kiran

    Not really of common use, I think, but WITH CHECK OPTION option could be one reason for using that. Let's see an example :
    SQL> INSERT INTO
      2  (SELECT empno, ename, deptno FROM emp WHERE deptno < 20)
      3* VALUES (1111, 'Brown', 30)
    SQL> /
    1 row created.That's the same as
    SQL> insert into emp (empno, ename, deptno)
      2  values(1111, 'Brown', 30);But
    SQL> INSERT INTO
      2  (SELECT empno, ename, deptno FROM emp WHERE deptno < 20 WITH CHECK OPTION)
      3* VALUES (2222, 'Green', 30)
    SQL> /
    (SELECT empno, ename, deptno FROM emp WHERE deptno < 20
    ERROR at line 2:
    ORA-01402: view WITH CHECK OPTION where-clause violation
    SQL>Paul

  • Help w/ Flash Object inserted into DW page

    Hi,
    I'm using DW MX2004 on a Pwrbk G4. I created a Flash object
    (a page-flipping gallery) in Flash, and while it previews fine in
    Flash MX'04 (size of the .swf in pixels, I WANT it to be 1050 W
    & 713 H so the page is big enough to view well on a browser and
    the pages can flip correctly), once the object is inserted into DW,
    it isn't showing up as the same size. The default size in DW is 550
    x 440 I think, and when I try to change the dimensions--even to the
    exact size it was in Flash--the images once previewed are always
    distorted or the preview shows only part of the image and the pages
    aren't flipping (this, I believe b'cos the entire .swf movie isn't
    displayed so the corners can be dragged/clicked). I know I'm doing
    something wrong or missing some step, can someone help?
    Thanks

    I am not sure what exactly you are experiencing but it sound
    like something somewhat similar to what I recently went through. I
    tried to embed a swf in my HTML page using DW and there was a
    border that would appear that was not there in FLash. I eventually
    found a setting in Flash Publish settings that said " no border "
    ...this was under the "HTML" settings in the Publish settings
    dialog box. I published my html page and then cut most of the code
    from that page and manually embed it in my Dw html page. Kind of
    pain but it worked.
    Try publishing the HTML page from flash and then viewing that
    page in DW and see if your swf is the right size. It may be that
    you can't use DW to Embed your SWF.
    Jordy

  • Unable to insert into remote table

    I have created a dblink (public), and a synonym(synonym1) pointing to a table in the remote database.
    When I try to create a form based on the synonym the form creation fails with many errors saying "Synonym Trnslation no longer supported". I have tested the synonym via a dynamic page an it is valid and working.
    I then try to refer to the object directly by using owner.table@dblink. This works fine until I try and insert into the remote table. Then I get the error "An unexpected error occurred: ORA-22816: unsupported feature with RETURNING clause (WWV-16016) ". Has anyone solved this. I can only assume that portal can somehow insert data into a remote table via a form. What use is it if it cant???

    I am not clear on that Synonym ... but the following note solved the problem:
    Subject: How to create a form on a view (and avoid WWV-16016)
    Doc ID: Note:155654.1 Type: PROBLEM
    Last Revision Date: 19-MAR-2003 Status: PUBLISHED
    Problem Description
    Portal 3.0.9.X
    If you create an updateable view on two tables, with the needed
    associated "INSTEAD_OF" trigger to perform the insert or update.
    A Form on this view created in Portal returns the following error on
    insert or update:
    An unexpected error occurred: ORA-22816: unsupported feature with
    RETURNING clause (WWV-16016).
    Let's take a sample:
    CREATE OR REPLACE VIEW V_EMP_DEPT ( EMPNO,
    ENAME, JOB, DEPTNO, DNAME,
    LOC ) AS select
    e.empno
    ,e.ename
    ,e.job
    ,d.deptno
    ,d.dname
    ,d.loc
    from emp e, dept d
    where e.deptno = d.deptno
    grant select,insert,update,delete on v_emp_dept to public;
    create or replace TRIGGER VEMPDEPT_INSTEAD_OF_TRG
    INSTEAD OF UPDATE or INSERT
    ON v_emp_dept
    REFERENCING OLD AS OLD NEW AS NEW
    declare
    begin
    if updating then
    if :new.empno != :old.empno then
    raise_application_error(20001,'EMPNO could not be modified');
    end if;
    if :new.loc != :old.loc then
    raise_application_error(20001,'LOC could not be modified');
    end if;
    if :new.dname != :old.dname then
    raise_application_error(20001,'dname could not be modified');
    end if;
    if :new.ename != :old.ename then
    update emp set ename=:new.ename where empno = :old.empno;
    end if;
    if :new.job != :old.job then
    update emp set job=:new.job where empno = :old.empno;
    end if;
    if :new.deptno != :old.deptno then
    update emp set deptno=:new.deptno where empno = :old.empno;
    end if;
    end if;
    if inserting then
    -- specify only valid deptumbers
    insert into emp(empno,ename,job,deptno) values
    (:new.empno,:new.ename,:new.job,:new.deptno);
    end if;
    end;
    - Create a "Forms Based on a Table or View" on this view : 'V_EMP_DEPT'
    - In the step 4, choose 'order by dname' in place of 'rowid'
    The rest is default
    - Run the form
    - Push on the button query
    - change one of the field and push the update button
    You will see the error
    Error: An unexpected error occurred: ORA-22816: unsupported feature
    with RETURNING clause (WWV-16016)
    Explanation
    You are running in Bug 1589656. The code generated by Portal is using
    RETURN clause for the UPDATE or INSERT SQL call to get the ROWID.
    This is not possible on a VIEW created on two (or more) tables.
    Solution Description
    A possible workaround is to replace the insert button code and update button
    code with calls to procedures doing exactly what is done in the trigger.
    Assumption is made that the empno column could not be updated.
    This implies that the validation options updatable checkbox for the empno column
    is unchecked.
    In the above example, this gives:
    -- procedure to insert data as done in the trigger
    create or replace procedure V_EMP_DEPT_INSERT(
    p_session in out PORTAL30.wwa_api_module_session
    IS
    "_block" varchar2(30) := 'DEFAULT';
    rec SCOTT.V_EMP_DEPT%ROWTYPE;
    begin
    rec.EMPNO:=p_session.get_value_as_NUMBER(
    p_block_name => "_block",
    p_attribute_name => 'A_EMPNO',
    p_index => 1
    rec.ENAME:=p_session.get_value_as_VARCHAR2(
    p_block_name => "_block",
    p_attribute_name => 'A_ENAME',
    p_index => 1
    rec.JOB:=p_session.get_value_as_VARCHAR2(
    p_block_name => "_block",
    p_attribute_name => 'A_JOB',
    p_index => 1
    rec.DEPTNO:=p_session.get_value_as_NUMBER(
    p_block_name => "_block",
    p_attribute_name => 'A_DEPTNO',
    p_index => 1
    insert into scott.emp(empno,ename,job,deptno)
    values (rec.empno,rec.ename,upper(rec.job),rec.deptno);
    exception
    when others then
    rollback;
    raise;
    end;
    -- procedure that update data as done in the trigger
    create or replace procedure V_EMP_DEPT_UPDATE(
    p_session in out PORTAL30.wwa_api_module_session
    IS
    "_block" varchar2(30) := 'DEFAULT';
    old_rec SCOTT.V_EMP_DEPT%ROWTYPE;
    new_rec SCOTT.V_EMP_DEPT%ROWTYPE;
    begin
    new_rec.EMPNO:=p_session.get_value_as_NUMBER(
    p_block_name => "_block",
    p_attribute_name => 'A_EMPNO',
    p_index => 1
    new_rec.ENAME:=p_session.get_value_as_VARCHAR2(
    p_block_name => "_block",
    p_attribute_name => 'A_ENAME',
    p_index => 1
    new_rec.JOB:=p_session.get_value_as_VARCHAR2(
    p_block_name => "_block",
    p_attribute_name => 'A_JOB',
    p_index => 1
    new_rec.DEPTNO:=p_session.get_value_as_NUMBER(
    p_block_name => "_block",
    p_attribute_name => 'A_DEPTNO',
    p_index => 1
    new_rec.LOC:=p_session.get_value_as_NUMBER(
    p_block_name => "_block",
    p_attribute_name => 'A_LOC',
    p_index => 1
    select empno, ename, job, deptno, loc
    into old_rec.empno, old_rec.ename, old_rec.job,
    old_rec.deptno, old_rec.loc from scott.V_EMP_DEPT
    where empno = new_rec.empno;
    if new_rec.empno != old_rec.empno then
    raise_application_error(20001,'EMPNO could not be modified');
    end if;
    if new_rec.loc != old_rec.loc then
    raise_application_error(20001,'LOC could not be modified');
    end if;
    if new_rec.dname != old_rec.dname then
    raise_application_error(20001,'dname could not be modified');
    end if;
    if new_rec.ename != old_rec.ename then
    update scott.emp set ename=new_rec.ename where empno =
    old_rec.empno;
    end if;
    if new_rec.job != old_rec.job then
    update scott.emp set job=new_rec.job where empno = old_rec.empno;
    end if;
    exception
    when NO_DATA_FOUND then
    raise_application_error(20001,'EMPNO could not be modified');
    end;
    After creating this two procedures you have to edit the form and replace the
    Insert and Update button PLSQL event handling code.
    For the insert button: Select Insert in the PL/SQL Button Event Handler window
    and replace the original code with the following one::
    --- Type your PL/SQL code here...
    -- doInsert;--- This is the default handler
    --- ...and here, thanks...
    V_EMP_DEPT_INSERT( p_session => p_session);
    For the update button: Select Update in the PL/SQL Button Event Handler window
    and replace the original code with the following one:
    --- Type your PL/SQL code here...
    -- doUpdate;--- This is the default handler
    --- ...and here, thanks...
    V_EMP_DEPT_UPDATE( p_session => p_session );
    Remarks
    1) Don't forget to uncheck the updatable validation option for the empno column or
    you may see some errors raised by the update procedure or update the wrong record.
    2) If you don't want to write the "instead of trigger", you can simplify
    the code above by:
    - writing no instead of trigger at all
    - write the logic to the underlying tables in PL/SQL trigger of Portal
    ( here V_EMP_DEPT_UPDATE, V_EMP_DEPT_INSERT)
    - Manohar

  • How to insert Serialised Object(XML DOM) into Oracle Table(as BLOB or CLOB)

    we need a urgent help. How can we insert and retrieve the XML Document DOM Object into Oracle Table.Actually we used BLOB for insert the DOM Object,its inserted finely but we have a problem in retrieving that object, we got error when v're retrieving. so could you anyone tell us what's this exact problem and how can we reslove this problem If anyone knows or used this kind operation, pls let us know immediately.
    Thanks in advance.

    Please repost your question in the appropriate XML forum, http://forums.oracle.com/forums/index.jsp?cat=51

  • Inconsistent datatypes error when inserting into a object

    I am trying to insert some test data into the table emp.I have managed to succesfully create the objects and types but when I try to insert into the emp table I get a inconsistent datatypes error however I have checked the datatypes and they all seem fine. Can anyone help me.
    thanks
    CREATE OR REPLACE TYPE Address_T AS object
    (ADDR1                VC2_40,
    ADDR2               VC2_40,
    CITY_TX          VC2_40,
    COUNTY_CD          VC2_40,
    POST_CD          VC2_40);
    CREATE OR REPLACE TYPE PERSON_T AS OBJECT (
    LNAME_TX           NAME_T,
    FNAME_TX           NAME_T,
    BIRTH_DATE          DATE,
    TELEPHONE          VC2_20,
    EMAIL               VC2_40);
    CREATE OR REPLACE TYPE EMP_T AS OBJECT (
    EMP_ID     NUMBER (10),
    PERSON     PERSON_T,
    ADDRESS ADDRESS_T,
    HIRE_DATE DATE)
    CREATE TABLE EMP OF EMP_T
    (EMP_ID NOT NULL PRIMARY KEY);
    INSERT INTO EMP VALUES (1,           
    PERSON_T('PETCH',
    'GAVIN',
    '23-JAN-80',
    '(01964)550700',
    '[email protected]'),
    ADDRESS_T('67 CANADA',
    'WALKINGTON',
    'BEVERLEY',
    'EAST YORKSHIRE',
    'HU17 7RL'),
    '11-FEB-02'
    ERROR at line 1:
    ORA-00932: inconsistent datatypes

    Gavin,
    What is your VC2_40 and NAME_T type definition? Your insert used these as varchar2, which is a built-in type not a user-defined type. If you explicitly define these to be varchar2's, the insert statement works fine.
    Regards,
    Geoff
    I am trying to insert some test data into the table emp.I have managed to succesfully create the objects and types but when I try to insert into the emp table I get a inconsistent datatypes error however I have checked the datatypes and they all seem fine. Can anyone help me.
    thanks
    CREATE OR REPLACE TYPE Address_T AS object
    (ADDR1                VC2_40,
    ADDR2               VC2_40,
    CITY_TX          VC2_40,
    COUNTY_CD          VC2_40,
    POST_CD          VC2_40);
    CREATE OR REPLACE TYPE PERSON_T AS OBJECT (
    LNAME_TX           NAME_T,
    FNAME_TX           NAME_T,
    BIRTH_DATE          DATE,
    TELEPHONE          VC2_20,
    EMAIL               VC2_40);
    CREATE OR REPLACE TYPE EMP_T AS OBJECT (
    EMP_ID     NUMBER (10),
    PERSON     PERSON_T,
    ADDRESS ADDRESS_T,
    HIRE_DATE DATE)
    CREATE TABLE EMP OF EMP_T
    (EMP_ID NOT NULL PRIMARY KEY);
    INSERT INTO EMP VALUES (1,           
    PERSON_T('PETCH',
    'GAVIN',
    '23-JAN-80',
    '(01964)550700',
    '[email protected]'),
    ADDRESS_T('67 CANADA',
    'WALKINGTON',
    'BEVERLEY',
    'EAST YORKSHIRE',
    'HU17 7RL'),
    '11-FEB-02'
    ERROR at line 1:
    ORA-00932: inconsistent datatypes

  • How to insert into collection type of objects?

    Hello,
    Can any one help with the follwoing code below,where i cant insert into an instance of the table type within the pl/sql block.
    create type courselist is table of varchar2(25);
    create type student as object
    (name varchar2(20),
    courses courselist);
    create type student_typ is table of student;
    create or replace procedure test_nested as
    my_courses1 student_typ:=student_typ(student('harry',courselist('eco 2010','math 2010','acct 2010')));
    n_numb number;
    begin
    dbms_output.put_line('hello initial'||'-'||my_courses1.count);
    my_courses1.extend;
    n_numb:=my_courses1.next(my_courses1.first);
    dbms_output.put_line('Next Subscript :'||n_numb);
    dbms_output.put_line('hello after extend'||'-'||my_courses1.count);
    my_courses1(n_numb):=student_typ(student('Potter',courselist('eng 2010','bio 2010')));
    dbms_output.put_line(my_courses1(n_numb).name);
    exception
    when others then
    dbms_output.put_line(sqlerrm);
    end;

    Look at:
    my_courses1(n_numb):=student_typ(student('Potter',courselist('eng 2010','bio 2010')));my_courses1(n_numb) is of student type while student_typ(student('Potter',courselist('eng 2010','bio 2010'))) is table of student type. Change it to:
    my_courses1(n_numb):=student('Potter',courselist('eng 2010','bio 2010'));and you will be fine:
    SQL> create or replace
      2    procedure test_nested
      3      as
      4          my_courses1 student_typ:=student_typ(student('harry',courselist('eco 2010','math 2010','acct 2010')));
      5          n_numb number;
      6      begin
      7          dbms_output.put_line('hello initial'||'-'||my_courses1.count);
      8          my_courses1.extend;
      9          n_numb:=my_courses1.next(my_courses1.first);
    10          dbms_output.put_line('Next Subscript :'||n_numb);
    11          dbms_output.put_line('hello after extend'||'-'||my_courses1.count);
    12          my_courses1(n_numb):=student('Potter',courselist('eng 2010','bio 2010'));
    13          dbms_output.put_line(my_courses1(n_numb).name);
    14        exception
    15          when others then
    16            dbms_output.put_line(sqlerrm);
    17  end;
    18  /
    Procedure created.
    SQL> exec test_nested
    hello initial-1
    Next Subscript :2
    hello after extend-2
    Potter
    PL/SQL procedure successfully completed.
    SQL> SY.

  • Inserting into a doubly nested table through an object view

    Can anyone give me an example of an INSTEAD OF trigger that will mediate an INSERT into a doubly nested table of an Object View? Is there syntax that will allow it?

    Here's some code to demonstrate. Note that relational tables, not an object table, are used to store object instances:
    create or replace type TInnerNestedTable
    is table of varchar2(20)
    create or replace type TOuterNestedTable
    is table of TInnerNestedTable
    create or replace type TMyObject
    is object
         id     varchar2(20)
    ,     tab     TOuterNestedTable
    create
    table     T_MY_OBJECT
         id          varchar2(20)     not null
    ,     primary key (id)
    create
    table     T_MY_OBJECT_TAB_OUTER
         id          varchar2(20)     not null
    ,     outerIndex     integer          not null
    ,     primary key (id, outerIndex)
    ,     foreign key (id) references T_MY_OBJECT on delete cascade
    create
    table     T_MY_OBJECT_TAB_INNER
         id          varchar2(20)     not null
    ,     outerIndex     integer          not null
    ,     innerIndex     integer          not null
    ,     innerValue     varchar2(20)
    ,     primary key (id, outerIndex, innerIndex)
    ,     foreign key (id, outerIndex) references T_MY_OBJECT_TAB_OUTER on delete cascade
    create or replace view V_MY_OBJECT
    of TMyObject
    with object identifier (id)
    as
    select     t.id
    ,     cast(multiset(
              select     cast(multiset(
                        select     i.innerValue
                        from     T_MY_OBJECT_TAB_INNER i
                        where     i.id = o.id
                        and     i.outerIndex = o.outerIndex
                   ) as TInnerNestedTable)
              from     T_MY_OBJECT_TAB_OUTER o
              where     o.id = t.id
         ) as TOuterNestedTable)
    from     T_MY_OBJECT t
    create or replace trigger TR_II_V_MY_OBJECT
    instead of insert on V_MY_OBJECT
    for each row
    begin
         insert
         into     T_MY_OBJECT
              id
         values     (
              :new.id
         insert
         into     T_MY_OBJECT_TAB_OUTER
              id
         ,     outerIndex
         select     :new.id
         ,     rownum
         from     table(:new.tab) o;
         insert
         into     T_MY_OBJECT_TAB_INNER
              id
         ,     outerIndex
         ,     innerIndex
         ,     innerValue
         select     :new.id
         ,     o.outerIndex
         ,     rownum
         ,     value(i)
         from     (
              select     :new.id
              ,     rownum outerIndex
              ,     value(o) innerTab
              from     table(:new.tab) o
              ) o
         ,     table(o.innerTab) i;
    end;
    insert
    into     V_MY_OBJECT
    values     (
         new TMyObject(
              'A'
         ,     TOuterNestedTable(
                   TInnerNestedTable('A','B','C')
              ,     TInnerNestedTable('AA')
              ,     TInnerNestedTable('AB')
    insert
    into     V_MY_OBJECT
    values     (
         new TMyObject(
              'B'
         ,     TOuterNestedTable(
                   TInnerNestedTable('X','Y','Z')
              ,     TInnerNestedTable('Hello', 'World!')
    /Selecting from the view shows the results:
    select     value(o)
    from     V_MY_OBJECT o
    VALUE(O)(ID, TAB)
    TMYOBJECT('A', TOUTERNESTEDTABLE(TINNERNESTEDTABLE('A', 'B', 'C'), TINNERNESTEDTABLE('AA'), TINNERNESTEDTABLE('AB')))
    TMYOBJECT('B', TOUTERNESTEDTABLE(TINNERNESTEDTABLE('X', 'Y', 'Z'), TINNERNESTEDTABLE('Hello', 'World!')))
    2 rows selected.Hope that helps...
    Gerard

  • Problem Inserting into object view with OracleXmlSave

    Gurus,
    I'm trying to insert into an object view with
    multiple collections of objects representing a master/detail relationship and a CLOB column, but I've this error:
    oracle.xml.sql.OracleXMLSQLException: Error Interno
    at oracle.xml.sql.dml.OracleXMLSave.saveXML(OracleXMLSave.java:1967)
    at oracle.xml.sql.dml.OracleXMLSave.insertXML(OracleXMLSave.java:1060)
    at onix.interface_isbn.OnixXmlLoader.doInsert(OnixXmlLoader.java:165)
    at onix.interface_isbn.OnixXmlLoader.setLoader(OnixXmlLoader.java, Compiled Code)
    at onix.interface_isbn.OnixXmlLoader.<init>(OnixXmlLoader.java:23)
    at onix.interface_isbn.correrLoader.main(correrLoader.java:77)
    I'm using OracleXmlSave with insertXML method to do this.
    Is There any limitations to do that? (example
    number of tables into the view, columns datatype).
    I'd appreciate any comments
    Thank

    No known limitations. Please post the sample DDL to create your object types and object view, along with an example of the example XML document you're trying to insert.

  • #include "%(Filename)_i.h" inserted into C++ source after adding connection points to ATL object using wizard.

    What is the subsitution for this appearant macro?  Solution will not build if removed.
    Using
    Adding Connection Points to an Object directions.

    Hi Shawn,
    Since you have posted this issue to the VC++ forum, I think you would get better support there:
    http://social.msdn.microsoft.com/Forums/vstudio/en-US/8494410e-9578-4b67-a08d-3380aac10fcf/include-filenameih-inserted-into-c-source-after-adding-connection-points-to-atl-object?forum=vcgeneral#503cbc06-40a2-4073-a56e-1b384b11b56e
    So I will move this thread to the Off-topic forum. Thanks for your understanding.
    Sincerely,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How insert into another entity object

    Hi ,
    i hope find the solution for this case
    i am using jdeveloper 11.2
    and i have two entity object based on two table as follow
    1 - DocTransaction entity
    Attributes ( id , createdOn, createdBy ,modifiedOn,modifiedBy , docStatus-- default = 1-- , EmpId )
    2- transHistory entity
    Attributes ( id , transId--FK-- , Transdate, TransBy ,ToEmp , docStatus , docAction )
    when inserting row in DocTrasaction it will insert row in transHistory and when update docStatus in DocTransaction it will insert row with updated status in transHistory and so on ( every DML in first entity ocure will insert it in first entity )
    the problem is when docStatus updated after 7 days from creation with value (2 or 5 ) i want the row inserted in second entity with docStatus = 3 not ( 2 or 5 )
    and if docStatus in first entity not updated within 7 days then automatically change its status to 3
    my incomplete code in DocTrasactionImpl as follow
    *protected void doDML(int operation, TransactionEvent e)  {*
    super.doDML(operation, e);
    *if (operation == DML_INSERT) {*
    EntityDefImpl secDef = TranshistoryImpl.getDefinitionObject();
    TranshistoryImpl insert = (TranshistoryImpl)secDef.createInstance2(getDBTransaction(), null);
    insert.setTransId(this.getId().getSequenceNumber());
    insert.setTransBy(this.getCreatedBy());
    insert.setToEmp(this.getEmpId());
    insert.setDocStatus(this.getDocStatus());
    insert.setTransStatus(new Number(1));       // transaction still open
    *if (operation == DML_UPDATE) {*
    *// insert into history when update the status by user to 2 or 5 before 7 days from created the task*
    Date today = new Date();
    Long dateDiff =(today.dateValue().getTime())-(getCreatedOn().dateValue().getTime());
    Boolean checkBefore=( (this.getDocStatus().intValue() == 2 && dateDiff <=7 )||( this.getDocStatus().intValue() == 5 && dateDiff<=7)) ; // change status before 7 days
    Boolean checkAfter=( (this.getDocStatus().intValue() == 2 && dateDiff > 7 )||( this.getDocStatus().intValue() == 5 && dateDiff > 7)); // change status after 7 days
    if  ( checkBefore )      // update by user
    EntityDefImpl secDef = TranshistoryImpl.getDefinitionObject();
    TranshistoryImpl insert = (TranshistoryImpl)secDef.createInstance2(getDBTransaction(), null);
    insert.setTransId(this.getId().getSequenceNumber());
    insert.setTransBy(this.getModifiedBy());
    insert.setToEmp(this.getEmpId());
    insert.setDocStatus(this.getDocStatus());
    insert.setTransStatus(new Number(2)); //close transaction
    else  if  (checkAfter )  // update by user
    EntityDefImpl secDef = TranshistoryImpl.getDefinitionObject();
    TranshistoryImpl insert = (TranshistoryImpl)secDef.createInstance2(getDBTransaction(), null);
    insert.setTransId(this.getId().getSequenceNumber());
    insert.setTransBy(this.getModifiedBy());
    insert.setToEmp(this.getEmpId());
    insert.setDocStatus(new Number(3));//رد متأخر
    insert.setTransStatus(new Number(2));// close transaction
    this code not working will and also how can i update the docStatus automatic after 7 days from value 1 to 3
    thank you
    }

    What is not working, your logic when to create/update or new EO rows itself are not getting updated or created ?
    Amit

  • May returning Clause be used w/ INSERT INTO...SELECT FROM

    Hi,
    I use Oracle 8i: 8.1.7.2.0.
    I'd like to insert multiple rows into a table, and get back certain inserted columns into a collection variable. Is this possible?
    Eg:
    INSERT INTO foo
    f1
    , f2
    SELECT b1, b2...
    FROM bar
    RETURNING f1 bulk collect into collection
    This compiles, but yields a "command not properly ended" error at runtime--I assume because the "returning" binds to the SELECT subquery, and not to the main INSERT query.
    Is there a way to do this?
    By the way, I already know this works when INSERTing just 1 row via the "values" clause.
    Regards,
    --IG                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Hi,
    Try this way:
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    SQL>
    SQL> SET SERVEROUTPUT ON
    SQL> DECLARE
      2     TYPE emp_t IS TABLE OF VARCHAR2(30);
      3     emp_list emp_t;
      4 
      5     TYPE emp_t2 IS TABLE OF NUMBER;
      6     emp_code emp_t2;
      7  BEGIN
      8 
      9     emp_list := emp_t('John',
    10                       'Doe',
    11                       'Max');
    12 
    13     FORALL i IN emp_list.FIRST .. emp_list.LAST
    14        INSERT INTO emp
    15           (id,
    16            NAME)
    17        VALUES
    18           (employees_seq.NEXTVAL,
    19            emp_list(i))
    20        RETURNING id BULK COLLECT INTO emp_code;
    21 
    22     FOR i IN emp_code.FIRST .. emp_code.LAST LOOP
    23        dbms_output.put_line(emp_code(i));
    24     END LOOP;
    25  END;
    26  /
    213
    214
    215
    PL/SQL procedure successfully completed
    SQL> commit;
    Commit complete
    SQL> select * from emp;
            ID NAME
           213 John
           214 Doe
           215 Max
    SQL>Regards,
    Edited by: Walter Fernández on May 8, 2009 12:59 PM -- Adding query on emp table...

  • Insertion into local table from remote table with contains clause

    Hi all,
    We are tasked to insert some rows into our database from another database. We tried to use DBLinks to link the 2 databases and were able to use Select statements to filter out the data that we need to insert into our database.
    These statements take the form of: Select * from RemoteTable where contains@RemoteLink(IndexColumn, 'car')>0;
    where RemoteLink is the DBLink that we have created.
    However Oracle gave us an error (ORA-00949: illegal reference to remote table) when we tried to insert the dataset from the above statement into our local table. We used the following statement in doing so: Insert Into LocalTable (Select * from RemoteTable where contains@RemoteLink(IndexColumn, 'car')>0);
    Even if we use Create Table, Oracle gave us the same error when we tried to push the data from the Select Statement into the new table.
    Could anyone advise us whether it is possible to insert such data into a local table? And if som what is the proper way of doing it?
    Many thanks to any advises.

    Hi,
    there is document 261741.1 on Metalink. This states explicitly that it is not possible to invoke remote user-defined operators, and contains is such. The solution given in the article is to create a wrapper function on the remote site and this one calling in stead of contains.
    Herald ten Dam
    htendam.wordpress.com

  • Insert into a temp table is to slow

    i'd like to know why if i created a temp table out of my procedure the insert into it get slower than if i create that temp table inside my procedure. follows an example:
    create table #Test (col1 varchar(max))
    go
    create proc dbo.test
    as
    begin
    truncate table #Test
    insert into #Test
    select 'teste'
    FROM sys.tables
    cross join sys.columns
    end
    go
    exec dbo.test
    go
    create table #Test2 (col1 varchar(max))
    go
    truncate table #Test2
    insert into #Test2
    select 'teste'
    FROM sys.tables
    cross join sys.columns
    At test, we get duration 71700, reads 45220, CPU 26052 At test2, we get duration 49636, reads 45166, cpu 24960
    best regards

    There should be no difference.
    You would have to repeat the test you designed a few times to take readings and then reverse the order.
    BOL: "
    Benefits of Using Stored Procedures
    The following list describes some benefits of using procedures.
    Reduced server/client network traffic          
    The commands in a procedure are executed as a single batch of code. This can significantly reduce network traffic between the server and client because only the call to execute the procedure is sent across the network. Without the code encapsulation provided
    by a procedure, every individual line of code would have to cross the network.
    Stronger security          
    Multiple users and client programs can perform operations on underlying database objects through a procedure, even if the users and programs do not have direct permissions on those underlying objects. The procedure controls what processes and activities
    are performed and protects the underlying database objects. This eliminates the requirement to grant permissions at the individual object level and simplifies the security layers.
    The EXECUTE AS
    clause can be specified in the CREATE PROCEDURE statement to enable impersonating another user, or enable users or applications to perform certain database activities without needing direct permissions on the underlying objects and commands. For example,
    some actions such as TRUNCATE TABLE, do not have grantable permissions. To execute TRUNCATE TABLE, the user must have ALTER permissions on the specified table. Granting a user ALTER permissions on a table may not be ideal because the user will effectively
    have permissions well beyond the ability to truncate a table. By incorporating the TRUNCATE TABLE statement in a module and specifying that module execute as a user who has permissions to modify the table, you can extend the permissions to truncate the table
    to the user that you grant EXECUTE permissions on the module.
    When calling a procedure over the network, only the call to execute the procedure is visible. Therefore, malicious users cannot see table and database object names, embed Transact-SQL statements of their own, or search for critical data.
    Using procedure parameters helps guard against SQL injection attacks. Since parameter input is treated as a literal value and not as executable code, it is more difficult for an attacker to insert a command into the Transact-SQL statement(s) inside
    the procedure and compromise security.
    Procedures can be encrypted, helping to obfuscate the source code. For more information, see SQL Server Encryption.
    Reuse of code          
    The code for any repetitious database operation is the perfect candidate for encapsulation in procedures. This eliminates needless rewrites of the same code, decreases code inconsistency, and allows the code to be accessed and executed by any user or application
    possessing the necessary permissions.
    Easier maintenance          
    When client applications call procedures and keep database operations in the data tier, only the procedures must be updated for any changes in the underlying database. The application tier remains separate and does not have to know how about any changes
    to database layouts, relationships, or processes.
    Improved performance          
    By default, a procedure compiles the first time it is executed and creates an execution plan that is reused for subsequent executions. Since the query processor does not have to create a new plan, it typically takes less time to process the procedure.
    If there has been significant change to the tables or data referenced by the procedure, the precompiled plan may actually cause the procedure to perform slower. In this case, recompiling the procedure and forcing a new execution plan can improve performance.
    LINK: http://technet.microsoft.com/en-us/library/ms190782.aspx
    Kalman Toth Database & OLAP Architect
    Free T-SQL Scripts
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Insert into oracle DB using vb2005

    I have a form that has click button1. The problem with this code is after insert command something should be inserted into oracle DB but nothing there(so how to execute insert command and commit it using VB2005), any suggestion should refer to the code.
    Imports System
    Imports System.Data ' VB.NET
    Imports Oracle.DataAccess.Client ' ODP.NET Oracle data provider
    Imports Excel = Microsoft.Office.Interop.Excel
    Public Class Form1
    'System.Data.OracleClient lets you access Oracle databases.
    Public con As System.Data.OracleClient.OracleConnection = New System.Data.OracleClient.OracleConnection() 'Oracle.DataAccess.Client.OracleConnection()
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim xlApp As Excel.Application
    Dim xlWorkBook As Excel.Workbook
    Dim xlWorkSheet As Excel.Worksheet
    Dim range As Excel.Range
    Dim rCnt As Integer
    Dim cCnt As Integer
    Dim Obj As Object
    xlApp = New Excel.ApplicationClass
    xlApp.Visible = True
    xlWorkBook = xlApp.Workbooks.Open("c:\employee.xls")
    xlWorkSheet = xlWorkBook.Worksheets("sheet1")
    range = xlWorkSheet.UsedRange
    For rCnt = 2 To range.Rows.Count
    For cCnt = 1 To range.Columns.Count
    Obj = CType(range.Cells(rCnt, cCnt), Excel.Range)
    'MsgBox(Obj.value)
    Next
    Next
    xlWorkBook.Close()
    xlApp.Quit()
    releaseObject(xlApp)
    releaseObject(xlWorkBook)
    releaseObject(xlWorkSheet)
    End Sub
    Private Sub releaseObject(ByVal obj As Object)
    Try
    System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
    obj = Nothing
    Catch ex As Exception
    obj = Nothing
    Finally
    GC.Collect()
    End Try
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim daOracle As New OracleDataAdapter
    Dim InsertCommand As New OracleCommand
    daOracle.InsertCommand = New OracleCommand
    '1.Create connection object to Oracle database
    Dim con As OracleConnection = New OracleConnection()
    Try
    '2.Specify connection string
    con.ConnectionString = ("Data Source=mgra;User Id=tmar; Password=grams")
    '3. Open the connection through ODP.NET
    con.Open()
    Catch ex As Exception
    '4.display if any error occurs
    MsgBox(ex.Message, Microsoft.VisualBasic.MsgBoxStyle.Exclamation, "OraScan")
    '3.Create command object to perform a query against the database:
    Dim cmdQuery As String = "SELECT * FROM employee"
    InsertCommand.CommandText = "insert into meta_objecttypes values(4,'table','table','ERStudio','Demo')"
    daOracle.InsertCommand = InsertCommand
    ' Create the OracleCommand object to work with select
    Dim cmd As OracleCommand = New OracleCommand(cmdQuery)
    cmd.Connection = con
    cmd.CommandType = CommandType.Text
    'get the DataReader object from command object
    Dim rdr As OracleDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
    cmd.ExecuteNonQuery()
    'check if it has any row
    While rdr.Read()
    rdr.Close()
    End While
    Finally
    ' Close and Dispose OracleConnection object
    con.Close()
    con.Dispose()
    End Try
    End Sub
    End Class

    For best results, please repost this to the ODP.NET forum.

Maybe you are looking for

  • Creation of Multiple Variables of same type at runtime

    Hi, I have a requirement in which I need to create multiple variables at run time . The variables should be TRPE REF TO CL_GENIOS_VARIABLE. The number of variables required will be determined at run time based on the number of materials in a Bill of

  • Command line program: can it implement keyListener??

    Hello, before I take the trouble to learn keyListener implementation, I am wondering if my program could even implement it. It is just a small game that just plays in the command window. I would like it to respond to the user pressing up, down, left

  • Help Please -Need video to NOT automatically load when not using autoplay feature

    Hi, I am hoping someone can help me or point me to the right place to find what I need! I use the standard skins in Flash for putting videos onto a webpage but I am having problems when I use more than one video on a page. I have the videos set to au

  • Oracle 9iLite on Palm with ODBC support

    Hi, I would like to build an application using CodeWarrior (C++) on PalmOS. What library and header files should be included to provide ODBC support? Thank you very much! Brian HO

  • Relationship import | Import manager

    Hi ,   I am trying to import relationships through import manager in the material repository . What I do is , there are some existing relationships that I created in the data manager . I export them first [ data manager > relationships > export to a