Please help --Error in insert into Statement
Error in insert into statement while connecting to ms-access.
import java.sql.*;
public class stupid8
public stupid8()
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};"+"DBQ=d:/Servlet/registration.mdb");
PreparedStatement s=con.prepareStatement("insert into Deposit (username,date,amount) values(?,?,?)");
s.setString(1,"username");
s.setString(2,"date");
s.setString(3,"amount");
s.executeUpdate();
System.out.println("Success");
catch(Exception e)
System.out.println("Error: "+e);
public static void main(String args[])
new stupid8();
}
My first guess is that the database is objecting to the use of "date" as a column name; "date" is often a reserved word in databases.
It would be less of a guess if you posted the actual error message.
Similar Messages
-
Error with INSERT INTO statement
My INSERT statement looks like the following:
String insert = "INSERT INTO UserDetails (lockedOut) VALUES (1)
where registrationNo = ('"+registrationNo+"')";
stmt.executeUpdate(insert);
The error message:
Missing semicolon (;) at end of SQL statement.
I've been trying to figure this out for 2 days now - has anyone got a suggestionHi.
You need to add a semicolon inside the string.
String insert = "INSERT INTO UserDetails (lockedOut) VALUES (1)
where registrationNo = ('"+registrationNo+"') ; ";
Nimo. -
Error while inserting into ms access using jsp
i am using the following code to insert values from textboxes into access database
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(url);
Statement stmt=con.createStatement();
//ResultSet rs = null;
//String sql = ("INSERT INTO co-ords VALUES ('" + nam + "','" + lat + "','" + lon + "','"+ latm +"','"+ lonm +"','"+ latmd +"','"+ lonmd +"','"+ latms +"','"+ lonms +"') ");
String sql = "INSERT INTO co-ords (nam ,lat , lon , latm ,lonm , latmd , lonmd ,latms , lonms) VALUES ('" + nam + "','" + lat + "','" + lon + "','"+ latm +"','"+ lonm +"','"+ latmd +"','"+ lonmd +"','"+ latms +"','"+ lonms +"') ";
out.println(sql);
stmt.executeUpdate(sql);
the output i get is
INSERT INTO co-ords (nam ,lat , lon , latm ,lonm , latmd , lonmd ,latms , lonms) VALUES ('cck','28.656529681148545','77.23440170288086','28','77','39','14','23.508','3.8472') Exception:java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
can somebody help me?Simple,
Some error in your query right. Unable to understand Quotation stuff.
Well understand it properly else error will follow forever :)
Without String, Straight Away Values
stmt1.executeUpdate("insert into Login_Details values('Example','Exmaple')");This is the query with Login_Id Pass_Word String containing the value
stmt1.executeUpdate("insert into Login_Details values('"+Login_Id+"','"+Pass_Word+"')");Then storing sql as string and pass it in executeUpdate(sql)
String sql="insert into Login_Details values ('example','example') "String + Values in String
String sql="insert into Login_Details values ('"+example+"','"+example+"') "Just first it . Hope this reply solve ur SQL EXCEPTIONG
Sachin Kokcha -
Hi,
I'm new to coldfusion and was doing a practice survey. I'm
getting the following error:
The INSERT INTO statement contains the following unknown
field name: 'recipes'. Make sure you have typed
the name correctly, and try the operation again.
The error occurred in (coldfusion form): line 405
403 :
(lname,fname,yourID,status,preprog_survey,recipes,activity,tips,stress,other,othertext,we ight_result,lbs_gained,lbs_lost,behaviors,desc_behaviors,most_help,improve_prog)
404 : values
405 :
('#lname#','#fname#','#yourID#','#status#','#preprog_survey#','#recipes#','#activity#','# tips#','#stress#','#other#','#othertext#','#weight_result#','#lbs_gained#','#lbs_lost#','# behaviors#','#desc_behaviors#','#most_help#','#improve_prog#')
406 : </cfquery>
407 :
SQL Insert into maintaint
(lname,fname,yourID,status,preprog_survey,recipes,activity,tips,stress,other,othertext,we ight_result,lbs_gained,lbs_lost,behaviors,desc_behaviors,most_help,improve_prog)
values ('last name','first
name','444444','member,'No','0','0','1','0','1','no work, all
play','gained',' too many','','Yes','Dreaming of eating better, but
not doing it','This survey!','no improvement suggestions'
VENDORERRORCODE -3502
SQLSTATE 42000
Can anyone tell me what this possibly means? I'm sure its
probably hard to understand without seeing the form. These are the
types of fields each are:
lname, fname, yourID = text
status = radio
preprog_survey = radio
recipes, activity,tips, stress, other, = checkboxes
othertext, = text
weight_result, = radio
lbs_gained,lbs_lost, = text
behaviors, = radio
desc_behaviors, most_help, improve_prog = textLooking at the code you supplied I noticed that for the
checkboxes values where '0' and '1'.
SQL Insert into maintaint
(lname,fname,yourID,status,preprog_survey,recipes,activity,tips,stress,other,othertext,we ight_result,lbs_gained,lbs_lost,behaviors,desc_behaviors,most_help,improve_prog)
values ('last name','first
name','444444','member,'No','0','0','1','0','1','no work, all
play','gained',' too many','','Yes','Dreaming of eating better, but
not doing it','This survey!','no improvement suggestions'
You don't need quotes around numeric values, only text.
Hope that helps you. -
[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 -
1 duplicate key error during insert into table
Dear Guru's
While upgrading the SAP_HR patch, I am facing this issue
Current level is SAPKE60455
Trying to apply patch - SAPKE60456
This is seen in the import log
Start import R3TRVDATV_512W_O ...
client 000: 1
client 001: 1
client 070: 1
client 080: 1
client 100: 1
client 320: 1
1 duplicate key error during insert into table T512T occured
End import R3TRVDATV_512W_O (with warnings)
Please help, thank in advance
R3trans is at version 6.19
Regards,
OmkarHello,
Issue was resolved after upgrading the R3trans
Regards,
Omkar -
Error while inserting into MS-SQL Server from Oracle using HS
Hi,
I am using hetrogeneous connection.
I want to insert into MS-SQL Server Table by selecting from Oracle Tables.
insert into tableone@mssql select * from table2;
Table2 is in oracle database.
while executing i'm getting
ORA-02025: all tables in the SQL statement must be at the remote database
Please guide me.
Regards
Salih KMsome guy come up a solution by himself before. go ahead and try it
ORA-02025 error while insert into emp@custard select .... -
INSERT INTO statement in java servlet.
Hiya
Was wondering if anyone knew how to use variables from an html form into a sql insert into statement? The constants work ok below, its just getting the variables to work.
//constants work ok.
rs = stmt.executeQuery("INSERT INTO ACCOUNTS " + " VALUES ('un', 'test2', 'test2', 'test2', 'test', 'test', 'test', 'test', 'test')");
//doesn't do anything no errors.
rs = stmt.executeQuery("INSERT INTO ACCOUNTS " + " VALUES ( '"+uname+"', " + " '"+fname+"', " + " '"+sname+"'," + "'"+address1+"'," + "'"+address2+"'," + "'"+town+"'," + "'"+county+"'," + "'"+postcode+"')");<html>
<head>
<title>
CreateAccount
</title>
</head>
<body>
<form method=get action=/servlet/website.CreateAccount>
<p> Username:
<input type=text name="username"> </p>
<p> Password:
<input type=text name="password"> </p>
<p> First Name:
<input type=text name="firstname"> </p>
<p> Surname:
<input type=text name="surname"> </p>
<p> 1st Line of Address:
<input type=text name="1address"> </p>
<p> 2nd Line of Address:
<input type=text name="2address"> </p>
<p> Town:
<input type=text name="town"> </p>
<p> County:
<input type=text name="county"> </p>
<p> Postcode:
<input type=text name="postcode"> </p>
<input type=submit>
</form>
</body>
</html>
package website;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CreateAccount extends HttpServlet {
private static final String CONTENT_TYPE = "text/html";
/**Initialize global variables*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
/**Process the HTTP Get request*/
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
ResultSet rs = null;
Connection con = null;
res.setContentType("text/html");
PrintWriter out = res.getWriter();
//get the variables entered in the form
String uname = req.getParameter("username");
String pwd = req.getParameter("password");
String fname = req.getParameter("firstname");
String sname = req.getParameter("surname");
String address1 = req.getParameter("1address");
String address2 = req.getParameter("2address");
String town = req.getParameter("town");
String county = req.getParameter("county");
String postcode = req.getParameter("postcode");
try {
// Load the database driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Get a Connection to the database
con = DriverManager.getConnection("jdbc:odbc:account", "", "");
//Add the data into the database
try
String sql = "INSERT INTO ACCOUNTS " + " VALUES (?,?,?,?,?,?,?,?)";
PreparedStatement statement = con.prepareStatement(sql);
statement.setString(1, uname);
statement.setString(2, fname);
statement.setString(3, sname);
statement.setString(4, address1);
statement.setString(5, address2);
statement.setString(6, town);
statement.setString(7, county);
statement.setString(8, postcode);
int numRowsChanged = statement.executeUpdate(sql);
statement.close();
//Statement stmt = null;
//stmt = con.createStatement();
//Create a Statement object
//constants work ok.
//rs = stmt.executeQuery("INSERT INTO ACCOUNTS " + " VALUES ('uname', 'test2', 'test2', 'test2', 'test', 'test', 'test', 'test', 'test')");
catch (Exception e)
// show that the new account has been created
out.println("<p> New account created: </p>");
out.println(" '"+uname+"'");
catch(ClassNotFoundException e) {
out.println("Couldn't load database driver: " + e.getMessage());
catch(SQLException e) {
out.println("SQLException caught: " + e.getMessage());
finally {
// Always close the database connection.
try {
if (con != null) con.close();
catch (SQLException ignored) { }
}ok now the regular statement with constant values inserts data into the database (the regular statement is being used with a result set ) but the prepared statement does not - there are no error messages but it does not insert any data either. The data is going into the variables due to the system.out.println, but is it going into the prepared statement? I believe the prepared statement is being executed with the executeupdate method. -
Please help error -9808 when downloading apps in itunes store anyone can help me out
please help error -9808 when downloading apps in itunes store anyone can help me out
Click here > iTunes: Advanced iTunes Store troubleshooting
Then "expand" Specific Conditions and Alert Messages
Then click 9808 -
I cant access my ymail PLEASE HELP I can log into yahoo but cant get to mail? Think the words configure & rand flash in address bar
Hi Acrylik,
Welcome to the Apple Support Communities!
For assistance resetting your Apple ID password, please use the information in the following article. I understand you have already attempted to reset via email and security questions, but the article also includes a link to contact Apple support if necessary.
If you forgot your Apple ID password
http://support.apple.com/kb/HT5787
Have a great day,
Joe -
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. -
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)
-
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 datatypesGavin,
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 -
Error when inserting into table - Undefined Variable
DB = Oracle 10.2.0.1
WEBSERV = Apache 2.0.55
LANG = PHP5
I have created (or more accurately, copied) a php script to insert data into one of my database tables when I press submit. The code is as follows (my connect string works fine and its included in the dbutils.php file):
<?php
if($submit == "submit"){
include "dbutils.php";
$query = "insert into users values (seq_user_usr_id.NEXTVAL, '$usr_name')";
$cursor = OCIParse ($db_conn, $query);
if ($cursor == false){
echo OCIError($cursor)."<BR>";
exit;
$result = OCIExecute ($cursor);
if ($result == false){
echo OCIError($cursor)."<BR>";
exit;
OCICommit ($db_conn);
OCILogoff ($db_conn);
else{
echo '
<html><body>
<form method="post" action="index.php">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Please enter a username:</td>
<td><input type="text" name="usr_name"></input><br></td>
</tr>
<tr>
<td><input type="submit" name="button" value="Submit"></input></td>
</tr>
</table>
</form>
</body></html>
?></p>I am getting the following error regarding an undefined variable:
[Fri Jan 20 13:11:22 2006] [error] [client 127.0.0.1] PHP Notice: Undefined variable: submit in C:\\Program Files\\Apache Group\\Apache2\\htdocs\\mywebsite\\test.php on line 3
Where would I declare this variable? It is just a check to see if the submit button is pressed as far as I can see. Any help would be greatfully appreciated.
W8I have changed the code to this:
<?php
if($submit == "submit"){
include "dbutils.php";
$usr_name = $_POST['usr_name'];
$query = "insert into users (column1, column2) values (seq_user_usr_id.NEXTVAL, '$usr_name')";
$cursor = OCIParse ($db_conn, $query);
if ($cursor == false){
echo OCIError($cursor)."
exit;
$result = OCIExecute ($cursor);
if ($result == false){
echo OCIError($cursor)."
exit;
OCICommit ($db_conn);
OCILogoff ($db_conn);
else{
$submit = $_POST['submit'];
echo '
<html><body>
<form method="post" action="index.php">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Please enter a username:</td>
<td><input type="text" name="usr_name"></input>
</td>
</tr>
<tr>
<td><input type="submit" name="submit" value="submit"></input></td>
</tr>
</table>
</form>
</body></html>
?>And now I am getting the following error:
[Mon Jan 23 13:45:32 2006] [error] [client 127.0.0.1] PHP Notice: Undefined index: submit in C:\\Program Files\\Apache Group\\Apache2\\htdocs\\mywebsite\\test2.php on line 24Does anyone have any ideas?
I am struggling to find an example to work from to get this working. If anyone can point me to any literature that will explain the code so that I can work this out for myself that would also be a great help. -
ORA-06502: error when inserting into table via db link with long datatype
Folks,
I am getting the following error:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small.
This occurs when an insert is done via a database link into a table that has a LONG data type for one of the columns, and the string contains some carriage returns and or line feeds.
I have checked by removing the db link, and inserting into a local table with identical column data types, where there is no error.
So this might be another db link bug?
So I need to remove the carriage returns and/or line feeds
in my pl/sql block in the page process. I have tried
l_text := REPLACE(l_text, CHR(10), ' ');
l_text := REPLACE(l_text, CHR(13), NULL);
but still getting the ORA-06502. Would really appreciate some advice here, please.
Cheers
KIMScott,
Time to 'fess up':
My fault sorry, the error was coming from another page process where I had allowed insufficient string length for one of the variables, and my error message did not identify the page process clearly.
This leads me to make a request for future releases, could the system error messages state which page process caused the problem?
One other thing I notice, and this might be a feature not a fault, the page processes are numbered: "Page Process: 3 of 5". However process 3 is not the 3rd one to be processed, and probably refers to the order in which they are created. Should the number reflect the process order?
Cheers
KIM
Maybe you are looking for
-
We are legally required to store all communications between any employees' and their clients for a period of 7 years. When we used Outlook 2010 this was not a problem with the PST file format. However our recent change to Exchange server now leave
-
How do I make a smart album with ONLY pictures of a face with no one else?
I'm not handy with logic so if this is simple, I apologize. I'm trying to make an album of pics of my girlfriend. So I do a smart album and it comes up with her pics. But what I WANT is only the photos where she's in them with no one else tagged. How
-
HT1338 Trying to update my desktop software... Help!
Trying to update my desktop software. I currently have OS X Version 10.5.8, I need a version 10.6.8 or higher. I tried with the Apple icon but says "software update doesn't have any new software for your computer at this time." Any advise anyone?
-
Exchange rate from the previous date
Hello, Is there a way to define the system to take the last available exchange, if todayu2019s rate doesnu2019t exists? Thanks Revital
-
SWC_GET_ELEMENT within GET_PROPERTY
Hi, I need to do the following. I have a BOR Object that is holding an ID in its container. That ID is filled properly for sure. Now I need this ID as a key to select a value from a dictionary table to set a property of that BOR object. The code so f