Insert order by records into a view with a instead of trigger
Hi all,
I have this DML query:
INSERT INTO table_view t (a,
b,
c,
d,
e)
SELECT a,
b,
c,
d,
e
FROM table_name
ORDER BY dtable_view is a view with an INSTEAD OF trigger and table_name is a table with my records to be inserted.
I need the ORDER BY clause because in my trigger i call a procedure who treat each record and insert into a table, used in the view. I need to garantee these order.
If i put an other SELECT statement outside, like this:
INSERT INTO table_view t (a,
b,
c,
d,
e)
SELECT a,
b,
c,
d,
e
FROM table_name
ORDER BY dIt works. But I can put these new SELECT because these query is created automatic by Oracle Data Integrator.
What I'm asking you is if there any solution to this problem without changing anything in the Oracle Data Integrator. Or, in other words, if there is any simple solution other than to add a new SELECT statement.
Thanks in advance,
Regards.
Sorry... copy+paste error :)
INSERT INTO table_view t (a,
b,
c,
d,
e)
SELECT *
FROM ( SELECT a,
b,
c,
d,
e
FROM table_name
ORDER BY d)I need to insert him by a D column order, because my trigger needs to validate each record and insert him. I have some restrictions. For example, my records are:
2 1 2006 M
1 2 2007 M
1 3 2007 S 2007
1 2 2007 S 2007
2 1 2009 S
2 1 2009 S
I want to insert the 'M' records first and then the 'S' records because the 'S' records only makes sense in target table is exists 'M' records
Regards,
Filipe Almeida
Similar Messages
-
Best way to insert millions of records into the table
Hi,
Performance point of view, I am looking for the suggestion to choose best way to insert millions of records into the table.
Also guide me How to implement in easier way to make better performance.
Thanks,
Orahar.Orahar wrote:
Its Distributed data. No. of clients and N no. of Transaction data fetching from the database based on the different conditions and insert into another transaction table which is like batch process.Sounds contradictory.
If the source data is already in the database, it is centralised.
In that case you ideally do not want the overhead of shipping that data to a client, the client processing it, and the client shipping the results back to the database to be stored (inserted).
It is must faster and more scalable for the client to instruct the database (via a stored proc or package) what to do, and that code (running on the database) to process the data.
For a stored proc, the same principle applies. It is faster for it to instruct the SQL engine what to do (via an INSERT..SELECT statement), then pulling the data from the SQL engine using a cursor fetch loop, and then pushing that data again to the SQL engine using an insert statement.
An INSERT..SELECT can also be done as a direct path insert. This introduces some limitations, but is faster than a normal insert.
If the data processing is too complex for an INSERT..SELECT, then pulling the data into PL/SQL, processing it there, and pushing it back into the database is the next best option. This should be done using bulk processing though in order to optimise the data transfer process between the PL/SQL and SQL engines.
Other performance considerations are the constraints on the insert table, the triggers, the indexes and so on. Make sure that data integrity is guaranteed (e.g. via PKs and FKs), and optimal (e.g. FKs should be indexes on the referenced table). Using triggers - well, that may not be the best approach (like for exampling using a trigger to assign a sequence value when it can be faster done in the insert SQL itself). Personally, I avoid using triggers - I rather have that code residing in a PL/SQL API for manipulating data in that table.
The type of table also plays a role. Make sure that the decision about the table structure, hashed, indexed, partitioned, etc, is the optimal one for the data structure that is to reside in that table. -
Problem in creating Entity for view which has "INSTEAD OF " trigger
Hi ,
I have an entity based on a Non updatable Database view (DB_VIEW).this database view has an INSTEAD OF trigger which validates
and save data into a table.
And I have a BC4J view based on this entity.
Problem :
When I try to insert a record using bc4j view object,I get following error
ORA-22816: unsupported feature with RETURNING clause
Query sent by view Object is :
BEGIN INSERT INTO DB_VIEW(COLUMN1,COLUMN2,COLUMN3) VALUES (:1,:2,:3) RETURNING ROWID INTO
:4; END;
I am not able to insert any record in that view.
I tried removing rowID from my BC4J entity and View but problem is that in Databae view there is no
column which can be set as a primary key other then ROWID.I had the same problem.
Oracle 9.2 sadly does not support the RETURNING clause for database views with INSTEAD OF triggers.
Here is Steves Solution:
1. Create a custom entity def impl class for your entity on the Java panel
2. override the isUseReturningClause() and return false
That should work in 9.0.3.4, 9.0.4 build 1419, and 9.0.5.1 production.
from How to disable generation of RETURNING clause?
Hth, Markus -
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
ThankNo 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.
-
Inserting records into a table with all caps
Hello
I have a procedure that inserts records into a table. How do I ensure that the text values inserted are recorded all capital letters into the table?
Thanks.You can use UPPER(..) function in your insert statement, so that values are converted to UPPER, before insert.
If you want to check at table level, you can achieve that by writting a before insert trigger and in that trigger check
IF UPPER(:new.<col>) != :new.<col> THEN
RAISE_APPLICATION_ERROR(-20101,'Error: Not all values are in upper case')
END IF; -
How to insert a specific record into alv
Hi everyone,
here is my problem:
I put an ALV GRID control in my screen , it display some records.
and I create a new button on the toolbar, and in the "handle user command class" , I need to
select a record from DB table into a work area.
after I select the record I need, here is the key question:
*I want to insert the record into the ALV at a specific row position which the user decided,
what should I do?*
METHOD HANDLE_ON_USER_COMMAND.
CASE E_UCOMM.
WHEN CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.
WHEN 'FC_ASSIGN'.
***I do some selection here
select %%%$$%%%^&&** into GS_HOLIDAYS.
*** after the selection, what should I do then????
*** I want to insert the work area GS_HOLIDAYS into ALV at a specific position
*** e.g. into the 3rd row.
*** how can I achieve that????
***call a method or something??????I don't know
WHEN 'FC_DELETE'.
WHEN OTHERS.
ENDCASE.
ENDMETHOD.
pls don't let me go through the programs in package "SLIS",because I have already done that and
I haven't solved my problems yet.
Thanks for your help.All u need to do is on user command for inserting new records u just insert a blank record in your internal table that u are displaying with required style informaion for making it editable and then refresh alv display by method REFRESH_TABLE_DISPLAY.
Thanks & Regards,
Vivek Gaur -
How can i use BAPI to insert a few records into standard table
Can anyone help me with how can i use BAPI to insert some records into a standard table from an internal table?
Hi,
First of All try to Explain your Question first.
This is a general question without mentioning the Table you want to Update.
Please give the details before posting a question so it will help people to understand your Problem.
Regards
Sandipan -
How to speed insert my 1000000 records into the database?
my code like:
<cfloop from="1" to="#inserteddb.getrecordcount()#"
index="x">
<!----
Here make the InsertFieldList and InsertValueList
--->
<cfquery datasource="#cfdsn#" name="insertdata">
insert into inputtest (#InsertFieldList#)
values (
<cfqueryparam value="#InsertValueList#"
cfsqltype="cf_sql_varchar" list="yes">
</cfquery>
</cfloop>
The test inserts 100,000 records, has spend I 30 minutes
time,but I have 1,000,000 record to insert , is there any way to
enhance the insertion speed?
Thanks a lot.By removing ColdFusion from the process as much as possible.
Where is the 'insertedDB' data coming from? It looks to be a
record set?
Are you moving data from one data source to another? If so,
some DBMS
have the ability to insert an entire record set in one step.
I do not
have the exact syntax at my finger tips, but I have done
something like
this in the past with Oracle. INSERT INTO aTable SELECT FROM
bTable.
Are you building a record set from a text file such as CSV?
If so, many
DBMS have the ability to do 'bulk' inserts from such text
files and CF
does not even need to be involved.
As you can see, knowing exactly what are you working with
will help us
provide suggestions an how to improve your process. -
INSERT of two records into different tables (pk value from first to second)
Hi there!
Have probably stupid question
Need to insert one record into table with primary key and then insert into other table record with value of primary key field from first record
How can I do it?
Thanks a lot!!!You have several possibilities. Most easiest one is listed first :)
SQL> create table a (a number);
Table created.
SQL> alter table a add constraint a_pk primary key (a);
Table altered.
SQL> create table b (a number);
Table created.
SQL> alter table b add constraint b_a_fk foreign key (a) references a(a);
Table altered.
SQL> insert into a values (0);
1 row created.
SQL> insert into b values (0);
1 row created.Though that may not help always, so the next possibility maybe just using sequence with nextval and currval (currval can be used only in the same session and only after you have issued at least one nextval)
SQL> create sequence a_seq;
Sequence created.
SQL> insert into a values (a_seq.nextval);
1 row created.
SQL> insert into b values (a_seq.currval);
1 row created.And you can use also famous returning clause. It is a bit easier to show that in the pl/sql block than pure SQL.
SQL> declare
2 v number;
3 begin
4 insert into a values (a_seq.nextval) returning a into v;
5 insert into b values (v);
6 end;
7 /
PL/SQL procedure successfully completed.And at last contents of the tables :)
SQL> select * from b;
A
0
1
2
SQL> select * from a;
A
0
1
2Gints Plivna
http://www.gplivna.eu -
ApEx 4.1.1: update record in a view with 'instead of update' trigger
I created a form against a view. The view is complex enough which prevents direct updates. To incorporate the update logic I created an 'instead of update' trigger on the view. When I open up the form, do changes, and click 'Apply Changes' button I am getting the following exception
ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc.
I understand that the standard 'Automatic Row Processing' process is trying to lock the record before updating using a cursor like
select *
from my_view
for update
and fails. Is it possible to bypass this locking while using the standard APEX processes?
I think I can create a custom PL/SQL process which would execute the UPDATE statement (at least, it works in SQL*Plus), but I would like to know if I can use a standard ApEx functionality for this.Hello,
Sorry for delay.
I had found a feedback about trigger issue when restore SQL Database from a BACPAC file. Microsoft said the fixed will be available in the next major release of DacFx.
Feedback:
SQL Azure fires a trigger when restoring from bacpac
You can refer to the workarounds in the feedback. For example, if there is small amount of triggers on the database, you can try to remove the triggers and then recreate when restore from bacpac file.
Regards,
Fanny Liu
Fanny Liu
TechNet Community Support -
ERROR - 16016 - FOR FORM CREATED ON A VIEW AND USING INSTEAD OF TRIGGER
I have created a form based on a view. The view has instead of Trigger on it.
When I try to update the form I get the following error:
Error: An unexpected error occurred: ORA-22816: unsupported feature with RETURNING clause (WWV-16016)
Can anyone tell what the problem is?
Thanks
nullTHANKS A LOT IT WORKED.
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Rene' Castle ([email protected]):
This is a bug with views. If you can edit the PL/SQL code that is generated, you can remove the RETURNING clause and it will work.
NOTE: This will have to be done every time you edit the form.
<HR></BLOCKQUOTE>
null -
Help Export TABLE Records into Flat File with INSERTs - error
Hi,
When i'm trying to run this procedure I got this error:
ORA-00932:inconsistent datatypes: expected - got -
Can anybody tell me why?
Thanks
CREATE OR REPLACE PROCEDURE generate_stmt(prm_table_name IN VARCHAR2,
prm_where_clause IN VARCHAR2,
prm_output_folder IN VARCHAR2,
prm_output_file IN VARCHAR2) IS
TYPE ref_cols IS REF CURSOR;
mmy_ref_cols ref_cols;
mmy_column_name VARCHAR2(100);
mmy_column_data_type VARCHAR2(1);
mmy_col_string VARCHAR2(32767);
mmy_query_col_string VARCHAR2(32767);
V_FILE_HNDL UTL_FILE.file_type;
begin
OPEN mmy_ref_cols FOR
SELECT LOWER(column_name) column_name
FROM user_tab_columns
WHERE table_name = UPPER(prm_table_name)
ORDER BY column_id;
LOOP
FETCH mmy_ref_cols
INTO mmy_column_name;
EXIT WHEN mmy_ref_cols%NOTFOUND;
mmy_col_string := mmy_col_string || mmy_column_name || ', ';
mmy_query_col_string := mmy_query_col_string || ' ' || mmy_column_name || ',';
END LOOP;
CLOSE mmy_ref_cols;
V_FILE_HNDL := UTL_FILE.FOPEN('TEST','TESST.TXT', 'W');
mmy_col_string := 'INSERT INTO ' || LOWER(prm_table_name) || ' (' ||
CHR(10) || CHR(9) || CHR(9) || mmy_col_string;
mmy_col_string := RTRIM(mmy_col_string, ', ');
mmy_col_string := mmy_col_string || ')' || CHR(10) || 'VALUES ( ' ||
CHR(9);
mmy_query_col_string := RTRIM(mmy_query_col_string,
' || ' || '''' || ',' || '''' || ' || ');
dbms_output.put_line(mmy_column_name);
OPEN mmy_ref_cols
FOR ' SELECT ' || mmy_query_col_string ||
' FROM ' || prm_table_name ||
' ' || prm_where_clause;
loop
FETCH mmy_ref_cols
INTO mmy_query_col_string;
EXIT WHEN mmy_ref_cols%NOTFOUND;
mmy_query_col_string := mmy_query_col_string || ');';
UTL_FILE.PUT_LINE(V_FILE_HNDL, mmy_col_string);
UTL_FILE.PUT_LINE(V_FILE_HNDL, mmy_query_col_string);
end loop;
end;Buddy,
Try this..
CREATE OR REPLACE PROCEDURE generate_stmt
(prm_table_name IN VARCHAR2,
prm_where_clause IN VARCHAR2,
prm_output_folder IN VARCHAR2,
prm_output_file IN VARCHAR2) IS
TYPE ref_cols IS REF CURSOR;
mmy_ref_cols ref_cols;
mmy_column_name VARCHAR2(100);
mmy_column_data_type VARCHAR2(1);
mmy_col_string VARCHAR2(32767);
mmy_query_col_string VARCHAR2(32767);
V_FILE_HNDL UTL_FILE.file_type;
begin
OPEN mmy_ref_cols FOR
SELECT LOWER(column_name) column_name
FROM user_tab_columns
WHERE table_name = UPPER(prm_table_name)
ORDER BY column_id;
LOOP
FETCH mmy_ref_cols
INTO mmy_column_name;
EXIT WHEN mmy_ref_cols%NOTFOUND;
mmy_col_string := mmy_col_string || mmy_column_name || ', ';
mmy_query_col_string := mmy_query_col_string || ' ' || mmy_column_name || ',';
END LOOP;
CLOSE mmy_ref_cols;
mmy_col_string := 'INSERT INTO ' || LOWER(prm_table_name) || ' (' ||CHR(10) || CHR(9) || CHR(9) || mmy_col_string;
mmy_col_string := RTRIM(mmy_col_string, ', ');
mmy_col_string := mmy_col_string || ')' || CHR(10) || 'VALUES ( ' ||CHR(9);
mmy_query_col_string := RTRIM(mmy_query_col_string,' || ' || '''' || ',' || '''' || ' || ');
V_FILE_HNDL := UTL_FILE.FOPEN('TEST','TESST.TXT', 'W');
OPEN mmy_ref_cols FOR 'SELECT ' || mmy_query_col_string ||' FROM ' || prm_table_name ||' ' || prm_where_clause;
loop
FETCH mmy_ref_cols INTO mmy_query_col_string;
EXIT WHEN mmy_ref_cols%NOTFOUND;
mmy_query_col_string := mmy_query_col_string || ');';
UTL_FILE.PUT_LINE(V_FILE_HNDL, mmy_col_string);
UTL_FILE.PUT_LINE(V_FILE_HNDL, mmy_query_col_string);
end loop;
UTL_FILE.FCLOSE(V_FILE_HNDL);
END;
This would work for table with one and only one column.
Look at the line below:
FETCH mmy_ref_cols INTO mmy_query_col_string;
mmy_query_col_string has been declared as string...So it would hold single value only.That's the reason when you try this block on table with more than one column,mmy_query_col_string would've to hold a table row type data which it would not...
Good luck!!
Bhagat -
Java executeBatch() - Problem in INSERT (Order of records not maintained)
When we make a executeBatch() . And when the use
select * from DUMMY_FILE_S order by ROWID
or
select * from DUMMY_FILE_SThe rows returned are in different order.( that is its not in the order what is inserted actually)
And this happens once in a While.
This is will happen only if we try many times also So please try with many INSERTs
Please find the Java Code and the Insert SQL.
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.io.*;
import java.sql.DriverManager;
public class warranty_dummy
public static void main(String args[])
String FILENAME = "D:/data.sql";
Connection conn = null;
//String db_file_name_prefix = "@localhost:1531:xxxx_y14";
try {
Class.forName("oracle.jdbc.OracleDriver").newInstance();
// DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
catch (ClassNotFoundException e) {
e.printStackTrace();
//System.out.println("INSIDE class forname :"+ e.getStackTrace());
}catch(Exception e){
e.printStackTrace();
try{
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1531:yyyy_xxxx","my_user","password");
Statement stmt = conn.createStatement();
BufferedReader in = new BufferedReader(new FileReader(FILENAME));
String line = in.readLine();
System.out.println("Line " + line);
while(line != null) {
System.out.println("Line 1" + line);
stmt.addBatch(line);
line = in.readLine();
System.out.println("Outside While");
in.close();
int iarray[] = stmt.executeBatch();
System.out.println("Count" + iarray.length);
catch (Exception e ){
System.out.println("Error attempting to store results for batch " + e.getMessage());
} finally {
try {
conn.commit();
conn.close();
} catch (Exception se) {
System.out.println("Error attempting to store results for batch "+ se.getMessage());
}SQL Data sample
INSERT INTO DUMMY_FILE_S (FILE_NO,S_NO) values (44444,'123456789')
INSERT INTO DUMMY_FILE_S (FILE_NO,S_NO) values (44444,'567891234')
INSERT INTO DUMMY_FILE_S (FILE_NO,S_NO) values (44444,'333333333')
INSERT INTO DUMMY_FILE_S (FILE_NO,S_NO) values (44444,'323232323')Thanks for your prompt reply.
If we even use ORDER BY clause, we still don't get the records in the order what we inserted.
And we see that the problem is in smt.executeBatch(); is not inserting the records the way its inserted
For Example.
if we insert
INSERT INTO MyTable (SERIAL_NUMBER, DESCRIPTION ) VALUES (1,"test1");
INSERT INTO MyTable (SERIAL_NUMBER, DESCRIPTION ) VALUES (2,"test2");
INSERT INTO MyTable (SERIAL_NUMBER, DESCRIPTION ) VALUES (3,"test3");
INSERT INTO MyTable (SERIAL_NUMBER, DESCRIPTION ) VALUES (4,"test4");Note : (Using smt.executeBatch();)
After that when we use
Select * from MyTable ORDER BY ROWIDFor some time we get the result of the query as ( In the order we Insert )
SERIAL_NUMBER, DESCRIPTION
==========================
1,test1
2,test2
3,test3
4,test4And For some time we get the result of the query as ( We don't get the records in the order we Insert )
SERIAL_NUMBER, DESCRIPTION
==========================
1,test1
3,test3
2,test2
4,test4Is there any work around for this?
Thanks in advance -
Insert result of query into a table with unique constraint
Hi,
I have a query result that I would like to store in a table. The target table has a unique constraint. In MySQL you can do
insert IGNORE into myResultTable <...select statement...>
The IGNORE clause means if inserting a row would violate a unique or primary key constraint, do not insert the row, but continue inserting the rest of the query. Leaving the IGNORE clause out would cause the insert to fail and an error to return.
I would like to do this in oracle... that is insert the results of a query that are not already in the target table. What is the best way to do this? One way is use a procedural language and loop through the first query, checking to see if each row is a duplicate before inserting it. I would think this would be slow if there are lots of records. Other options...
insert into myTargetTable
select value from mySourceTable where ... and not exists (select 'x' from myTargetTable where value = mySourceTable.value)
insert into myTargetTable
select mySourceTable.value
from myTargetTable RIGHT JOIN mySourceTable
ON myTargetTable.value = mySourceTable.value
where ...
and myTargetTable.value IS NULL
any other suggestions?
Thanks,
SimonTry doing a MINUS instead of not exists., ie Source MINUS Target.
Disabling the constraint will not help you since this will allow the duplicate rows to be inserted into the table. I don't think you want this.
--kalpana -
Inserting new input record into the table through screen
Hi,
Example UserTable and PaymentTable
UserTable - UserID - Primary Key
PaymentTable - containg couple of fields and UserId is foreign Key.
I designed the page for to insert the new input record using the steps given in the doc "http://download-uk.oracle.com/docs/cd/B32110_01/web.1013/b28967/web_adv007.htm".
When i click the persistEntity method its throws TopLink error cannot insert null value into UserId column in PaymentTable.
Currently i am posting this reply from home... that's why i mentioning the scenario rather than posting the error.
Please tell how to populate the values from the screen to PaymentTable.
Thanks & Regards
Vimalan BalanHi Vimalan,
Did you find an answer for you question?
Regards,
Phil
Maybe you are looking for
-
what must i do? im a student and dont have backup for my work. Im in desperate need of a solution where i wont lose my work from my desktop.
-
Need to show proof of purchase to my insurance company, but my phone was replaced by apple so has a different imei number to the one on my receipt, how do you sort this out??
-
How do I send my display to a projector via HDMI?
I am new to Mac. I recently purchased a projector and I want to use my Macbook Air to display presentations via my projector. With PC, I think I used "F8". How do I on Mac? Please help...
-
FrameworkException/Error in Sun Application Server 8.1
While undeploying an EJB module, I am getting the following problem. While clicking on the "EJB Modules", the right pane is showing A "com.sun.enterprise.tools.guiframework.exception.FrameworkError" was caught. The message from the exception: "Unable
-
since i have upgrade to itunes 8, i have lost the album images on may ipod classic. On the pc itunes the images are correct, but i don´t know wy most of the images on the ipod are blank, not all? please do anybody know haw can i solve this problem. t