SpringJdbcTemplate: SQL state [null]; error code [17004]; Invalid column type 1111 while executing function with return value as JavaObject - java-7

I am using Spring jdbcTemplate with oracle 11g in my project. I have faced problem in executing function with return value as java type. Please kindly help me for this issue.
Here I have added the outline of structure:
create or replace FUNCTION FUNC_DETAILS(
P_FIRST NUMBER DEFAULT 0,
P_SECOND VARCHAR2 DEFAULT 'N')
RETURN JAVA_OBJ_TYPE
AS
create or replace TYPE JAVA_OBJ_TYPE
AS
OBJECT
(
dash_board ANOTHER_JAVA_OBJ,
card_dtls ANOTHER2_JAVA_OBJ,
address_dtls ANOTHER3_JAVA_OBJ
)
create or replace TYPE ANOTHER_JAVA_OBJ
AS
OBJECT
(
FIRST_NUMBER VARCHAR2(50),
SECOND_NUMBER VARCHAR2(50),
)
create or replace TYPE ANOTHER2_JAVA_OBJ
AS
OBJECT
(
FIRST_NUMBER VARCHAR2(50),
SECOND_NUMBER VARCHAR2(50),
)
create or replace TYPE ANOTHER3_JAVA_OBJ
AS
OBJECT
(
FIRST_NUMBER VARCHAR2(50),
SECOND_NUMBER VARCHAR2(50),
)
In java code:
SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate)
.withCatalogName(packageName) // package name
.withFunctionName(functionName);
return simpleJdbcCall.executeFunction(JavaObj.class, in)
It throws this error:
SpringJdbcTemplate: SQL state [null]; error code [17004]; Invalid column type 1111 while executing function with return value as JavaObject

Related

ORA-00927: missing equal sign when trying to update table in object-relational DB

i'm trying to understand object-relational technology and created parent type:
CREATE OR REPLACE TYPE STUDENT
AS OBJECT(
FIO VARCHAR2(200),
Bday DATE,
Pas_Id NUMBER(20),
Address VARCHAR2(50))
NOT INSTANTIABLE
NOT FINAL;
child type:
CREATE OR REPLACE TYPE BACH
UNDER STUDENT(
fieldOfStud varchar2(200),
Group_N number(4),
ege number(4),
GPA number(4),
MEMBER FUNCTION year_N RETURN NUMBER);
--тело типа бакалавр
CREATE OR REPLACE TYPE BODY BACH IS
MEMBER FUNCTION year_N RETURN NUMBER IS
BEGIN
IF SUBSTR(Group_N, 1, 1) BETWEEN 1 and 4 THEN
RETURN SUBSTR(Group_N, 1, 1);
END IF;
RETURN 0;
END;
END;
created table:
CREATE TABLE Students_Table(
SID NUMBER CONSTRAINT id_pk PRIMARY KEY,
stdt STUDENT
);
and inserted data. I am 100% sure it exists.
I want to update table and change group, for example, from 5231 to 6231:
update Students_Table st
set TREAT(stdt as maga).Group_N = TREAT(stdt as maga).Group_N+1000
where TREAT(stdt AS MAGA).Pas_Id = 241122
but get error
ORA-00927: missing equal sign
You need to apply the conversion earlier in the statement, so that the update only sees the subtype:
update ( select s.sid, treat(stdt as bach) as stdt from students_table s ) st
set st.stdt.group_n = st.stdt.group_n + 1000
where st.stdt.pas_id = 241122;
DB Fiddle

Inconsistent datatypes: expected CHAR got REF

CREATE TYPE empresa_type AS OBJECT (
CNPJ INTEGER,
nome_fantasia VARCHAR2(30),
pais VARCHAR2(25),
fundacao DATE
)
CREATE TYPE funcionario_type AS OBJECT (
CPF INTEGER,
nome VARCHAR2(30),
sexo CHAR(1),
nasc DATE,
empresa REF empresa_type
)
CREATE TABLE empresa_tab OF empresa_type (PRIMARY KEY(CNPJ))
CREATE TABLE funcionario_tab OF funcionario_type (PRIMARY KEY(CPF), FOREIGN KEY(empresa) REFERENCES empresa_tab)
report error:
ORA-00932: inconsistent datatypes: expected CHAR got REF MY_WKSP.EMPRESA_TYPE
You want to create the table and then add a SCOPE to the reference (rather than trying to define it as a foreign key, because it is not):
CREATE TABLE funcionario_tab OF funcionario_type (
PRIMARY KEY(CPF)
);
ALTER TABLE funcionario_tab ADD SCOPE FOR ( empresa ) IS empresa_tab;
db<>fiddle here

ORA-00909 error when Insert object in object table

I am getting an error ORA-00909 in when inserting an object of a superType in an object table. These are the definitions for the objects:
CREATE OR REPLACE TYPE address AS OBJECT (
street VARCHAR(20),
country VARCHAR(20),
province VARCHAR(20),
city VARCHAR2(20),
zipcode VARCHAR(10)
) FINAL;
CREATE OR REPLACE TYPE company AS OBJECT (
CIF VARCHAR2(9),
code VARCHAR2(10),
name VARCHAR2(20),
signUpDate DATE,
email VARCHAR2(20),
adminAddress address
) NOT FINAL;
CREATE OR REPLACE TYPE inCourseCompany UNDER company (
postalAddress address,
numEmployees NUMBER
) FINAL;
And the object table:
CREATE TABLE companies_objtab OF company (PRIMARY KEY CIF) OBJECT IDENTIFIER IS PRIMARY KEY;
I try to insert an object with the following statement:
INSERT INTO companies_objtab VALUES (
company('J12345678','000001','Test Company',TO_DATE(sysdate, 'dd/mm/yyyy hh24:mi:ss'),'',address('','','','',''))
);
and I get error Error
SQL: ORA-00909: invalid number of arguments
00909. 00000 - "invalid number of arguments"
However, when I insert an object of the subtype inCourseCompany it is inserted correctly:
INSERT INTO companies_objtab VALUES (
inCourseCompany('G11111111','','',TO_DATE(sysdate, 'dd/mm/yyyy hh24:mi:ss'),'',address('','','','',''), address('','','','',''), 100)
);
Any hint about what causes the error?
I am using Oracle SQL Developer 4.0.2.15.21 and Oracle Database Express Edition 11g Release 2.
Thank you in advance.
i tried all your statements right as you posted them (copy-paste). Both on 12c and 11gR2. Everything worked, both inserts. The only thing I noticed is that your create table is a bit incorrect. This is the correct one (but this does not explain the error you get). HTH KR
CREATE TABLE companies_objtab OF company (CIF PRIMARY KEY) OBJECT IDENTIFIER IS PRIMARY KEY;
Maybe try dropping the table and creating it again.

Error in creating nested table involving inheritence

I have a somewhat complex structure as follows :
create or replace type user_typ as object(
user_id number(19,0),
username nvarchar2(40 char)
);
I inherit an applicant_typ from this :
create or replace type applicant_typ under user_typ (
resume_text nclob
);
My design involves jobs to which applicants can apply. To this end, I create an application_typ as follows :
create or replace TYPE Application_typ AS OBJECT (
application_id NUMBER,
candidate applicant_typ,
time_of_app DATE
);
CREATE TYPE Application_tab IS TABLE OF Application_typ;
And now I want to create an object type called Job_typ, and a table containing those objects, wherein there will be a nested table for applications :
CREATE OR REPLACE TYPE Job_typ AS OBJECT (
job_ID NUMBER,
company_ID NUMBER,
description NVARCHAR2(1000),
name NVARCHAR2(200),
application Application_tab,
MAP MEMBER FUNCTION job_no RETURN NUMBER,
MEMBER PROCEDURE no_of_applicants
);
All of this works fine. The issue is when I try to create a table of type Job_typ :
CREATE TABLE Job_tab OF Job_typ
NESTED TABLE application STORE AS application_nt;
This doesn't work, giving the error :
SQL Error: ORA-02320: failure in creating storage table for nested table column APPLICATION
ORA-22913: must specify table name for nested table column or attribute
02320. 00000 - "failure in creating storage table for nested table column %s"
*Cause: An error occurred while creating the storage table for the
specified nested table column.
What am I doing wrong?
EDIT : I tried some different things. If I change application_typ as follows :
CREATE OR REPLACE TYPE Application_typ AS OBJECT (
application_id NUMBER,
candidate User_Typ, -- NOTE: This attribute is now of type User_typ instead of the inherited type
time_of_app DATE,
);
CREATE TYPE Application_tab IS TABLE OF Application_typ;
Then everything else works, and I am able to create the Job table. Why do I get the error on using the inherited type?
I tried the following in Oracle 11.2.0.1 and didn't get any error. I made a slight change though:
CREATE OR REPLACE TYPE user_typ AS OBJECT
(
user_id NUMBER (19, 0),
username NVARCHAR2 (40 CHAR)
) NOT FINAL; -- << Notice the NOT FINAL keyword
create or replace type applicant_typ under user_typ (
resume_text nclob
);
CREATE OR REPLACE TYPE Application_typ AS OBJECT
(
application_id NUMBER,
candidate applicant_typ,
time_of_app DATE
);
CREATE TYPE Application_tab IS TABLE OF Application_typ;
CREATE OR REPLACE TYPE Job_typ AS OBJECT
(
job_ID NUMBER,
company_ID NUMBER,
description NVARCHAR2 (1000),
name NVARCHAR2 (200),
application Application_tab,
MAP MEMBER FUNCTION job_no
RETURN NUMBER,
MEMBER PROCEDURE no_of_applicants
);
CREATE TABLE Job_tab OF Job_typ
NESTED TABLE application
STORE AS application_nt;
While trying to create all your types and keywords, I got the error:
[Error] PLS-00590 (10.1): PLS-00590: attempting to create a subtype UNDER a FINAL type
This is because Oracle doesn't allow creation of a subtype on a FINAL type. If you don't define any finalizing clause for the base type, the default is FINAL.
Read more on Oracle Docs.
If you are coding for the real world (read industry), I'd advise against using nested tables as column types. You end up spending your entire life trying to nest and un-nest these. I'd suggest you normalize your schema as much as you can or need and leave nested tables for operations in PL/SQL code blocks.

Oracle multiple statments do not run correctly

I have a file with 3 "create type" statements. I do not understand why, when I run the script it creates only the first type. When I open created type I see all three create statements inside. What am I missing here?
CODE:
create type SplitPathTableType as table of varchar2(450);
create TYPE TSMNodesRecord AS OBJECT (
NodeID number(20),
IsDataNode number(1),
Path nvarchar2 (450),
ParentID number(20),
TimeStep number(20)
);
create type TSMNODESTABLE as table of TSMNODESRECORD;
You need / after each statement...
create type SplitPathTableType as table of varchar2(450);
/
create TYPE TSMNodesRecord AS OBJECT (
NodeID number(20),
IsDataNode number(1),
Path nvarchar2 (450),
vParentID number(20),
TimeStep number(20)
);
/
create type TSMNODESTABLE as table of TSMNODESRECORD;
/

Resources