I am trying to select table from an oracle database using datastage.
In the ODBC Connector, If i do
select *
from Table_Name
I get this error -
'ODBC function "SQLNumResultCols" reportted: STATE=102:Native Error
Code = 0: Msg = [IBM(DataDirect OEM)][ODBC 20101 driver] 251'.
However if i use -
select cast(colA as varchar(50) as A,
cast(colB as varchar(50) as B
instead of
select *
from table_name
it works just fine. The data type of these columns is NVARCHAR2.
Is there a way to directly get it from
select *
from table_name
(there are about 20 columns in each of these tables)
Found a fix. Changed nvarchar parameter in odbc file
Related
struggling with a PL/SQL Function here (new to me) - and what makes this weird is it appears to work on Oracle XE (local) and Oracle 12c - but when applied to AWS RDS Oracle instances it does not work.
I have a function which is returning a query column value from another table, and I am trying to add a function derived column to a new table.
The database is currently empty as it is being designed.
TableA
CompanyID Integer
VALUE VARCHAR2(128)
Function - This works executing in SQL Developer
create or replace FUNCTION MyFunction
(
CompanyID IN INT
) RETURN VARCHAR2
DETERMINISTIC
IS result VARCHAR2(128);
BEGIN
SELECT "VALUE" INTO result
FROM "TableA"
WHERE "CompanyID" = CompanyID;
RETURN result;
END MyFunction;
Next - Alter TableB to add column referencing MyFunction
ALTER TABLE "TableB" ADD "TableAValue" VARCHAR2(128) AS (MyFunction("CompanyID"))
Observe error
ORA-12899: value too large for column "TableAValue" (actual: 32767, maximum: 128)
12899. 00000 - "value too large for column %s (actual: %s, maximum: %s)"
It's working OK in Oracle XE as mentioned - but when trying to create my database on AWS RDS Oracle, it's like it cannot determine that the size of column TableA.VALUE is only 128 in size, and treating it as maximum (for extended string size settings).
Am I missing something in the function that can force the DB Engine to see that it is appropriately sized? I have tried casting the SELECT "VALUE" to VARCHAR2(128) as well but that made no difference.
A bit confused, appreciate any insight!
Don't use a function and don't declare non-deterministic functions as DETERMINISTIC when they are not.
Instead, create a view:
CREATE VIEW tableb_view AS
SELECT b.*,
a.value AS tableavalue
FROM tableb b
LEFT OUTER JOIN tablea a
ON b.id = a.id
If you really want to use your function (DON'T) then you can specify the size using CAST:
ALTER TABLE TableB ADD TableAValue VARCHAR2(128) AS (
CAST( MyFunction(CompanyID) AS VARCHAR2(128) )
)
I have this query I am trying to run but I keep running into this error. I am trying to do a Where clause that compares the data (BLOB column) to :var2 which is a blob object.
Here is my code.
SELECT max(id)
INTO :var1
FROM table_name
where data = :var2;
Any suggestions to why I would be getting this ORA-00932 error?
I am comparing a blob to a blob column, shouldn't that be fine?
Thanks
They aren't simple types and you need to use a function to compare them.
SELECT max(id)
INTO :var1
FROM table_name
where dbms_lob.compare(data,:var2) = 0;
I am new to SQL and recently installed Oracle 11g. I read the post here on selecting all tables from user_tables. I'm trying to select a specific table and following some of the suggestions in the post does not appear to work.
The following executes fine and returns all tables available to me including a table named faculty_t:
select * from user_tables;
select * from dba_tables;
select * from all_tables;
desc faculty_t;
But I get error when I do the following:
select * from user_tables where table_name = FACULTY_T;
The first set of statements confirm that I do have a table named faculty_t. However, trying to select this table from user_tables, all_tables, or dba_tables does not appear to work for me right now. The error message reads something like:
ORA-00904: "FACULTY_T": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error at Line: 208 Column: 8
Any thoughts? Thanks!
String literals in SQL are wrapped in '. So:
select * from user_tables where table_name = 'FACULTY_T';
When you did a desc faculty_t, the SQL engine knew that a table name was expected at that spot (the syntax expects a table name there). But in your select query, sql is just looking for the value of a column that happens to have a string data type, so you need to use the ' for a string literal.
I have a table (AKADMIN) with an XMLTYPE column which name is XML.
I would like to use the getClobVal() with this column.
select t.xml.getClobVal() /**/
, t.xml.getClobVal() --
, t.xml.getClobVal() as clobval
, t.xml.getClobVal()
from akadmin t where ROWID = 'AAAQc6AAIAAAADDAAA' ;
In the resultset the first 4 column give CLOB type, but the fifth column XMLTYPE. I have to type any comment or alias after getClobVal() to correct (CLOB) type of the result. Why?
Another issue, when I leave the alias of tablename:
select xml.getClobVal()
from akadmin t where ROWID = 'AAAQc6AAIAAAADDAAA' ;
It throws an ORA-00904 string: invalid identifier
Hmmm...
Does anybody have any idea?
Addition info about environment:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0;
PL/SQL Developer 10.0.5.1710
But a tried this in our Java apllication via OJDBC6 with same results
You should put xml in a brackets:
select (xml).getClobVal() from akadmin;
works for me
I have the following (example) query that I'm trying to run
SELECT some_field
FROM MY_VIEW
WHERE date_field >= TO_DATE('2011-06-22', 'yyyy-mm-dd')
When I run this in SQL*Plus, I get a set of results, when I try through JDBC (using java.sql.Statement) I get the following error: java.sql.SQLException: ORA-01722: invalid number.
To make it even stranger, the following code works through the JDBC:
select field_1
FROM MY_VIEW v1
WHERE field_2 != 'some value'
AND not exists (
SELECT field_1
FROM MY_VIEW v2
WHERE v1.field_1 = v2.field_1
and t1.timestamp < t2.timestamp
)
But the code below (which still works in SQL*Plus) doesn't (same ORA-01722 error):
select field_1
FROM MY_VIEW v1
WHERE field_2 != 'some value'
AND not exists (
SELECT field_1
FROM MY_VIEW v2
WHERE v1.field_1 = v2.field_1
and v2.field_2 = 'some value' -- Does not work with this line (same value as above)
and v1.timestamp < v2.timestamp
)
I'm running Java 6, connecting to Oracle 10g, and using the ojdbc14.jar. I think it's important to note that the view being queried (MY_VIEW) is a fairly complicated thing, including more then one field being casted from varchar to numeric. My current suspicion is that Oracle is creating a different, unworkable, execution plan for the jdbc query then for the SQL*Plus.
Any suggestions on what I should do from here?
Thanks.