SQL query parsing Issue with joining a table with a view for apex tabular form - oracle

I am using the following SQL query as a basis for an Apex tabular form:
SELECT G."INDICATOR_NAME", V.INDICATOR_TYPE, V.INDICATOR_PERIOD, V.INDICATOR_VALUE, V.METRIC_USER, V."METRIC_USER_GROUPID"
FROM STG_VALUES V, "#OWNER#"."GETMETRICGROUPID_V" G WHERE V.INDICATOR_NAME = G."INDICATOR_NAME" AND V.METRIC_USER_GROUPID = G."METRIC_USER_GROUP_ID"
and V.INDICATOR_PERIOD BETWEEN TO_DATE(TO_CHAR(ADD_MONTHS(TRUNC(SYSDATE,'MM'),-36), 'MM/DD/YYYY'), 'MM/DD/YYYY') AND TO_DATE(TO_CHAR(SYSDATE,'MM/DD/YYYY'),'MM/DD/YYYY')
Here I'm joining a table (STG_VALUES) with a view (GETMETRICGROUUPID_V)
Here's the script for the GETMETRICGROUPID_V:
CREATE OR REPLACE FORCE VIEW STG.GETMETRICGROUPID_V
(
INDICATOR_NAME,
METRIC_USER_GROUP_ID
)
AS
SELECT INDICATOR_NAME, METRIC_USER_GROUP_ID
FROM STG_MST_USER_ASSIGNED_METRICS
WHERE METRIC_USER = NVL (v ('APP_USER'), USER)
OR METRIC_USER = LOWER (NVL (v ('APP_USER'), USER));
Here's my issue:
When I ran the above SQL Query in the Apex SQL Commands area, I got the
correct results. But when I used the same SQL Query inside the Apex tabular
form, I received the following error message:
failed to parse SQL query:
ORA-01403: no data found
It looks like Apex has issues joining a table with a view when used as a basis for the tabular form. Any thoughts on this ? I've searched the Internet for
answers/solutions and could not find any.
olecramon74

ORA-01403:no data found comes when the Select query returns no result in a PL/SQL code or function. Check the output of the v ('APP_USER') function in the query, it should be returning no result when you are running the query from APEX

Related

Oracle not using index, Entity Framework & Devart DotConnect for oracle

The table in question has ~30mio records. Using Entity Framework I write a LINQ Query like this:
dbContext.MyTable.FirstOrDefault(t => t.Col3 == "BQJCRHHNABKAKU-KBQPJGBKSA-N");
Devart DotConnect for Oracle generates this:
SELECT
Extent1.COL1,
Extent1.COL2,
Extent1.COL3
FROM MY_TABLE Extent1
WHERE (Extent1.COL3 = :p__linq__0) OR ((Extent1.COL3 IS NULL) AND (:p__linq__0 IS NULL))
FETCH FIRST 1 ROWS ONLY
The query takes about four minutes, obviously a full table scan.
However, handcrafting this SQL:
SELECT
Extent1.COL1,
Extent1.COL2,
Extent1.COL3
FROM MY_TABLE Extent1
WHERE Extent1.COL3 = :p__linq__0
FETCH FIRST 1 ROWS ONLY
returns the expected match in 200ms.
Question: Why is it so? I would expect the query optimizer to note that the right part is false if the parameter is not null, so why doesn't the first query hit the index?
Please set UseCSharpNullComparisonBehavior=false explicitly:
var config = Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfig.Instance;
config.QueryOptions.UseCSharpNullComparisonBehavior = false;
If this doesn't help, send us a small test project with the corresponding DDL script so that we can investigate the issue.

Error ORA-00933 on create editioning view

I'm trying to create an editioning view in Oracle 11g and it's giving the error "ORA-00933 SQL command not properly ended", I ran it with the owner of schema and sys, but the error persists.
CREATE OR REPLACE FORCE EDITIONING VIEW "CEGASV3"."VE_COML_FACTIVEL"(
"PK_FACTIVEL", "FACTIVEL", "ENDERECO", "NOMECONTATO", "TELCONTATO01", "TELCONTATO02",
"EMAIL", "SEGMENTO", "DT_DIGIT", "RESPONSAVEL", "INFOUTEIS", "NOME_TABELA_HISTORICO",
"DATA_HORA","VPD_GEMPI","ORA_GEOMETRY","ORA_GEOMETRY_GOOGLE","STATUS"
) AS
SELECT F.PK_FACTIVEL, F.FACTIVEL, F.ENDERECO, F.NOMECONTATO, F.TELCONTATO01, F.TELCONTATO02,
F.EMAIL, F.SEGMENTO, F.DT_DIGIT, F.RESPONSAVEL, F.INFOUTEIS, F.NOME_TABELA_HISTORICO,
F.DATA_HORA, F.VPD_GEMPI, F.ORA_GEOMETRY, F.ORA_GEOMETRY_GOOGLE, F.STATUS
FROM CEGASV3.COML_FACTIVEL F
LEFT JOIN CEGASV3.COML_PROSPECT P ON P.FK_FACTIVEL = F.PK_FACTIVEL
WHERE P.PK_PROSPECT IS NULL;
You can not create complex view as editioning view. It means you can not use multiple tables as a query of the view, It must be a single table view.
Editioning views are a wrapper over the base table. It can only be a
straight query of the base table, but can display a subset of the
columns and give alias to them.
Read more about editioning view here.
Cheers!!

performing an update query with a select subquery returning ora-01427 error

I need to update a column in one table with the results from a select sub-query (and they should ultimately be different). But When I do this, I get the 'ORA-01427: single row sub-query returns more than one row query' error.
Can you please take a look and see what it is that I am overlooking? (I could just be overlooking something simple for all I know)
UPDATE AIRMODEL_NETWORK_SUMMARY ans
SET ANS.NBR_RETURNS = (
SELECT SUM(RQ.RETURN_QTY)
FROM RETURN_QTY RQ JOIN AIRMODEL_NETWORK_SUMMARY ANS ON RQ.LOC_ID = ANS.LOC_ID
WHERE RQ.FSCL_YR_NUM = ans.FSCL_YR_NUM
AND RQ.FSCL_WK_IN_YR_NUM =
ans.FSCL_WK_IN_YR_NUM
GROUP BY ANS.LOC_ID,
ans.FSCL_WK_IN_YR_NUM,
ANS.FSCL_YR_NUM
);
I think that your inner query is not well correlated to the table that you're trying to update. Please look here Oracle SQL: Update a table with data from another table. You should add some kind of a where condition that ties the rows you're trying to update with the values calculated by the inner statement.

Like Operator is not working in oracle view

I have created a view in oracle. Now i would like to fetch data from that view. So i have written a SQL Query. But the query is not working for not having a specific condition. But if I give that condition the query executes. But the problem is not occurring if i joined the same number of tables (that were used to create view) instead of using view. In the following I am giving the oracle query.
SELECT *
FROM "920_search_report"
WHERE lm_culture = '7aacb509-271d-4aca-e040-e00adea40aae'
AND hand_person_info_guid = 'eebd4257-7856-4c6e-b6b8-9b886e89e397'
AND ( Lower(handicap_type) LIKE Lower('%DQ871J%')
OR Lower(skskodenr) LIKE Lower('%DQ871J%') );
The above query executes and returns one record but if I omit or comment the third line then the query does not return any records, but it should return one or two. the query is given below:
SELECT *
FROM "920_search_report"
WHERE lm_culture = '7aacb509-271d-4aca-e040-e00adea40aae'
--AND HAND_PERSON_INFO_GUID='eebd4257-7856-4c6e-b6b8-9b886e89e397'
AND ( Lower(handicap_type) LIKE Lower('%DQ871J%')
OR Lower(skskodenr) LIKE Lower('%DQ871J%') );
Can anyone help me to solve the problem.

What the linq query for SQL like and Soudex for sql server 2008?

In sql server, we can issue sql to get data like
select * from table where column like '%myword%'
select * from person where Soundex(LastName) = Soundex('Ann')
what's the linq query to match above sql?
from t in table
where t.column.Contains("myword")
select t
In .Net 4.0 you can use the SoundCode function, probably like this:
from p in person
where SqlFunctions.SoundCode(p.LastName) == SqlFunctions.SoundCode('Ann')
select p
you may want to use the difference function
http://msdn.microsoft.com/en-us/library/system.data.objects.sqlclient.sqlfunctions.difference%28VS.100%29.aspx
you could also create your own
https://web.archive.org/web/1/http://blogs.techrepublic%2ecom%2ecom/programming-and-development/?p=656

Resources