Oracle Mybatis insert all - oracle

I am trying to do a mybatis batch insert with Oracle.
I tried the insert all on my sql developer it works, but with Mybatis here, it complains.
How could I fix this?
<insert
id="insertBatch"
parameterType="java.util.List"
keyProperty="id"
keyColumn="COMMENT_ID"
useGeneratedKeys="true">
INSERT ALL
<foreach collection="list" item="comment" index="index">
INTO COMMENT (value1, value2)
VALUES (#{comment.value1}, #{comment.value2})
</foreach>
SELECT *
FROM dual
</insert>
And I got error like this
org.springframework.jdbc.BadSqlGrammarException:
Error updating database. Cause: java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
The error may involve xxxx-Inline
The error occurred while setting parameters
SQL: INSERT ALL INTO COMMENT ( VALUE1, VALUE2) VALUES ( ?, ? ) INTO COMMENT ( VALUE1, VALUE2 ) VALUES ( ?, ? ) SELECT * FROM dual;
Cause: java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended

Related

Oracle - ORA-00907: missing right parenthesis in query generated by Odata query generator

this is the query generated by an Odata Sql query generator and I am on Oracle 12c
SELECT ID
FROM MY_TABLE
WHERE (
NAME LIKE 'abc' = true
)
;
and the error it generates is
ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error at Line: 4 Column: 14
Any ideas on how to fix the query ?
Thanks in advance
I know nothing about "Odata Sql query generator", but - if you want to fix this query, then it would be
select id from my_table where name like 'abc'
On the other hand, that's same as
select id from my_table where name = 'abc'
so perhaps you actually meant to use wildcards:
select id from my_table where name like '%abc%'

mybatis insert all nextval unique constraint error in #transaction mdoe

MyBatis 3 spring - java
I am trying to batch insert and and getting following error when there are more then 1 records. it works perfect with one recrod
I beleive b/c it is in transaction nextval is not generating nextval on each iteration. am i correct any help on that ?
nested exception is java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (LINEAR_UPSELL.SYS_C0016697) violated
and my method has Transaction annotation in java file
#Transactional(propagation=Propagation.REQUIRED, readOnly=false, rollbackFor=Exception.class)
in mapper file following is my insert statement
<insert id="insertService" parameterType="java.util.List">
insert all
<foreach collection="list" item="ch" index="index" >
into tva_upselladmin_channel (id, source_id, service_id, name) values (
TVA_UPSELLADMIN_CHANNEL_SEQ.nextVal,
#{ch.sourceId},
#{ch.serviceId},
#{ch.name}
)
</foreach>
SELECT * FROM dual
</insert>
in oracle nextval does not work very well with insert all statement. you have to find work around as following
extractvalue(dbms_xmlgen.getxmltype('select TVA_UPSELLADMIN_CHANNEL_SEQ.nextval - 1 from dual'),'//text()')
complete insert as following have no idea with -1 is there.
<insert id="insertServiceMappings" parameterType="java.util.List">
insert all
<foreach collection="list" item="channel" index="index" >
into tva_upselladmin_channel (id, source_id, service_id, name) values (
extractvalue(dbms_xmlgen.getxmltype('select TVA_UPSELLADMIN_CHANNEL_SEQ.nextval - 1 from dual'),'//text()'),
#{channel.sourceId},
#{channel.serviceId},
#{channel.name}
)
</foreach>
SELECT * FROM dual
</insert>

SELECT a table from oracle data dictionary

I am new to SQL and recently installed Oracle 11g. I read the post here on selecting all tables from user_tables. I'm trying to select a specific table and following some of the suggestions in the post does not appear to work.
The following executes fine and returns all tables available to me including a table named faculty_t:
select * from user_tables;
select * from dba_tables;
select * from all_tables;
desc faculty_t;
But I get error when I do the following:
select * from user_tables where table_name = FACULTY_T;
The first set of statements confirm that I do have a table named faculty_t. However, trying to select this table from user_tables, all_tables, or dba_tables does not appear to work for me right now. The error message reads something like:
ORA-00904: "FACULTY_T": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error at Line: 208 Column: 8
Any thoughts? Thanks!
String literals in SQL are wrapped in '. So:
select * from user_tables where table_name = 'FACULTY_T';
When you did a desc faculty_t, the SQL engine knew that a table name was expected at that spot (the syntax expects a table name there). But in your select query, sql is just looking for the value of a column that happens to have a string data type, so you need to use the ' for a string literal.

Ora-00905 missing keyword error

Im getting below error while executing below line,
SELECT * INTO employee_Backup FROM employee
Error:
Ora-00905 missing keyword error
Your query should be
INSERT INTO employee_backup
SELECT *
FROM employee
Discussed here
And the syntax is
INSERT INTO table_name
SELECT *
FROM table_name
This is sql-server syntax you're trying to use.
The Oracle equivalent would be:
INSERT INTO employee_backup
(SELECT * FROM employee)

SQL Minus and lower/upper dont work together in Jdbc

i got a HSQLDB 2.2.9 and the following statement:
(SELECT lower(MyCol) FROM MyTable WHERE ID = ?)
MINUS
(SELECT lower(MyCol) FROM MyTable WHERE ID = ?)
And it works in my Squirrel. But when i execute this in my program which uses Jdbc i get the following exception:
Exception in thread "main" org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [(SELECT lower(MyCol) FROM MyTable WHERE ID = ? ) MINUS (SELECT lower(MyCol) FROM MyTable WHERE ID_CENTER = ?)]; Column not found: MyCol; nested exception is java.sql.SQLException: Column not found: MyCol
If i delete the lower() that statement works but its case sensitive which i want to eliminate here.
Can please someone tell me why i get this error and how to fix it?
This exception is not thrown by HSQLDB 2.2.9. If the column could not be found, the exception message would be in this form:
user lacks privilege or object not found: MYCOL
Please check your Spring data source settings.

Resources