How to format & in insert statement
SQL> insert into test
2 values('aaa & aaa');
Enter value for aaa: a
old 2: values('aaa & aaa')
new 2: values('aaa a')
The values should contain 'aaa & aaa'. But seem oracle recognize & as a keyword. Have the way to format & as a string?
Daron
Use
set define OFFto prevent SQL*Plus from parsing scripts for substitution variables.
Similar Messages
-
How to tune the Insert statement?
Hi ,
I am using 10.2.0.4.0 version of oracle.
i am having one insert statement , which comes almost all the time in the TOP of my AWR elapsed time section.
And its somewhat similar to as below.
Query:
INSERT INTO a (InvoicePK, CheckPK)
SELECT DISTINCT ih.InvoicePK, cd.CheckPK
FROM at,
cd,
ih,
rd
WHERE at.AttachmentPK = :1
AND cd.CheckPK = at.CheckPK
AND at.AttachmentPK = rd.AttachPK
AND ih.PAYPK = cd.PAYEEPAYPK
AND ih.PayerNS = cd.PayerNS
AND ih.PayerPayId = cd.PayerPayId
AND ih.UpperInvoiceNum = rd.UPPERINVNUM
AND ih.InvoiceStatusCD NOT IN ('REJ', 'DNY');
Below is the plan for the 'Select ' statement i.e. used in the insert statement.
Execution Plan:
Plan hash value: 2232002808
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 1 | 193 | 9 (23)| 00:00:01 | | |
| 1 | HASH UNIQUE | | 1 | 193 | 9 (23)| 00:00:01 | | |
|* 2 | HASH JOIN | | 1 | 193 | 8 (13)| 00:00:01 | | |
| 3 | NESTED LOOPS | | 10 | 1740 | 4 (0)| 00:00:01 | | |
| 4 | NESTED LOOPS | | 1 | 85 | 3 (0)| 00:00:01 | | |
| 5 | TABLE ACCESS BY INDEX ROWID | at | 1 | 16 | 2 (0)| 00:00:01 | | |
|* 6 | INDEX UNIQUE SCAN | atpk1 | 1 | | 1 (0)| 00:00:01 | | |
| 7 | TABLE ACCESS BY INDEX ROWID | cd | 7359K| 484M| 1 (0)| 00:00:01 | | |
|* 8 | INDEX UNIQUE SCAN | cdpk1 | 1 | | 1 (0)| 00:00:01 | | |
|* 9 | TABLE ACCESS BY GLOBAL INDEX ROWID| ih | 10 | 890 | 2 (0)| 00:00:01 | ROWID | ROWID |
|* 10 | INDEX RANGE SCAN | IH_PAYPK_PAYERNS_PAYID | 5 | | 1 (0)| 00:00:01 | | |
| 11 | TABLE ACCESS BY INDEX ROWID | rd | 9 | 171 | 3 (0)| 00:00:01 | | |
|* 12 | INDEX RANGE SCAN | IDX_rd | 9 | | 2 (0)| 00:00:01 | | |
Predicate Information (identified by operation id):
2 - access("IH"."UPPERINVOICENUM"="RD"."UPPERINVNUM")
6 - access("AT"."ATTACHMENTPK"=7794833983)
8 - access("CD"."CHECKPK"="AT"."CHECKPK")
9 - filter("IH"."INVOICESTATUSCD"<>'REJ' AND "IH"."INVOICESTATUSCD"<>'DNY')
10 - access("IH"."PAYPK"="CD"."PAYEEPAYPK" AND "IH"."PAYERNS"="CD"."PAYERNS" AND "IH"."PAYERPAYID"="CD"."PAYERPAYID")
12 - access("RD"."ATTACHPK"=7794833983)
Statistics
1 recursive calls
0 db block gets
71 consistent gets
0 physical reads
0 redo size
316 bytes sent via SQL*Net to client
240 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
3 rows processed
The 'select' Statement executes with in seconds resulting 3 distinct records, but the insert statement takes ~20sec(Elaps time per execution
as shown in AWR report) for one time execution, so what must be the reason , and how should i proceed to resolve this performance issue?You can do as follows:
- Enable trace
- execute the insert statement
- use tkprof (and put the results here) to see where's its taking long
Also, while insert is being executed, what are the wait events you see ?
I dont think there is problem with plan. -
How to prepare an INSERT statement from the resultset
Hi Friends ,
I have to generate CREATE and INSERT statements for the Table already present in the database .
I can prepare CREATE statement by getting the MetaData from the database . Is it possible to create INSERT statement for the data already present in the database table if so how.
Thanks ,
Rajesh ReddyYou should be able to do something like SELECT * FROM foo WHERE 1 = 2. No rows will be returned. Call ResultSet#getMetaData() to get the meta data for the column names and types. You should then be able to dynamically create your own INSERT statement.
- Saish -
How to change Bulk Insert statement from MS SQL to Oracle
Hi All,
Good day, I would like to bulk insert the content of a file into Oracle db. May I know how to change the below MS SQL syntax to Oracle syntax?
Statement statement = objConnection.createStatement();
statement.execute("BULK INSERT [TBL_MERCHANT] FROM '" MERCHANT_FILE_DIR "' WITH ( FIELDTERMINATOR = '~~', ROWTERMINATOR = '##' )");
Thanks in advance.
cs.Oracle SQL Loader utility allows you to insert data from flat file to database tables.
Go to SQL Loader links on following url to learn more on this utility
http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/server.920/a96652/toc.htm
Chandar -
How to execute these insert statements as a batch?
Hello,
I have these three insert sql statements which execute individually. I want to execute them as a batch:
sql = "Insert into FirstTable (MessageId, MsgDate, MsgTitle) values (?, ?, ?)";
insertStatement = connection.prepareStatement(sql);
insertStatement.setInt(1, jmsgid);
insertStatement.setString(2, jlogdate);
insertStatement.setString(3, jmsgtitle);
insertStatement.executeUpdate();
sql = "Insert into SecondTable (MessageId, MsgDate, MsgTitle) values (?, ?, ?)";
insertStatement = connection.prepareStatement(sql);
insertStatement.setInt(1, jmsgid);
insertStatement.setString(2, jlogdate);
insertStatement.setString(3, jmsgtitle);
insertStatement.executeUpdate();
sql = "Insert into ThirdTable (MessageId, MsgDate, MsgTitle) values (?, ?, ?)";
insertStatement = connection.prepareStatement(sql);
insertStatement.setInt(1, jmsgid);
insertStatement.setString(2, jlogdate);
insertStatement.setString(3, jmsgtitle);
insertStatement.executeUpdate();
I tried the following method, but something is wrong. Can somebody help with executing these inserts as a batch?
stmt = connection.createStatement(); // connection pool
sql = "Insert into FirstTable (MessageId, MsgDate, MsgTitle) values (?, ?, ?)";
insertStatement.setInt(1, jmsgid);
insertStatement.setString(2, jlogdate);
insertStatement.setString(3, jmsgtitle);
stmt.addBatch(sql);
sql = "Insert into SecondTable (MessageId, MsgDate, MsgTitle) values (?, ?, ?)";
insertStatement.setInt(1, jmsgid);
insertStatement.setString(2, jlogdate);
insertStatement.setString(3, jmsgtitle);
stmt.addBatch(sql);
sql = "Insert into ThirdTable (MessageId, MsgDate, MsgTitle) values (?, ?, ?)";
insertStatement.setInt(1, jmsgid);
insertStatement.setString(2, jlogdate);
insertStatement.setString(3, jmsgtitle);
stmt.addBatch(sql);
stmt.executeBatch();
Thank you,
LoganErrr I can't for the life of me understand why you thought that would work. I am bit concerned about how you assembled this code... did you copy and paste and hope for the best?
It should be.....
1) Get a preparedStatement using your sql. Do this step once.
2) For each query you want to batch.... set each of the parameters and call addBatch. Call all this on the prepared statement.
3) Then call executeBatch on the prepared statement.
You do not need the other vanilla statement for anything.
One important thing to note. When you batch parameters for batch prepared statement execution you can only (hopefully obviously) batch for the same SQL query. You can't do one insert and another update in the same query. It has to be all the same query.. just different parameters. This won't effect what you are doing in the above but sometimes it confuses people and they get into trouble later so I thought I would mention it now. -
Relation between record in a form and insert statement written in button
hi all,
i am using Forms [32 Bit] Version 6.0.8.24.1 (Production).
i have a master detail form with relation
A is master of B, B is master of C and a button which resides on control block(other than A,B,C).
so i will insert a one record into the block 'A' and i will press button which will insert particular record into particular table.
so when i try to move to next record('A' block) it is asking for database change. when i give 'yes' everything is ok. but when i give 'no'(w.r.t that record) and moves to next record and inserts the record and insert record throguh button also, at this time user press 'yes' then the first record is not saving but what ever i have inserted through the insert statement is not rolling back.
How can i control insert statement with the respect to datablock change in the block.
The block 'C' data is going to the other table through insert statement the block 'C' i am posting. So due to 'post' the block is not getting cleared so insert statement is also firing.
In other words i want to unpost the posted data when user press 'no' in the database message.
I know there is nothing to do with the forms message. But is its possible to control when user press 'no' then the insert statement should not gets saved into the table.
Please help.
Thanks..
Edited by: GD on Jun 27, 2011 5:38 AMFirst off, you need to understand how Oracle Forms interacts with an Oracle database. Forms natively handles all DML transactions for you. Meaning, if you have a Forms data block based on a database table, Forms will generate all the necessary DML to handle any changes that occur in that block. You do not need to write your own DML statements in code.
so i will insert a one record into the block 'A' and i will press button which will insert particular record into particular table.Is Block "A" based on a table? How are you inserting the record into the table? If you are writting your own DML to insert the record this would explain why you are being prompted to save when you change records. As I mentioned, if your block is based on a table, Forms will know if you change a value within the block.
How can i control insert statement with the respect to datablock change in the block.If your blocks are based on tables, let Forms handle the DML! don't do it yourself.
In other words i want to unpost the posted data when user press 'no' in the database messageIf your block is based on a table, when you are prompted to save changes - answering 'NO' will automatically clear the current record of the data block (in essence - rollback the change).
Craig... -
Does anyone know how to create an INSERT statement with JSP using
variables??
I can do the insert if I code the values of the variables in the statement,
but when I try to use variables to do the insert it tries to insert the
variable name and not the value of the variable into the table.
Thanks,
Doug
"Doug Schaible" <[email protected]> wrote in message news:<bicO7.1279268$[email protected]>...
> I can do the insert if I code the values of the variables in the statement,
> but when I try to use variables to do the insert it tries to insert the
> variable name and not the value of the variable into the table.
Doug,
I think you missed the <%= blahblah %> syntax.
Regards
drit
-
How to convert XML content into SQL INSERT statements
Hi all,
I'm very new to XML. Forgive me if I don't use technical XML terms. :-)
We are planning to convert SQL queries into XML format using a third party tool.
After that we have to read the XML files and use the tokens to insert into custom tables.
So, basically we have to create INSERT statements using the data stored in the XML file.
How do we go about reading / parsing the XML file in Java?
Pls help!
Regards,
SamThis is the requirement with an example.
eg. if the following SQL query is fed into the 3rd party system,
select last_name,job_id,salary from employees a, deptno b
where a.deptno = b.deptno
the output would be,
<?xml version="1.0" ?>
<sqlscript dbvendor="MSSQL">
<fullselectstmt nestlevel="0">
<subselectstmt><selectclause><fieldlist>
<field><fieldname>
<attr>
<sourcetoken toketype="" dbobjtype="field">last_name</sourcetoken>
</attr>
</fieldname>
</field>
<field><fieldname>
<attr>
<sourcetoken toketype="" dbobjtype="field">job_id</sourcetoken>
</attr>
</fieldname>
</field>
<field><fieldname>
<attr>
<sourcetoken toketype="" dbobjtype="field">salary</sourcetoken>
</attr>
</fieldname>
</field>
</fieldlist></selectclause>
<fromclause><joinlist><join nestlevel="0">
<lztable><simpletable><attr>
<sourcetoken toketype="" dbobjtype="table">employees</sourcetoken>
</attr><aliasclause withas="false"><sourcetoken toketype="" dbobjtype="table alias">a</sourcetoken></aliasclause></simpletable></lztable></join><join nestlevel="0">
<lztable><simpletable><attr>
<sourcetoken toketype="" dbobjtype="table">deptno</sourcetoken>
</attr><aliasclause withas="false"><sourcetoken toketype="" dbobjtype="table alias">b</sourcetoken></aliasclause></simpletable></lztable></join></joinlist></fromclause>
<whereclause><expression exprtype="Expr_Comparison" exproop="="><attr>
<sourcetoken toketype="" dbobjtype="table alias">a</sourcetoken>
<sourcetoken toketype="" dbobjtype="unknown">.</sourcetoken>
<sourcetoken toketype="" dbobjtype="field">deptno</sourcetoken>
</attr><attr>
<sourcetoken toketype="" dbobjtype="table alias">b</sourcetoken>
<sourcetoken toketype="" dbobjtype="unknown">.</sourcetoken>
<sourcetoken toketype="" dbobjtype="field">deptno</sourcetoken>
</attr></expression>
</whereclause></subselectstmt></fullselectstmt>
</sqlscript>
So, using the output file, the list of columns (under token "field") last_name,job_id and salary should be inserted into LIST_COLUMNS table. So 3 INSERT statements should be created for 3 columns.
The list of tables (under token "table") employees and dept should be inserted into LIST_TABLES table. So 2 INSERT statements should be created for the 2 tables.
Regards,
Sam -
How to insert 20 rows in single insert statement
I have one table with one column user_name. I have list of 20 users. how do I insert 20 user in a single insert statement.
table name bp_portal_vault_users.
user name will be like this.
[email protected]
[email protected]
Thank you.insert into bp_portal_vault_users(yourColumn)
select 'User1' from dual union all
select 'User2' from dual union all
select 'User3' from dual union all
select 'User4' from dual union all
select 'User5' from dual union all
select 'User6' from dual union all
select 'User7' from dual union all
select 'User8' from dual union all
select 'User9' from dual union all
select 'User10' from dual union all
select 'User20' from dual -
How to improve performance of insert statement
Hi all,
How to improve performance of insert statement
I am inserting 1lac records into table it takes around 20 min..
Plz help.
Thanx In Advance.I tried :
SQL> create table test as select * from dba_objects;
Table created.
SQL> delete from test;
3635 rows deleted.
SQL> commit;
Commit complete.
SQL> select count(*) from dba_extents where segment_name='TEST';
COUNT(*)
4
SQL> insert /*+ APPEND */ into test select * from dba_objects;
3635 rows created.
SQL> commit;
Commit complete.
SQL> select count(*) from dba_extents where segment_name='TEST';
COUNT(*)
6
Cheers, Bhupinder -
How to retrieve value from insert statement
hi,
how can i get a certain value from insert statement and store it in a variable.
suppose i am inserting emp_no , emp_name , emp_salary to employee table
and i want to store the emp_name in a variable for other processing,
how can i accomplish this ? i'm guessing that i have to use trigger,
but dont know the procedure .
any help will be greatly appreciated
thanksinsert into <table> valiues (....) returning <expression> into <variable>
You could and should have found this using the SQL Language reference manual
or
http://www.morganslibrary.org/reference/insert.html
Sybrand Bakker
Senior Oracle DBA -
How to get the table name and bind columns names in an INSERT statement ?
I have an INSERT statement with input parameters (for example
INSERT INTO my_table VALUES (:a, :a, :a)) and I want to know
without parsing the statement which is the name of table to
insert to and the corresponding columns.
This is needed to generate the SELECT FOR UPDATE statement to
refetch a BLOB before actually writing to it. The code does not
know in advance the schema (generic code).
Thanks in advance,
Joseph CanedoOnce you have prepared your statement, you can execute the
statement with the OCI_DESCRIBE_ONLY mode before binding any
columns. Then you can use OCIParamGet to find out about each
column (column index is 1-based). You should get OCI_NO_DATA or
ORA-24334 if there are no more columns in the statement. Note
that the parameter descriptor from OCIParamGet is
allocated/freed internally by OCI; you do not need to manage it
explicitly. The parameter descriptor is passed to OCIAttrGet in
order to obtain for instance the maximum size of data in the
column OCI_ATTR_DATA_SIZE. You can also get the column name in
this way, although I do not remember the #define off the top of
my head. Getting the table name appears to be much more
difficult; I have never had to do that yet. Good luck. -Ralph -
How to assign value from insert statement to variable from a trigger
Hi,
I got this really annoying problem and I don't know if I am doing it correctly.
I have a BEFORE INSERT trigger on a table. When someone executes an insert statement I want to grab the value of a column from that statement and assign it to a variable and then do stuff with it. I'm stuck on the assignment.. look below..
CREATE OR REPLACE TRIGGER CARS.geotest2_trigger
BEFORE INSERT ON CARS.GEO_TEST2
FOR EACH ROW
DECLARE
v_chainkey nchar(32);
v_chainkey2 nchar(32);
not_exists EXCEPTION;
BEGIN
:NEW.CHAINKEY := v_chainkey;
SELECT GEO_TEST.CHAINKEY INTO v_chainkey2 FROM GEO_TEST WHERE GEO_TEST.CHAINKEY = v_chainkey;
IF v_chainkey2 = '' or v_chainkey2 is null THEN
RAISE not_exists;
ELSE
INSERT INTO GEO_TEST2 VALUES(:NEW.CHAINKEY, :NEW.BLA, :NEW.FOO);
END IF;
EXCEPTION
WHEN not_exists THEN
RAISE_APPLICATION_ERROR(-20010, 'Chainkey does not exist in parent table GEO_TEST');
END;
I keep getting this error
Error: ORA-04098: trigger 'CARS.GEOTEST2_TRIGGER' is invalid and failed re-validation
SQLState: 42000
ErrorCode: 4098It isn't assigning because v_chainkey is not at the left hand side of the assignment statement.
test@ORA10G>
test@ORA10G>
test@ORA10G> declare
2 x number := 5;
3 y number;
4 begin
5 x := y; -- does not assign anything to y; assigns NULL to x,
6 -- because y is NULL at this point
7 -- so, essentially the value 5 of x is *LOST* now
8 dbms_output.put_line('x = '||x);
9 end;
10 /
x =
PL/SQL procedure successfully completed.
test@ORA10G>
test@ORA10G>
test@ORA10G>In any case, here's what you are probably looking for:
test@ORA10G>
test@ORA10G> --
test@ORA10G> drop table geo_test;
drop table geo_test
ERROR at line 1:
ORA-00942: table or view does not exist
test@ORA10G> drop table geo_test2;
drop table geo_test2
ERROR at line 1:
ORA-00942: table or view does not exist
test@ORA10G>
test@ORA10G> create table geo_test (chainkey nchar(32));
Table created.
test@ORA10G> insert into geo_test (chainkey) values ('a');
1 row created.
test@ORA10G> insert into geo_test (chainkey) values ('');
1 row created.
test@ORA10G>
test@ORA10G> create table geo_test2 (chainkey nchar(32), bla number(1), foo number(1));
Table created.
test@ORA10G>
test@ORA10G>
test@ORA10G> CREATE OR REPLACE TRIGGER geotest2_trigger
2 BEFORE INSERT ON GEO_TEST2
3 FOR EACH ROW
4 DECLARE
5 v_chainkey2 nchar(32);
6 not_exists EXCEPTION;
7 BEGIN
8 SELECT GEO_TEST.CHAINKEY INTO v_chainkey2 FROM GEO_TEST WHERE nvl(GEO_TEST.CHAINKEY,'~') = nvl(:new.chainkey,'~');
9 IF v_chainkey2 is null THEN
10 RAISE not_exists;
11 END IF;
12 EXCEPTION
13 WHEN not_exists THEN
14 RAISE_APPLICATION_ERROR(-20010, 'Chainkey does not exist in parent table GEO_TEST');
15 END;
16 /
Trigger created.
test@ORA10G>
test@ORA10G> --
test@ORA10G> insert into geo_test2 (chainkey,bla,foo) values ('b',1,1);
insert into geo_test2 (chainkey,bla,foo) values ('b',1,1)
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at "TEST.GEOTEST2_TRIGGER", line 5
ORA-04088: error during execution of trigger 'TEST.GEOTEST2_TRIGGER'
test@ORA10G>
test@ORA10G> --
test@ORA10G> insert into geo_test2 (chainkey,bla,foo) values (null,1,1);
insert into geo_test2 (chainkey,bla,foo) values (null,1,1)
ERROR at line 1:
ORA-20010: Chainkey does not exist in parent table GEO_TEST
ORA-06512: at "TEST.GEOTEST2_TRIGGER", line 11
ORA-04088: error during execution of trigger 'TEST.GEOTEST2_TRIGGER'
test@ORA10G>
test@ORA10G> --
test@ORA10G> insert into geo_test2 (chainkey,bla,foo) values ('a',1,1);
1 row created.
test@ORA10G>
test@ORA10G>
test@ORA10G>pratz
I think the sole purpose of that "not_exists" exception is this -
If you try to insert a NULL value for GEO_TEST2.CHAINKEY, then this trigger will throw an error even if at least one NULL value exists in GEO_TEST.CHAINKEY column.
Not sure if that's something that you wanted.
Message was edited by:
pratz -
How to use the structure on my insert statement.
I have a function and returning a structure:
<CFSET stLoc_and_AttIDs=StructNew(1)>
<CFSET
stLoc_and_AttIDs["LocID"]="#getLocID.LocationID#">
<CFSET
stLoc_and_AttIDs["AttID"]="#getLocID.AttachmentID#">
I call this function like this:
<CFSET LocAndAttIDs= MyFunction(LocName)>
I'm having difficulty in refering to the values of this
structure in my insert statement:
I'm doing it this way and got error, I'm sure I didn't do it
right, please help.
Insert Into MyTable (Column1, Column2, Column3, .....)
VALUES (#LocAndAttIDs.stLoc_and_AttIDs["LocID"]="#,
#LocAndAttIDs.stLoc_and_AttIDs["AttID"], 23)is that the actual code? if so, it looks like your # aren't
matched up properly. for example, i count 3. there should be an
even number :)
you don't seem to have a closing # after the 2nd variable,
and the closing # for the first variable seems to be a little....
late. it should be after the closing bracket ( ] ), since that's
where the variable name ends. -
How to do an insert with a select statement, with unique values
Hi,
I have an insert statement like this
INSERT INTO TABLEA (ID, zzz
SELECT sequence.nextval, zzz FROM TABLEB
The problem is TABLEA won't allow any duplicates and TABLEB will return duplicates. Yet I can't use the distinct keyword since I am using a sequence.
Thanks.Samuel411 wrote:
Hi,
I have an insert statement like this
INSERT INTO TABLEA (ID, zzz
SELECT sequence.nextval, zzz FROM TABLEB
The problem is TABLEA won't allow any duplicates and TABLEB will return duplicates. Yet I can't use the distinct keyword since I am using a sequence.
Thanks.Why not?
drop sequence s
create sequence s;
create table distincting (col1 number, object_owner varchar2(30));
TUBBY_TUBBZ?
insert into distincting
select s.nextval, object_owner
from
select
distinct
owner as object_owner
from dba_objects
9 );
37 rows created.
TUBBY_TUBBZ?
Maybe you are looking for
-
How to create the selection screen dynamically
Hi, I have a requirement to create the selection screen Dynamically. All the fields that should appear on the selection screen will be available in a custom table. So, based on the entries available in the Z tables, the selection screen should be bui
-
7942G IP phone does not upgrade and does not accept locale
Hello everyone! I stumbled upon a rather strange behavior on a CP-7942G IP phone. It is a new phone, which I have myself unpacked from the box, along with 2 others. Now, the problem is, this particular phone did not load the user-locale, specified in
-
Required fields in a presentation
In a bpm object presentation we want to have some of the text input fileds required. When they are not filled in we want a message to display to the user. i tried setting the Not Null attribute in the bpm object but that does not work. We are using 6
-
Three way switch compaitable with labview 2010 SP1
Hi, I am in need of three way switch which is compaitable with labview 2010 SP1. Plz help me .. thanks mahadev
-
Hi, i've found some errors in the error_log_crit apache logs. I would understand what does they mean. Any help please.. MOD_OC4J_0184: Failed to find an oc4j process for destination: OC4J_PCRM MOD_OC4J_0145: There is no oc4j process (for destination: