Please Help me in inserting record in a table
Hi,
Kindly help me on how to insert records in a table that the values are from the another table.
for example :
i have table1, all of the records in column1 of table1 will be inserted to table2 column2 . .
I already tested it to a visual foxpro programming language and it's ok, i used this command :
*"INSERT INTO table1 (column1) SELECT column2 FROM table2"*
but when I try it to a JAVA Program, there's an error.
Please help me.. Thank You.
Sir, this is what you mean?
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3256)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1313)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1585)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1500)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1485)
at remittance.utility.security.frmRole.addtoPermission(frmRole.java:197)
at remittance.utility.security.frmRole.btnADDActionPerformed(frmRole.java:177)
at remittance.utility.security.frmRole.access$200(frmRole.java:22)
at remittance.utility.security.frmRole$3.actionPerformed(frmRole.java:92)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:5517)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3135)
at java.awt.Component.processEvent(Component.java:5282)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3984)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1791)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Similar Messages
-
[b]please help me to insert recored to MS_Access Table [/b]
please help me to insert recored to MS_Access Table please can you modify my program becouse it is not working
import java.awt.*;
import java.util.*;
import java.awt.event.* ;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;
class ProductMast2 extends JFrame
private JTextField txtProd_Id;
private JButton btnAdd;
String url,sql;
String sqlI;
Container cp ;
Connection conn;
Statement stmt;
ResultSet rs;
public ProductMast2()
cp = getContentPane() ;
txtProd_Id = new JTextField( "" , 8 ) ;
btnAdd =new JButton ("add");
cp.add(txtProd_Id , BorderLayout.SOUTH ) ;
cp.add(btnAdd , BorderLayout.NORTH ) ;
this.connection();
btnAdd.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ee)
try
sqlI="Insert into Pro"
+"(Prod_Id)"
+"values('"+txtProd_Id+"')";
txtProd_Id.setText("");
rs=stmt.executeQuery(sqlI);
//rs=stmt.executeUpdate(sqlI);
while (rs.next()) {
txtProd_Id.setText(rs.getString(1));
// should be in finally block
rs.close();
stmt.close();
conn.close();
catch (Exception e)
System.out.println("Exception caught as: " + e.toString());
public void connection()
url="jdbc:odbc:Pro";
try
// Loading thr Driver by passing it to Class name() method.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//creating a connection object by passing the name of the 32bit ODBC driver
//throut the Driver Manger getConnection()mathod
conn=DriverManager.getConnection(url);
//creat Statement object
stmt=conn.createStatement();
System.out.println("Successfuly connected");
// conn.close();
sql="SELECT * FROM Pro";
rs=stmt.executeQuery(sql);
rs.next();
txtProd_Id.setText(rs.getString(1));
catch(Exception sqlExcep)
System.out.print("ERROR:"+sqlExcep);
class Pro
public static void main( String[] args )
ProductMast2 emp = new ProductMast2() ;
// ProductMast2 emp = new ProductMast2() ;
emp.connection();
///////// ProductMast1.connection();
emp.setTitle( " Product Master1 SOPS For Al-Hesn For Cloding And Trading" ) ;
emp.setSize( 900, 250 ) ;
emp.setVisible( true );
//emp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//System.exit(0);
//public void windowClosing(WindowEvent WE)
return ;
Hi,
you surely would need a good tutorial for jdbc and one for sql.
sqlI="Insert into Pro"
+"(Prod_Id)"
+"values('"+txtProd_Id+"')";
txtProd_Id.setText(""); Please use prepared statements that concated sql strings
rs=stmt.executeQuery(sqlI);
//rs=stmt.executeUpdate(sqlI);
while (rs.next()) {
txtProd_Id.setText(rs.getString(1));
}You must be joking here. Statement.executeQuery is used for SELECTing data. You insert statement is never going to return a resultset. ExecuteUpdate, which you have commented by the way, does the job but it returns an int(RecordsAffected).
Kiros -
Please help with multiple insert query into nested table!!!!
I am having a problem with inserting multiple references to objects into a nested table using the following query:
INSERT INTO TABLE(SELECT Taken_by FROM courses WHERE course_number= 001)
(SELECT REF(p) FROM persons p
WHERE p.enroled_in = 'Computing for Business'
The database says that p.enroled_in is an invalid identifier. I know why this is. This is because the field enroled_in is part of a subtype of person called student_type and the query above is not accounting for this properly. I would like to know the correct syntax to use so I can insert into the nested table wherever a student is enroled into the 'computing for business' course. My full schema is below:
CREATE TYPE person_type;
CREATE TYPE student_type;
CREATE TYPE staff_type;
CREATE TYPE course_type;
CREATE TYPE module_type;
CREATE TYPE address_type AS OBJECT
Street VARCHAR2 (30),
Town VARCHAR2 (30),
County VARCHAR2 (30),
Postcode VARCHAR2 (9)
CREATE TYPE person_type AS OBJECT
Name VARCHAR2 (50),
Address address_type,
DOB DATE
) NOT FINAL;
CREATE TYPE staff_type UNDER person_type
Staff_number NUMBER (2,0)
) FINAL;
CREATE TYPE student_type UNDER person_type (
Student_number NUMBER (2,0),
Enroled_in VARCHAR2(50),
MEMBER FUNCTION getAge RETURN NUMBER
)NOT FINAL;
CREATE OR REPLACE TYPE BODY student_type AS
MEMBER FUNCTION getAge RETURN NUMBER AS
BEGIN
RETURN Trunc(Months_Between(Sysdate, DOB)/12);
END getAge;
END;
CREATE TYPE module_type AS OBJECT
Module_number VARCHAR2(6),
Module_name VARCHAR2(50),
Credit NUMBER(2,0),
Taught_in VARCHAR2(50)
CREATE TYPE students_tab AS TABLE OF REF person_type;
CREATE TYPE modules_tab AS TABLE OF REF module_type;
CREATE TYPE course_type AS OBJECT
Course_number NUMBER (2,0),
Course_name VARCHAR2(50),
Dept_name VARCHAR2(50),
Taken_by Students_tab,
Contains Modules_tab
CREATE TABLE modules OF module_type(
constraint pk_modules primary key (Module_number)
CREATE TABLE courses OF course_type(
constraint pk_courses primary key (Course_number)
NESTED TABLE Taken_by STORE AS students_nt,
NESTED TABLE Contains STORE AS modules_nt;By the way I am using oracle 9i and trying to insert into the nested table data from a subtype (i.e student is a subtype of person)
-
How to insert records into the Table?
Dear Sir,
I'm new to JDeveloper. Now I managed to create a Frame in JDeveloper with many Text fields and a button. In the back end, I have a procedure to insert records to a table, to which I pass the values of the fields as parameters. Now I'm not getting the steps to call the PL/SQL Stored procedure when I click on the button. I'm using Oracle 9i JDeveloper version 9.0.3.1. and Oracle 9i Database.
Please give me the complete steps to achieve my task - it is quite urgent.
Thanking You in advance.
Regards,
Senthil .A. Perumal.The JDBC tutorial will show you how to call a stored procedure from Java:
http://download-west.oracle.com/docs/cd/B10501_01/java.920/a96654/basic.htm
One more thing, why are you using such an old version of JDeveloper? any reason not to upgrade to the 10.1.3 version of JDeveloper?
Also you might want to look into ADF and how it makes these type of database interactions easier.
See this demo:
http://www.oracle.com/technology/obe/obe1013jdev/adf_swing/master_detail_page_adfswing_bc.htm -
Retrive last inserted record from database table
Hi,
some body inserting a record into table 'A' through some procedure/java program.i want to retrive the last inserted record from database table.records are not stored in order.Can any body help me.In general, unless you are storing a timestamp as part of the row or you have some sort of auditing in place, Oracle has no idea what the "first" or "last" record in a table is. Nor does it track when a row was inserted.
- If you have the archived logs from the point in time when the row was inserted, you could use LogMiner to find the timestamp
- If the insert happened recently (i.e. within hours), you may be able to use flashback query to get the value
- If you're on 10g or later and the table was built with ROWDEPENDENCIES and the insert happened in the last few days and you can deal with a granularity of a few seconds and you don't need 100% accuracy, you could get the ORA_ROWSCN of the row and convert that to a timestamp.
If this is something you contemplate needing, you need to store the data in the row or set up some sort of auditing.
Justin -
How to find last inserted record in the table.
Version: Oracle 10g
I have a table called "Manufacture" and 3 columns as mfno,itemname,quantity.
How to find last inserted record in the table "Manufacture".
As i come to know that Rowid is not result perfect results. Please provide your inputs.user13416294 wrote:
Version: Oracle 10gThat is not a version. That is a product name. A version is 10.1.0.2 or 10.2.0.4, etc.
I have a table called "Manufacture" and 3 columns as mfno,itemname,quantity.
How to find last inserted record in the table "Manufacture".Not possible as your data model does not cater for it. That simple.
If there is a need to determine some order or associate some time to an entity, then that should be part of the data model - and a relationship, or one or more attributes are needed to represent that information. Thus your data model in this case is unable to meet your requirements.
If the requirements are valid, fix the data model. In other words - your question has nothing to do with Oracle and nothing to do with rowid, rowscn or other pseudo columns in Oracle. It is a pure data modeling issue. Nothing more. -
Reg : first inserted record in a table
Hello all,
Could any of you help me in writing a query to get the first
inserted record into a table.
Suppose I've the following table :
my_table : structure
Name Null? Type
ID NOT NULL NUMBER
Ive inserted value 20 into the table first, and then inserted
value 10. I want to retrieve the first inserted record with
value 20. How do I write the query for that ??????
Awaiting for the reply,
Thanks in Advance...
SriniOne small disagreement with Andrew's posting, but
rownum is assigned to rows after they have been identified
as part of the result set, but before the ORDER BY is
applied. Hence the two queries ...
select * from my_table
where rownum = 1
order by id ASC
... and ...
select * from my_table
where rownum = 1
order by id DESC
... will probably return the same result.
However in neither case is the result guaranteed to be the
first inserted row.
If you had created a table very recently, and it had only a
single extent, you could get the first row of the first block of
that extent with ...
select * from my_table where rowid =
(select min(rowid) from my_table)
... but as Andrew says, the only way to do the job properly is
to timestamp the rows as they are inserted. Anything else
would only be of theoretical interest. -
How to insert record in sorted table
Hi,
Please tell me how to inser the record in the sorted internal table. This is the code which is not working properly. just tell me what r the changes need to b done.
Thanks,(reward points for sure)
DATA: BEGIN OF connection,
cityfrom TYPE spfli-cityfrom,
cityto TYPE spfli-cityto,
distid TYPE spfli-distid,
distance TYPE spfli-distance,
END OF connection.
DATA connection_tab LIKE sorted TABLE OF connection
WITH KEY cityfrom
with header line.
SELECT cityfrom cityto distid distance
FROM spfli
INTO connection.
INSERT connection INTO connection_tab.
ENDSELECT.
loop at connection_tab.
write: / connection_tab-cityfrom, connection_tab-cityto, connection_tab-distid, connection_tab-distance.
endloop.
connection-cityfrom = 'Bangalore'.
connection-cityto = 'Delhi'.
connection-cityfrom = 'KL'.
connection-cityfrom = '2500'.
insert connection to connection_tab .
loop at connection_tab.
write: / connection_tab-cityfrom, connection_tab-cityto, connection_tab-distid, connection_tab-distance.
endloop.Hi,
sorry that's by mistake.. but i m getting runtime error if i insert record into sorted table
DATA: BEGIN OF connection,
cityfrom TYPE spfli-cityfrom,
cityto TYPE spfli-cityto,
distid TYPE spfli-distid,
distance TYPE spfli-distance,
END OF connection.
DATA connection_tab LIKE sorted TABLE OF connection
WITH unique KEY cityfrom
with header line.
SELECT cityfrom cityto distid distance
FROM spfli
INTO connection.
INSERT connection INTO connection_tab.
ENDSELECT.
loop at connection_tab.
write: / connection_tab-cityfrom, connection_tab-cityto, connection_tab-distid, connection_tab-distance.
endloop.
connection-cityfrom = 'Bangalore'.
connection-cityto = 'Delhi'.
connection-distid = 'KL'.
connection-distance = '2500'.
insert connection into table connection_tab .
loop at connection_tab.
write: / connection_tab-cityfrom, connection_tab-cityto, connection_tab-distid, connection_tab-distance.
endloop. -
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; -
Inserting records from internal table to database table
Hi all,
i want to insert records from internal table to zDatabase table, can u plz guide me which statement is better in performance to insert the records.
1) insert one by one record from internal table
loop at itab.
insert ztable from wa.
endloop.
2) insert total records at a time
INSERT <dbtabname> CLIENT SPECIFIED FROM TABLE itab.
or let me know if any other statement is there with high performance.
i internal table contains nearly 40000 records.
thanks.Hi,
Insert the entire table at atime rather than a record so as to increase the performance.
you can use INSERT <dbtabname> CLIENT SPECIFIED FROM TABLE itab.
or
MODIFY ZPRODUCT FROM TABLE GI_AFPO.
Regards,
Raj. -
Using Crystal 2008 to insert records into a table
Hi,
We have a unique need to use Crystal to insert records into a table. We have managed to test a report that can write into a temporary table. This is done by using sql command object and uses the following code :
INSERT INTO TEMP_TABLE (ORDERID)
VALUES ({?orderid}) (-- where orderid a parameter).
This test report asks for an order id and then inserts the record perfectly fine.
Now moving on to the real report - This report basically prints orders in batches and we want to insert order id into a temporary table to ensure we don't print orders that were already printed. To do this we created a sub report "insert orders" that has the above insert command. The main report passes the orderid to subreport and the idea is that the subreport would insert each time an order is passed. So if main report printed 50 orders ids, the then it would do 50 inserts individually into the temp table.
This however is NOT working. The report runs fine but there is no insert. Our hunch is that Crystal is not committing after every order id is passed from the main report. Not sure if we can set the AUTO COMMIT ON as a default somewhere?
Wondering if any one has attempted this or has any insights?
Regards,
Mohit.
Environment is - Crystal 2008 and Oracle 11GR2, we are using Oracle drivers (and not odbc)Hmmm... I don't use Oracle but the syntax looks good...
You've already tested it and I assume that you are using the same driver in the production report as you used in the test, so that shouldn't be an issue...
how are you pulling the data? Is the final SELECT statement that pulls the report data in the same command as the INSERT script, or is the INSERT script in it's own command?
The reason I ask... If you are trying to pass a multi-valued parameter to a command, it won't work. If you have the insert command as it's own command while the data is being pulled with linked tables or a separate command, it is possible that the report itself will execute as expected w/o passing a value to the insert script.
If it's all in 1 command (as it should be), a bad parameter would fail in the final SELECT causing an error.
Also... are rows null or empty string values being added to table when the report executes? This would be an indication that the command is being executed but isn't getting the parameter value.
Jason -
Find the latest updated or the latest inserted record in a table
Hi All,
Thanks in advance
Just a simple question
How do we find the latest updated or the latest inserted record in a table ?
Provide some queries in SQL?You can order by rowid desc to get lately inserted records, but I'm not sure about updated records.That is incorrect, Oracle might use old rowid's even in inserts and you cannot assure that the max(rowid) refers to the latest record.
If the table is created with rowdependencies one can use ORA_ROWSCN pseudo column to check on date/time when the last dml has been performed over that table. But, that has some limitations too, Old snapshots will be erased hence one can check the last dml with a time frame of few days.
Regards,
Prazy -
Can BO Enterprize SDK inserts records into user table
From Infostore can we create a jsp script using Java SDK to inserts records into user table??
Thanks
AmarHi Amar,
I want to retrieve data/records from Infostore and insert into a user table using JSP script. Is it possible to do this?
Infostore is a database used by BO Server. so any changes made in infostore through BO enterprise session is valid.
Say u want to retrive on of report present in folder <my folder>.
The you have to query for that. for eg.
boinfostore.query("select * from ci_infoobjects where si_kind ='report' and si_foldername='my folder'");
Create/add/insert any new information in infostore is done by functionalities provide by SDK.
like adding the user or scheduling a report will add new object to infostore.
If you directly access cms database and make any changes then , I am afraid you will end up with nightmare.
So it is always recommneded to access infostore/ cms database only from bo session.
For more information refer below link
[http://devlibrary.businessobjects.com/BusinessObjectsXIR2SP2/en/devsuite.htm]
then under Contents
BusinessObjects Enterprise SDK >> COM developer guide and API reference >> Query Language Reference
do revert if any queries
Thanks,
Praveen. -
Please help me in inserting data into table from XML message.
Hi Experts,
Please provide a procedure to implement my below requirement.
Since I am new to queue concept.
[code]- <MESSAGES>
- <MESSAGE ID="3026900">
<MSG_ID>3026900</MSG_ID>
<DT_POSTED>6/20/2013 08:15:48</DT_POSTED>
<POSTED_BY>GPD_MSG_EXTRACTOR</POSTED_BY>
<DT_LAST_QUEUED />
- <MSG>
- <WORK_SET TRANSACTION_ID="@TRANS_ID" TRANSACTION_TYPE="Batch" IS_ACID="@IS_ACID">
- <WORK_UNIT GROUP="LEAD_TIME" ACTION="UPDATE" AFFECTED="LEAD_TIME">
- <RECORDSET TABLE_NAME="LEAD_TIME">
- <xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
- <rs:data>
<z:row business_unit_id="3838" geo="AT" sku="A0814818" dw_maint_flag="False" stock_status_id="0" lead_time="30" est_qty="0" leadtime_lock="False" update_dts="2013-06-12T02:08:30.367" update_uid="DEACTIVATE_SKU_PROCESS" leadtime_dts="2010-05-22T02:21:21.707" leadtime_uid="Lead_Time_Rules" />
<z:row business_unit_id="202" geo="GB" sku="A0814819" dw_maint_flag="False" stock_status_id="0" lead_time="30" est_qty="0" leadtime_lock="False" update_dts="2013-06-12T02:08:30.367" update_uid="DEACTIVATE_SKU_PROCESS" leadtime_dts="2010-05-22T02:21:21.707" leadtime_uid="Lead_Time_Rules" />
<z:row business_unit_id="2828" geo="BE" sku="A0814820" dw_maint_flag="False" stock_status_id="0" lead_time="30" est_qty="0" leadtime_lock="False" update_dts="2013-06-12T02:08:30.367" update_uid="DEACTIVATE_SKU_PROCESS" leadtime_dts="2010-05-22T02:21:21.707" leadtime_uid="Lead_Time_Rules" />
</rs:data>
</xml>
</RECORDSET>
</WORK_UNIT>
- <WORK_UNIT GROUP="LEAD_TIME" ACTION="ADD" AFFECTED="LEAD_TIME">
- <RECORDSET TABLE_NAME="LEAD_TIME">
- <xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
- <rs:data>
<z:row business_unit_id="202" geo="GB" sku="A0814821" dw_maint_flag="False" stock_status_id="0" lead_time="30" est_qty="0" leadtime_lock="False" update_dts="2013-06-12T02:08:30.367" update_uid="DEACTIVATE_SKU_PROCESS" leadtime_dts="2010-05-22T02:21:21.707" leadtime_uid="Lead_Time_Rules" />
<z:row business_unit_id="2828" geo="BE" sku="A0814822" dw_maint_flag="False" stock_status_id="0" lead_time="30" est_qty="0" leadtime_lock="False" update_dts="2013-06-12T02:08:30.367" update_uid="DEACTIVATE_SKU_PROCESS" leadtime_dts="2010-05-22T02:21:21.707" leadtime_uid="Lead_Time_Rules" />
</rs:data>
</xml>
</RECORDSET>
</WORK_UNIT>
- <WORK_UNIT GROUP="LEAD_TIME" ACTION="DELETE" AFFECTED="LEAD_TIME">
- <RECORDSET TABLE_NAME="LEAD_TIME">
- <xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
- <rs:data>
<z:row business_unit_id="202" geo="GB" sku="A0814817" dw_maint_flag="False" stock_status_id="0" lead_time="30" est_qty="0" leadtime_lock="False" update_dts="2013-06-12T02:08:30.367" update_uid="DEACTIVATE_SKU_PROCESS" leadtime_dts="2010-05-22T02:21:21.707" leadtime_uid="Lead_Time_Rules" />
<z:row business_unit_id="2828" geo="BE" sku="A0814816" dw_maint_flag="False" stock_status_id="0" lead_time="30" est_qty="0" leadtime_lock="False" update_dts="2013-06-12T02:08:30.367" update_uid="DEACTIVATE_SKU_PROCESS" leadtime_dts="2010-05-22T02:21:21.707" leadtime_uid="Lead_Time_Rules" />
</rs:data>
</xml>
</RECORDSET>
</WORK_UNIT>
</WORK_SET>
</MSG>
</MESSAGE>
</MESSAGES>[/code]
The above XML message is receieved by our oracle queue.Once the message is receieved to our queue.
We have to process the message according to the action(UPDATE ADD DELETE).
From this message we have to process only 3 fields (geo sku lead_time).
These three feilds data should be processed into the SKU_LEAD_TIME table based on the action.
Req1:
IF the action is update then the records should be updated in the "LEAD_TIME_TABLE" table
IF the action is update then the records should be updated in the "LEAD_TIME_TABLE" table
based on the below condition.
[code]UPDATE LEAD_TIME_TABLE SET lead_time= lead time from xml message
WHERE LEAD_TIME_TABLE.SKU=sku from xml message AND LEAD_TIME_TABLE.GEO=geo from xml message;[/code]
Req2:
IF the action is delete then the records should be deleted from the "LEAD_TIME_TABLE" table.
based on the below condition.
[code]DELETE FROM LEAD_TIME_TABLE
WHERE LEAD_TIME_TABLE.SKU=sku from xml message AND LEAD_TIME_TABLE.GEO=geo from xml message;[/code]
Req3:
IF the action is add then the records should be inserted in the "LEAD_TIME_TABLE" and "LEAD_TIME_TABLE_STAGING" table
based on the below conditions.
Req3.1:
If SKU from XML message is available in "SKU_TABLE" table
then the three parameter(GEO SKU LEAD_TIME) values from XML message should be inserted into "LEAD_TIME_TABLE" table.
Req3.2:
If SKU from XML message is not available in "SKU_TABLE" table
then the three parameter(GEO SKU LEAD_TIME) values from XML message should be inserted into "LEAD_TIME_TABLE_STAGING" table.
Req3.3:
Once the new SKU is avilable in "SKU_TABLE" table then the corresponding SKU record should be
inserted into "LEAD_TIME_TABLE" table and that record should be deleted from "LEAD_TIME_TABLE_STAGING" table.
I am posting required scripts and test cases.
[code]CREATE TABLE LEAD_TIME_TABLE(sku VARCHAR2(20),model VARCHAR2(20),class CHAR(1),geo VARCHAR2(6),lead_time NUMBER,created DATE);
CREATE TABLE LEAD_TIME_TABLE_STAGING(sku VARCHAR2(20),geo VARCHAR2(6),lead_time NUMBER);
CREATE TABLE SKU_TABLE(sku VARCHAR2(20),geo VARCHAR2(6),lead_time NUMBER);
INSERT INTO SKU_TABLE VALUES('A0814817','GB',30);
INSERT INTO SKU_TABLE VALUES('A0814818','AT',30);
INSERT INTO SKU_TABLE VALUES('A0814819','GB',30);
INSERT INTO SKU_TABLE VALUES('A0814820','BE',30);
INSERT INTO SKU_TABLE VALUES('A0814821','GB',30);
INSERT INTO LEAD_TIME_TABLE(SKU,GEO,LEAD_TIME) VALUES('A0814817','GB',30);
INSERT INTO LEAD_TIME_TABLE(SKU,GEO,LEAD_TIME) VALUES('A0814818','AT',20);
INSERT INTO LEAD_TIME_TABLE(SKU,GEO,LEAD_TIME) VALUES('A0814819','GB',20);
INSERT INTO LEAD_TIME_TABLE(SKU,GEO,LEAD_TIME) VALUES('A0814820','BE',20);
INSERT INTO LEAD_TIME_TABLE_STAGING VALUES('A0814822','BE',30);[/code]
From the above message.
Test case for req3.1:
The action for SKU numbers "A0814821" "A0814822" are insert.
The SKU number "A0814821" is available in SKU_TABLE table.
so the record should be inserted in the LEAD_TIME_TABLE.
[code]SELECT * FROM LEAD_TIME_TABLE;
SKU GEO LEAD_TIME
A0814817 GB 30
A0814818 AT 20
A0814819 GB 20
A0814820 BE 20
A0814821 GB 30[/code]
Test case for req3.2:
The action for SKU numbers "A0814821" "A0814822" are insert.
The SKU number "A0814822" is not available in SKU_TABLE table.
so the record should be inserted in the LEAD_TIME_TABLE_STAGING.
[code]SELECT * FROM LEAD_TIME_TABLE_STAGING;
SKU GEO LEAD_TIME
A0814822 BE 30[/code]
Test case for req3.3:
The action for SKU numbers "A0814821" "A0814822" are insert.
The SKU number "A0814822" is not available in SKU_TABLE table.
Once I insert SKU number "A0814822" in SKU_TABLE table.
The corresponding records automatically should be inserted in the LEAD_TIME_TABLE
and should be deleted from LEAD_TIME_TABLE_STAGING.
[code]SELECT * FROM LEAD_TIME_TABLE_STAGING; --- should return NULL.
SELECT * FROM LEAD_TIME_TABLE;
SKU GEO LEAD_TIME
A0814817 GB 30
A0814818 AT 20
A0814819 GB 20
A0814820 BE 20
A0814821 GB 30
A0814822 BE 30[/code]
Please help me.
Thanks in advance.Hi,
I have resolved this issue.
But I have stuck up in implementing some of the scenarios.
Req1:
IF the action is update then the records should be updated in the "LEAD_TIME_TABLE" table
IF the action is update then the records should be updated in the "LEAD_TIME_TABLE" table
based on the below condition.
UPDATE LEAD_TIME_TABLE SET lead_time= lead time from xml message
WHERE LEAD_TIME_TABLE.SKU=sku from xml message AND LEAD_TIME_TABLE.GEO=geo from xml message;
Req3:
IF the action is add then the records should be inserted in the "LEAD_TIME_TABLE" and "LEAD_TIME_TABLE_STAGING" table
based on the below conditions.
Req3.1:
If SKU from XML message is available in "schema_name.SKU_TABLE" table.
The schema_name.SKU_TABLE table should be selected based on "business_unit_id" of XML message and "sid" of MAPPING table WHERE business_unit_id=sid.
then the three parameter(GEO SKU LEAD_TIME) values from XML message and two fields MODEL,CLASS from SKU_TABLE
should be inserted into "LEAD_TIME_TABLE" table.
Req3.2:
If SKU from XML message is not available in "schema_name.SKU_TABLE" table
The schema_name.SKU_TABLE table should be selected based on "business_unit_id" of XML message and "sid" of MAPPING table WHERE business_unit_id=sid.
then the four parameter(BUSINESS_UNIT_ID GEO SKU LEAD_TIME) values from XML message
should be inserted into "LEAD_TIME_TABLE_STAGING" table.
Req3.3:
Once the new SKU is avilable in "schema_name.SKU_TABLE" table then the corresponding SKU record should be
inserted into "LEAD_TIME_TABLE" table and that record should be deleted from "LEAD_TIME_TABLE_STAGING" table.
The schema_name.SKU_TABLE table should be selected based on "business_unit_id" of LEAD_TIME_TABLE_STAGING and "sid" of MAPPING table WHERE business_unit_id=sid.
I am posting required scripts and test cases.
[code]CREATE TABLE LEAD_TIME_TABLE(sku VARCHAR2(20),model VARCHAR2(20),class CHAR(1),geo VARCHAR2(6),lead_time NUMBER,created DATE);
CREATE TABLE LEAD_TIME_TABLE_STAGING(business_unit_id NUMBER,sku VARCHAR2(20),geo VARCHAR2(6),lead_time NUMBER);
CREATE TABLE SKU_TABLE(sku VARCHAR2(20),model VARCHAR2(20),class VARCHAR2(10));
CREATE TABLE mapping(sid NUMBER,schema_name VARCHAR2(20));
INSERT INTO LEAD_TIME_TABLE(SKU,GEO,LEAD_TIME) VALUES('A0814817','GB',30);
INSERT INTO LEAD_TIME_TABLE(SKU,GEO,LEAD_TIME) VALUES('A0814818','AT',20);
INSERT INTO LEAD_TIME_TABLE(SKU,GEO,LEAD_TIME) VALUES('A0814819','GB',20);
INSERT INTO LEAD_TIME_TABLE(SKU,GEO,LEAD_TIME) VALUES('A0814820','BE',20);
INSERT INTO SKU_TABLE VALUES('A0814817','M125','C111');
INSERT INTO SKU_TABLE VALUES('A0814818','M127','A111');
INSERT INTO SKU_TABLE VALUES('A0814819','M126','A111');
INSERT INTO SKU_TABLE VALUES('A0814820','N100','B111');
INSERT INTO SKU_TABLE VALUES('A0814821','P123','B111');
INSERT INTO mapping VALUES(202,'WEDB');
INSERT INTO mapping VALUES(2828,'HR');
INSERT INTO mapping VALUES(3838,'BB');
[/code]
Test case for req3.1:
The action for SKU numbers "A0814821" "A0814822" are insert.
The SKU number "A0814821" is available in schema_name.SKU_TABLE table.
so the record should be inserted in the LEAD_TIME_TABLE.
[code]SELECT * FROM LEAD_TIME_TABLE;
SKU MODEL CLASS GEO LEAD_TIME
A0814817 M125 C111 GB 30
A0814818 M127 A111 AT 20
A0814819 M126 A111 GB 20
A0814820 N100 B111 BE 20
A0814821 P123 B111 GB 30
[/code]
Test case for req3.2:
The action for SKU numbers "A0814821" "A0814822" are insert.
The SKU number "A0814822" is not available in SKU_TABLE table.
so the record should be inserted in the LEAD_TIME_TABLE_STAGING.
[code]SELECT * FROM LEAD_TIME_TABLE_STAGING;
BUSINESS_UNIT_ID SKU GEO LEAD_TIME
2828 A0814822 BE 30[/code]
Test case3.3.3:
The action for SKU numbers "A0814821" "A0814822" are insert.
The SKU number "A0814822" is not available in SKU_TABLE table.
Once I insert SKU number "A0814822" in SKU_TABLE table.
The corresponding records automatically should be inserted in the LEAD_TIME_TABLE
and should be deleted from LEAD_TIME_TABLE_STAGING.
[code]INSERT INTO SKU_TABLE VALUES('A0814822','P123','B111');
SELECT * FROM LEAD_TIME_TABLE_STAGING; --- should return NULL.
SELECT * FROM LEAD_TIME_TABLE;
SKU MODEL CLASS GEO LEAD_TIME
A0814817 M125 C111 GB 30
A0814818 M127 A111 AT 20
A0814819 M126 A111 GB 20
A0814820 N100 B111 BE 20
A0814821 P123 B111 GB 30
A0814822 P123 B111 GB 30[/code]
I am able to implement Req1 and Req3.1 for action UPDATE and INSERT in single merge statement.
However my code is not taking care of all my requirements.
Please find my below code.
[code] CREATE OR REPLACE PACKAGE BODY messg_values_process
AS
procedure ProcessInboundLtimeMessage(p_xml_message XmlType)
is
begin
for work_unit in (
select message.MESSAGE_ID
, work_unit.ACTION
, work_unit.LEADTIME_NODES
from XmlTable(
'/MESSAGES/MESSAGE'
passing p_xml_message
columns
MESSAGE_NO for ordinality
, MESSAGE_ID number path '@ID'
, WORK_UNIT_NODES XmlType path 'MSG/WORK_SET/WORK_UNIT'
) message
, XmlTable(
XmlNamespaces(
'urn:schemas-microsoft-com:rowset' as "rs"
, '#RowsetSchema' as "z"
'/WORK_UNIT'
passing message.WORK_UNIT_NODES
columns
WORK_UNIT_NO for ordinality
, ACTION varchar2(10 char) path '@ACTION'
, LEADTIME_NODES XmlType path 'RECORDSET[@TABLE_NAME="LEAD_TIME"]/xml/rs:data/z:row'
) work_unit
LOOP
CASE work_unit.ACTION
WHEN 'ADD' THEN MergeData(work_unit.LEADTIME_NODES);
WHEN 'UPDATE' THEN MergeData(work_unit.LEADTIME_NODES);
WHEN 'DELETE' THEN RemoveData(work_unit.LEADTIME_NODES);
ELSE null;
END CASE;
END LOOP;
END ProcessInboundLtimeMessage;
procedure MergeData(p_leadtime_nodes XmlType)
is
begin
if (p_leadtime_nodes is not null) then
merge into LEAD_TIME_TABLE old
using(
select *
from XmlTable(
XmlNamespaces(
'urn:schemas-microsoft-com:rowset' as "rs"
, '#RowsetSchema' as "z"
'/z:row[not(@business_unit_id=following-sibling::z:row/@business_unit_id)]'
passing p_leadtime_nodes
columns
ITEM_NO for ordinality
, BUSINESS_UNIT_ID number path '@business_unit_id'
, GEO varchar2(20 char) path '@geo'
, SKU varchar2(20 char) path '@sku'
, LEAD_TIME number path '@lead_time'
) NEW
ON (old.VK_UNIT = new.SKU
AND old.GEO=new.GEO)
when matched then update
set old.LEAD_TIME = new.LEAD_TIME
when not matched then INSERT
( old.VK_UNIT
, old.MODEL
, old.CLASS
, old.GEO
, old.LEAD_TIME
, old.COUNTDOWN
, old.LAST_UPDATED_DATE
values
( new.SKU
,'A123'
,'A1234'
, new.GEO
, new.LEAD_TIME
, 'N'
, sysdate
end if;
exception
when others then
LogDataError(
'MergeData Procedure Failed #: '||chr(10)||sqlerrm
, null
, null
END MergeData;
END messg_values_process;
/[/code]
Please help me.
Thanks. -
Insert record from one table to another with help of cursor
Plz help!!!
tables are - 1. country( country_id pk, country_name, region_id)
2. a( country_id , country_name, region_id)
table a data are
1 a 1
2 b 2
3 c 3
null d 4
5 e 5
6 f 6
7 g 7
insert record from table a to country table with help of cursor, insert all not null records.
this procedure does not give correct result
create or replace
procedure amit as
cursor c1 is select * from a;
rw a%rowtype;
begin
open c1;
fetch c1 into rw;
while(c1%found)
loop
insert into countries values(rw.country_id,rw.country_name,rw.region_id);
commit;
fetch c1 into rw;
if rw.country_id is null then
fetch c1 into rw;
end if;
end loop;
close c1;
exception
when others then
dbms_output.put_line('exception name= '||rw.country_name);
end;bluefrog wrote:
You don't need cursor at all;
create or replace procedure amit as
begin
insert into countries (Country_ID, Country_Name, Region_ID)
(select a.Country_ID
,a.Country_Name
,a.Region_ID
from a
dbms_output.put_line('Rows inserted : ' || sql%rowcount);
commit;
end;
Bluefrog you missed where clause. :)
insert into countries (Country_ID, Country_Name, Region_ID)
(select a.Country_ID
,a.Country_Name
,a.Region_ID
from a
where country_id is not null
);
Maybe you are looking for
-
LCD 20" Cinema Display Not Working on MBP
Hi people! Somehow, the Apple Cinema Display (LCD) of 20" isn't working when I plug it to the MBP (late 2011). The monitor remains black after pluging it. Sometimes is detected by the MBP, and sometimes it isn't. Quite random thing. Same hapens when
-
I have buttons on my Bookmarks bar for any site that I frequently visit. How do I prevent ANYTHING from coming up when I type in the address bar? I found it a long time ago but I never changed it. Now I can't figure out how to get back there.
-
Eclipse "cannot be resolved to a type" and new .JAR lib - config prob?
I'm trying to make use of the Commons HttpClient library in a project being built in Eclipse (3.1). I have a sample program (PostXML) that runs into "cannot be resolved to a type" on the "HttpClient" object. I think the problem is that the JRE 1.4.2
-
How to disable folders snapping to grid on desktop
I want to disable snap to grid of all folders, icons, jpegs, etc. on desktop. What I want is ability to move stuff around randomly.
-
Jdev 11g taking more time to display data on screen
HI I am using Jdeveloper 11g , I am experiencing very slow when the web page gets loaded, The screen has ADF table with the 20 columns and all columns are editable,sortable and filterable. Approximately It is taking 8 to 11 seconds just to display da