Oracle: Error when executing query - oracle11g

I have a table SyncTokenLock that has column lockName that is of CLOB type. When I run following query from SQLDeveloper -
select * from SyncTokenLock where
lockName='com.vmware.horizon.datastore.impl.ProvisioningStateDataServiceImpl';
I get following exception -
ORA-00932: inconsistent datatypes: expected - got CLOB
00932. 00000 - "inconsistent datatypes: expected %s got %s"
I get similar error when this query is executed through Hibernate (3.6.10) against Oracle 11g. Hibernate throws following exception -
ORA-00932: inconsistent datatypes: expected - got CLOB
Any idea what could the reason be.

Correct, you can't use equality with a CLOB in the WHERE clause. But you can do this:
SELECT * FROM SyncTokenLock
WHERE dbms_lob.substr(lockName, 100) =
'com.vmware.horizon.datastore.impl.ProvisioningStateDataServiceImpl';
Does your column really need to be a CLOB? Are you expecting values over 4000 characters? If not, use a VARCHAR2.

Instead of using the equal sign, you may use like:
select * from SyncTokenLock where lockName like 'com.vmware.horizon.datastore.impl.ProvisioningStateDataServiceImpl';

Related

SQLite Subquery Syntax Error when using Multiple Columns

It seems so simple; but I can't get this working.
select ISIN, QuoteTimestamp
from QuoteData
where (ISIN, QuoteTimestamp) IN
(select ISIN, MAX(QuoteTimestamp) QuoteTimestamp
from QuoteData
group by ISIN)
This query gives me a syntax error. If I amend it to only use a single column (remove the MAX(QuoteTimewstamp)) it works.
It seems to be correct, as per the documentation.
Adding "AS" for the subquery alias makes no difference.
Here's the full error message from SQLite Manager.
SQLiteManager: Likely SQL syntax error: select ISIN, QuoteTimestamp
from QuoteData
where (ISIN, QuoteTimestamp) IN
(select ISIN, MAX(QuoteTimestamp) AS QuoteTimestamp
from QuoteData
group by ISIN)
[ near ",": syntax error ]
Exception Name: NS_ERROR_FAILURE
Exception Message: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [mozIStorageConnection.createStatement]
This seems to work although, to me, it seems counter-intuitive. It is returning "Symbol", "Bid" and "Ask" from the row with MAX(QuoteTimestamp).
select ISIN, Symbol, Bid, Ask, MAX(QuoteTimestamp)
from QuoteData
group by ISIN
I'm sure Oracle and their ilk would tell me that Symbol, Bid and Ask are not group-by expressions.
Thanks for all the help.
Thanks,
Al.
In SQLite 3.7.11 or later, you do not need to use a subquery at all:
select ISIN, MAX(QuoteTimestamp) QuoteTimestamp
from QuoteData
group by ISIN

Getting invalid datatype error while parsing xml in Oracle

I am trying to parse XML in PL SQL. But getting following error
Error report:
ORA-06550: line 21, column 43:
PL/SQL: ORA-00902: invalid datatype
ORA-06550: line 17, column 1:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
I am trying to run below query
DECLARE
l_xml xmltype:= xmltype('<Table>
<Data>
<DataKey>Test</DataKey>
<DataTypeID>8</DataTypeID>
<DataValue>test1</DataValue>
<Id>eb96c9c1-6236-403d-9afa-6d45ec623dbc</Id>
</Data>
</Table>');
begin
select * FROM
xmltable ('/Table/Data' passing l_xml
columns
DataKey nvarchar2(50) path '/Data/DataKey'
,DataTypeID int, path '/Data/DataTypeID'
, DataValue nvarchar2(1024) path '/Data/DataValue');
end;
/
I am new to PL/SQL, so not able to figure out the error. Can anybody help me here?
Thanks
You have an extra comma between int and path:
,DataTypeID int, path '/Data/DataTypeID'
should be
,DataTypeID int path '/Data/DataTypeID'
Or you could use number instead of int.
Your select also has to be selecting into something, since this is in a PL/SQL context. So now you'll get a PLS-00428 error. Without knowing what you plan to do with the results it isn't entirely obvious how you should correct that - whether you don't actually need PL/SQL, or you want to loop over the results to do something with them, or insert into another table, or...

RS-DBI driver warning: (unrecognized MySQL field type 7 in column 1 imported as character)

I'm trying to run a simple query that works with MySQL or other MySQL connector API's,
SELECT * FROM `table` WHERE type = 'farmer'
I've tried various methods using the RMySQL package and they all get the same error
RS-DBI driver warning: (unrecognized MySQL field type 7 in column 1 imported as character)
Type = 'farmer'
(Query<-paste0("SELECT * FROM `table` WHERE type = '%",Type,"%'"))
res<-dbGetQuery(con, Query)
Query<-paste("SELECT * FROM `table` WHERE type = \'farmer\'")
Query<-paste("SELECT * FROM `table` WHERE type = 'farmer'")
What am I doing wrong?
"type" is a keyword in MYSQL. Surround the it with backticks to escape field names.
SELECT * FROM `table` WHERE `type` = 'farmer'
Also you probably have a time stamp column in your table. R is known to not recognize that column type. Convert it to a unix time stamp in the portion of the SQL statement.
Looks like the db schema has something in column which is of type 7 -- and that type appears to be unknown to the RMySQL driver.
I try to exclude column one in the query, or cast it at the select * ... level eg via something like
select foo as character, bar, bim, bom from 'table' where ...
To be clear, when I encountered this error message, it was because my data field was a time stamp.
I verified this by changing my query to SELECT created_at FROM ... which caused the error. I also verified this by changing the query not to include the column names that were timestamps, then I had no errors.
Note too, that the error message counts columns starting from 0 (instead of 1 as R does)
IMHO, the answer is you aren't doing anything wrong, but it's something that needs to be fixed in RMySQL.
The workaround is after you read in your data, you need to call one of the several possible character to datetime conversion functions. (Which one depends on what you want to do with the time stamp exactly.)

Unable to convert a long datatype to xml in oracle

I have an oracle column with a long data type that stores an xml. Now I want to perform the EXTRACT and EXTRACTVALUE functions on this column. For this purpose, I need to convert the long to xmltype. But when I do : xmltype.createxml(long_col_name), I get :illegal use of long datatype
I know long is deprecated, but it is legacy db.So...
EDIT: Upon the suggestion, i tried:
SELECT
EXTRACTVALUE( XMLTYPE (to_lob(long_col_name)), xpath_str) as value_date
FROM table_1;
I get:
[Error] Execution (2: 24): ORA-00932: inconsistent datatypes: expected - got LONG
Check this link
good example
in short you need to do the following:
with xml as
(select dbms_xmlgen.getxmltype('select long_col_name from table_1') as xml from dual)
select extractValue(xs.object_value,'/ROW/long_col_name') as value_date
from xml x, table(xmlsequence(extract(x.xml,'/ROWSET/ROW'))) xs
where extractValue(xs.object_value,'/ROW/long_col_name') like '%xxxx%';
Hope this helps.
you'd better to migrate the LONG column type to CLOB. It will also benefit you in future. then you can use xmltype on the CLOB column.

Oracle unable to convert from LONG datatype to CLOB datatype( incosistent datatype error)

Oracle 11g is giving me the following error while trying to convert a long datatype to a clob.
I try: select to_lob(long_col_name) from table1.
I get :
[Error] Execution (1: 39): ORA-00932: inconsistent datatypes: expected - got LONG
What am i doing wrong here?
Found the answer here with the help of a colleague:
http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions185.htm
But no idea why this restriction is in place
You can apply this function only to a LONG or LONG RAW column, and only in the select list of a subquery in an INSERT statement.
I suggest a workaround like this, hope this helps to somebody.
SELECT substr(Y.longtoclob,
43 + length('ALIASLONG'),
DBMS_LOB.GETLENGTH(Y.longtoclob) -
2 * (32 + length('ALIASLONG'))) longtoclob
from dual,
(select (dbms_xmlgen.getxml('SELECT t.column_long ALIASLONG
FROM TABLE_LONG_CLOB t WHERE t.id = 2')) longtoclob
from dual) Y where DBMS_LOB.GETLENGTH(Y.longtoclob) > 0
You can't directly fetch LONG to LOB. You might want to convert it to VARCHAR2 first

Resources