When i change NLS ora gives "ORA-00979: not a GROUP BY expression" error - oracle

My Oracle NLS parameters is:
NLS_SORT = TURKISH
NLS_COMP= BINARY
COLUMNA1=VARCHAR2
query:
SELECT COLUMNA1,
(SELECT TABLEB.COLUMB1 FROM TABLEB WHERE TABLEB.COLUMNB2 = TABLEA.COLUMNA1)
FROM TABLEA GROUP BY TABLEA.COLUMNA1
This query worked and return data.
But when i change
NLS_SORT = TURKISH_AI
NLS_COMP= LINGUISTIC
This query points "= TABLEA.COLUMNA1" and gives "ORA-00979: not a GROUP BY expression" error?
In my project, i have a lot of query like this, and i couldnt change all.
And if my query wrong, why run before?
Thanks in advance!

Related

Optional parameter in query does not work for db2 but works in oracle

Below query works fine for Oracle database, but for Db2 it throws error sqlcode -417.
I have looked up similar problems but did not get any definitive answer:
#Query(value = "select * from tableName f where (aC is null or f.a_c = aC)", nativeQuery = true)
Page<tablename> findByFilters(String aC, Pageable pageable);
On execution the error code is -417
One way to solve this problem would be to rewrite the query as the following:
select * from tableName f where f.a_c = coalesce(aC, f.a_c)
The form of query above is likely to be accepted. In order to find out the exact reason of the error you get, it is necessary to trace the actual SQL statement passed to Db2.
Another option of solving the problem may be to add the CAST operator, which would define the data type of your parameter:
select * from tableName f where (cast(aC as integer) is null or f.a_c = aC)
This is suggested in the description of the error you get

INNER JOIN two table get error SQL Statment not ended properly

I have two table which I want to select Name from t2.
The situation is following.
I have t1 Policy which containt EmployeeID
And table t2 which containt Name
Now I want to select which Employee release policy.
So in t1(Policy- AUTO.POL) I have column: SIFRA_RAD
and t2(Employee-AUTO.SIFRAD) I have colum: SIFRA_R, Ime
I try something like this:
select auto.pol.sifra_rad, auto.sifrad.ime
from auto.sifrad
inner join auto.pol on auto.sifrad.ime = auto.pol.sifra_rad;
After that I get error
ORA-00933: SQL command not properly ended
I have no idea what is wrong here. Any suggestion?
The problem comes from query, and we fix it
select p.sifra_rad, s.ime from auto.sifrad s, auto.pol p where s.ime = p.sifra_rad

How to resolve Case sensitive issue while using sub query in oracle

select * from ur_username u
join ur_username_person up
on up.username_id=u.username_id
join ur_person p on up.person_id=p.person_id
join ur_system s on u.system_id=s.system_id
WHERE U.USERNAME IN (select username from ur_username where system_id=349 and status='DISABLED') AND U.STATUS='ACTIVE'
in the above code in where clause all the username from the sub query will be stored and I want the all username irrespective of case should be stored in the where clause i tried using (UPPER) but only getting upper case user names alone.
Please give any suggestions here.
For example in the sub query I am getting "ccku" as result but when it comes to where clause I want store both "ccku" and "CCKU" .
Please help me with the above issue
When you tried upper, did you do this in your where clause?
WHERE
UPPER(U.USERNAME) IN
UPPER(select username from ur_username where system_id=349 and status='DISABLED')
This isn't going to be super efficient but you might be able to check the subquery twice. once using upper() and once using lower().
WHERE (upper(U.USERNAME) IN (select username from ur_username where system_id=349 and status='DISABLED')
or lower(U.USERNAME) IN (select username from ur_username where system_id=349 and status='DISABLED'))
AND U.STATUS='ACTIVE'
It is because you have settings of SEC_CASE_SENSITIVE_LOGON parameter as 'TRUE',
setting this parameter to 'FALSE' maybe solves your issue.
SQL> show parameter sec_case_sensitive_logon
SQL> alter system set sec_case_sensitive_logon=false scope=both;

PostgreSQL - migrate a query with 'start with' and 'connect by' in oracle

I have the following query in oracle. I want to convert it to PostgreSQL form. Could someone help me out in this,
SELECT user_id, user_name, reports_to, position
FROM pr_operators
START WITH reports_to = 'dpercival'
CONNECT BY PRIOR user_id = reports_to;
A something like this should work for you (SQL Fiddle):
WITH RECURSIVE q AS (
SELECT po.user_id,po.user_name,po.reports_to,po.position
FROM pr_operators po
WHERE po.reports_to = 'dpercival'
UNION ALL
SELECT po.user_id,po.user_name,po.reports_to,po.position
FROM pr_operators po
JOIN q ON q.user_id=po.reports_to
)
SELECT * FROM q;
You can read more on recursive CTE's in the docs.
Note: your design looks strange -- reports_to contains string literals, yet it is being comapred with user_id which typicaly is of type integer.

Oracle: function based index using dynamic values

I have one complex SQL queries. One of the simple part of the queries looks like:
Query 1:
SELECT *
FROM table1 t1, table2 t2
WHERE t1.number = t2.number
AND UPPER(t1.name) = UPPER(t2.name)
AND t1.prefix = p_in_prefix;
Query 2:
SELECT *
FROM table1 t1, table2 t2
WHERE t1.number = t2.number
AND UPPER(t1.name) = UPPER(p_in_prefix || t2.name)
AND t1.prefix = p_in_prefix;
I have function based index on table1 as (number, UPPER(name)). I have function based index on my table2 as (number, UPPER(NAME)). p_in_prefix is a input parameter (basically a number).
Because of these indexes my Query 1 runs efficiently. But Query 2 has a performance issue, as in Query 2, 't2.name' is prefixed with p_in_prefix.
I can not create function based index for Query 2 because p_in_prefix is a input parameter and I don't know while creating index, what values it might hold. How to resolve performace issue in this scenario? Any hint/idea would be appreciated. If you require more information, please let me know.
Thanks.
Use AND UPPER(t1.name) = UPPER(p_in_prefix) || UPPER(t2.name).
As you have a function based index as UPPER(NAME) of table2, you should have an operand with the same expression in the query in order to make use of the function based index.
Using UPPER(p_in_prefix || t2.name) will not use the function based index as this does not match the function expression UPPER(NAME). Note here that using UPPER(t2.name) does not cause any problems as t2 is just a column alias.
Along with this, you can also pass an optimizer hint in your query in order to instruct the optimizer to use the index.
For more information read "Oracle Database 11g SQL" by Jason Price.
Also read Oracle Docs here and here and for optimizer hints here.

Resources