Execute Immediate. Insert from materialized view.

Hi,
I'm using Execute Immediate in a function to insert rows into a table. (Oracle 10G) The function in tern is used in a materialized view. So, effectively the view does an insert.
When I just had a regular insert statment the view would not compile. When I changed the insert statment into the execute immediate it started working.
Here are my questions:
1. Do I need a commit or execute immediate does it automatically? When I create my view that calls the function it looks like the rows do get inserted as expected. But I couldn't find documentation that explains whether execute immediate does the commit.
2. Is there a drawback to using execute immediate in a function that is used in a materialized view? Is there other way to insert rows from a materialized view? Can I call a stored procedure instead of a function in a materialized view?
Your help is greatly appreciated.
Thanks
NK

there are things that I'm not able to question yet :)It's a lot easier to write decent programs if we understand the why of the requirement as well as the what. I think you will create a better impression in your new job if you demonstrate some liveliness of thought and personality - by asking questions - rather than merely following orders.
The question I proposed is not necessarily a hostile one (I can think of at least one good reason for doing what you've been asked to do). Broadening your knowledge of your new system is a good thing in its own right. But you never know, asking the right question may prevent you doing unnecessary work.
Cheers, APC

Similar Messages

  • Moving data from Materialized View to downstream application

    Database Version: 9i Release 2
    I've created a Materialized View on a base table, the purpose of which is to capture data changes to send to a downstream application
    (I've been advizsed to avoid using Streams for now until we upgrade to 10g)
    I need to either:
    a) Make that data available for another process to pick up and have knowledge of what it needs to pick up versus what it has already picked up
    or
    b) Send/Update a table or MV at a downstream MS SQL Server database (resides within our firewall)
    Some notes/questions
    I cannot change the structure of the underlying base table
    On the MV I could capture a date-time which records each time a record is touched on the base table, the problem is that many of these updates are “meaningless” and I should not send such updates downstream
    1.Is there a way I can timestamp/flag the records as they get inserted/updated on the MV? (potentially used by the pickup process to identify what it needs to pick up)
    2. If I flag the records e.g. “needs pickup” – would it be ok to make the MV updateable so the process can then mark the records as “picked up”. Performance?
    3. Can I create a trigger on the MV to write records to a secondary table as they are inserted/updated on the MV?
    4. Could I use the MV log tables MLOG$ to help me in any way?
    I’m guessing there is no way to do the following but:
    5. Is there a way to include a column on a Materialized View but ignore it in terms of capturing changes. e.g. I have columns a,b,c,d,e on my base table, I want to include a,b,c in my Materialized View but I only want my MV to be updated if a or b is updated on base table. If only column c is updated do not send any update to MV
    Many thanks for any insight

    Yes I do have a unique identifier on each record in the base table and therefore also in the MV.
    So now the Downstream application has to update some of its own database tables based on what is in the MV that I provide - just so I understand how would that work e.g.:
    1. MV gets refreshed from my base table every minute
    2. Some records are newly inserted and some simply updated
    and this is the part I don't understand (I might be missing something obvious)....
    3. Downstream application interrogates the MV every (say 1-2 minutes) and updates its own tables based on the data there.....but let's say MV contains 10,000 records and in the last minute 100 of those records have been updated and another 100 inserted - how will it know the 200 records it needs to pull?
    Thanks again

  • [help]why data on table (master ) different  from materialized view(slave)?

    We have had Oracle RAC 2 Groups (master and slave).
    We have created materialized from slave to master. and I have created materialized view log on master .
    When slave group job is broken a long time(12 Hrs). We refreshed job and runned job id.
    But I have found database on materialized view (slave) different from TABLE on master group. (m$log =0row)
    Please tell me how can we resolve Or because that problem is m$log

    Yes I do have a unique identifier on each record in the base table and therefore also in the MV.
    So now the Downstream application has to update some of its own database tables based on what is in the MV that I provide - just so I understand how would that work e.g.:
    1. MV gets refreshed from my base table every minute
    2. Some records are newly inserted and some simply updated
    and this is the part I don't understand (I might be missing something obvious)....
    3. Downstream application interrogates the MV every (say 1-2 minutes) and updates its own tables based on the data there.....but let's say MV contains 10,000 records and in the last minute 100 of those records have been updated and another 100 inserted - how will it know the 200 records it needs to pull?
    Thanks again

  • How to take output of execute immediate 'select * from table' into a file ?

    hi all,
    below is my code .....
    declare
    var_column_name varchar2(2000);
    main_string varchar2(12000);
    var_table_name varchar2(30);
    base_string varchar2(2000);
    final_string varchar2(2000);
    cursor c1 is
    select
    object_name
    from user_objects
    where object_type in ('TABLE','VIEW') and rownum < 2 ;
    cursor c2 is
    select
    column_name
    from user_tab_columns
    where upper(table_name) = upper(var_table_name);
    begin
    --var_column_name := null;
    -- main_string :=null;
    -- table_name :=null ;
    -- base_string :=null;
    -- final_string := null;
    open c1;
    fetch c1 into var_table_name;
    close c1;
    for c2_var in c2
    loop
    main_string := c2_var.column_name||','||main_string;
    end loop;
    select rtrim(main_string,',') into final_string from dual;
    dbms_output.put_line(final_string);
    base_string := 'Select '||final_string ||' from '||var_table_name||'' ;
    dbms_output.put_line(base_string);
    spool tete.lst;
    execute immediate base_string;
    spool off;
    end;
    i want to take the output of the execute immediate in a file on unix server ....
    please suggest
    rgds
    s

    Were you looking for something like this?
    SELECT
         CASE WHEN Columns.Column_Id = 1 THEN 'SELECT ' || CHR(10) END
              || CHR(09) || Columns.Column_Name
              || CASE
                   WHEN Columns.Column_Id = Info.Total_Columns THEN
                           CHR(10) || 'FROM'
                        || CHR(10) || CHR(09) || Columns.Table_Name || ';'
                        || CHR(10)
                   ELSE ','
                 END          Statement
    FROM
         User_Tab_Columns     Columns,
          SELECT
              Table_Name,
              MAX(Column_Id) Total_Columns
          FROM
              User_Tab_Columns
          GROUP BY
              Table_Name
         )               Info
    WHERE
         Columns.Table_Name = Info.Table_Name
    ORDER BY
         Columns.Table_Name,
         Columns.Column_Id;

  • OWB 10.1 error when execute a mapping from a view to a table

    Hi everyone,
    I have one mapping that is from a view to a target table, both are reside on the schema, it's a very simple mapping, just one to one, no transformation. Deployment is OK, but when I execute, it give me warning " ORA-942 table or view does not exist", however when I check my target table, the data seems to be loaded fine. Does anyone experience the same problem?

    Please check SCD Type 2 and ORA-00923: FROM keyword not found where expected

  • Invalid Column Name on select from materialized view?

    Hey all, I have created this materialized view for my java to select from. For some reason when I try to select from it, I get invalid column name. Here is my mat view statement in its simplest form:
    create materialized view mv_pgridtcevcluster_property as
    select distinct clustername_ as "OBJECT_ID", CLUSTERNAME_, LICENSEMODE_
    from p_gridtcevcluster p
    order by clustername_;
    Now when I run my select statement from jdbc:
    SQL: select object_id from MV_PGRIDTCEVCLUSTER_PROPERTY
    java.sql.SQLException: Invalid column name
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
         at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3319)
         at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1926)
         at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:1515)
         at com.mchange.v2.c3p0.impl.NewProxyResultSet.getString(NewProxyResultSet.java:3342)
         at historian.objects.mgmt.udrManagerTest.gatherObjects(udrManagerTest.java:73)
    Anyone have issues with this before? It seems to throw the error sporatically, any help would be much appreciated!
    Regards,
    TimS
    Edited by: TimS on Mar 30, 2009 1:54 PM
    Nevermind, figured it out. Was using wrong column name identifier when picking values from resultset.

    Since you have "OBJECT_ID" in quotes, Oracle stores the column name literally and case sensitively, and the column name must be capitalized when referenced.
    From a regular sql*plus window, try
    select object_id from mv_pgridtcevcluster_property;
    select OBJECT_ID from mv_pgridtcevcluster_property;
    select "OBJECT_ID" from mv_pgridtcevcluster_property;What is the result from each of them?

  • Hiding a column from materialized view

    Hello All,
    I have created a materialized view which aggregates the monthly wise data, as we know, for refresh on commit of this view i have selected count(*) and count(col).
    My problem is i don't want these columns to appear in the materialized view.
    regards

    If you include the columns in the select statement that generates the materialized view they will be visible. So your choices are:
    (1) don't include them in the query
    (2) overley the materialized view with a plain view.
    Apparently you don't like option 2, which leaves option 1. I must confess I don't understand your original post, so maybe you could explain in more depth why you have these columns you don't want. There may be some other way of achieving your aim.
    Cheers, APC

  • EXECUTE IMMEDIATE Procedure from another schema

    When running this procedure... I get an error ORA-00900.
    Does someone kwow the problem? Can we launch procdeure in EXECUTE IMMEDIATE?
    DECLARE
    jobname VARCHAR2(10) := 'test';
    datedebut DATE := SYSDATE;
    statut VARCHAR2(10) := 'En cours';
    BEGIN
    EXECUTE IMMEDIATE 'WEXPSTAGN_DEVL.bicstg_standard.ins_log_job('''||jobname||''',
    '''||statut ||''',
    '||datedebut ||')';
    END;
    Edited by: 995370 on 2013-03-21 07:58

    995370 wrote:
    When running this procedure... I get an error ORA-00900.
    Does someone kwow the problem? Can we launch procdeure in EXECUTE IMMEDIATE?
    DECLARE
    jobname VARCHAR2(10) := 'test';
    datedebut DATE := SYSDATE;
    statut VARCHAR2(10) := 'En cours';
    BEGIN
    EXECUTE IMMEDIATE 'WEXPSTAGN_DEVL.bicstg_standard.ins_log_job('''||jobname||''',
    '''||statut ||''',
    '||datedebut ||')';
    END;
    Edited by: 995370 on 2013-03-21 07:58You just want to do...
    DECLARE
      jobname VARCHAR2(10) := 'test';
      datedebut DATE := SYSDATE;
      statut VARCHAR2(10) := 'En cours';
    BEGIN
      WEXPSTAGN_DEVL.bicstg_standard.ins_log_job(jobname,statut,datedebut);
    END;No need for execute immediate (and you were using it wrongly anyway)

  • VA01 and from material view and last SO it shows wrong last sales price

    Hi,
    In sales order condtions the current flow is as follows:
    sales price PR00 - 8.36
    insurance ZZC0 - 0.03
    So the total value is 8.39 inr.
    But the client requirement is, the total value should be 8.36 only.  Insurance value should not add to the net price, but it should display in sales order condtions.
    we can do the pricing as statistical in pricing procedure for insurance.  But  client is not accepting for that.
    please letme know is there any other alternative way to get the required solution.
    look forward for your answers.
    thanks in anticipation.
    br,
    Hari.
    Moderator message: not directly related to ABAP development, please post again in the appropriate functional forum.(ERP SD?)
    Edited by: Thomas Zloch on Jul 13, 2010 2:43 PM

    When you use the query as a formatted search with auto refresh the query will Populate the Value of the first column from the first row of the query result.  Therefore the user will not see the last 2 prices for which the SELECT statement was created.
    To see the last 2 prices the user has to manually press ShiftF2 which is the same effort as CTRLTab.
    Writing a simple SQL is easy but it is important to educate the client with the benefits of using out of the box functionality when one already exists
    -Suda

  • Error while insert data using execute immediate in dynamic table in oracle

    Error while insert data using execute immediate in dynamic table created in oracle 11g .
    first the dynamic nested table (op_sample) was created using the executed immediate...
    object is
    CREATE OR REPLACE TYPE ASI.sub_mark AS OBJECT (
    mark1 number,
    mark2 number
    t_sub_mark is a class of type sub_mark
    CREATE OR REPLACE TYPE ASI.t_sub_mark is table of sub_mark;
    create table sam1(id number,name varchar2(30));
    nested table is created below:
    begin
    EXECUTE IMMEDIATE ' create table '||op_sample||'
    (id number,name varchar2(30),subject_obj t_sub_mark) nested table subject_obj store as nest_tab return as value';
    end;
    now data from sam1 table and object (subject_obj) are inserted into the dynamic table
    declare
    subject_obj t_sub_mark;
    begin
    subject_obj:= t_sub_mark();
    EXECUTE IMMEDIATE 'insert into op_sample (select id,name,subject_obj from sam1) ';
    end;
    and got the below error:
    ORA-00904: "SUBJECT_OBJ": invalid identifier
    ORA-06512: at line 7
    then when we tried to insert the data into the dynam_table with the subject_marks object as null,we received the following error..
    execute immediate 'insert into '||dynam_table ||'
    (SELECT

    887684 wrote:
    ORA-00904: "SUBJECT_OBJ": invalid identifier
    ORA-06512: at line 7The problem is that your variable subject_obj is not in scope inside the dynamic SQL you are building. The SQL engine does not know your PL/SQL variable, so it tries to find a column named SUBJECT_OBJ in your SAM1 table.
    If you need to use dynamic SQL for this, then you must bind the variable. Something like this:
    EXECUTE IMMEDIATE 'insert into op_sample (select id,name,:bind_subject_obj from sam1) ' USING subject_obj;Alternatively you might figure out to use static SQL rather than dynamic SQL (if possible for your project.) In static SQL the PL/SQL engine binds the variables for you automatically.

  • Some Times Table is inserting Partial record from a view Why?

    The query consists of a simple insert statement where the data is inserted from a view. The issue is that some times only the first retreived record from the select statement are inserted into the table from a view and the rest are ignored when we scheduled in the batch job of EM console. Some times it inserted correctly.
    For Ex.
    INSERT INTO Table_COLL(COL_A, COL_B, COL_C)
    SELECT COL_A, COL_B, COL_C
    FROM COLL_VIEW
    WHERE DATE=TRUNC(SYSDATE);
    COMMIT;
    The select statement retreives 200 records and the insert statement works perfectly as expected when executed in SQL* plus.
    However the issue happens where only one record is inserted when the same query is scheduled in the batch job of the EM console or a procedure is created for the query and the same is scheduled in the EM console as a batch job and Some times it inserted correctly in EM Console.
    Can anyone explain as why this is hapenning? (DB is Oracle 10g& size is 100gb )

    I doubt that there is a bug. I suspect the query runs when you schedule it at a point of time where TRUNC(SYSDATE) gives less rows...
    You could store the COUNT(*) and execution time before you run the INSERT in a LOG table. Any transaction based on two times (runtime and systime) can lead to unexpected results.
    What about something like this:
    INSERT INTO Table_COLL(COL_A, COL_B, COL_C)
    SELECT COL_A, COL_B, COL_C
    FROM COLL_VIEW a
    LEFT JOIN Table_COLL B
    ON (      a.COL_A = b.COL_A
          AND a.COL_B = b.COL_B
          AND a.COL_C = b.COL_C)
    WHERE a.DATE>=TRUNC(SYSDATE)-1
    AND b.COL_A IS NULL;
    COMMIT;

  • Problem to insert using execute immediate

    Have a procedure like this:
    create or replace procedure proc_set_category(
    VC_object_id IN number,
    VC_object IN varchar2,
    VC_category_id IN varchar2
    is
    sq varchar2(200);
    BEGIN
         sq:='INSERT INTO ' || VC_object ||'_category (' || VC_object || '_id,category_id) VALUES (' || VC_object_id || ',' || VC_category_id ||')';
         EXECUTE IMMEDIATE sq;
    END;
    Procedure created.
    but when i try to execute the following query it generates an error
    execute proc_set_category(1,'news','event')
    ERROR at line 1:
    ORA-00984: column not allowed here
    ORA-06512: at "SCOTT.PROC_SET_CATEGORY", line 10
    ORA-06512: at line 1
    I have a news_category table.where is the problem?

    sq:='INSERT INTO ' || VC_object ||'_category (' || VC_object || '_id,category_id) VALUES (' || VC_object_id || ',' || VC_category_id ||')';
    EXECUTE IMMEDIATE sq;
    execute immediate 'INSERT INTO ' || VC_object ||'_category (' || VC_object || '_id,category_id) VALUES (:1, :2)'
      using VC_object_id, VC_category_id;

  • Insertion Using Execute Immediate

    How to use Execute Immedaite in Inserting while with dynamic table name. Is that possible or we can use only the dynamic values.
    Execute Immediate "Insert Into " || DYNAMIC TABLE NAME || "Values"
    Using (Value_1, Value 2, Value3).

    Why would tables be added later? Are they storing the same structure of data? If so you should be using a single table possibly with partitioning.
    If they are of different structures then you should have one procedure for each structure, otherwise you're going down the Bad Design ^tm^ route. A single procedure should perform a single task. Trying to make generic code is generally considered a lazy design and often leads to performance issues and difficult to track bugs.

  • Inserting variables to table by "execute immediate' statement

    EXECUTE IMMEDIATE 'INSERT INTO aTABLETKA_HISTORY
    (update_id,
    update_type,
    update_date,
    old_db_version,
    description,
    patch_number)
    values
    (' || m_id(v_rec) || ',
    '||m_package(v_rec)||',
    ''07-NOV-07'',
    ''snezi'',
    '||m_desc(v_rec)||',
    '||m_new(v_rec)||')';
    ORA-00917: missing comma
    ORA-06512: at line 142
    i cannot solve this,. can anybody help me?
    i have simillar insert:
    EXECUTE IMMEDIATE 'INSERT INTO ab_table_VERSION(property,version) values (''wiz_datalink'',' || my_version || ')';
    and this one statement work correctly

    Do NOT use "execute immediate". What is the reason for trying it this way?
    If the column update_date is of type date, then you have a bug in the code, as you are trying to insert a string. If it is not a date data type, then you have a bug, because it is not of type date.
    What is the outcome of:
    INSERT INTO aTABLETKA_HISTORY (update_id, update_type, update_date,
          old_db_version, description, patch_number)
       values (m_id(v_rec), m_package(v_rec), to_date('07-NOV-2007', 'dd-MON-yyyy'),
          snezi, m_desc(v_rec), m_new(v_rec) )
    /

  • EXECUTE IMMEDIATE AND BULK INSERT

    Hi,
    I have a code
    EXECUTE IMMEDIATE 'INSERT INTO PRC_ExcelDocumentStore_T(object_id,seg_index,segment,value,seg_length) VALUES (:object_id,:seg_index,:segment,:value,:seg_length)'
    USING SELF.object_id,p_index,p_segment,p_value,lengthc(v_value)+2;
    But due to some performance issue ,I can't use like this.Can you please suggest can i use Bulk Inserts instead of 'EXECUTE IMMEDIATE' statement.
    If I can do,please give me an example.
    Thanks in advance

    user10619377 wrote:
    Hi,
    I have a code
    EXECUTE IMMEDIATE 'INSERT INTO PRC_ExcelDocumentStore_T(object_id,seg_index,segment,value,seg_length) VALUES (:object_id,:seg_index,:segment,:value,:seg_length)'
    USING SELF.object_id,p_index,p_segment,p_value,lengthc(v_value)+2;
    But due to some performance issue ,I can't use like this.Can you please suggest can i use Bulk Inserts instead of 'EXECUTE IMMEDIATE' statement.
    If I can do,please give me an example.How can we give example when we don't know what you have now or what exactly needs to be done.?

Maybe you are looking for

  • Out bound delivery against STO

    Hi My client requirement is to trace every movement against STO i-e system should track each GR against each GI against STO. Meaning when we issue a goods against STO system should track against which GI user post GR as in the system there is no stan

  • Can't start Application server

    Hi, When I am to start Application server within Jdev 11.1.1.4, I have got this Caused by: java.lang.ClassNotFoundException: weblogic.Server      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)      at java.security.AccessController.doPrivi

  • Two macs, one can connect to iPhone update server, one cannot

    We have multiple macs and iphones in the house.  One mac can connect to the iphone update server without any problems.  the other cannot.  Both are on the same network.  Both have identical firewall settings.  One mac can manually download the iphone

  • RCA CCMS BI SETUP

    Hi, We see that the below info cube are active (not greyed) in RSA1. Still the program CCMSBI_SETUP_E2E is giving below error: HELP:Attempt to activate object CUBE:0DB6_C01M manually in transaction RSOR. ERROR:Activation of InfoCube 0DB6_C02D failed

  • WAP4410N stops responding with 2.0.0.5

    Any news on this? I have the same problem. After a day or so it just stops responding. I recently bought 3 of these to my office. Running 2.0.0.5 etc.