ORA-00937: not a single-group group function in 11g,12c - oracle

Query1:
select 1 from (select count(*),col1 from table1);
O/P:
1
Version: 11g
Query2:
select * from (select count(*),col1 from table1);
O/P:
Error:
Execution (1: 32): ORA-00937: not a single-group group function
Version: 11g
As, we are in same version,
1. For Query2, why we are getting error?
2. With out group by how query1 is returning result?
In Version 12C, both queries are returning error as shared above.

You should be getting the error for query 1 in 11g too. The fact that you don't may be down to bug 16989676, which affected 11gR2 and was fixed in 12cR1. You'll need a support account and contract to see the details - which I can't reproduce here. Suffice to say that it looks very similar; but mentions you can get the wrong results too (e.g. using select count(*) instead of select 1) - if you ignore the syntax being invalid, that is, since there is no correct result really.

Related

Error with a user defined report in Oracel SQL Developer - Missing IN or OUT parameter at index:: 1

I have created a user defined report within Oracle SQL Developer, with a bind variable.
The report consists of a master_report (style is table), child_report_a containing with a style of 'table' and child_report_b which is the same query, but with the style of 'script'.
I am able to select a cell/row of my master report, and child_report_a data changes accordingly (ie, it returns the cells of the same date I selected.
However, when I try to view this in child_report_b (With the 'script' style) it errors with "Missing IN or OUT parameter at index:: 1".
So the setup is:
tablea
id_pk (number)
name_pk (varchar2)
1
Jack
2
John
3
Amy
tableb
id_fk (number)
start_time(timestamp(6))
1
01-JAN-23 12.00.00.123000000
2
01-JAN-23 13.00.00.123000000
3
02-JAN-23 14.05.00.123000000
User Defined Report:
master_report (Style=Table):
SELECT * FROM tablea
child_report_a (Style=Table) & child_report_b (Style=Script):
SELECT * FROM tablea a INNER JOIN tableb b ON b.id_fk = a.id_pk WHERE trunc(start_time) = trunc(to_timestamp(:STARTTIME)
Any help is appreciated.
EDIT: Included better example of setup.
My goal is to be able to select a row from the master_report, and the child_report_b would return all results which match the date (as currently happens in child_report_a) in the script format.
Welcome to StackOverflow!
The reporting feature is one of my favorites in SQL Developer, so I will try to get you started.
We can't technically answer your question without a fair bit of guessing. We know what's happening on one side of the JOIN, you have a timestamp that you're using TRUNC on.
But we can't tell what is on the other side of the equality predicate in your JOIN.
Here's a working example, see if this helps you.
Parent Query
select trunc(systimestamp) A
from dual
Child Query
select object_name, object_type, last_ddl_time
from user_objects where :A > (trunc(systimestamp) - 30)
And the report -
To debug your report, substitute the bind :STARTTIME with a literal value that is equivalent to what your parent query would return. If that works, so should your report.
Disclaimer: I work for Oracle and am a product manager for SQL Developer.

Very slow query using FROM DUAL UNION ALL in a CTE

I'm using Oracle SQL Developer for find the issue with the data that the MERGE statement raises the ORA-30926 error.
ORA-30926: unable to get a stable set of rows in the source tables
The problem I have is that this issue is happening on production server and we don't have insert privileges - we can only query the data.
So, I decide to use CTEs for build the sub-query "with the data the table used by the MERGE statement".
The CTE is as follows:
WITH SAMPLE_TABL
AS
(
SELECT 8 IIY_CODEN, '1016755' NUM_DCSM, 1 RW_NSKD FROM DUAL UNION ALL
SELECT 1 IIY_CODEN, '30029' NUM_DCSM, 1 RW_NSKD FROM DUAL UNION ALL
SELECT 1 IIY_CODEN, '21652019' NUM_DCSM, 1 RW_NSKD FROM DUAL UNION ALL
SELECT 1 IIY_CODEN, '10038' NUM_DCSM, 1 RW_NSKD FROM DUAL UNION ALL
SELECT 1 IIY_CODEN, '110004567448' NUM_DCSM, 1 RW_NSKD FROM DUAL
[...] -- 32706 rows
)
SELECT T1.*
FROM SAMPLE_TABL T1;
I'm constructing this sub-query for emulate the content of a table
that is used on a MERGE statement that raises the ORA-30926 error.
With this result of the sub-query, I then run the SELECT that is
used on the MERGE statement and export such results. Then, I can
check which are the duplicated rows.
The SELECT used in the MERGE has already a DISTINCT keyword on
it, so, I'm narrow it down to steps for see the data that is executed
on that specific MERGE.
The information that is used on the CTE was supplied by the customer
on a Excel file, so, I had to create the CTE in this way.
NOTE: If anyone know alternative(s) about how this issue can be handled, I'm open to suggestions.
This CTE has 32706 rows and, testing in a different database, the query completes after 12 minutes.
I tried this query on production and I have to cancel the query after 24 minutes and the cancellation took another more minutes.
I suspect this "result" is due to oracle/sql developer limitations in GUI or probably the database engine itself, but, I really don't know how then I can have a running sub-query with these 32K rows in order to check further the cause of the ORA-30926 error.
These are the details of the SQL Developer instance I'm using - and I know that according to this comment, this SQL Developer version is very old, but, that's what I got for work.
About
---------
Oracle SQL Developer 17.2.0.188
Versión 17.2.0.188
Versión Interna 188.1159
IDE Version: 13.0.0.1.42.170225.0201
Product ID: oracle.sqldeveloper
Product Version: 17.2.0.188.1159
Versión
-------
Componente Versión
========== =======
Oracle IDE 17.2.0.188.1159
Plataforma Java(TM) 1.8.0_131
Soporte de Control de Versiones 17.2.0.188.1159
I narrow this question as down to:
How I can have a running and working sub-query with 32K rows?

How can I get this syntax to work in Oracle?

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
simplest repo, how can I get this to work in Oracle?
SELECT 'X' NewColumn, * FROM MyTable;
I get
ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action: Error at Line: 1 Column: 23
My actual issue is:
I'm using an ETL tool that allows automapping if I use SELECT *
I want to use ORA_ROWSCN to implement incremental loads
So the real query I'm running is:
SELECT ORA_ROWSCN, * FROM MyTable;
I get the same error for this
The syntax is valid if you alias the table and the *.
SELECT ORA_ROWSCN, t.* FROM MyTable t;
No idea whether your ETL tool knows how to do that. Of course, you could always create a view vw_table that runs this select and then use the view in the ETL tool.

UNION on dynamic SQL statements

What I am trying to accomplish is essentially this:
SELECT 1 FROM DUAL
UNION
EXECUTE IMMEDIATE 'SELECT 2 FROM dual';
I am actually a penetration tester trying to bypass a web application firewall, so I am sure this looks silly/strange from the other side. Basically, I need to be able to do a UNION with dynamic queries in order to bypass a filter. So, in this example, you are passing a string from Java into an Oracle DB using this function.
I don't have any feedback from the database on what is wrong with my query, and could not find any documentation for someone doing something similar. I need a simple example where I UNION a normal query with a simple dynamic SQL string.
The execute immediate statement is only valid inside a PL/SQL block. You can't mix it with plain SQL. You can run (only) PL/SQL dynamically too, but again not mixing the two in one statement like you've tried.
If you run what you showed in a normal client you'd see it complains:
Error starting at line : 1 in command -
SELECT 1 FROM DUAL
UNION
EXECUTE IMMEDIATE 'SELECT 2 FROM dual'
Error at Command Line : 3 Column : 1
Error report -
SQL Error: ORA-00928: missing SELECT keyword
00928. 00000 - "missing SELECT keyword"
*Cause:
*Action:
Even if the statement you pass is itself executed dynamically, you'd see the same error:
BEGIN
EXECUTE IMMEDIATE q'[SELECT 1 FROM DUAL
UNION
EXECUTE IMMEDIATE 'SELECT 2 FROM dual']';
END;
/
Error report -
ORA-00928: missing SELECT keyword
ORA-06512: at line 2
00928. 00000 - "missing SELECT keyword"
A further consideration, though it's a bit moot here, is that a dynamic query isn't actually executed if you aren't consuming the results by selecting into a variable (see the note here.

How does oracle execute an sql statement?

such as:
select country
from table1
inner join table2 on table1.id=table2.id
where table1.name='a' and table2.name='b'
group by country
after the parse, which part will be executed first?
It looks like you want to know the execution plan chosen by Oracle. You can get that ouput from Oracle itself:
set serveroutput off
< your query with hint "/*+ gather_plan_statistics */" inserted after SELECT >
select * from table(dbms_xplan.display_cursor(null, null, 'last allstats'));
See here for an explanation how to read a query plan: http://download.oracle.com/docs/cd/E11882_01/server.112/e16638/ex_plan.htm#i16971
Be aware however that the choice of a query plan is not fixed. Oracle tries to find the currently best query plan, based on available statistics data.
There are plenty of places you can find the order in which SQL is executed:
FROM clause
WHERE clause
GROUP BY clause
HAVING clause
SELECT clause
ORDER BY clause
But note that this is the "theoretical" order - SQL engines are allowed to perform the operations in other orders, provided that the end result appears to have been produced by using the above order.
If you install the free tool SQL*Developer from Oracle, then you can click a button to get the explain plan.
A quick explanation is at http://www.seeingwithc.org/sqltuning.html

Resources