Compare two CLOB columns in Oracle SQL Developer - sql

I am trying to compare two columns of CLOB datatype in Oracle SQL Developer. Below is the query used,
select *
from t1
join t2 on t1.reference_no = t2.reference_no
where dbms_lob.compare (t1.text, t2.t_col_clob) = 0;
Getting error message as
ORA-00904: : invalid identifier.
This means I don't have access to dbms_lob.compare
How comparison can be done with using dbms_lob.compare?
Please note raised this as separate because all the information available is using dbms_lob.compare, Found nothing how this can be done without using dbms_lob.compare and also I won't be getting access to dbms_lob.compare. Please suggest a SQL way to compare this.

Related

How to store the result of select statement into the temporary table in Oracle?

We can write select column1,column2 into #temp from tableName in SQL Server. But I am unable to write the same query in an Oracle database.
I want to store the result of select/insert/delete/update or any result set into a local temporary table in oracle database. How I can do this?
I am executing below query in my Oracle sql developer tool:
select * into #temp
from bmi;
but I am getting the error as follow please help to find this error.
when I execute the same query in Microsoft SQL Server it get executed & #temp table get created which is not present in the database but it can hold the data for that particular session. so i want same scenario in ORACLE database.
ORA-00911: invalid character
00911. 00000 - "invalid character"
*Cause: identifiers may not start with any ASCII character other than
letters and numbers. $#_ are also allowed after the first
character. Identifiers enclosed by doublequotes may contain
any character other than a doublequote. Alternative quotes
(q'#...#') cannot use spaces, tabs, or carriage returns as
delimiters. For all other contexts, consult the SQL Language
Reference Manual.
*Action:
Error at Line: 1 Column: 15
I want to store the result of select/insert/delete/update or any result set into a local temporary table in oracle database,How I can Do This?
You can't. Oracle doesn't have local temporary tables, it doesn't work like that. But it doesn't need to. Oracle has a very different internal model from SQL Server which means a lot of SQL Server practices are unnecessary in Oracle. (To be fair SQL Server has neat things which Oracle doesn't, like ANSI 92 Joins for DML.)
The key insight is: you don't want to store the result of select/insert/delete/update or any result set into a local temporary table. That is something you had to do in T-SQL to achieve the end goal of implementing some business logic. But what you actually wanted to do in SQL Server and what you want to do in Oracle is write some code which delivers value to your organisation.
So, with that mindset in place, what do you need to do?
If you want to loop round a result set then perhaps a Cursor Loop is what you're looking for?
for rec in ( select * from some_table
where the_date = date '2018-02-01' )
loop
...
If you want to work on some data prior to inserting it into a data then perhaps you should use a PL/SQL collection:
type l_recs is table of some_table%rowtype;
But maybe you just need to understand Oracle's Transaction Management model. A lot of things are possible in pure SQL without any need for procedural framework.
Create temporary table :
create global temporary table
results_temp (column1, column2)
on commit preserve rows;
and then insert to it from your table:
insert into results_temp (column1, column2 )
SELECT column1,column2
FROM source_table
create global temporary table temp_table_name
on commit preserve rows as select column1,column2,columnN from your_table;

Bigquery type cast on JOIN Clause

I'm trying to join two tables on two columns
-- query to join two tables
SELECT
*
FROM
[raw.raw_sales] AS game_records
JOIN
[facebook_aggregate.avg_aggregate] AS avg_aggregate
ON
(game_records.Away_team = avg_aggregate.team_name)
AND (game_records.game_date = avg_aggregate.time_update)
it gives me this error Error: 10.30 - 10.56: Timestamp literal or explicit conversion to timestamp is required. because game_records.game_date is type STRING and avg_aggregate.time_update is type DATE.
but if I do the conversion within the JOIN..ON.. clause
-- query to join two tables
SELECT
*
FROM
[raw.raw_sales] AS game_records
JOIN
[facebook_aggregate.avg_aggregate] AS avg_aggregate
ON
(game_records.Away_team = avg_aggregate.team_name)
AND (DATE(game_records.game_date) = DATE(avg_aggregate.time_update))
It gives me this error:
Error: ON clause must be AND of = comparisons of one field name from each table, with all field names prefixed with table name. .
Is there any way to do this without creating an intermediate table? Thanks!
Try using standard SQL (uncheck "Use Legacy SQL" under "Show Options"). You shouldn't need to do anything aside from remove the brackets around the table names:
SELECT
*
FROM
raw.raw_sales AS game_records
JOIN
facebook_aggregate.avg_aggregate AS avg_aggregate
ON
game_records.Away_team = avg_aggregate.team_name
AND game_records.game_date = avg_aggregate.time_update;
BigQuery Standard SQL (see Enabling Standard SQL) does not have this limitation for ON clause. Try running your query in Standard SQL.
As Elliott mentioned - make sure you are not using square brackets around tables references. In Standard SQL - when you need to escape special chars - yo should use back-ticks
Also check Migrating from legacy SQL if you will follow above direction

SQL Queries "00904. 00000 - "%s: invalid identifier"

Hi I have the following code
SELECT entertainer_id,
entertainer_groupname
FROM casestudy_entertainer
INNER JOIN casestudy_availability ON
casestudy_entertainer.entertainer_id
= CASESTUDY_AVAILABILITY.AVAILABILITY_ENTERTAINERID
INNER JOIN casestudy_calendardates ON
CASESTUDY_AVAILABILITY.AVAILIBILITY_CALENDARDATEID
= casestudy_calendardates.calendar_Id
WHERE entertainer_type = '&Entertainer_TYPE'
AND casestudy_calendardates.calendar_date = '&Event_date'
And I don't seem to be able to figure out what its not liking when I run this.
It gives me the following error
ORA-00904: "CASESTUDY_AVAILIBILITY"."AVAILIBILITY_CALENDARDATEID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error at Line: 7 Column: 4
I do have all the tables in place with all the correct rows.
The only thing is I have no data as of yet, Could this possibly be the issue?
You should try the lower case for the table/column identifiers(like in from/inner join clauses):
SELECT entertainer_id,
entertainer_groupname
FROM casestudy_entertainer
INNER JOIN casestudy_availability ON casestudy_entertainer.entertainer_id = casestudy_availability.availability_entertainerid
INNER JOIN casestudy_calendardates ON casestudy_availability.availibility_calendardateid = casestudy_calendardates.calendar_id
WHERE entertainer_type = '&Entertainer_TYPE'
AND casestudy_calendardates.calendar_date = '&Event_date'
This Error is caused by a special character in one of the columns of the database table. DBA will be able to help you.
You have same tablenames in your tables while left joining.
Change tablename of one , it will work.
no data is not the issue, you won't simply get a null result. ORA-00904 indicates, that you used a column that does not exist or does not comply to the Oracle specification.
Please check for correct naming. You might be better of with shorter names or at least table aliasses to get to code more readable.
Without knowing your table structure I cannot tell you where the error is. do a describe table_name;
It would also help to have the oracle version number SELECT * FROM V$VERSION or SELECT version FROM V$INSTANCE
and your client software you are using
What is interesting, Oracle gives that message not only if the name of the column is bad, but also if the name of the table/alias is bad - not defined alias, twice defined (as mentioned #PrajwalRai), error in the table name.
Old question, but maybe it helps:
sometimes you copy and paste text from a source that has a different character set ...
Type it over in sql-dev for instance and see if the error is gone
I was able to clear this error in an Oracle DB using Oracle SQL Developer by placing strings in single quotes instead of double quotes

SQL Server DBLlink to oracle returns numbers as string

I have an Oracle database containing my data and an SQL Server database getting the data from Oracle through DBLink.
Problem is - all numbers from the Oracle tables are accepted at the SQL Server as nvarchar. As a result, when i try to filter the query in the SQL Server with some_number_field = 0 i get:
"Conversion failed when converting the nvarchar value '3.141' to data type int."
This also happens if i try to select "some_number_field * 1" or similar expressions.
Any idea ?
Today I ran into the same kind of problem. It seems that Oracle field with datatype NUMBER are shown as nvarchar where querying through a linked server. However, NUMBER(x,y) not.
E.g. colB is the NUMBER field from an Oracle View (or table)
Try this:
SELECT colA, CAST(colB AS DECIMAL(23,2)) colB
FROM OPENQUERY(LINKED_SERVER_NAME, 'select * from myView')
Note: the DECIMAL(xx,y) values depends of course on your data. Also, remember, if your NUMBER column is a repetitive fraction (eg. 33.33333333 etc), you need to place a round() on the oracle side otherwise the CAST will throw an error.

OleDbDataReader not giving same results as SQL Developer

The following query on my oracle db gives results that look fine when run in SQL Developer.
select *
from guideline$ a left outer join textfragment$ t
on (a.TEXTFRAGMENT_CODE = t.TEXTFRAGMENT$_CODE)
start with a.knowledge$_Code = 71122 and a.guideline$_pcode is null
connect by prior a.guideline$_Code = a.guideline$_pcode
order SIBLINGS by a.tag_order
All rows are populated correctly. When the same exact query is ran in my program using OleDbReader.ExecuteReader() some of the rows contain a null value for a specific column when they didn't in my SQL Developer results. The data type of that column is CLOB. I can not see any pattern as to why some of the rows have a null value and some do not.
Not sure what other information would be helpful...
Does anyone have any ideas on what might be going on?
Your problem may be related to the way that binary data is retrieved with OleDbDataReader.
You should use GetBytes(), and follow this article.