Closed Drezir closed 3 years ago
Thanks for the report. ORA-0092 indicates that there's a syntax error in your SQL. It's not clear from your description why you think that this is a Spring Boot problem? Also, I'm a little bit confused by the configuration that you've shown. With spring.sql.init.mode
set to never
, DataSourceScriptDatabaseInitializer
should not be doing anything. However, we can see from the stack trace that it is. That makes me suspect that there's something more to your problem that you haven't shown.
If you'd like us to spend some more time investigating, can you please provide a complete yet minimal example that reproduces the problem using Oracle XE?
Sorry for the configuration issue. I forgot to change it for this report. Basically, I can run this script just fine in IntelliJ console but not using spring sql init scripts.
I am going to fix that mode.
I don't think there's a bug with Spring Boot here, it's sending the SQL as expected. The problem is that your script isn't being split up correctly.
If you change your application.yaml
to contain the following:
spring:
sql:
init:
mode: always
platform: oracle
separator: ;;
encoding: utf-8
Then the script will split on ;;
rather than ;
. You can then update your script as follows and it will work:
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE MY_USER';
EXCEPTION
WHEN OTHERS THEN
IF SQLCODE != -942 THEN
RAISE;
END IF;
END;
;;
create table MY_USER
(
id number(10) primary key,
name varchar2(100)
)
;;
create or replace function insert_user_get_fn(id IN NUMBER,
name IN VARCHAR2)
return SYS_REFCURSOR
as
users SYS_REFCURSOR;
begin
insert into MY_USER values (id, name);
open users for select * from MY_USER;
return users;
end;
;;
create or replace procedure insert_user_get_proc(id IN NUMBER,
name IN VARCHAR2,
users out sys_refcursor)
as
begin
insert into MY_USER values (id, name);
open users for select * from MY_USER;
end;
;;
create or replace procedure insert_user(id IN NUMBER,
name IN VARCHAR2)
is
begin
insert into MY_USER values (id, name);
end;
;;
@philwebb
Is there any reason why forward slash /
does not work as statement separator? Or is it the spaces between statements and separator that are required?
The example doesn't appear to use /
as a separator in the script:
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE MY_USER';
EXCEPTION
WHEN OTHERS THEN
IF SQLCODE != -942 THEN
RAISE;
END IF;
END;
create table MY_USER
(
id number(10) primary key,
name varchar2(100)
);
create or replace function insert_user_get_fn(id IN NUMBER,
name IN VARCHAR2)
return SYS_REFCURSOR
as
users SYS_REFCURSOR;
begin
insert into MY_USER values (id, name);
open users for select * from MY_USER;
return users;
end;
create or replace procedure insert_user_get_proc(id IN NUMBER,
name IN VARCHAR2,
users out sys_refcursor)
as
begin
insert into MY_USER values (id, name);
open users for select * from MY_USER;
end;
create or replace procedure insert_user(id IN NUMBER,
name IN VARCHAR2)
is
begin
insert into MY_USER values (id, name);
end;
Nor does it customize the separator in application.yaml
:
spring:
datasource:
url: jdbc:oracle:thin:@localhost:1521:ORCLCDB
username: sys as sysdba
password: Oradoc_db1
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.Oracle12cDialect
@wilkinsona Sorry for the example, it is not super correct because I forgot to revert changes I made. If I had separator specified and statements separated by it, it would not work at least on my system.
Nothing special, just starter project with just oracle driver and spring data jpa: