Subquery inside INSERT INTO
Hi !
I have a problem to put a Subquery inside an INSERT INTO-Statement.
I try it this way: (the select-statemnet alone is running fine) (the listing is shortened)
INSERT INTO W_CACS_ENTRY
location_code
,case_num
,billing_account_id
select
a.location_code
,a.case_num
,billing.billing_account_id
from
select
max(billing_account_id) as billing_account_id
from
select /*+ parallel ( a 4)*/
account_no
,external_id
) case,
w_billing_accounts bill
where
case.account_no = bill.account_no
) billing
w_CO_CASE_HIST a
where .....bla...
When I try to compile it i get the following error:
ORA-Seperator S223:
(S223) Expecting: statement_terminator BEGIN CASE DECLARE END IDENTIFIER IF LOOP
Is it forbidden to use Subquerys inside an INSERT TO statement?
Are there any other possibilities?
thanks and greets
bang
yes, it's inside a PL/SQL-Package. I'm using TOAD to develop it.
Here is the whole query:
INSERT INTO W_CACS_ENTRY
location_code
,case_num
,EVENT_TYPE
,EVENT_DATE
,event_id
,cacs_case_sequence
,part
,billing_account_id
select
a.location_code
,a.case_num
,'CACS IN' as EVENT_TYPE
,a.DATE_TIME as EVENT_DATE
,a.sequence_number as event_id
,seq_cacs_case_dwh.nextval as cacs_case_sequence
,substr(seq_cacs_case_dwh.currval, -1) as part
,billing.billing_account_id
from
select /*+ use_hash (case bill) parallel (bill 4) */
case_num
,LOCATION_CODE
,max(billing_account_id) as billing_account_id
from
select /*+ parallel ( a 4)*/
account_no
,external_id as case_num
,101010 as LOCATION_CODE
from
w_CUSTOMER_ID_ACCT_MAP ar
union all
select /*+ parallel ( a 4)*/
account_no
,external_id as case_num
,202020 as LOCATION_CODE
from
c_CUSTOMER_ID_ACCT_MAP ar
) casec,
w_billing_accounts bill
where
casec.account_no = bill.account_no
group by
case_num
,LOCATION_CODE
) billing
w_CO_CASE_HIST a
where a.coll_activity_code in ('EN','MS')
and a.DATE_TIME > to_date ('01.01.2006','dd.mm.yyyy')
and billing.case_num = a.case_num
and billing.location_code = a.location_code
;
Similar Messages
-
Subquery in insert into clause
what is the use of using subquery in insert into clause.
e.g. insert into (select empno from emp)
values(1234)
regards
kiranNot really of common use, I think, but WITH CHECK OPTION option could be one reason for using that. Let's see an example :
SQL> INSERT INTO
2 (SELECT empno, ename, deptno FROM emp WHERE deptno < 20)
3* VALUES (1111, 'Brown', 30)
SQL> /
1 row created.That's the same as
SQL> insert into emp (empno, ename, deptno)
2 values(1111, 'Brown', 30);But
SQL> INSERT INTO
2 (SELECT empno, ename, deptno FROM emp WHERE deptno < 20 WITH CHECK OPTION)
3* VALUES (2222, 'Green', 30)
SQL> /
(SELECT empno, ename, deptno FROM emp WHERE deptno < 20
ERROR at line 2:
ORA-01402: view WITH CHECK OPTION where-clause violation
SQL>Paul -
Subquery inside Merge Into under 11g
create or replace
PROCEDURE SP_IN_CURRENCY
IS
CURSOR csr IS SELECT currency_code FROM in_currency ORDER BY currency_code;
v_hkd_rate NUMBER(15,9);
BEGIN
SELECT spot_rate INTO v_hkd_rate FROM in_currency WHERE in_currency.currency_code = 'HKD';
MERGE INTO currency USING
(SELECT currency_code, spot_rate FROM in_currency WHERE in_currency.currency_code = 'HKD') rec_in_currency
ON (currency.currency_code = rec_in_currency.currency_code)
WHEN MATCHED THEN
UPDATE
SET currency.CURRENCY_NAME = NVL(
(SELECT value
FROM tb_resources
WHERE PACKAGE = 'currency'
AND locale = 'en_US'
AND KEY = rec_in_currency.currency_code
), currency.CURRENCY_NAME),
currency.spot_rate = (v_hkd_rate/rec_in_currency.spot_rate),
currency.SPOT_RATE_IN_USD = rec_in_currency.spot_rate
WHEN NOT MATCHED THEN
INSERT
currency_code,
CURRENCY_NAME,
spot_rate,
SPOT_RATE_IN_USD
VALUES
rec_in_currency.currency_code,
(SELECT value FROM tb_resources WHERE PACKAGE = 'currency' AND locale = 'en_US' AND KEY = rec_in_currency.currency_code),
(v_hkd_rate/rec_in_currency.spot_rate),
rec_in_currency.spot_rate
COMMIT;
END SP_IN_CURRENCY;
The above stored procedure created successfully in 9i but retrun the following error when create on 11g. Anyone has idea? is it the limitation of 11g? The problem was caused by this subquery:
(SELECT value FROM tb_resources WHERE PACKAGE = 'currency' AND locale = 'en_US' AND KEY = rec_in_currency.currency_code),
Error(38,99): PL/SQL: ORA-00904: "REC_IN_CURRENCY"."CURRENCY_CODE": invalid identifiervalue assign in variable equals value return by subquery in USING clause
so (V_HKD_RATE / REC_IN_CURRENCY.SPOT_RATE) = 1
and CURRENCY_CODE = 'HKD'
key = rec_in_currency.currency_code is always 'HKD'
let's say
SPOT_RATE = 999
v_hkd_rate = 999
-- BEFORE:
select spot_rate
into v_hkd_rate
from in_currency
where in_currency.currency_code = 'HKD';
merge into currency using
select currency_code, spot_rate
from in_currency
where in_currency.currency_code = 'HKD'
) rec_in_currency
on
currency.currency_code = rec_in_currency.currency_code
when matched then update set
currency.currency_name = nvl
select value
from tb_resources
where package = 'currency'
and locale = 'en_US'
and key = rec_in_currency.currency_code
, currency.currency_name
,currency.spot_rate = (v_hkd_rate / rec_in_currency.spot_rate)
,currency.spot_rate_in_usd = rec_in_currency.spot_rate
when not matched then insert
currency_code
, currency_name
, spot_rate
, spot_rate_in_usd
values
rec_in_currency.currency_code
select value
from tb_resources
where package = 'currency'
and locale = 'en_US'
and key = rec_in_currency.currency_code
, (v_hkd_rate/rec_in_currency.spot_rate)
, rec_in_currency.spot_rate
-- AFTER:
merge into currency using
select currency_code, spot_rate
-- 'HKD', 999
from in_currency
where in_currency.currency_code = 'HKD'
) rec_in_currency
on
currency.currency_code = 'HKD'
when matched then update set
/* If value IS NULL update with current value? I think you should change it... */
currency.currency_name = nvl
select value
from tb_resources
where package = 'currency'
and locale = 'en_US'
and key ='HKD'
, currency.currency_name
, currency.spot_rate = 999/999
, currency.spot_rate_in_usd = 999
when not matched then insert
currency_code
, currency_name
, spot_rate
, spot_rate_in_usd
values
'HKD'
select value
from tb_resources
where package = 'currency'
and locale = 'en_US'
and key = 'HKD'
, 999/999
, 999
Can anybody check it?
*/ -
How to INSERT into table using CORRELATED subquery
I have 3 tables:
1.TEMP_PHONE(person_id, phonenumber, phone_type) - this holds all phone numbers relating to a person(just a temporary holding area)
2.PHONE_CONNECT(PERSON_ID, PHONE_ID) this table shows all the phone numbers relating to an individual. Phone_id is a unique number to identify a phonenumber and type(cell, work, home) - so in this table a person can have multiple phone ids)
3.MASTER_PHONE(PHONE_ID, PHONENUMBER, PHONE_TYPE) this is a master phone table. each combination of phone number and type has a unique identifier-phone_id.
What i need to figure out is how to populate PHONE_CONNECT with the information from TEMP_PHONE IF PERSON_ID already exists but phone_id is different. In other words, if the person gets a new phone number, i need to insert a new row into phone_connect.
Before that step is started, the master_phone is populated first with a new phone_id associated to the phonenumber/type
any help would be much appreciated. Thanks in advance.
So far, this is what i have come up with, but not sure if it makes sense:
insert into phone_connect(person_id)
select a.person_id
from temp_phone a
where
person_id = (select b.person_id from phone_connect b, master_phone c
where
a.person_id=b.person_id
and b.phone_id <> c.phone_id
and c.phonenumber||c.phone_type=a.phonenumber||a.phone_type);
update phone_connect c
set phone_id=(
select b.phone_id
from temp_phone a, master_phone b
where a.person_id = c.person_id
and a.phonenumber||a.phone_type = b.phonenumber||b.phone_type)
where phone_id is null;It does. You are right. But that's what i need help with. I don't think my code is correct. After the insert, the code is actually updating the same exact record I just inserted. I'm sure this all can be done with one insert. I just really don't know how to show that in my code.
I need to insert a new record into phone_connect with person_id and phone_id. phone_id is already populated in master_phone. I guess my problem is how to go about creating the joins to all three tables to make sure im inserting the data correctly, or not inserting data that already exists. -
Subquery for inserting doesn't work in Oracle package
I have experienced a very strange scenario while inserting data inside a Oracle package.
I have two tables:
- table "A"
Columns: "ID", "Value1", "...."
- table "A_Backup", which contains backup data for table A. It has one more column "BATCH_NUMBER" than table A
Columns: "BATCH_NUMBER", "ID", "Value1", "...."
I created following procedure in a package to backup data from table "A" to "A_Backup".
procedure proc_backup (v_id in number) is
declare
v_batch_number varchar2(20);
begin
/** generate a batch number using system date */
select 'BATCH' || to_char(sysdate, 'YYYYMMDDHH24MISS') into v_batch_number from dual;
/** insert Batch_NUMBER + data from A into A_BACKUP */
insert into A_BACKUP (select v_batch_number, id, value1, ... from A where A.id = v_id);
end proc_backup;
When I debug the procedure, it will not insert any data into A_BACKUP. Apparently, there are some data in table "A" meets criteria "A.id = v_id".
The strange thing: If I create same procedure. But this time I didn't put procedure inside the package, insert query will work.
Please help, I have spent a couple of days on this and never make it work. I also tried cursor, it doesn't work either. It seems Oracle package doesn't support "virtual table" (subquery in insert) or whatever you call it.Welcome to the forum!
Whenever you post provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION).
I don't see any package or test code that calls the procedure or error messages or results from any procedure calls.
You say you have a problem with a package but don't post the package version of the code you are having a problem with.
How is anyone supposed to find a problem in code that you don't post? And when you post use \ tags as discussed in the FAQ. -
How to insert into a table with a nested table which refer to another table
Hello everybody,
As the title of this thread might not be very understandable, I'm going to explain it :
In a context of a library, I have an object table about Book, and an object table about Subscriber.
In the table Subscriber, I have a nested table modeling the Loan made by the subscriber.
And finally, this nested table refers to the Book table.
Here the code concerning the creation of theses tables :
Book :
create or replace type TBook as object
number int,
title varchar2(50)
Loan :
create or replace type TLoan as object
book ref TBook,
loaning_date date
create or replace type NTLoan as table of TLoan;
Subscriber :
create or replace type TSubscriber as object
sub_id int,
name varchar2(25)
loans NTLoan
Now, my problem is how to insert into a table of TSubscriber... I tried this query, without any success...
insert into OSubscriber values
*(1, 'LEVEQUE', NTLoan(*
select TLoan(ref(b), '10/03/85') from OBook b where b.number = 1)
Of course, there is an occurrence of book in the table OBook with the number attribute 1.
Oracle returned me this error :
SQL error : ORA-00936: missing expression
00936. 00000 - "missing expression"
Thank you for your help1) NUMBER is a reserved word - you can't use it as identifier:
SQL> create or replace type TBook as object
2 (
3 number int,
4 title varchar2(50)
5 );
6 /
Warning: Type created with compilation errors.
SQL> show err
Errors for TYPE TBOOK:
LINE/COL ERROR
0/0 PL/SQL: Compilation unit analysis terminated
3/1 PLS-00330: invalid use of type name or subtype name2) Subquery must be enclosed in parenthesis:
SQL> create table OSubscriber of TSubscriber
2 nested table loans store as loans
3 /
Table created.
SQL> create table OBook of TBook
2 /
Table created.
SQL> insert
2 into OBook
3 values(
4 1,
5 'No Title'
6 )
7 /
1 row created.
SQL> commit
2 /
Commit complete.
SQL> insert into OSubscriber
2 values(
3 1,
4 'LEVEQUE',
5 NTLoan(
6 (select TLoan(ref(b),DATE '1985-10-03') from OBook b where b.num = 1)
7 )
8 )
9 /
1 row created.
SQL> select *
2 from OSubscriber
3 /
SUB_ID NAME
LOANS(BOOK, LOANING_DATE)
1 LEVEQUE
NTLOAN(TLOAN(000022020863025C8D48614D708DB5CD98524013DC88599E34C3D34E9B9DBA1418E49F1EB2, '03-OCT-85'))
SQL> SY. -
Customized Insert into Command
Dear All,
Here, I want to make a SQL script to do an INSERT INTO Statement from TABLE “A” to “B” like this
Insert into A select * from B
But catch is that – TABLE “A” is having e 4 extra columns(Year, Month, Week, Day), those not exists in TABLE “B”, & due to this Plain INSERT INTO statement is not working.
Therefore, I want to create a dynamic INSERT INTO command with skip of 4 said columns.
You can better understand this in this way..
My Desired.
Insert into A ( Id,Name,Address,City,Zip)
select Id,Name,Address,City,Zip from B
Please Help !
Thanks..Hi Visakh16,
Sorry for my earlier remark I was unclear.
Actually Error message is like this ..
Msg 512, Level 16, State 1, Line 4
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
If I’m executing this piece of code..
DECLARE @SQl varchar(max)
SELECT @SQL = 'INSERT A (' +
STUFF(
(SELECT ',' + COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = t.TABLE_NAME
AND TABLE_SCHEMA = t.TABLE_SCHEMA
),1,1,'') + ')
SELECT ' +
STUFF(
(SELECT ',' + COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = t.TABLE_NAME
AND TABLE_SCHEMA = t.TABLE_SCHEMA
),1,1,'') + ' FROM ' + TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES as t
WHERE TABLE_NAME = 'Sale2013'
--print @SQL
EXEC (@SQL)
Please help me to diagnose this .. -
I have a problem while executing an insert-statement from an ASP-script.
The problem is, that a statement like :
Insert into test(test1,test2) values('testing','testagain')
inserts 2 identical records instead of just 1
I'm working with Oracle 8i on win98
Any solutions ?
JesperHi,
You please check the asp code whether the insert is inside a loop. Check whether are you calling the form again. You please check whether are you doing refresh for the same form.
These are the possible places where these type of problem may occur.
bye -
MS SQL Server 2014: Error inserting into Temp table with index and identity field
In this thread, I mentioned a problem with SQL Server 2014:
SQL Server 2014: Bug with IDENTITY INSERT ON
The question was answered, it is a bug. To keep you informed on this issue, I open this discussion.
Problem:
The code below works perfectly fine on MS SQL Server 2008 R2 and MS SQL Server 2012, but gives an error every second time the proc is executed on MS SQL Server 2014. If I do not define any index on the temp table, the problem disappears. Defining the index
after the insert, does not help.
SET NOCOUNT ON
GO
IF EXISTS (SELECT 1 FROM sys.procedures WHERE name = 'usp_Test') DROP PROC dbo.usp_Test;
GO
CREATE PROC dbo.usp_Test AS
BEGIN
SET NOCOUNT ON
CREATE TABLE #Source(ID integer NOT NULL);
INSERT INTO #Source VALUES (1), (2), (3);
CREATE TABLE #Dest (ID integer IDENTITY(1,1) NOT NULL);
CREATE INDEX #IDX_Dest ON #Dest (ID);
PRINT 'Check if the insert might cause an identity crisis';
SELECT 'Source' AS SourceTable, * FROM #Source;
SELECT 'Destination' AS DestTable, * FROM #Dest;
SET IDENTITY_INSERT #Dest ON;
PRINT 'Do the insert';
INSERT INTO #Dest (ID) SELECT ID FROM #Source;
PRINT 'Insert ready';
SET IDENTITY_INSERT #Dest OFF;
SELECT * FROM #Dest;
DROP TABLE #Source;
DROP TABLE #Dest;
END;
GO
PRINT 'First execution of the proc, everything OK';
EXEC dbo.usp_Test;
PRINT '';
PRINT 'Second execution of the proc, the insert fails.';
PRINT 'Removing the index #IDX_Dest causes the error to disappear.';
EXEC dbo.usp_Test;
GO
DROP PROC dbo.usp_Test;
GOThere is some progress. Communication from a former Microsoft employee tells us this:
Shivendra Vishal
Engineer at Microsoft
I am no longer with MS, and I do not have code access, however from the public symbols, I could make out following:
sqlmin!SetidentI2I4+0x1f3:
000007fe`f4d865d3 488b10 mov rdx,qword ptr [rax] ds:00000000`00000000=????????????????
ExceptionAddress: 000007fef4d865d3 (sqlmin!SetidentI2I4+0x00000000000001f3)
ExceptionCode: c0000005 (Access violation)
ExceptionFlags: 00000000
NumberParameters: 2
Parameter[0]: 0000000000000000
Parameter[1]: 0000000000000000
Attempt to read from address 0000000000000000
This is a read AV and from registers it is clear that we were trying to move the value of location pointed by qword of register rax which is not valid:
rax=0000000000000000 rbx=0000000000000038 rcx=0000000000001030
rdx=0000000000000006 rsi=00000001f55def98 rdi=00000000106fd070
rip=000007fef4d865d3 rsp=00000000106fcf40 rbp=00000000106fcfe9
r8=0000000000000000 r9=00000001f55def60 r10=00000001f55defa0
r11=00000000106fcd20 r12=0000000000000000 r13=0000000000000002
r14=00000001f49c3860 r15=00000001f58c0040
iopl=0 nv up ei pl nz na po nc
cs=0033 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010206
The stack is:
# Child-SP RetAddr Call Site
00 00000000`106fcf40 000007fe`f30c1437 sqlmin!SetidentI2I4+0x1f3
01 00000000`106fd050 000007fe`f474e7ce sqlTsEs!CEsExec::GeneralEval4+0xe7
02 00000000`106fd120 000007fe`f470e6ef sqlmin!CQScanUpdateNew::GetRow+0x43d
03 00000000`106fd1d0 000007fe`f08ff517 sqlmin!CQueryScan::GetRow+0x81
04 00000000`106fd200 000007fe`f091cebe sqllang!CXStmtQuery::ErsqExecuteQuery+0x36d
05 00000000`106fd390 000007fe`f091ccb9 sqllang!CXStmtDML::XretDMLExecute+0x2ee
06 00000000`106fd480 000007fe`f08fa058 sqllang!CXStmtDML::XretExecute+0xad
07 00000000`106fd4b0 000007fe`f08fb66b sqllang!CMsqlExecContext::ExecuteStmts<1,1>+0x427
08 00000000`106fd5f0 000007fe`f08fac2e sqllang!CMsqlExecContext::FExecute+0xa33
09 00000000`106fd7e0 000007fe`f152cfaa sqllang!CSQLSource::Execute+0x86c
0a 00000000`106fd9b0 000007fe`f152c9e8 sqllang!CStmtExecProc::XretLocalExec+0x25a
0b 00000000`106fda30 000007fe`f152a1d8 sqllang!CStmtExecProc::XretExecExecute+0x4e8
0c 00000000`106fe1e0 000007fe`f08fa058 sqllang!CXStmtExecProc::XretExecute+0x38
0d 00000000`106fe220 000007fe`f08fb66b sqllang!CMsqlExecContext::ExecuteStmts<1,1>+0x427
0e 00000000`106fe360 000007fe`f08fac2e sqllang!CMsqlExecContext::FExecute+0xa33
0f 00000000`106fe550 000007fe`f0902267 sqllang!CSQLSource::Execute+0x86c
10 00000000`106fe720 000007fe`f0909087 sqllang!process_request+0xa57
11 00000000`106feee0 000007fe`f2bf49d0 sqllang!process_commands+0x4a3
12 00000000`106ff200 000007fe`f2bf47b4 sqldk!SOS_Task::Param::Execute+0x21e
13 00000000`106ff800 000007fe`f2bf45b6 sqldk!SOS_Scheduler::RunTask+0xa8
14 00000000`106ff870 000007fe`f2c136ff sqldk!SOS_Scheduler::ProcessTasks+0x279
15 00000000`106ff8f0 000007fe`f2c138f0 sqldk!SchedulerManager::WorkerEntryPoint+0x24c
16 00000000`106ff990 000007fe`f2c13246 sqldk!SystemThread::RunWorker+0x8f
17 00000000`106ff9c0 000007fe`f2c13558 sqldk!SystemThreadDispatcher::ProcessWorker+0x3ab
18 00000000`106ffa70 00000000`775d59ed sqldk!SchedulerManager::ThreadEntryPoint+0x226
19 00000000`106ffb10 00000000`7780c541 kernel32!BaseThreadInitThunk+0xd
1a 00000000`106ffb40 00000000`00000000 ntdll!RtlUserThreadStart+0x21
Unassembling the function:
000007fe`f4d8658e 4c8b10 mov r10,qword ptr [rax]
000007fe`f4d86591 4533e4 xor r12d,r12d
000007fe`f4d86594 410fb7d5 movzx edx,r13w
000007fe`f4d86598 4533c9 xor r9d,r9d
000007fe`f4d8659b 4533c0 xor r8d,r8d
000007fe`f4d8659e 488bc8 mov rcx,rax
000007fe`f4d865a1 4489642420 mov dword ptr [rsp+20h],r12d
000007fe`f4d865a6 41ff5230 call qword ptr [r10+30h]
000007fe`f4d865aa 8b5597 mov edx,dword ptr [rbp-69h]
000007fe`f4d865ad 4c8b10 mov r10,qword ptr [rax]
000007fe`f4d865b0 4489642438 mov dword ptr [rsp+38h],r12d
000007fe`f4d865b5 4489642430 mov dword ptr [rsp+30h],r12d
000007fe`f4d865ba 458d442401 lea r8d,[r12+1]
000007fe`f4d865bf 4533c9 xor r9d,r9d
000007fe`f4d865c2 488bc8 mov rcx,rax
000007fe`f4d865c5 c644242801 mov byte ptr [rsp+28h],1
000007fe`f4d865ca 4488642420 mov byte ptr [rsp+20h],r12b
000007fe`f4d865cf 41ff5250 call qword ptr [r10+50h]
000007fe`f4d865d3 488b10 mov rdx,qword ptr [rax] <=================== AV happened over here
000007fe`f4d865d6 488bc8 mov rcx,rax
000007fe`f4d865d9 4c8bf0 mov r14,rax
000007fe`f4d865dc ff5268 call qword ptr [rdx+68h]
000007fe`f4d865df 488d55e7 lea rdx,[rbp-19h]
000007fe`f4d865e3 4c8b00 mov r8,qword ptr [rax]
000007fe`f4d865e6 488bc8 mov rcx,rax
000007fe`f4d865e9 41ff5010 call qword ptr [r8+10h]
000007fe`f4d865ed f6450a04 test byte ptr [rbp+0Ah],4
I remember few issues with scan2ident function, I am not sure if they have fixed it however it appears that this is intoduced to SQL 2014 and we need help from MS to get this resolved as it needs code analysis.
It is not getting simulated for other versions of SQL apart from SQL 2014.
Also to add, interestingly, the value of rax is not visibly changed and it was successfully passed on to rcx, which has a valid value, so something should have changed the value of rax inside call to function using call qword ptr [r10+50h], and looking at this
it appears that it might be a list of functions and we are going at particular offset [50h]. So, bottom line is that the call to function qword ptr [r10+50h], should be changing something in rax, and debugging/analyzing this code might give us some more idea. -
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. -
Dear sirs,
please i want to write code inside button on form, this code for insert into table, and i want to write commit_form, but before execute always give me message, is there syntax for make commit after insert into
known that i use form 6i
best regards for all
YasserYasser,
I can't understand what you mean by but before execute always give me message,
And to write insert into statements in form, its better to use FORMS_DDL built-in, because, by this, we can commit the database without commiting the form.
FORMS_DDL('<insert into statement>');
FORMS_DDL('COMMIT');Regards,
Manu.
If my response or the response of another was helpful or Correct, please mark it accordingly -
Insert Into Vs Insert through a Procedure
Hi All,
I want to make a comparison between insertion into a table through normal insert into staement and through a procedure.
I create a table call test_table with 6 columns and a procedure to insert in that table.
I opened a session that make normal insert for 32 times and another session that uses the procedure to insert for 39 times. My experience says that insertion through a procedure is faster than normal insert into statement. but when i make trace for both sessions here is the results:
Session1(Normal Insert)
INSERT INTO TEST_TABLE
VALUES(:"SYS_B_0", :"SYS_B_1", :"SYS_B_2", :"SYS_B_3", :"SYS_B_4", :"SYS_B_5")
call count cpu elapsed disk query current rows
Parse 32 0.00 0.00 0 0 0 0
Execute 32 0.01 0.02 0 32 129 32
Fetch 0 0.00 0.00 0 0 0 0
total 64 0.01 0.03 0 32 129 32
Misses in library cache during parse: 1
Optimizer mode: CHOOSE
Parsing user id: 125 (CALLCNTR44)
Rows Execution Plan
0 INSERT STATEMENT MODE: CHOOSE
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 32 0.00 0.00 0 0 0 0
Execute 32 0.01 0.02 0 32 129 32
Fetch 0 0.00 0.00 0 0 0 0
total 64 0.01 0.03 0 32 129 32
Misses in library cache during parse: 1
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 0 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
total 0 0.00 0.00 0 0 0 0
Misses in library cache during parse: 0
32 user SQL statements in session.
0 internal SQL statements in session.
32 SQL statements in session.
1 statement EXPLAINed in this session.
Trace for Session2(Procedure Insert)
BEGIN sec1.INSERT_INTO_TEXT_TABLE (); END;
call count cpu elapsed disk query current rows
Parse 39 0.04 0.00 0 0 0 0
Execute 39 0.00 0.00 0 0 0 39
Fetch 0 0.00 0.00 0 0 0 0
total 78 0.04 0.01 0 0 0 39
Misses in library cache during parse: 1
Optimizer mode: CHOOSE
Parsing user id: 125 (CALLCNTR44)
INSERT INTO TEST_TABLE
VALUES('TEST COL1', 'TEST COL2', 'TEST COL3', 'TEST COL4', 'TEST COL5', 'TEST COL6')
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 39 0.03 0.00 0 0 80 39
Fetch 0 0.00 0.00 0 0 0 0
total 39 0.03 0.00 0 0 80 39
Misses in library cache during parse: 0
Optimizer mode: CHOOSE
Parsing user id: 474 (SEC1) (recursive depth: 1)
Rows Execution Plan
0 INSERT STATEMENT MODE: CHOOSE
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 117 0.04 0.02 0 0 0 0
Execute 117 0.03 0.03 0 0 0 78
Fetch 39 0.03 0.00 0 312 0 0
total 273 0.10 0.06 0 312 0 78
Misses in library cache during parse: 3
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 2 0.00 0.00 0 0 0 0
Execute 41 0.04 0.01 0 0 80 39
Fetch 2 0.00 0.00 1 5 0 2
total 45 0.04 0.02 1 5 80 41
Misses in library cache during parse: 2
118 user SQL statements in session.
2 internal SQL statements in session.
120 SQL statements in session.
1 statement EXPLAINed in this session.
So in session 2 parsing of the procedure it self is still done in each execution but for the statment inside it no and in session1 parsing for the insert is done for every execution. So does this proof my knowledge or it is wrong?
I see that instead of parsing the insert in session1 there is parsing for the procedure in session2 is that correct?
Thanks in advanceTomy3k_Bakr, you are doing the comparison wrong. Are you running these from sqlplus over and over again? Sqlplus parses every statement you send, this is not the correct way to compare.
Try this instead.
YAS@10G>create table t (a number,b number,c number);
Table created.
YAS@10G>r
1 create or replace procedure insert_t(pa number,pb number,pc number) as
2 begin
3 insert into t values(pa,pb,pc);
4* end;
Procedure created.Run this and see the results.
exec RUNSTATS_PKG.rs_start;
begin
for i in 1..10000 loop
insert /*+ sql */ into t values(i,i,i);
end loop;
end;
exec RUNSTATS_PKG.rs_middle;
begin
for i in 1..10000 loop
insert_t(i,i,i);
end loop;
end;
exec RUNSTATS_PKG.rs_stop;
Run1 ran in 124 hsecs
Run2 ran in 139 hsecs
run 1 ran in 89.21% of the time
Name Run1 Run2 Diff
LATCH.list of block allocation 1 0 -1
STAT...redo ordering marks 92 91 -1
STAT...table scans (short tabl 3 2 -1
LATCH.session idle bit 27 26 -1
LATCH.In memory undo latch 0 1 1
LATCH.file cache latch 3 2 -1
LATCH.redo allocation 8 7 -1
LATCH.archive process latch 1 0 -1
LATCH.Consistent RBA 2 3 1
LATCH.lgwr LWN SCN 3 2 -1
LATCH.mostly latch-free SCN 3 2 -1
LATCH.KMG MMAN ready and start 1 0 -1
LATCH.compile environment latc 3 2 -1
LATCH.session timer 0 1 1
LATCH.shared pool 2 3 1
STAT...change write time 11 12 1
STAT...table scan blocks gotte 6 4 -2
STAT...messages sent 2 4 2
STAT...data blocks consistent 3 1 -2
LATCH.channel operations paren 8 6 -2
STAT...rollbacks only - consis 3 1 -2
STAT...cleanout - number of kt 27 31 4
STAT...index fetch by key 6 2 -4
STAT...cluster key scans 6 2 -4
STAT...active txn count during 27 31 4
STAT...deferred (CURRENT) bloc 6 2 -4
STAT...consistent changes 20 24 4
STAT...consistent gets - exami 39 35 -4
STAT...session cursor cache hi 11 7 -4
STAT...CR blocks created 6 2 -4
STAT...commit cleanouts succes 6 2 -4
STAT...commit cleanouts 6 2 -4
STAT...workarea memory allocat 5 1 -4
STAT...calls to kcmgcs 27 31 4
STAT...execute count 10,014 10,009 -5
LATCH.active checkpoint queue 5 0 -5
STAT...opened cursors cumulati 14 8 -6
STAT...db block changes 20,324 20,318 -6
LATCH.redo writing 14 8 -6
STAT...parse count (total) 14 8 -6
STAT...CPU used when call star 131 138 7
STAT...calls to kcmgas 101 94 -7
LATCH.undo global data 50 43 -7
STAT...no work - consistent re 15 7 -8
LATCH.dml lock allocation 12 4 -8
STAT...DB time 132 140 8
STAT...cluster key scan block 12 4 -8
LATCH.library cache lock 16 8 -8
STAT...buffer is not pinned co 12 4 -8
LATCH.messages 27 17 -10
STAT...db block gets from cach 10,484 10,473 -11
STAT...db block gets 10,484 10,473 -11
STAT...enqueue releases 24 13 -11
STAT...enqueue requests 24 13 -11
STAT...recursive cpu usage 96 107 11
STAT...Elapsed Time 127 140 13
LATCH.enqueues 35 22 -13
STAT...redo entries 10,181 10,195 14
STAT...CPU used by this sessio 124 138 14
LATCH.library cache pin 20,072 20,056 -16
LATCH.cache buffers lru chain 135 153 18
STAT...table scan rows gotten 54 36 -18
STAT...calls to get snapshot s 37 19 -18
LATCH.library cache 20,094 20,073 -21
LATCH.enqueue hash chains 50 26 -24
STAT...bytes received via SQL* 1,210 1,185 -25
STAT...consistent gets 91 63 -28
STAT...consistent gets from ca 91 63 -28
STAT...free buffer requested 118 152 34
STAT...session logical reads 10,575 10,536 -39
LATCH.row cache objects 153 106 -47
LATCH.checkpoint queue latch 57 0 -57
LATCH.SQL memory manager worka 73 6 -67
LATCH.cache buffer handles 16 84 68
STAT...recursive calls 10,132 10,053 -79
LATCH.object queue header oper 334 437 103
LATCH.cache buffers chains 51,652 51,526 -126
LATCH.session allocation 258 104 -154
STAT...free buffer inspected 448 188 -260
LATCH.simulator lru latch 440 865 425
LATCH.simulator hash latch 458 892 434
STAT...hot buffers moved to he 1,222 276 -946
STAT...undo change vector size 684,064 682,932 -1,132
STAT...redo size 2,586,108 2,583,908 -2,200
Run1 latches total versus runs -- difference and pct
Run1 Run2 Diff Pct
94,017 94,489 472 99.50%For runstats see http://asktom.oracle.com/tkyte/runstats.html. -
ORA-01461: can bind a LONG value only for insert into a LONG colu
Hello - I have a variable defined in a package as VARCHAR2(32720). This is not a table column. I am building a string inside the vairable, loading in invoice data in sections one at a time. It seems that once I get a larger number of invoices (say 100+) to load in, I get the "ORA-01461: can bind a LONG value only for insert into a LONG column" error. I am not trying to insert into a table column; just stringing together data in this large variable.
Why would I be getting this error ? And is there a workaround ? The variable is read back out iin 80 byte strings which are then loaded to a table column that is varchar2(80).
Thanks !!
Jim Ernst
Invacare CorporationHere is the definition of the field:
l_EDI820_Data VARCHAR2(32720);
And here is the loop used to populate the field. As i mentioned, it seems that once the process gets over 100 invoices coming in that the field hits the error; seems as if we are hitting say 4000 characters or near it at that point...
FOR r_INVOICE_DETAIL IN cr_INVOICE_DETAILS LOOP
l_EDI820_Data := l_EDI820_Data
||l_RMR_Statement
||r_INVOICE_DETAIL.INVOICE_NUM
||'*PI*'
||LTRIM(TO_CHAR(NVL(r_INVOICE_DETAIL.PAYMENT_AMOUNT,0))) -- Net Amount to be applied
||'*'
||LTRIM(TO_CHAR(r_INVOICE_DETAIL.INVOICE_AMOUNT,'999999.99')) -- Gross Amount
||l_Delimiter;
l_TOTAL_SEGMENTS := l_TOTAL_SEGMENTS + 1;
END LOOP; -- r_INVOICE_DETAIL
There are some other statements that are adding additional data onto l_EDI820_Data ; this one is the loop that is basedon the invoices coming in.
This code writes it to the table (field EDI820_DATA in the table is VARCHAR2(94)):
l_EDI820_String_Length := LENGTH(RTRIM(l_EDI820_Data));
l_EDI820_SUBSTR_START := 1;
l_RECORD_SEQ_NO := 1;
WHILE SUBSTR(l_EDI820_Data, l_EDI820_SUBSTR_START, 80) <> ' ' LOOP
INSERT INTO XXAP_NACHA_EDI820_GTEMP_TBL
SELECTED_CHECK_ID
,EDI820_SEQ
,EDI820_DATA
VALUES (
r_CHECK_IDS.SELECTED_CHECK_ID
,l_RECORD_SEQ_NO
,'705'||SUBSTR(l_EDI820_Data, l_EDI820_SUBSTR_START, 80)
-- * Increment starting point for substring and also record sequence number
l_EDI820_SUBSTR_START := l_EDI820_SUBSTR_START + 80;
l_RECORD_SEQ_NO := l_RECORD_SEQ_NO + 1;
END LOOP; -- WHILE Loop -
Hi,
I want to insert data into table by subquery and some value by manully.
How can I insert data into table.SQL> create table t(no integer, obj_name varchar2(100))
2 /
Table created.
SQL> create sequence my_seq
2 /
Sequence created.
SQL> create or replace function get_next_val return integer
2 as
3 lSeq integer;
4 begin
5 select my_seq.nextval into lseq from dual;
6 return lseq;
7 end;
8 /
Function created.
SQL> insert into t
2 select get_next_val,
3 MAX(object_name)
4 from all_objects
5 where object_type = 'TABLE' group by owner
6 /
17 rows created.
SQL> select * from t
2 /
NO OBJ_NAME
1 PSDBOWNER
2 SDO_XML_SCHEMAS
3 SRS$
4 DM$P_MODEL_TABLES
5 OL$NODES
6 SYS_IOT_OVER_40928
7 XML_LOAD_RECORDS
8 T
9 SQLPLUS_PRODUCT_PROFILE
10 SYS_IOT_OVER_42490
11 SALGRADE
NO OBJ_NAME
12 MGMT_TEMPT_SQL
13 SI_VALUES_TAB
14 SYS_IOT_OVER_49872
15 xdb-log9_TAB
16 XDB_INSTALLATION_TAB
17 WM$WORKSPACE_SAVEPOINTS_TABLE
17 rows selected.
SQL> -
How to use INSERT INTO ALL statement in jdbc prepared statement with beans
Kindly give me some example that how we can use "INSERT INTO ALL STATEMENT" in jdbc prepared statement inside a jsf bean?
Actually i want to take employee id's of present employees using single jsf page and using one textbox for each employee id.
How can i use INSERT INTO ALL statement to achieve this?
Following is my code snippet.
AttendanceBean.java:
public class AttendanceBean {
private int atteid;
private String attdname;
private int attday;
private int attmonth;
private int attyear;
public static Connection getAttConnection() throws Exception {
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:globldb3";
String username = "scott";
String password = "tiger";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
return conn;
public String addAttendance(){
Connection conn = null;
PreparedStatement pstmt = null;
boolean committed = false;
try {
conn = getAttConnection();
conn.setAutoCommit(false);
String query = "INSERT ALL INTO attendance VALUES (?,?,?,?,?)";
pstmt = conn.prepareStatement(query);
pstmt.setInt(1,this.atteid);
pstmt.setString(2,this.attdname);
pstmt.setInt(3,this.attday);
pstmt.setInt(4,this.attmonth);
pstmt.setInt(5,this.attyear);
pstmt.executeUpdate();
conn.commit();
conn.setAutoCommit(true);
committed = true;
return "home.xhtml";
} catch (Exception e) {
e.printStackTrace();
return "CRM.xhtml";
} finally {
try{
if (!committed) conn.rollback();
if (pstmt != null) pstmt.close();
if (conn != null) conn.close();
}catch(Exception e){
e.printStackTrace();
}Check this program for some info on Push buttons:
1-DEMO_DYNPRO_PUSH_BUTTON
2-DEMO_DYNPRO_MODULE
3-DEMO_DYNPRO_ON_CONDITION
Suppose Your screen is 101
Then in that screen create one push button and assign it a function code.
Now in the PAI of the 101 screen
Create Module for user command
Inside that module checc the sy-ucomm if sy-ucomm eq <Function code of your push button>
Insert the values in database.
*& Module USER_COMMAND_0101 INPUT
process after input for screen 0101 *
MODULE USER_COMMAND_0101 INPUT.
CASE OK_CODE.
WHEN 'SAVE'.
*Insert the values here
WHEN 'DISP'.
ENDCASE.
CLEAR OK_CODE.
ENDMODULE. " USER_COMMAND_0101 INPUT
Regards
Neha
Edited by: Neha Shukla on Dec 3, 2008 1:02 AM
Edited by: Neha Shukla on Dec 3, 2008 1:02 AM
Edited by: Neha Shukla on Dec 3, 2008 1:06 AM
Maybe you are looking for
-
Officejet 4500 printing problems
My officejet 4500 print jobs keep showing up as error in the que. I can print a test page, but can't seem to get anything else printed. thanks for your help
-
How do I delete my i-cloud account without deleting Pages documents?
Hi! I am currently in panic mode. In a way, my problem is four or five-fold. My I-pad is only charging now and then. So it has suddenly become urgent for me to back-up all my stuff. I don't sync with another computer. I only have the i-pad. So I
-
Returns Excise FI entry is wrong
Hi All, Issue : Kindly help to understand why Returns Excise entry is wrong? Other details:I have created sales invoice and excise invoice for 40 qty and created returns invoice and Return excise invoice with J1is t code for qty of 20: 1. VA01->VL01n
-
We would like to delete a customer (set deletion flag) via RFC. The problem is that the BAPI_CUSTOMER_DELETE calls screens which means that it cannot be called. We want to avoid doing database updates on KNA1-LOEVM because we want such deletions reco
-
Ubuntu 11.10 for lenovo G570
I have previosly used Ubuntu Linux for an year on my desktop and would like to switch to Ubuntu on laptop too. But I have some specific worried which I want to clarify before really stepping in it so I don't land on troubles. My Laptop details: Lenov