| ORA-00932: inconsistent datatypes: expected UDT got CHAR [message #518687] |
Fri, 05 August 2011 08:10  |
 |
a_oracle
Messages: 98 Registered: November 2010
|
Member |
|
|
Hi Guys,
out of testing purpose i create the below object and a procedure.
The requirement is to pass parameters of emp_name to the procedure with multiple values as a string from java application. the value
would have been passed like:
'Jack','Jill'
and the procedure will contain the select statement which will display the emp_name based on the parameter that is being passed.
Remember guys, this is just a testing that I am doing to incorporate the same in my business logic. But, encountered
error here only.
Can somebody suggest the changes i have to make the below procedure work?
---- table details with insert scripts
create table EMPLOYEES
(
EMP_ID NUMBER,
EMP_NAME VARCHAR2(100)
);
insert into EMPLOYEES (EMP_ID, EMP_NAME)
values (10, 'Jack');
insert into EMPLOYEES (EMP_ID, EMP_NAME)
values (20, 'Jill');
insert into EMPLOYEES (EMP_ID, EMP_NAME)
values (30, 'hill');
commit;
---- the objects created and the error encountered are shown below:
SQL> create or replace type empname is table of varchar2(40);
2 /
Type created
SQL> create or replace type empdet is table of varchar2(40);
2 /
Type created
SQL> create or replace procedure test_emp (p_emp_name varchar2)
2 is
3 v_str varchar2(200) := p_emp_name||','||' ';
4 v_emp empname := empname();
5 v_pos number;
6 --v_len := length(p_emp_name);
7 empd empdet := empdet();
8 begin
9 loop
10 exit when v_str is null;
11 v_pos := instr(v_str,',');
12 v_emp.extend;
13 v_emp(v_emp.count):=ltrim(rtrim(substr(v_str,1,v_pos-1)));
14 v_str := substr(v_str,v_pos+1);
15 end loop;
16 select emp_name into empd from employees where emp_name in
(select * from table(cast(v_emp as empname)));
17 FOR i in 1..empd.count loop
18 dbms_output.put_line(empd(i));
19 end loop;
20 end;
21 /
Warning: Procedure created with compilation errors
SQL> show errors;
Errors for PROCEDURE SLDDEVELOPER.TEST_EMP:
LINE/COL ERROR
-------- ----------------------------------------------------------------
16/8 PL/SQL: ORA-00932: inconsistent datatypes: expected UDT got CHAR
16/1 PL/SQL: SQL Statement ignored
[Updated on: Fri, 05 August 2011 08:45] by Moderator Report message to a moderator
|
|
|
|
| Re: ORA-00932: inconsistent datatypes: expected UDT got CHAR [message #518696 is a reply to message #518687] |
Fri, 05 August 2011 08:47  |
 |
Michel Cadot
Messages: 68773 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
emp_name is a string, empd is an array, datatypes do not match, are inconsistent so the error.
Search BULK COLLECT in the documentation.
And remember that a query can be written on several lines and even splitted at appropriate places and indented.
Regards
Michel
|
|
|
|