ORA-00928 selecting from view over DB link, but works locally - oracle

I have a view with a query of the following form which works perfectly when I query it on the local server from any schema:
WITH dates AS (
SELECT /*+ materialize */ ... FROM ( SELECT ... FROM table#link)
UNION ALL
SELECT * FROM ( SELECT /*+ materialize */ FROM table#link )
)
SELECT ... FROM (
SELECT ... FROM (
SELECT ... FROM (
SELECT ... FROM (
SELECT ... FROM
)
) foo
LEFT OUTER JOIN (
SELECT /*+ USE_MERGE(hle dates) */ ... FROM
) bar ON conditions
)
)
UNION ALL
SELECT ... FROM (
SELECT ... FROM (
SELECT ... FROM (
SELECT ... FROM (
SELECT ... FROM
)
) foo
LEFT OUTER JOIN (
SELECT /*+ USE_MERGE(hle dates) */ ... FROM
) bar ON conditions
)
)
When I run the query from any remote db link on any other server, e.g. SELECT * from someschema.my_view#db_link, I get:
ORA-00928: missing SELECT keyword
ORA-02063: preceding line from PLLDB
00928. 00000 - "missing SELECT keyword"
*Cause:
*Action:
Error at Line: 2 Column: 9
Oracle thinks line 2 is a problem. Here are the first five actual lines:
WITH dates AS (
-- Get days
SELECT /*+ materialize */
row_number() OVER (ORDER BY begin_period DESC) rn,
'D' AS interval_type,
All other views work perfectly over the DB link (once edited to work around any related Oracle bugs).
Why does this view work perfectly locally but not over a db link?

Referring from Here
BUG 768478 The message "ORA-00928: missing SELECT keyword" can occur when Oracle cost-based optimization attempts to rewrite a query that contains a set operator (e.g. UNION, MINUS, or INTERSECT) with a materialized view.
There are three workarounds:
1. Disable query rewrite with an "ALTER {SESSION|SYSTEM} DISABLE QUERY REWRITE" statement.
2. Use a NOREWRITE hint with all SELECT statements referenced by the set operator.
3. Use a REWRITE(mv) hint with all SELECT statements in the set operator to tell the optimizer to explicitly use a materialized view.
Scalar expressions referencing SQL factoring elements ( WITH ... AS ) are not fully supported within view's subqueries. Acessing it locally work fine but remote access via dblinks errors out every time.

Related

Oracle Invalid Identifier (with Inner Join)

I'm having an "Invalid Identifier" in Oracle because of the "B.username" (username column does exist in USER table). When i remove this, it's working fine. How to resolve this issue? I came from a MySQL background.
SELECT * FROM (SELECT qNA.assignment, qNA.regDate, B.username, (
SELECT DISTINCT NVL(idx, 0)
FROM EK_USERGRADE
WHERE year = (SELECT DISTINCT userGradeNo FROM EK_USER WHERE ID = qNA.userIdx)
) AS userGradeIdx
FROM EK_NEWTESTAPPLICANT qNA
WHERE IDX = :idx ) A
INNER JOIN EK_USER B ON (A.userIdx = B.ID)
Let's try this with a simplified version of your query:
-- test tables
create table NEWTESTAPPLICANT as select 1 useridx from dual ;
create table B as select 1 id, 'name1' username from dual ;
-- query
select *
from (
select B.username
from NEWTESTAPPLICANT qNA
) A join B on A.useridx = B.id ;
-- ORA-00904: "B"."USERNAME": invalid identifier
There's no "username" column in the NEWTESTAPPLICANT table, which causes the error. A LATERAL inline view (examples see here) may do the trick ...
-- query
select
*
from B, lateral (
select B.username
from NEWTESTAPPLICANT qNA
) A ;
-- result
ID USERNAME USERNAME
1 name1 name1
This works with Oracle 12c.
The problem is, that both your virtual table A and users B have the same column name "username". Specify alias in the main select, like "Select A.* , B.* from(...".
Is it ORA-00903?
User is a reserved word are you sure you created this table? Table name cannot be a reserved word.

Select query succeeds however Insert using same query fails with ORA-00979 (not a GROUP BY expression)

I am having a hard time finding why the below insert would fail while the select alone executes successfully.
INSERT INTO I6_POC_ADJ_OUTPUT
(LOADID,ADJ_ID,ADJ_CATEGORY,ADJ_COMMENT,ITEM,CHANNEL,FDATE,ADJ_TOT_QTY,FQTY)
SELECT
ADJ.LOADID,ADJ.ADJ_ID,ADJ.ADJ_CATEGORY,ADJ.ADJ_COMMENT,ADJ.ITEM,ADJ.CHANNEL,ADJ.FDATE,MAX(ADJ.FQTY) ADJ_TOT_QTY,
SUM(ADJ.TP_SPLIT) FQTY
FROM I3_POC_ADJ_INPUT ADJ,V_POC_HIST_BASE BASE
WHERE ADJ.ITEM=BASE.ITEM(+) AND ADJ.CHANNEL=BASE.CHANNEL(+) AND ADJ.FDATE=BASE.FDATE(+)
AND ADJ.LOADID=71 AND ADJ.ITEM='10-56-034' AND ADJ.CHANNEL='CH1820' AND ADJ.FDATE=DATE'2017-09-03'
GROUP BY ADJ.LOADID,ADJ.ADJ_ID,ADJ.ADJ_CATEGORY,ADJ.ADJ_COMMENT,ADJ.ITEM,ADJ.CHANNEL,ADJ.FDATE;
Select and Insert Executions
Update:
Tried with a simple CTAS and it works.
CREATE TABLE TEST_ADJ_OUTPUT AS
SELECT * FROM (
SELECT
ADJ.LOADID,ADJ.ADJ_ID,ADJ.ADJ_CATEGORY,ADJ.ADJ_COMMENT,ADJ.ITEM,ADJ.CHANNEL,ADJ.FDATE,MAX(ADJ.FQTY),
SUM(ADJ.FQTY*ADJ.TP_SPLIT)
FROM I3_POC_ADJ_INPUT ADJ,V_POC_HIST_BASE BASE
WHERE ADJ.ITEM=BASE.ITEM(+) AND ADJ.CHANNEL=BASE.CHANNEL(+) AND ADJ.FDATE=BASE.FDATE(+)
AND ADJ.LOADID=71 AND ADJ.ITEM='10-56-034' AND ADJ.CHANNEL='CH1820' AND ADJ.FDATE=DATE'2017-09-03'
GROUP BY ADJ.LOADID,ADJ.ADJ_ID,ADJ.ADJ_CATEGORY,ADJ.ADJ_COMMENT,ADJ.ITEM,ADJ.CHANNEL,ADJ.FDATE
);
Truncated the same table and tried inserting into the same but if fails with the same error. "SQL Error: ORA-00979: not a GROUP BY expression"
TRUNCATE TABLE TEST_ADJ_OUTPUT;
INSERT INTO TEST_ADJ_OUTPUT
SELECT * FROM (
SELECT
ADJ.LOADID,ADJ.ADJ_ID,ADJ.ADJ_CATEGORY,ADJ.ADJ_COMMENT,ADJ.ITEM,ADJ.CHANNEL,ADJ.FDATE,MAX(ADJ.FQTY),
SUM(ADJ.FQTY*ADJ.TP_SPLIT)
FROM I3_POC_ADJ_INPUT ADJ,V_POC_HIST_BASE BASE
WHERE ADJ.ITEM=BASE.ITEM(+) AND ADJ.CHANNEL=BASE.CHANNEL(+) AND ADJ.FDATE=BASE.FDATE(+)
AND ADJ.LOADID=71 AND ADJ.ITEM='10-56-034' AND ADJ.CHANNEL='CH1820' AND ADJ.FDATE=DATE'2017-09-03'
GROUP BY ADJ.LOADID,ADJ.ADJ_ID,ADJ.ADJ_CATEGORY,ADJ.ADJ_COMMENT,ADJ.ITEM,ADJ.CHANNEL,ADJ.FDATE
);
Appreciate your help.
Thanks,
Manoj

ora 22992 on a LOB field i am not using

I have the following simple oracle query:
select A.field
from table1 A
left join table2#remotedb B on A.id = B.id
Where table B has a BLOB field
It runs fine
If i add a concat to the select:
select A.field||'x'
from table1 A
left join table2#remotedb B on A.id = B.id
I get the following error:
"ora-22992 cannot use lob locators selected from remote tables"
Why adding a concat to a filed which isn't the LOB file is giving me this error?!?
What can i do to avoid it?
check this
with sub1 as
(
select /*+ materialize */ A.field
from table1 A
left join table2#remotedb B on A.id = B.id
)
select field || 'x'
from sub1
I just ran into similar issue. It seems Oracle requires it must be guaranteed any work with clob is avoided at remote side.
Assuming #remotedb is db link to another Oracle db, consider this minimized case:
select dummy from dual; -- works
select to_clob(dummy) from dual; -- works
select dummy from dual#remotedb; -- works
select to_clob(dummy) from dual#remotedb; -- fails - ORA-22992
with m as (select /*+ MATERIALIZE */ dummy from dual#remotedb)
select to_clob(dummy) from m; -- works again, fails without hint
I also tried to find workaround based on forcing computation to local db (select /*+DRIVING_SITE(local)*/ to_clob(r.dummy) from dual local, dual#remotedb r) but with no success.

can i set up an SSRS report where users input parameters to a table

I have an oracle query that uses a created table as part of the code. Every time I need to run a report I delete current data and import the new data I receive. This is one column of id's. I need to create a report on SSRS in which the user can input this data into said table as a parameter. I have designed a simple report that they can enter some of the id's into a parameter, but there may be times when they need to enter in a few thousand id's, and the report already runs long. Here is what the SSRS code currently says:
select distinct n.id, n.notes
from notes n
join (
select max(seq_num) as seqnum, id from notes group by id) maxresults
on n.id = maxresults.ID
where n.seq_num = maxresults.seqnum
and n.id in (#MyParam)
Is there a way to have MyParam insert data into a table I would join called My_ID, joining as Join My_Id id on n.id = id.id
I do not have permissions to create functions or procedures in the database.
Thank you
You may try the trick with MATERIALIZE hint which normally forces Oracle to create a temporary table :
WITH cte1 AS
( SELECT /*+ MATERIALIZE */ 1 as id FROM DUAL
UNION ALL
SELECT 2 DUAL
)
SELECT a.*
FROM table1 a
INNER JOIN cte1 b ON b.id = a.id

Pro*C syntax with select in select

Why won't this compile?
EXEC SQL insert into ssa (id )
select ( select max(id)
from ss s
where s.id = t.id )
from temp_sca t
where not exists
(select null
from sca ssa 2
where ssa2.ss_id = ( select max (id)
from ss s
where s.x = t.ss_id )
and ssa2.x = t.x )
Error I get:
select ( select max ( id)
...................1
PCC-D-02201, Encountered the symbol "max" when expecting one fo the following:
( ) * + ...
The symbol "(" was substituted for "max" to continue
Can we not embed a select in the select clause in Pro*C?
Oracle 11g on Solaris 10
Or is there a work-around?
Yep, converted the before mentioned to a dynamic sql c-string, then did an EXEC SQL EXECUTE IMMEDIATE on the resulting sql/c string, and all is well. Hopefully someone else may find this solution helpful.
MAX function is used here and MAX should be used with a GROUP BY. So, when Pro*C compiler tries to compile this, it does not find a GROUP BY and throwing this compilation error.

Resources