[8i] Case statement generates ORA-00932: inconsistent datatypes
Note: I am working with an 8i database (yes, it is quite old), and in this situation, I have to deal with the datatypes (i.e. CHAR), I am given to work with.
I am attempting to calculate the amount of time product waits between manufacturing steps. As I've discovered though, sometimes I get a negative value when subtracting the date the previous step completes from the date the current step starts. As it is generally impossible to start a later step before an earlier step (imagine trying to screw a cap onto a bottle that doesn't have threads cut yet--it just can't happen), what I've found is that sometimes two steps are started on the same day and finished on the same day (though not necessarily the day they started). This situation CAN happen when one person did both steps and logged on to both steps at the same time, rather than logging on to one, then the other. So, what I need to do in these situations is replace the negative number with a zero (I'll treat the later step as having no wait time).
Here is some sample data:
(Note: the real data set is the result of a query, and has around 200K rows and more columns, but this should be representative enough to find a solution that works on my actual application.)
CREATE TABLE steps
( item_id CHAR(25)
, ord_nbr CHAR(10)
, sub_nbr CHAR(3)
, step_nbr CHAR(4)
, start_date DATE
, finish_date DATE
INSERT INTO steps
VALUES ('A','0000000001','001','0010',TO_DATE('01/01/2011','mm/dd/yyyy'),TO_DATE('01/02/2011','mm/dd/yyyy'));
INSERT INTO steps
VALUES ('A','0000000001','001','0020',TO_DATE('01/01/2011','mm/dd/yyyy'),TO_DATE('01/02/2011','mm/dd/yyyy'));
INSERT INTO steps
VALUES ('A','0000000001','001','0030',TO_DATE('01/05/2011','mm/dd/yyyy'),TO_DATE('01/06/2011','mm/dd/yyyy'));
INSERT INTO steps
VALUES ('A','0000000001','002','0010',TO_DATE('01/01/2011','mm/dd/yyyy'),TO_DATE('01/02/2011','mm/dd/yyyy'));
INSERT INTO steps
VALUES ('A','0000000001','002','0020',TO_DATE('01/04/2011','mm/dd/yyyy'),TO_DATE('01/04/2011','mm/dd/yyyy'));
INSERT INTO steps
VALUES ('A','0000000001','002','0030',TO_DATE('01/06/2011','mm/dd/yyyy'),TO_DATE('01/07/2011','mm/dd/yyyy'));
INSERT INTO steps
VALUES ('B','0000000002','001','0005',TO_DATE('01/10/2011','mm/dd/yyyy'),TO_DATE('01/12/2011','mm/dd/yyyy'));
INSERT INTO steps
VALUES ('B','0000000002','001','0025',TO_DATE('01/10/2011','mm/dd/yyyy'),TO_DATE('01/12/2011','mm/dd/yyyy'));Here is the query I use that returns negative values sometimes:
SELECT item_id
, ord_nbr
, sub_nbr
, step_nbr
, start_date - last_step_finished
FROM (
SELECT s.*
, LAG (s.finish_date) OVER (
PARTITION BY s.item_id
, s.ord_nbr
, s.sub_nbr
ORDER BY s.step_nbr
) AS last_step_finished
FROM steps s
Returns:
ITEM_ID ORD_NBR SUB STEP START_DATE-LAST_STEP_FINISHED
A 0000000001 001 0010
A 0000000001 001 0020 -1.000
A 0000000001 001 0030 3.000
A 0000000001 002 0010
A 0000000001 002 0020 2.000
A 0000000001 002 0030 2.000
B 0000000002 001 0005
B 0000000002 001 0025 -2.000These are the results I want to see:
ITEM_ID ORD_NBR SUB STEP START_DATE-LAST_STEP_FINISHED
A 0000000001 001 0010
A 0000000001 001 0020 0.000
A 0000000001 001 0030 3.000
A 0000000001 002 0010
A 0000000001 002 0020 2.000
A 0000000001 002 0030 2.000
B 0000000002 001 0005
B 0000000002 001 0025 0.000And this is what I tried to do to get those results (comment notes what line generated the error):
SELECT item_id
, ord_nbr
, sub_nbr
, step_nbr
, CASE
WHEN start_dt - last_step_finished < 0
THEN 0
ELSE start_dt - last_step_finished -- THIS LINE GENERATES THE ORA-00932 ERROR
END AS days_in_queue
FROM (
SELECT s.*
, LAG (s.finish_date) OVER ( PARTITION BY s.item_id
, s.ord_nbr
, s.sub_nbr
ORDER BY s.step_nbr
) AS last_step_finished
FROM steps s
);I know I've had inconsistent datatype errors before with case statements in this particular 8i database, but I can't seem to figure out why I'm getting one this time. I think it has something to do with the NULL values that can occur for last_step_finished. Also, if I change the case statement to:
, CASE
WHEN start_dt - last_step_finished < 0
THEN NULL
ELSE start_dt - last_step_finished -- THIS LINE GENERATES THE ORA-00932 ERROR
END the query runs just fine. But, I don't want NULL, I want 0. In the next level of this query, I will be taking averages by item_id/step_nbr, and I want the 0's to be included in the average. (NULL values, as far as I can tell, would be excluded. AVG(NULL, 1, 2) =AVG (1,2) = 1.5 NOT AVG(0,1,2) = 1).
Thanks in advance!
Thanks, TO_NUMBER did the trick. Since you didn't state in your post where to use TO_NUMBER, here is my final solution, in case anyone in the future looks through this thread to find an answer to their question:
SELECT item_id
, ord_nbr
, sub_nbr
, step_nbr
, CASE
WHEN start_dt - last_step_finished < 0
THEN 0
ELSE TO_NUMBER(start_dt - last_step_finished)
END AS days_in_queue
FROM (
SELECT s.*
, LAG (s.finish_date) OVER ( PARTITION BY s.item_id
, s.ord_nbr
, s.sub_nbr
ORDER BY s.step_nbr
) AS last_step_finished
FROM steps s
);Edited by: user11033437 on Jun 27, 2011 11:17 AM
I see you edited your post to add TO_NUMBER to it.
Similar Messages
-
Case expression and ORA-00932: inconsistent datatypes
I m trying to use the following case condition
select
case
when
count(exception.exception_number) > 1
then 0
else
ENTITY_TYPE_DEF.NAME
end as NAME
In table exception , exception_number has a varchar2 datatype. My requirement is such as if the count of exception number is more than 1 , it should show 0 (integer ) and if not then show name column (varchar2) from table entity_type_def .
My query fails with following error
ERROR at line 7:
ORA-00932: inconsistent datatypes: expected NUMBER got CHAR
Please could someone suggest a workaround for above issue.Whatever is the data type of the first case result, it expects all case results to be the same. The first part of your CASE returns 0 which is a number, it expects the second part to also return a number but it returns a string. Hence the error. You can fix it by returning a string in the first part of your case which you do by putting single quotes around your 0.
CASE WHEN count(exception.exception_number) > THEN '0'
ELSE entity_type_def.name END -
Help with error select case statement (ORA-00932: inconsistent datatypes)
Hi,
I'm struggling to get my sql query work on Oracle..
I have a table MyTable with 5 columns ( Column1, Column2, Column3, Column4, Column5 ) all are of type NVARCHAR2.
I need to check whether Column 3, Column 4 are empty or not in that order..and if they values then I wanna append it to Column2.
For example
If a row contains the following values,
Column 2 = a.b
Column 3 = 123
Column 4 = xyz
then column CA = a.b/123/xyz where column CA = temp column
If either Column 3 or Column 4 is empty/null, then I don't need to append value for that column..
For example
Column 2 = a.b
Column 3 = either NULL or ''
Column 4 = xyz
then CA = a.b/xyz where column CA = temp column
similarly..
Column 2 = a.b
Column 3 = 123
Column 4 = either NULL or ''
then CA = a.b/123 where column CA = temp column
Here is my query..
select MyTable.Column1 as CA0,
MyTable.Column2 as CA1,
MyTable.Column3 as CA2,
MyTable.Column4 as CA3,
MyTable.Column5 as CA4,
MyTable.Column2 + CASE WHEN MyTable.Column3 > '' THEN '/' + MyTable.Column3 ELSE '' END + CASE WHEN MyTable.Column4 > '' THEN '/' + MyTable.Column4 ELSE '' END CA
from MyTable;
This query works just fine against SQL Server db, but gainst Oracle I'm getting
ORA-00932: inconsistent datatypes: expected NUMBER got CHAR
00932. 00000 - "inconsistent datatypes: expected %s got %s"
Could you please let me know what I'm doing wrong. I need to get this query working on both SQL Server and Oracle..
Please let me know your suggestions and thoughts..
Cheers,I need to check whether Column 3, Column 4 are empty or not in that order..and if they values then I wanna append it to Column2. In Oracle, you can do it this way - no need to do all kinds of difficult things:
select col2||col3||col4
from tbl -
PL/SQL: ORA-00932: inconsistent datatypes: expected UDT got NUMBER
Hi all,
Wondering if you could assist? I'm exploring User Types and having a small problem. I'm getting the above error for a user type I have created which I'm calling in a function. Here's what my code looks like which I'm running the 'scott' schema for testing purposes
SQL> CREATE OR REPLACE TYPE NBR_COLL AS TABLE OF NUMBER;
2 /
Type created.
SQL> create or replace FUNCTION first_rec_only
2 (
3 NUM_ID IN NUMBER
4 ) RETURN NUMBER IS
5 v_num NBR_COLL;
6 BEGIN
7 select deptno into v_num from dept;
8 RETURN v_num(v_num.FIRST);
9 END first_rec_only;
10 /
Warning: Function created with compilation errors.
SQL> show errors
Errors for FUNCTION FIRST_REC_ONLY:
LINE/COL ERROR
7/4 PL/SQL: SQL Statement ignored
7/11 PL/SQL: ORA-00932: inconsistent datatypes: expected UDT got
NUMBER
SQL>
Any clues to what I'm doing wrong? Cheers.The deptno column is a number, you cannot directly select a number into your type, you need to use your type's constructor.
Something like:
CREATE OR REPLACE FUNCTION first_rec_only (NUM_ID IN NUMBER) RETURN NUMBER IS
v_num NBR_COLL;
BEGIN
SELECT nbr_coll(deptno) INTO v_num from dept;
RETURN v_num(v_num.FIRST);
END first_rec_only;Note that although this will compile, it will throw ORA-01422: exact fetch returns more than requested number of rows when you run it. you need to either use the input parameter as a predicate on your query against dept, use rownum = 1 in the query or use bulk BULK COLLECT INTO, depending on what exactly you want to accomplish.
John -
PL/SQL: ORA-00932: inconsistent datatypes: expected REF got CHAR
SQL> desc o.rel_module;
Name Null? Type
ID NOT NULL NUMBER(6)
TYPE NOT NULL CHAR(7)
BUILDDATE NOT NULL NUMBER(4)
DESIGNROOT NOT NULL NUMBER(6)
SQL> desc rel_module
Name Null? Type
ID NOT NULL NUMBER(6)
DESIGNROOT NOT NULL NUMBER(6)
REL_COMPOSITEPARTS REL_COMPOSITEPART_TAB
SQL> desc REL_COMPOSITEPART_TAB
REL_COMPOSITEPART_TAB TABLE OF REL_COMPOSITEPART
SQL> desc REL_COMPOSITEPART
Name Null? Type
TYPE CHAR(7)
BUILDDATE NUMBER(4)
SQL> create or replace procedure rel_module_p
2 as
3 cursor c is select ID, TYPE, BUILDDATE, DESIGNROOT from o.rel_module;
4 begin
5 FOR i in c
6 LOOP
7 INSERT into rel_module(id,REL_CompositeParts,DESIGNROOT)
Values (i.ID,REL_CompositePart_TAB(i.type,i.builddate), i.designroot);
8 END LOOP;
9 END;
10 /
Warning: Procedure created with compilation errors.
SQL> show err
Errors for PROCEDURE REL_MODULE_P:
LINE/COL ERROR
7/1 PL/SQL: SQL Statement ignored
7/93 PL/SQL: ORA-00932: inconsistent datatypes: expected REF got CHAR
Can you please tell me where needs correction.801556 wrote:
Can you please tell me where needs correction.Just a fix would be:
create or replace procedure rel_module_p
as
cursor c is select ID, TYPE, BUILDDATE, DESIGNROOT from o.rel_module;
begin
FOR i in c
LOOP
INSERT into rel_module(id,REL_CompositeParts,DESIGNROOT)
values (i.ID,REL_CompositePart_TAB(REL_COMPOSITEPART(i.type,i.builddate)), i.designroot);
END LOOP;
END;
/However, I'd assume what you want is:
create or replace procedure rel_module_p
as
cursor c is select ID,CAST(COLLECT(REL_COMPOSITEPART(TYPE,BUILDDATE)) AS REL_CompositePart_TAB) REL_COMPOSITEPARTS, DESIGNROOT
from rel_module
group by id,DESIGNROOT;
begin
FOR i in c
LOOP
INSERT into rel_moduleX(id,REL_CompositeParts,DESIGNROOT)
values (i.ID,i.REL_COMPOSITEPARTS, i.designroot);
END LOOP;
END;
/SY. -
ORA-00932: inconsistent datatypes: expected - got - In 11g, WORKS in 9i!
Hello,
Involved in migration of a 9i database to 11g, R2. One of our procedures works in 9i but in 11g gives us "ORA-00932: inconsistent datatypes: expected - got - "
We tracked down the error in a statement where oracle does a fetch into a sys_refcursor. The fetch happens on a dynamically constructed select statement ( built by varchar concatenation).
The select statement selects 3 fields, but the fetch into passes 2 variables to the fetch statement. This causes ORA-00932 in 11g R2, but works in 9i.
Below is a modified procedure we built to demonstrate the problem. if you compile and test, you will see that the procedure runs in 9i but not 11g.
create or replace procedure testORA00932 is
v_now date;
v_fsqltext varchar2(2000);
v_curs sys_refcursor;
begin
v_fsqltext := 'select sysdate, sysdate+1 from dual'; -- select 2 fields
open v_curs for v_fsqltext;
loop
fetch v_curs into v_now; -- fetch 1 field, this statement fails in 11g (ORA-00932), works in 9i
dbms_output.put_line(v_now);
exit when v_curs%notfound;
end loop;
close v_curs;
end;
Is there a compatibility flag we can turn on to resove this problem?
Edited by: chrisl08 on Mar 29, 2012 11:11 PMAfter researching this a little more, this is a know bug to oracle: Bug 4381035
According to Oracle, the only available workaround is to provide the same number of define variables as columns in the SELECT statement. -
ORA-00932: inconsistent datatypes: expected - got SCOTT.TEST_T
I am trying to copy the data from one tabel t Other table. Both are located in diffrent schemas.
while doing so, i am getting the below error.
CONN SCOTT/TIGER
CREATE OR REPLACE TYPE TEST_T AS TABLE OF VARCHAR2(20);
CREATE TABLE TEST_TAB
(ID NUMBER,
NAME TEST_T,
LOCATION VARCHAR2(100)
GRANT SELECT ON TEST_TAB TO LOCALUSR;
GRANT EXECUTE ON TEST_T TO LOCALUSR;
CONN LOCALUSR/LOCALUSR
CREATE OR REPLACE TYPE TEST_T AS TABLE OF VARCHAR2(20);
CREATE TABLE TEST_TAB
(ID NUMBER,
NAME TEST_T,
LOCATION VARCHAR2(100)
INSERT INTO TEST_TAB
SELECT * FROM SCOTT.TEST_TAB;
ORA-00932: inconsistent datatypes: expected - got SCOTT.TEST_T Pls suggest.
Raj
Edited by: KrChowdary on Jun 11, 2009 12:52 PMYou have two different objects (one for localuser and one for scott) which you might think are identical but they are not. Basically it is the same as
SQL> create or replace type test_t as table of varchar2 (20)
Type created.
SQL> create table test_tab (id number, name test_t, location varchar2 (100))
nested table name store as nested_tab
return as value
Table created.
SQL> create or replace type test2_t as table of varchar2 (20)
Type created.
SQL> create table test2_tab (id number, name test2_t, location varchar2 (100))
nested table name store as nested2_tab
return as value
Table created.
SQL> insert into test_tab
values (1, test_t (1, 2, 3), 'some location')
1 row created.
SQL> insert into test2_tab
select * from test_tab
insert into test2_tab
select * from test_tab
Error at line 21
ORA-00932: inconsistent datatypes: expected - got MICHAEL.TEST_T
SQL> insert into test2_tab
select id, cast(name as test2_t), location from test_tab
1 row created.As shown, the insert succeeds (at least on 11g) when casting the type to the table's type.
In your case I'd try
insert into test_tab select id, cast(name as localuser.test_t) location from scott.test_tab -
Hi Friends,
I am getting this error : ORA-00932: inconsistent datatypes: expected DATE got NUMBER at OCI call OCIStmtExecute when I am trying to put the filter condition on the date column.
"Dim-Time"."Day" <= cast(MAX("Dim-Time"."Day") as date) and "Dim-Time"."Day" >= TIMESTAMPADD(SQL_TSI_MONTH, -1,cast(MAX("Dim-Time"."Day") as date).
I have casted the max date but though I am getting the above error. I am thinking max(date) is creating the problem.
Please suggest your on opinion this.
Thanks.Not sure why you need cast in your statement if at all it is required then you need to do as below
cast("Dim-Time"."Day" as date)<= cast(MAX("Dim-Time"."Day") as date) and cast("Dim-Time"."Day" as date) >= TIMESTAMPADD(SQL_TSI_MONTH, -1,cast(MAX("Dim-Time"."Day") as date).
~ http://cool-bi.com -
"ORA-00932: inconsistent datatypes: expected - got CHAR"
i got SQL error during statement preparation. Statement: SELECT Emp.EMPNO, Emp.ENAME, Emp.JOB, Emp.MGR, Emp.HIREDATE, Emp.SAL, Emp.COMM, Emp.DEPTNO, Emp.ROWID FROM EMP Emp WHERE (EMPNO in (SELECT * FROM TABLE(CAST(:no AS TABLE_OF_NO))))
Oct 29, 2008 1:53:09 PM oracle.adf.controller.faces.lifecycle.FacesPageLifecycle addMessage
WARNING: ORA-00932: inconsistent datatypes: expected - got CHAR
while running the emp.jspx page.
Thanks
Rama.
Edited by: user634195 on Oct 31, 2008 5:10 AM
Edited by: user634195 on Oct 31, 2008 5:13 AM"ORA-00932: inconsistent datatypes: expected - got CHAR"
i got SQL error during statement preparation. Statement: SELECT Emp.EMPNO, Emp.ENAME, Emp.JOB, Emp.MGR, Emp.HIREDATE, Emp.SAL, Emp.COMM, Emp.DEPTNO, Emp.ROWID FROM EMP Emp WHERE (EMPNO in (SELECT * FROM TABLE(CAST(:no AS TABLE_OF_NO))))
Oct 29, 2008 1:53:09 PM oracle.adf.controller.faces.lifecycle.FacesPageLifecycle addMessage
WARNING: ORA-00932: inconsistent datatypes: expected - got CHAR
while running the emp.jspx page.
Thanks
Rama.
Edited by: user634195 on Oct 31, 2008 5:10 AM
Edited by: user634195 on Oct 31, 2008 5:13 AM -
Error: PL/SQL ORA-00932 inconsistent datatype when using LONG value
Good morning:
I am using a work PL/SQL script where I am using a LONG value in a cursor. When I execute it, I am receiving:
PL/SQL ORA-00932 inconsistent datatype: expected NUMBER got LONG
set serveroutput ON SIZE 1000000
set heading off
set feedback off
set trimspool off
set echo off
set term off
set pagesize 0
SPOOL &so_outfile;
DECLARE
v_data_file varchar2(30);
-- v_sch_code varchar2(10);
-- v_instance_name varchar2(10);
ws_path payroll.pybutfl.pybutfl_utl_file_path%TYPE;
v_data_line VARCHAR2 (2000) := NULL;
fhandle_o UTL_FILE.file_type;
v_line_count NUMBER := 0;
v_selected_count NUMBER := 0;
v_error_count NUMBER := 0;
v_written_count NUMBER := 0;
v_error_text VARCHAR2 (50) := ' AMACONF_ERR: Unable to write the line. ';
v_errm VARCHAR2 (255);
v_sqlerrm VARCHAR2 (255);
v_payment_type VARCHAR2(10);
CURSOR C1 IS
select RTRIM
AMRCONF_PIDM_ERR ||'|'||
AMRCONF_IDEN_CODE_ERR ||'|'||
AMRCONF_ENTRY_DATE_ERR ||'|'||
AMRCONF_CONFID_IND_ERR ||'|'||
*AMRCONF_COMMENT_ERR ||'|'||*
AMRSUBJ_SUBJ_CODE_ERR ||'|'||
ERROR_CODE ||'|'||
ERROR_CODE_TEXT ) data_line
from WSUALUMNI.AMRCONF_ERR;
BEGIN
DBMS_OUTPUT.put_line ('Program Generating AMACOMT Mass Update Error File ');
IF UTL_FILE.is_open (fhandle_o)
THEN
UTL_FILE.fclose (fhandle_o);
END IF;
/* Name The File Here */
v_data_file := ('Amaconf_error.txt');
SELECT RTRIM (pybutfl_utl_file_path)
INTO ws_path
FROM payroll.pybutfl;
fhandle_o := UTL_FILE.fopen (ws_path, v_data_file, 'w');
DBMS_OUTPUT.put_line ('UTLFILE file for this run is: ' || ws_path||'/'||v_data_file);
v_written_count := 0;
FOR c1_rec IN C1 LOOP
BEGIN
v_selected_count := v_selected_count + 1;
v_data_line := rtrim(c1_rec.data_line);
UTL_FILE.put_line (fhandle_o, v_data_line);
v_written_count := v_written_count + 1;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (v_error_text);
v_error_count := v_error_count + 1;
END;
END LOOP;
DBMS_OUTPUT.put_line ('Number of Records Selected: ' || v_selected_count);
DBMS_OUTPUT.put_line ('Number of Records Written: ' || v_written_count);
IF UTL_FILE.is_open (fhandle_o)
THEN
UTL_FILE.fclose (fhandle_o);
END IF;
END;
SPOOL OFF;If I comment out the "AMRCONF_COMMENT_ERR ||'|'||" line, then the script works fine. The table was created as:
Create Table WSUALUMNI.AMRCONF_ERR
AMRCONF_PIDM_ERR NUMBER (8) NOT NULL,
AMRCONF_IDEN_CODE_ERR VARCHAR2(5) NOT NULL,
AMRCONF_ENTRY_DATE_ERR DATE NOT NULL,
AMRCONF_CONFID_IND_ERR VARCHAR2(1),
AMRCONF_COMMENT_ERR LONG,
AMRSUBJ_SUBJ_CODE_ERR VARCHAR2(5) NOT NULL,
ERROR_CODE VARCHAR2(12) NOT NULL,
ERROR_CODE_TEXT VARCHAR2(50) NOT NULL
); I don't get what is the problem here in the script.Hi,
Feew suggestions
1) LONG is a deprecated type hence if possible start working on changing that column
2) CLOB will your preferred datatype over LONG.
3) you cannot use RTRIM on long.
here is a very quick example
drop table h
create table h (x long,y varchar2(100))
select rtrim(x) from h
select rtrim(y) from hSolution:
[http://www.oracle.com/technology/oramag/code/tips2003/052503.html]
need a better solution change the datatype to clob and
drop table h
create table h (x clob,y varchar2(100))
select dbms_lob.substr( x, 4000, 1 ) from h
select rtrim(y) from hCheers!!!
Bhushan -
Error message - ORA-00932: inconsistent datatypes: expected CHAR got NUMBER
Here is my Report Query...
select
from DW_RFA_JOBDATA
where FINISH_TIME >= :P1_START_DATE
and FINISH_TIME < :P1_END_DATE
AND RFA_FLAG = (CASE :P1_JOB_CLASSIFICATION WHEN '0' THEN 'LSF'
WHEN '1' THEN 'NON-LSF'
ELSE RFA_FLAG END)The column RFA_FLAG data type is NUMBER(*,0)... i am displaying LSF and Non-LSF in the select list box , but i get the error ORA-00932: inconsistent datatypes: expected CHAR got NUMBER >
I have created static LOV with LSF display 0 return
NON-LSF display 1 return..
Could any body please help me in truble shooting the error ? how do i convert datatype into number i dont have any privileges to make changes to the table...Are there multiple columns in the table you are using from your LOV?
Your LOV select is:
select
from DW_RFA_JOBDATA
where FINISH_TIME >= :P1_START_DATE
and FINISH_TIME < :P1_END_DATE
AND RFA_FLAG = (CASE :P1_JOB_CLASSIFICATION WHEN '0' THEN 'LSF'
WHEN '1' THEN 'NON-LSF'
ELSE RFA_FLAG END)Maybe try this:
select
from DW_RFA_JOBDATA
where FINISH_TIME >= :P1_START_DATE
and FINISH_TIME < :P1_END_DATE
AND TO_CHAR(RFA_FLAG) = DECODE(:P1_JOB_CLASSIFICATION,'0','LSF','1','NON-LSF',RFA_FLAG) -
Why do I get this error? ORA-00932: inconsistent datatypes
This is my stored procedure I've created to select only the exact amount of records per page for a GridView (for ASP.NET):
CREATE OR REPLACE
PROCEDURE SELECT_COMMAND
(pTable IN VARCHAR2
, pFields IN VARCHAR2
, pSortField IN VARCHAR2
, pPageIndex IN NUMBER
, pTotalRecs IN NUMBER
, pResultSet OUT SYS_REFCURSOR
) AS
BEGIN
EXECUTE IMMEDIATE
'SELECT ' || pFields || ' FROM '
|| '(SELECT '|| pFields ||', ROW_NUMBER() OVER(ORDER BY '|| pSortField ||') ROW_NUM '
|| 'FROM '|| pTable ||') WHERE ROW_NUM BETWEEN '|| to_char(pPageIndex*pTotalRecs) ||' AND '
|| to_char((pPageIndex+1)*pTotalRecs)
INTO pResultSet;
-- Plus 1 to our index because GridView is a zeroth index collection
END SELECT_COMMAND;I then do a test case with the following paremeters:
declare
p_test sys_refcursor;
begin
select_command('v_sig_devices', '"JOB", "LINE"', '"DEVICE_ID"', 0, 10, p_test);
end;But I get the following error:
>
Error report: ORA-00932: inconsistent datatypes: expected - got -
ORA-06512: at "SIM.SELECT_COMMAND", line 10
ORA-06512: at line 4
00932. 00000 - "inconsistent datatypes: expected %s got %s"
>
At first Oracle gave me an error because the numbers were not a string. Then I convert them into a string (with to_char) and Oracle is still not happy! Any ideas as to why this is happening?
Thanks for any help that you can provide.You don't select into ref cursors, you open them:
SQL> create table t(c varchar2(1));
Table created.
SQL> insert into t values ('a');
1 row created.
SQL> insert into t values ('b');
1 row created.
SQL> insert into t values ('c');
1 row created.
SQL> commit;
Commit complete.
SQL> create or replace
2 procedure p (p_ref out sys_refcursor) as
3 begin
4 open p_ref for 'select c from t';
5 end;
6 /
Procedure created.
SQL> var results refcursor
SQL> exec p(:results);
PL/SQL procedure successfully completed.
SQL> print results
C
a
b
c -
[Oracle 8i] ORA-00932 Inconsistent Datatypes
Hopefully this is a quick question to answer. In running a query I get the 'inconsistent datatypes' error, and I've narrowed the error down to one part of my query:
SELECT CASE
WHEN sopn.plan_start_dt < SYSDATE THEN SYSDATE
ELSE sopn.plan_start_dt
END
FROM SOPN sopn(replacing SYSDATE with an actual hard-coded date doesn't work either)
The field sopn.plan_start_dt is definitely a date datatype. If I do a simple query for just that field with a date parameter in my where statement, it works just fine, for example:
SELECT sopn.plan_start_dt
FROM SOPN sopn
WHERE sopn.plan_start_dt<SYSDATEdoes not give me any errors.
I'm guessing there's something wrong with my case statement, or maybe case statements with date parameters are something Oracle 8i doesn't get along with...
If anyone can tell me why my case statement is causing an 'inconsistent datatype' error, I'd appreciate it. Thanks!Well, this tells me column sopn.plan_start_dt datatype is not DATE. CASE requires all branches to return same type expressions. Most likely sopn.plan_start_dt is VARCHAR2 and it is very bad coding to rely on implicit comversions. Use TO_DATE with proper format. For example:
SELECT CASE
WHEN TO_DATE(sopn.plan_start_dt,'DD-MON-YY') < SYSDATE THEN SYSDATE
ELSE TO_DATE(sopn.plan_start_dt,'DD-MON-YY')
END
FROM SOPN sopnSY. -
Oracle 10g Issue [ORA-00932: inconsistent datatypes: expected ]
Hi,
The following Code Snippet works fine in Oracle 9i DB but gives "ORA-00932: inconsistent datatypes: expected - got -; " error in 10g DB. We are facing lot of issues with this since we migrated application to 10g
create or replace procedure cca is
TYPE Cur_OPCols_Typ IS REF CURSOR;
l_Cur_OPCols Cur_OPCols_Typ;
str VARCHAR2(32767) :='select sysdate, 123 from dual';
TYPE StringTyp IS TABLE OF VARCHAR2(7000) INDEX BY BINARY_INTEGER;
capture StringTyp;
BEGIN
Open l_Cur_OPCols FOR str;
FETCH l_Cur_OPCols BULK COLLECT INTO capture;
dbms_output.put_line (capture.COUNT);
Close l_Cur_OPCols;
END cca;
Please advise...
Regards,
ChinmayBut...
SQL> select * from v$version;
BANNER
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
PL/SQL Release 9.2.0.1.0 - Production
CORE 9.2.0.1.0 Production
TNS for Solaris: Version 9.2.0.1.0 - Production
NLSRTL Version 9.2.0.1.0 - Production
<br>
<br>
"afiedt.buf" 13 lines, 370 characters
1 declare
2 TYPE Cur_OPCols_Typ IS REF CURSOR;
3 l_Cur_OPCols Cur_OPCols_Typ;
4 str VARCHAR2(32767) :='select sysdate, 123 from dual';
5 TYPE StringTyp IS TABLE OF VARCHAR2(7000) INDEX BY BINARY_INTEGER;
6 capture StringTyp;
7 BEGIN
8 Open l_Cur_OPCols FOR str;
9 FETCH l_Cur_OPCols BULK COLLECT INTO capture;
10 dbms_output.put_line (capture.COUNT);
11 Close l_Cur_OPCols;
12* END cca;
SQL> /
declare
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected - got -
ORA-06512: at line 9 -
ORA-00932: inconsistent datatypes: expected - got -
Hi,
I have writen PL/SQL packages for data loging through pipe lined function for better peformance.The below packages has been compiled sucessfully but during the run time it shows an error
like "ORA-00932: inconsistent datatypes: expected - got -".
CREATE OR REPLACE PACKAGE pkg_mkt_hub_load
AS
PROCEDURE sp_final_load_mkt_hub;
FUNCTION fnc_pipe_tot_lvl_idx_mon_hub
(pi_input_cur IN SYS_REFCURSOR)
RETURN tot_lvl_idx_mon_tt
PIPELINED;
END pkg_mkt_hub_load;
CREATE OR REPLACE PACKAGE BODY pkg_mkt_hub_load
AS
c_default_limit CONSTANT PLS_INTEGER:=5000;
c_created_dt CONSTANT DATE:=SYSDATE;
c_created_user CONSTANT VARCHAR2(20):='SYSTEM';
c_updated_dt CONSTANT DATE:=SYSDATE;
c_updated_user CONSTANT VARCHAR2(20):='SYSTEM';
-- to get the debug desc for updating process log table
vg_debug_log_desc mkt_process_log.debug_log_desc%TYPE;
--to get process log key
vg_process_log_ky mkt_process_log.process_log_ky%TYPE;
-- reset the all variables.
PROCEDURE sp_reset_global_variables;
PROCEDURE sp_final_lvl_idx_mon_hub;
--PROCEDURE sp_final_lvl_idx_dly_hub;
FUNCTION fnc_pipe_tot_lvl_idx_mon_hub
(pi_input_cur IN SYS_REFCURSOR)
RETURN tot_lvl_idx_mon_tt
PIPELINED
AS
vl_lvl_idx_mon_cur_data tot_lvl_idx_mon_tt;
BEGIN
LOOP
FETCH pi_input_cur BULK COLLECT INTO vl_lvl_idx_mon_cur_data LIMIT c_default_limit;
EXIT WHEN vl_lvl_idx_mon_cur_data.COUNT = 0;
FOR i IN 1 .. vl_lvl_idx_mon_cur_data.COUNT
LOOP
PIPE ROW (tot_lvl_idx_mon_ot(vl_lvl_idx_mon_cur_data(i).SSIA_INDEX_ID,
vl_lvl_idx_mon_cur_data(i).start_date,vl_lvl_idx_mon_cur_data(i).currency,
vl_lvl_idx_mon_cur_data(i).level1,vl_lvl_idx_mon_cur_data(i).type,
vl_lvl_idx_mon_cur_data(i).RETURN_MONTH,vl_lvl_idx_mon_cur_data(i).RETURN_3MONTHS,
vl_lvl_idx_mon_cur_data(i).RETURN_6MONTHS,vl_lvl_idx_mon_cur_data(i).RETURN_YTD,
vl_lvl_idx_mon_cur_data(i).RETURN_1YEAR,vl_lvl_idx_mon_cur_data(i).RETURN_3YEARS,
vl_lvl_idx_mon_cur_data(i).RETURN_5YEARS,vl_lvl_idx_mon_cur_data(i).RETURN_10YEARS,
vl_lvl_idx_mon_cur_data(i).MARKET_CAP));
END LOOP;
END LOOP;
CLOSE pi_input_cur;
RETURN;
END fnc_pipe_tot_lvl_idx_mon_hub;
PROCEDURE sp_final_lvl_idx_mon_hub
AS
BEGIN
MERGE INTO mkt_total_lvl_indx_mon_hub idxhub
USING TABLE(pkg_mkt_hub_load.fnc_pipe_tot_lvl_idx_mon_hub(CURSOR(SELECT idxmap.ssia_index_code,idxstg.start_date,idxstg.currency,idxstg.level1,idxstg.type,
idxstg.return_month,idxstg.return_3months, idxstg.return_6months, idxstg.return_ytd, idxstg.return_1year,
idxstg.return_3years, idxstg.return_5years,idxstg.return_10years,idxstg.market_cap
FROM mkt_total_lvl_indx_mon_stg idxstg,
md_vendor_index_map idxmap
WHERE idxmap.source = idxstg.source
AND idxmap.base_currency = idxstg.currency
AND idxmap.return_type = idxstg.TYPE
AND idxmap.mkt_index_id = idxstg.vendor_code
AND idxmap.monthly = 'Y'
AND idxmap.file_type = 'T'))) idxmonstg
ON (idxhub.ssia_index_id=idxmonstg.ssia_index_id)
WHEN MATCHED THEN
UPDATE set effective_date=idxmonstg.start_date,
CURRENCY=idxmonstg.currency,
INDEX_LEVEL=idxmonstg.LEVEL1,
TYPE=idxmonstg.type,
return_month=idxmonstg.return_month,
return_3months=idxmonstg.return_3months,
return_6months=idxmonstg.return_6months,
return_ytd=idxmonstg.return_ytd,
return_1year=idxmonstg.return_1year,
return_3years=idxmonstg.return_3years,
return_5years=idxmonstg.return_5years,
return_10years=idxmonstg.return_10years,
market_cap=idxmonstg.market_cap,
updated_dt=SYSDATE,
updated_user='MICHAEL'
WHEN NOT MATCHED THEN
INSERT ( ssia_index_id,
effective_date,
currency,
INDEX_LEVEL,
TYPE,
return_month,
return_3months,
return_6months,
return_ytd,
return_1year,
return_3years,
return_5years,
return_10years,
market_cap,
created_dt,
created_user)
VALUES( idxmonstg.ssia_index_id,
idxmonstg.start_date,
idxmonstg.currency,
idxmonstg.LEVEL1,
idxmonstg.type,
idxmonstg.return_month,
idxmonstg.return_3months,
idxmonstg.return_6months,
idxmonstg.return_ytd,
idxmonstg.return_1year,
idxmonstg.return_3years,
idxmonstg.return_5years,
idxmonstg.return_10years,
idxmonstg.market_cap,
SYSDATE,
'MICHAEL');
END sp_final_lvl_idx_mon_hub;
PROCEDURE sp_final_load_mkt_hub
as
BEGIN
sp_final_lvl_idx_mon_hub;
END sp_final_load_mkt_hub;
PROCEDURE Sp_reset_global_variables
AS
BEGIN
vg_debug_log_desc := NULL;
END sp_reset_global_variables;
END pkg_mkt_hub_load;
SHOW ERRORS Error:
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected - got -
ORA-06512: at "GPAIHMKTDTA.PKG_MKT_HUB_LOAD", line 33
ORA-06512: at "GPAIHMKTDTA.PKG_MKT_HUB_LOAD", line 55
ORA-06512: at "GPAIHMKTDTA.PKG_MKT_HUB_LOAD", line 92
ORA-06512: at line 1
types scripts:
create or replace type tot_lvl_idx_mon_ot as object
(SSIA_INDEX_ID VARCHAR2(60),
start_date date,
CURRENCY VARCHAR2(10),
LEVEL1 NUMBER(31,11),
TYPE VARCHAR2(31) ,
RETURN_MONTH NUMBER(31,11),
RETURN_3MONTHS NUMBER(31,11),
RETURN_6MONTHS NUMBER(31,11),
RETURN_YTD NUMBER(31,11),
RETURN_1YEAR NUMBER(31,11),
RETURN_3YEARS NUMBER(31,11),
RETURN_5YEARS NUMBER(31,11),
RETURN_10YEARS NUMBER(31,11),
MARKET_CAP NUMBER(31,11));
create or replace type tot_lvl_idx_mon_tt is table of tot_lvl_idx_mon_ot;how to resolve this issue?>
could you please pointed out whether ref cursor used method correct or not?
>
The use looks correct but without your tables and DDL we can't even try to reproduce the problem.
Notice how you had to break down the process to find out the query that is causing the problem?
select *
from TABLE(pkg_mkt_hub_load.fnc_pipe_tot_lvl_idx_mon_hub(CURSOR(SELECT . . .Unfortunately, this is where you should have started when you began creating the process.
You are trying to design, implement and debug a process using code that has 3,4, 5 or more layers and objects and tables that have a dozen or more columns.
That is not the way I would recommend especially if you do not have experience with some of the pieces like object types and tables, pipelined functions and ref cursors. You are trying to deal with too many complications at the same time.
Here is how I would approach this if I were you.
1. Get the process to work first and then build on it. Start by copying and hacking up what you already have.
2. Create a very simple version of each of the pieces
3. Create an object type like 'tot_lvl_idx_mon_ot' with only one or two columns.
4. Create an object type like 'tot_lvl_idx_mon_tt' as a table of that simple object type
5. Create a pipelined function that uses the two new simple types, simply hard-codes a value for one or two rows and then pipes out the rows.
6. Use a simple query like the last one you posted to query the simple pipelined function
select *
from TABLE(pkg_mkt_hub_load.simpe_pipeline_function(CURSOR(SELECT . . .Work on that simple set of objects until you have the process defined and working.
Then expand the now working example to use get the data values dynamically and to use more complicated objects.
Start with something simple that works. Then build on it.
It will take a lot less time and will point out other issues with your approach to this. Also, if you try a simple version using the SCOTT emp or dept table and it doesn't work you can post the code and we can try to reproduce it and help find the problem.
Maybe you are looking for
-
How do I install Windows with my OEM disc?
So I bought the Windows 8.1 64-bit OEM installation disc, and was using BCA (Boot Camp Assistant) to install it on my Late 2012 Mac mini. I did as I was prompted: plugged in an 8GB USB drive, inserted my disc into my external reader, opened BCA, chec
-
Referencing static LOV from plsql
I have a number of static LOV's. How can I reference these in PL/SQL. For example, I am creating a report using PL/SQL so that I can create the exact layout I require. The data uses a number of list of values so I need to convert the value fields int
-
Adobe Pro 11 conflict with Adobe reader on Firefox
I downloaded adobe acrobat pro 11 trial version and also have adobe reader on my Windows 7. I get error only on firefox when trying to open the pdf attachment stating "there was an error opening this document. The file is damaged and could not be re
-
Document/literal web service with WSDL
Hi I is so hard to get an easily written example of how to do a Document/literal web service in java, to generate a WSDL descripbing it and then deploying it on Apache. I first belived that I should use JAXM. But I think it is just SOAP and there is
-
MW not showing Internet Expenses pre-upgrade tasks
User logins to MW, Selects project from "Select Role" "Engineer", Select category "Prep for Upgrade" from Process Steps. An assigned task/step for that user does not appear. For this particular user it is Category=Prep for Upgrade, Prod Family=Financ