Oracle 18.1 sql query error - oracle

I have an sql query
SELECT ("SL/VL".TOTAL_SICK_LEAVE - SUM(EMPLOYEE_INFO.DAYS_TAKEN_SICK))
FROM EMPLOYEE_INFO
INNER JOIN "SL/VL"
ON EMPLOYEE_INFO.EMPLOYEE_NAME = "SL/VL".EMPLOYEE_NAME
where contract_year='Year 1'and
employee_info.EMPLOYEE_NAME = :P4_EMPLOYEE_NAME
GROUP BY "SL/VL".TOTAL_SICK_LEAVE
which was giving me the desired results when I had oracle apex 5.1. Now I upgraded my database to oracle 18.1 I am getting the"ORA-20999: Column name "("SL/VL".TOTAL_SICK_LEAVE-SUM(EMPLOYEE_INFO.DAYS_TAKEN_SICK))" is invalid for the LOV SQL query. Make sure that you use valid alias names for your columns."

It appears that 18.1 wants a column alias on the expression ("SL/VL".TOTAL_SICK_LEAVE - SUM(EMPLOYEE_INFO.DAYS_TAKEN_SICK)). Perhaps if you redo your SQL as
SELECT (s.TOTAL_SICK_LEAVE - SUM(e.DAYS_TAKEN_SICK)) AS SICK_LEAVE_REMAINING
FROM EMPLOYEE_INFO e
INNER JOIN "SL/VL" s
ON e.EMPLOYEE_NAME = s.EMPLOYEE_NAME
WHERE CONTRACT_YEAR = 'Year 1' AND
e.EMPLOYEE_NAME = :P4_EMPLOYEE_NAME
GROUP BY s.TOTAL_SICK_LEAVE
the database will be happier.

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.

Query failing on Oracle 12c and 18c when changing NLS_SORT to BINARY_CI

I have the following query which correctly returns records when I execute it via code or Oracle SQL Developer.
SELECT TABLE_T.COL_P,
1234 AS COL_C,
TABLE_T.COL_D,
SUM(SOME_COLUMN) Value
FROM TABLE_T
INNER JOIN TABLE_E E ON TABLE_T.COL_P = E.COL_P
AND TABLE_T.COL_C = E.COL_C
AND TABLE_T.COL_CC = E.COL_CC
AND TABLE_T.COL_CL = E.COL_CL
INNER JOIN TABLE_C C1 ON C1.COL_P = E.COL_P
AND C1.COL_C = E.COL_C
INNER JOIN TABLE_C C2 ON C2.COL_P = C1.COL_P
AND C2.COL_CX = C1.COL_CX
AND C2.COL_CY = C1.COL_CY
AND C2.COL_CZ = C1.COL_CZ
WHERE TABLE_T.COL_P = 'Some Text'
AND C2.COL_C = 1234
AND TABLE_T.COL_CL IN
(SELECT COL_CL
FROM TABLE_CL
WHERE COL_P = 'Some Text'
AND ((COL_CLTYPE = 'VALUE_A')
OR (COL_CLTYPE = 'VALUE_B')
OR (COL_CLTYPE = 'VALUE_C')
OR (COL_CLTYPE = 'VALUE_D')) )
GROUP BY TABLE_T.COL_P,
TABLE_T.COL_D
However, it fails to return records once I execute the following session commands:
ALTER SESSION SET NLS_COMP = LINGUISTIC;
ALTER SESSION SET NLS_SORT = BINARY_CI;
This problem only occurs when I'm running against an Oracle 12c or 18c database.
It works find with/without the session commands when running against an Oracle 12C R2 or 11g database.
I've already checked the Explain Plan for 12c/18c and 12cR2 and its creating the same plan.
I found out that by adding an ORDER BY clause to the query (ORDER BY TABLE_T.COL_D, it resolves the problem.
Any ideas on what might be causing this problem?
I know the ORDER BY solution works, but I'd like to know what the underlying cause is and if there's a better solution to it.

oracle sql query [Microsoft][ODBC Text Driver] Syntax error in FROM clause

Select
CPC.BAN,
CPC.IO_SEQ_NO,
CPA.ATTR_NAME,
CPA.ATTR_VALUE
from CPC_PROMOS CPC
JOIN CPC_PROMO_QUAL_ATTR CPA
ON CPA.SUBSCRIBER_NO = CPC.SUBSCRIBER_NO
WHERE CPC.SUBSCRIBER_NO IN (select SUBSCRIBER_NO FROM `Load.csv`);
The input file load.csv has data like
SUBSCRIBER_NO
123
456
789
When I'm tying to import the csv table using toad in my oracle query, its throwing out Syntax error in FROM clause.
Can someone please help.

Oracle - Update COUNT of rows with specific value

This question has been posted several times but I am not able to get it work. I tried the approach mentioned in Update column to the COUNT of rows for specific values in another column. SQL Server. It gives me SQLException: java.sql.SQLException: ORA-01427: single-row subquery returns more than one row error not sure what I can do.
Below is my problem
UPDATE dataTable
SET ACCX = (select b.cnt
from dataTable a
join
(SELECT Account,
COUNT(1) cnt
FROM dataTable
GROUP BY Account) b
on a.Account=b.Account)
,ACCR = 15481
,ACCF = 3
WHERE ID = 1625
I only have the access & can change to the bold part since rest of the query is generated by the tool I cannot change it & I have to update ACCX column with the count of the value in column Account. Is it possible to do?
Note: - Account column is already populated with values.
You cannot follow that query because it is for sqlserver and NOT oracle. It is simpler in oracle and does not need a join to itself.
This update will set the count for id 1625 only based on number of account numbers in datatable. See demo here;
http://sqlfiddle.com/#!4/d154c/1
update dataTable a
set ACCR = 15481,
ACCF = 3,
a.ACCX = (
select COUNT(*)
from dataTable b
where b.Account=a.Account)
WHERE a.ID = 1625;

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

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

Resources