ORA-00935: group function is nested too deeply - SQL Query is correct...
select s.sname, to_char(sum(t.amount), 'fm$999999.00')
from transactions t, salespeople s
where t.sid = s.sid
group by s.sname, t.year
having (t.year = 1997) and max(sum(t.amount));
I'm trying to print sales person name who had the highest total sell in 1997. I do not see where did i go wrong in the above query...Isn't nested group function allowed?!
What about this?
select s.sname, to_char(sum(t.amount), 'fm$999999.00') as "TOTAL"
from transactions t, salespeople s
where t.sid = s.sid
group by s.sname, t.year
having (t.year = 1997) and sum(t.amount) = (select max(amount) from transactions where year = 1997);
It should return something, but it does not due lack of data in database. I think the above code is correct. I just need to confirm from you...
select s.sname, (case when sum(t.amount) > sum(t2.amount)
then sum(t.amount)
else sum(t2.amount)
end) "TOTAL"
from transactions t, salespeople s
where t.sid = s.sid
group by s.sname, t.year
having t.year = 1997
union
select s.sname, sum(t2.amount)
from transactions t2, salespeople s
where t2.sid = s.sid
group by s.sname, t2.year
having t2.year = 1997;
Your code looks good, but it does not work in Oracle Developer...
The above should work isn't it? The inner query gets executed then the outer one so the result i get in
Similar Messages
-
I met ORA-00935 group function is nested too deeply Message.
Hi all,
I made a table like below,
==============================
CREATE TABLE ser_1m_det (
time TIMESTAMP,
proto NUMBER(3,0),
port NUMBER(5,0),
pkts NUMBER(17,0),
vol_m NUMBER(17,4)
====================================
Then I want to use below SQL
====================================
SELECT proto, port, SUM(pkts) pkts, SUM(vol_m) vol_m
FROM ser_1m_det
GROUP BY (proto, port)
HAVING time < SYSTIMESTAMP AND ROWNUM<10
ORDER BY SUM(pkts);
====================================
When I execute upper sql, I met this error message;
===================================
ORDER BY SUM(pkts)
ORA-00935 group function is nested too deeply
===================================
Then I search what this message mean.
====================================
ORA-00935 group function is nested too deeply
Cause: This is an internal error message not usually issued.
Action: Contact Oracle Support Services.
====================================
I install Oracle9iAS Infrastructure 9.0.2.0.0 on WIN2000.
(I am using DBMS in Oracle9iAS @.@)
-> DBMS version is Oracle9i Enterprise Edition Release 9.0.1.3.1
Anybody know why I met upper error message?
Thanks in advance.well,
first you want to group,
then you want to order,
and most probably then you are interested in the N top records.
I had a try on table USER_OBJECTS to make things easier:
select * from
(select
object_type
,status
,nvl(oi ,0) oi
,nvl(doi,0) doi
from
( select
object_type
,status
,sum(object_id) oi
,sum(data_object_id) doi
from
user_objects
where
created between sysdate -1000 and sysdate
group by
object_type
,status
) A
order by
oi desc
) B
where rownum < 5
; -
ORA - 00935, Group function nested to deep
Hi
Suggestions on ho to go round such errors, or if is it any configuration in the database that may be changed.
Extended a view with some lines to aggregate som amounts.
The lines included is as follows:
Sum(Decode(InStr(Upper(rca.lcdescription),'VAL1'),0,0,Nvl(rca.lnprice,0)),
Sum(Decode(InStr(Upper(rca.lcdescription),'VAL2'),0,0,Nvl(rca.lnprice,0)),
Then the ORA - 00935 occured.
The full select looked something like:
SELECT
mg.lcid,
mg.lcdescription,
ro.lcfkestateid,
me.lcestatename,
ro.lcfkbuildid,
mb.lcbuildname,
ro.lcrentobjid,
ro.lcrentobjname,
rot.lcdescription,
ro.lcadr1,
ro.lcadr1,
ro.lcpostcode,
rop.lcpostname,
ro.lnrooms,
rr.lcrenterid,
rr.lcname,
rr.lcrenterid2,
rr.lcaddress1,
rr.lcaddress2,
rr.lcpostcode,
rrp.lcpostname,
rc.lccontractid,
rct.lcdescription,
rc.ldprevailingrentdate,
rc.ldstatusdate,
Sum(Decode(InStr(Upper(rca.lcdescription),'VAL1'),0,0,Nvl(rca.lnprice,0)),
Sum(Decode(InStr(Upper(rca.lcdescription),'VAL2'),0,0,Nvl(rca.lnprice,0)),
Sum(Nvl(mr.lngrossarea,0)) BOA
FROM
tab13 rrp,tab12 rr,tab11 rca,tab10 rct,tab9 rc,tab8 rcs,
tab7 rop,tab6 mr,tab5 mg,tab4 mb,tab3 me,tab2 rot,tab1 ro
WHERE me.lcestateid = ro.lcfkestateid
AND mb.lcestateid = ro.lcfkestateid AND mb.lcbuildid = ro.lcfkbuildid
AND mg.lcgeokey = me.lcgeokey
AND rot.lnrentobjtypkey (+) = ro.lnfkrentobjtype
AND rcs.lnrentobjkey (+) = ro.lnrentobjkey
AND rc.lncontractkey (+) = rcs.lncontractkey
AND rca.lncontractkey (+) = rc.lncontractkey
AND rr.lcrenterid (+) = rc.lcfkrenter
AND mr.lnrentobjkey (+) = ro.lnrentobjkey
AND rop.lcpostcode (+) = ro.lcpostcode
AND rrp.lcpostcode (+) = rr.lcpostcode
AND rct.lncntrtypekey (+) = rc.lnfkconttype
AND rca.lncontractkey (+) = rc.lnfkconttype
GROUP BY
mg.lcid,
mg.lcdescription,
ro.lcfkestateid,
me.lcestatename,
ro.lcfkbuildid,
mb.lcbuildname,
ro.lcrentobjid,
ro.lcrentobjname,
rot.lcdescription,
ro.lcadr1,
ro.lcadr1,
ro.lcpostcode,
rop.lcpostname,
ro.lnrooms,
rr.lcrenterid,
rr.lcname,
rr.lcrenterid2,
rr.lcaddress1,
rr.lcaddress2,
rr.lcpostcode,
rrp.lcpostname,
rc.lccontractid,
rct.lcdescription,
rc.ldprevailingrentdate,
rc.ldstatusdateStein,
Is it possible to put the sum(decode statements into another table with the keys you need to join? Then create a view using the newly created sum values table? -
ORA-00934: group function is not allowed here
Hi,
My requirement is to check oi.quantity is equal to sum of packing_detail. quantity
by order_number
select oi.quantity_ordered oi_qu, pd.quantity pq
from ordered_items oi, packing_details pd
where oi.ordered_item_id = pd.ordered_item_id
and oi.quantity_ordered = sum(pd.quantity)
and oi.order_number = '29';
after executing above query I get error
SQL Error: ORA-00934: group function is not allowed here
00934. 00000 - "group function is not allowed here"
Please tell me how to resolve it.
Thanks in advance
SandyYou have to make use of a subquery;
select oi.quantity_ordered oi_qu, pd.quantity pq
from ordered_items oi, packing_details pd
where oi.ordered_item_id = pd.ordered_item_id
and oi.quantity_ordered = *(select sum(pd.quantity) from packing_details pd1 group by pd1.ordered_item_id)*
and oi.order_number = '29'; This is based on the assumption that ordered_items is the summarize data and packing_details are the line item level data.
regards,
Dipankar. -
PL/SQL: ORA-00934: group function is not allowed here
Hi,
I am writing a PL/SQL procedure. The structure is like :
SET SERVEROUTPUT ON;
CREATE OR REPLACE Procedure abc
IS
v_total_ip_rec number(14);
v_total_op_rec number(14);
v_total_rec number(14);
BEGIN
SELECT SUM (CASE
WHEN <condition 1>
THEN 1
ELSE 0
END
) into v_total_ip_rec,
SUM (CASE
WHEN <condition 2>
THEN 1
ELSE 0
END
) into v_total_op_rec,
SUM (1) into v_total_rec
FROM A,B
WHERE A.Col1=B.Col1;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
END;
When I run this procedure it gives me following error:
"PL/SQL: ORA-00934: group function is not allowed here"
Anybody have any idea?
Any help would be appreciated.
Thanks.Hi Arunkumar ,
I think you don't need subquery.
Regards Salim.
Or.
SELECT COUNT (CASE
WHEN <condition 1>
THEN 1
END) v_total_ip_rec,
COUNT (CASE
WHEN <condition 2>
THEN 1
END) v_total_op_rec,
COUNT (1) v_total_rec
FROM a, b
WHERE a.col1 = b.col1 -
Hi! I´m Getting the following error when trying to restart the AppFabric Cache Cluster:
PS C:\temp> .\restartappfabric.ps1
Serialized xml is nested too deeply.
+ CategoryInfo : OperationStopped: (ServerName:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : JobFailure
+ PSComputerName :
ServerName
Here's The Script:
$ServerName="ServerName"
$sc = {
Import-module DistributedCacheAdministration
Use-CacheCluster
Restart-CacheCluster
Invoke-Command -computername $ServerName -scriptblock $sc
Powershell remoting is fully enabled and working fine con remote computers. When testing the script against a TEST computer is working fine, but when executing the script against PRE & PROD servers I get the error described above.
Running the lines within the scriptblock locally in the servers works fine.
Any help on this would be appreciated.
ThanksThanks man for your help. Tried using the connectionstring but got the same results
PS C:\temp> Invoke-Command -ComputerName Servername {import-Module DistributedCacheAdministration;Use-CacheCluster -P
rovider XML -ConnectionString "\\vmbcorp.com\FS\ApplicationContent\PRE\AppFabricCache" ;Restart-CacheCluster}
Serialized xml is nested too deeply.
+ CategoryInfo : OperationStopped: (BBLAMTPDAFC01:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : JobFailure
+ PSComputerName : BBLAMTPDAFC01
PS C:\temp>
Running the commands locally with the ConnectionString swith works as well. Running out of Ideas.. May be using psexec.. -
Collect Files Error - Folder Nested too deeply?
I'm getting a new error when trying to collect files.
"Folders are too deeply nested to create full path for file "filename"" 3:32
I'm a little puzzled because this source folder isn't more deeply nested than any other source file in my project. How deep can AE create folders?That's a great resource, Myles! Thanks.
I'll have to investigate further. My source footage isn't buried deep, but I think when AE is collecting files, it's creating folders too deep for it to save it at the destination. -
ORA-00934: group function is not allowed here Error - On validation screen
Can anyone help me with this funtion Returning boolean PL/SQL expression
begin
select max(sim_trip.finish_time) into finish_time,
max(sim_trip.start_time) into start_time from sim_trip
WHERE ((sim_trip.operator_counter = :P500_operator_counter));
if (:P500_start_time > finish_time)
then return true;
else
return false;
end if;
end;Lucy,
begin
select max(sim_trip.finish_time) into finish_time,
max(sim_trip.start_time) into start_time from sim_trip
WHERE ((sim_trip.operator_counter = :P500_operator_counter));
if (:P500_start_time > finish_time)
then return true;
else
return false;
end if;
end;Your select statement is wrong. It should be:
begin
select max(sim_trip.finish_time),max(sim_trip.start_time)
into :P500_start_time,:P500_finsh_time
from sim_trip
WHERE ((sim_trip.operator_counter = :P500_operator_counter));
if (:P500_start_time > :P500_finish_time)
then return true;
else
return false;
end if;
end;Robert
http://apexjscss.blogspot.com -
PL/SQL equivalent of T-SQL - "group function is not allowed here"
Hi all, hope someone can give me a hand as I'm pretty stuck! I have been trying to convert some MS SQL Server T-SQL statements into Oracle PL/SQL and am stuck on the below one:
SELECT
CA.AssessmentID,
(SELECT ProductName + ISNULL(' - ' + PrincipalBenefit,'')
FROM rptPolicySnapshot WHERE PolicyID = MAX(CA.PolicyID)
AND SnapshotID = 1),
MAX(CA.PolicyID)
FROM rptClaimInvoiceLineSnapshot CIL
INNER JOIN rptClaimAssessmentSnapshot CA
ON CIL.AssessmentID = CA.AssessmentID
AND CIL.SnapshotID = CA.SnapshotID
WHERE CIL.SnapshotID = 1
GROUP BY CA.AssessmentID
This works fine in MSSQL but returns the below error in Oracle:
'ORA-00934: group function is not allowed here'
If I take out the subquery the query works fine.
Any ideas as to the syntax? I am new to Oracle so not sure as to how I should go about writing this.
Thanks in advance!
LeoWITH x AS (SELECT ca.assessmentid,
MAX (ca.policyid) policy_id
FROM rptclaiminvoicelinesnapshot cil
INNER JOIN rptclaimassessmentsnapshot ca
ON cil.assessmentid = ca.assessmentid
AND cil.snapshotid = ca.snapshotid
WHERE cil.snapshotid = 1
GROUP BY ca.assessmentid
SELECT x.assessment_id,
x.policy_id,
productname + decode(principalbenefit,null,null,' - ' || principalbenefit ) prodname
FROM rptpolicysnapshot, x
WHERE policyid = x.policy_id
AND snapshotid = 1I think that's in the neighbourhood. -
Getting Group Function is not Allowed
Hello All....
When I run the following in the SQL command screen it works fine... But when I try to use it in APEX to populate page values, it gives me the error...
ERROR
1 error has occurred
ORA-06550: line 25, column 74: PL/SQL: ORA-00934: group function is not allowed here ORA-06550: line 24, column 1: PL/SQL: SQL Statement ignored
CODE THAT WORKS IN SQL COMMAND SCREEN
SELECT
SUM(CASE WHEN SLOT = 'Q' THEN '1' ELSE '0' END) AS C_SLOT,
SUM(CASE WHEN TEST = 'P' THEN '1' ELSE '0' END) AS C_TEST,
FROM TBL_REC;
CODE THAT GIVES ERROR ON APPLICATION EXPRESS PAGE
SELECT
SUM(CASE WHEN SLOT = 'Q' THEN '1' ELSE '0' END) INTO :P2_C_SLOT,
SUM(CASE WHEN TEST = 'P' THEN '1' ELSE '0' END) INTO :P2_C_TEST,
FROM TBL_REC;
The colums SLOT and TEST have letter codes, I just want it to count just when it matches a certain letter. In the SQL Command Screen, it is returning one row, with the counts, everything is fine. It is only a problem when I try to use it anywere on a page in Application Express.
The full version has about 20 lines that are all sum lines, but I can not even get the 2 line ver above to work.
Any thoughts?This will work .. the into clause goes after the select columns ... into var1 ,var2 etc ..
SELECT SUM(CASE
WHEN SLOT = 'Q' THEN
'1'
ELSE
'0'
END),
SUM(CASE
WHEN TEST = 'P' THEN
'1'
ELSE
'0'
END)
INTO :P2_C_SLOT, :P2_C_TEST,
FROM TBL_REC;SS -
Clarification on using function in where clause of oracle sql query
I have an issue in regarding function using where clause of sql query..
We are facing performance issue while executing query, so in what ways to improve the performance of the query which i have posted below.
select col ,case when my_function(parameter)
from tab1 a ,tab2 b,tabl3 c
where a.column1=b.column2
and b.column3 =c.column6
and my_function(parameter)>0
Regards
Dinesh
Edited by: wild fire on May 18, 2012 4:15 PMDinesh,
remind that when you use a function in the where clause it normally will get started for each record in the table.
So your answer is two-fold:
1. make the function only start when needed by adding a function based index on the table (this will make inserts and updates slower)
2. make the function faster by adding the DETERMINISTIC clause if possible. this will make Oracle "cache" the result of the function.
Regards,
Richard
blog: http://blog.warp11.nl
twitter: @rhjmartens
If this question is answered, please mark the thread as closed and assign points where earned.. -
Pl/sql function body returning SQL query - Print function
Hello all,
I have pl/sql function body returning SQL query for my reports for my new project that I am developing. We dont have any BI tool or anything for APEX so we use Oracle reports to get the same reports to be printed in PDF format. I had been using SQL function for Reports all these days and grabbing the data using SQL query was easy in Oracle reports. But this time we had atleast 8 fields in search criteria and hence I thouhgt PL/sql function body returning SQL query could be something easy to handle that scenario. We have 11 such reports in our project. Now when we tried to use the same PL/sql function to oracle reports , I was told by one of our Oracle reports expert, that we have to write it into functions and use it in SQL query to get the Reports in Oracle reports. Is there any Easy way to convert the same Pl/SQL function or get a PDF format of the same report in APEX without going thru the much pains of rewriting the whole SQL Query.
thank you
DevisriHi,
give this a go.
I can't test it as I don't have the tables in my schema.
create or replace package MK_TEST_PF is
-- Author : MK
-- Created : 21/06/2010 16:30:19
-- Purpose : FOR LUCY_DISCOVER
-- Public type declarations
/* -- just guess the table row types.....
-- otherwise it won't compile
type test_rec is record
(INV REP.inv%type
,cNUMBER REP.cNUMBER%type
,OPENDATE REP.OPENDATE%type
,TARGETDATE REP.ESTCOMPLETE%type
,DATECLOSED REP.COMPLETED%type
,STATUS REP.STATUS%type
,cCODE REP.cCODE%type
,line varchar2(4000)
,SIGc varchar2(4000)
,CLASS REP.CLASS%type
,SUMM REP.SUMM%type
,AREA REP.AREA%type
type test_rec is record
(INV varchar2(4000)
,cNUMBER varchar2(4000)
,OPENDATE varchar2(4000)
,TARGETDATE varchar2(4000)
,DATECLOSED varchar2(4000)
,STATUS varchar2(4000)
,cCODE varchar2(4000)
,line varchar2(4000)
,SIGc varchar2(4000)
,CLASS varchar2(4000)
,SUMM varchar2(4000)
,AREA varchar2(4000)
type test_tab is table of test_rec;
-- Public constant declarations
-- Public variable declarations
-- Public function and procedure declarations
end MK_TEST_PF;
create or replace package body MK_TEST_PF is
-- Private type declarations
-- Private constant declarations
-- Private variable declarations
-- Function and procedure implementations
function get_query_f
(p_inv VARCHAR2 := UPPER(v('P44_INV'))
,p_reg VARCHAR2 := UPPER(v('P44_CLASS'))
,p_proarea VARCHAR2 := UPPER(v('P44_PROGRAM_AREA'))
,p_disp VARCHAR2 := UPPER(v('P44_DISPOSITION'))
,p_coding VARCHAR2 := UPPER(v('P44_CODING'))
,p_status VARCHAR2 := UPPER(v('P44_STATUS'))
,p_SIG VARCHAR2 := UPPER(v('P44_SIG_c'))
,p_inc_sum VARCHAR2 := UPPER(v('P44_INCLUDE_SUMM_FIELD'))
,p_word VARCHAR2 := UPPER(v('P44_WORD_IN_SUMM'))
,p_timeframe VARCHAR2 := UPPER(v('P44_TIME_FRAME'))
,p_rec VARCHAR2 := UPPER(v('P44_RECORD_KEEPING'))
,p_WORD_IN_SUMM VARCHAR2 := UPPER(v('P44_WORD_IN_SUMM'))
,p_ON_AFTER VARCHAR2 := UPPER(v('P44_ON_AFTER'))
,p_ON_BEFORE VARCHAR2 := UPPER(v('P44_ON_BEFORE'))
return varchar2
is
v_sql VARCHAR2(5000);
-- v_inv VARCHAR2(100);
-- v_reg VARCHAR2(100);
-- v_proarea VARCHAR2(100);
-- v_status VARCHAR2(100);
-- v_SIG VARCHAR2(100);
-- v_disp VARCHAR2(100);
-- v_coding VARCHAR2(100);
-- v_inc_sum VARCHAR2(4);
-- v_word VARCHAR2(4000);
v_wildcard VARCHAR2(2000);
-- v_timeframe VARCHAR2(100);
-- v_rec VARCHAR2(5);
v_record VARCHAR2(5);
v_open VARCHAR2(100);
v_closed VARCHAR2(100);
v_PEND VARCHAR2(100);
v_refSIG VARCHAR2(100);
v_refreg VARCHAR2(100);
v_refother VARCHAR2(100);
v_y varchar2(100);
BEGIN
--v_inv := UPPER(v('P44_INV')) ;
v_record := 'R%';
v_wildcard := '%';
v_open := 'OPEN';
v_closed := 'CLOSED';
v_PEND := 'PEND';
v_refSIG := 'REF - SIG';
v_refreg := 'REF - CLASS';
v_refother := 'REF - OTHER';
v_y := 'Y';
v_sql := 'SELECT REP.INV as INV, REP.cNUMBER as cNUMBER, REP.OPENDATE as OPENDATE,
REP.ESTCOMPLETE as TARGETDATE, REP.COMPLETED as DATECLOSED, REP.STATUS as STATUS,
REP.cCODE as cCODE, apex_item.checkbox(1,REP.line,null,'''||v_y||''') line , apex_item.checkbox(1,REP.SIG,null,'''||v_y||''') SIGc ,
REP.CLASS as CLASS, REP.SUMM as SUMM, REP.AREA as AREA from REP where 1=1';
IF p_rec is not null then
IF p_rec = 'E' then
v_sql := v_sql|| ' and upper(REP.cnumber) not like '''||v_record||'''';
ELSIF p_rec = 'D' then
v_sql := v_sql|| ' and upper(REP.cnumber) like '''||v_record||'''';
ELSIF p_rec = 'I' then
v_sql := v_sql|| ' and REP.cnumber = REP.cnumber ';
end if ;
end if ;
IF upper(p_status) not like '%NULL%' then
IF upper(p_status) like '%OPEN%' then
v_sql := v_sql||' AND upper(REP.status) like '''||v_open||'''';
ELSIF upper(p_status) like '%CLOSED%' then
v_sql := v_sql||' AND upper(REP.status) like '''||v_closed||'''';
ELSIF upper(v_PEND) like '%PEND%' then
v_sql := v_sql||' AND upper(REP.status) like '''||v_PEND||'''';
ELSIF upper(v_refSIG) like '%REF - SIG%' then
v_sql := v_sql||' AND upper(REP.status) like '''||v_refSIG||'''';
ELSIF upper(v_refreg) like '%REF - CLASS%' then
v_sql := v_sql||' AND upper(REP.status) like '''||v_refreg||'''';
ELSIF upper(v_refother) like '%REF - OTHER%' then
v_sql := v_sql||' AND upper(REP.status) like '''||v_refother||'''';
END IF ;
END IF ;
IF p_inv = 'NULL' THEN
v_sql := v_sql||' AND instr(upper(REP.INV),'''||p_inv||''') > 0';
END IF ;
IF p_reg = 'NULL' THEN
v_sql := v_sql||' AND instr(upper(REP.CLASS),'''||p_reg||''') > 0';
END IF ;
IF p_proarea = 'NULL' THEN
v_sql := v_sql||' AND instr(upper(REP.AREA),'''||p_proarea||''') > 0';
END IF ;
IF p_disp = 'NULL' THEN
v_sql := v_sql||' AND instr(upper(REP.disposition),'''||p_disp||''') > 0';
END IF ;
IF p_coding = 'NULL' THEN
v_sql := v_sql||' AND instr(upper(REP.ccode),'''||p_coding||''') > 0';
END IF ;
IF p_SIG = ' ' THEN
v_sql := v_sql||' AND instr(upper(REP.SIG),'''||p_SIG||''') > 0';
END IF ;
IF p_word is not null then
v_sql := v_sql|| ' and
instr(upper(REP.SUMM),
upper(nvl('''||p_WORD_IN_SUMM||''',REP.SUMM))) > 0';
end if ;
If p_timeframe is not null then
if upper(p_timeframe) = 'OPEN' then
v_sql := v_sql|| ' and to_date(REP.opendate) between to_date ('''||p_ON_AFTER||''') and to_date('''||p_ON_BEFORE||''')';
elsif upper(p_timeframe) = 'CLOSED' then
v_sql := v_sql|| ' and to_date(REP.completed) between to_date ('''||p_ON_AFTER||''') and to_date('''||p_ON_BEFORE||''')';
elsif upper(p_timeframe) = 'EST' then
v_sql := v_sql|| ' and to_date(REP.estcomplete) between to_date ('''||p_ON_AFTER||''') and to_date('''||p_ON_BEFORE||''')';
end if;
end if;
v_sql := v_sql ||' order by REP.INV ';
return v_sql;
end get_query_f;
function test_pf
(p_inv VARCHAR2 := UPPER(v('P44_INV'))
,p_reg VARCHAR2 := UPPER(v('P44_CLASS'))
,p_proarea VARCHAR2 := UPPER(v('P44_PROGRAM_AREA'))
,p_disp VARCHAR2 := UPPER(v('P44_DISPOSITION'))
,p_coding VARCHAR2 := UPPER(v('P44_CODING'))
,p_status VARCHAR2 := UPPER(v('P44_STATUS'))
,p_SIG VARCHAR2 := UPPER(v('P44_SIG_c'))
,p_inc_sum VARCHAR2 := UPPER(v('P44_INCLUDE_SUMM_FIELD'))
,p_word VARCHAR2 := UPPER(v('P44_WORD_IN_SUMM'))
,p_timeframe VARCHAR2 := UPPER(v('P44_TIME_FRAME'))
,p_rec VARCHAR2 := UPPER(v('P44_RECORD_KEEPING'))
,p_WORD_IN_SUMM VARCHAR2 := UPPER(v('P44_WORD_IN_SUMM'))
,p_ON_AFTER VARCHAR2 := UPPER(v('P44_ON_AFTER'))
,p_ON_BEFORE VARCHAR2 := UPPER(v('P44_ON_BEFORE'))
RETURN test_tab PIPELINED
is
type test_c is ref cursor;
v_row test_tab;
v_sql varchar2(4000);
v_cursor test_c;
begin
v_sql := get_query_f
(p_inv
,p_reg
,p_proarea
,p_disp
,p_coding
,p_status
,p_SIG
,p_inc_sum
,p_word
,p_timeframe
,p_rec
,p_WORD_IN_SUMM
,p_ON_AFTER
,p_ON_BEFORE
open v_cursor for v_sql;
fetch v_cursor bulk collect into v_row;
close v_cursor;
for i in 1 .. v_row.count loop
pipe row (v_row(i));
end loop;
return;
end test_pf;
end MK_TEST_PF;
/Regards
Michael -
Writing a function to find whether a value is present in a sql query output
Hi gurus,
I would like to write a function to which i will pass a value and a sql query as parameters.
Now the function needs to execute that sql query and find whether the given value is present in the output list
when the query is executed. If it is present it should return 'T' otherwise 'F'
My function will look like
CREATE FUNCTION CHECK_VALUE(VALUE VARCHAR2,V_SQL VARCHAR2) RETURN VARCHAR2
SELECT CHECK_VALUE('Dallas','SELECT LOCATION_CODE FROM HR_LOCATIONS')
It should check whether the value 'Dallas' is present in the output list returned by the sql query.
Any help will be appreciated.
Thank you.CREATE OR REPLACE
FUNCTION CHECK_VALUE(
VALUE VARCHAR2,
V_SQL VARCHAR2
RETURN VARCHAR2
IS
RETVAL VARCHAR2(4000);
REFCUR SYS_REFCURSOR;
BEGIN
OPEN REFCUR FOR V_SQL;
LOOP
FETCH REFCUR INTO RETVAL;
EXIT WHEN REFCUR%NOTFOUND;
IF RETVAL = VALUE
THEN
CLOSE REFCUR;
RETURN 'T';
END IF;
END LOOP;
CLOSE REFCUR;
RETURN 'F';
END;
Function created.
SQL> SET SERVEROUTPUT ON
SQL> EXEC DBMS_OUTPUT.PUT_LINE(CHECK_VALUE('DALLAS','select loc from dept'));
T
PL/SQL procedure successfully completed.
SQL> EXEC DBMS_OUTPUT.PUT_LINE(CHECK_VALUE('PARIS','select loc from dept'));
F
PL/SQL procedure successfully completed.
SQL> SY. -
Error in nested group function used with column name.
Hi Team,
If i used nested group function with column name its not working. Could you please any one suggest me.
How to use it.
Regards,
Venkat.
Please find Spool ........
SQL> select user_name,max(max(CNT)) from (select USER_NAME,count(*) CNT from v$open_cursor group by USER_NAME)
2 group by user_name,CNT;
select user_name,max(max(CNT)) from (select USER_NAME,count(*) CNT from v$open_cursor group by USER_NAME)
ERROR at line 1:
ORA-00937: not a single-group group function
SQL> select max(max(CNT)) from(select USER_NAME,count(*) CNT from v$open_cursor group by USER_NAME)
2 group by user_name;
MAX(MAX(CNT))
605Venkat wrote:
Hi Sayan
Its giving output like below, but not given maximum CNT.
SQL> select user_name,max(CNT)from (select USER_NAME,count(*) CNT from v$open_cursor group by USER_NAME)
2 group by user_name;
USER_NAME MAX(CNT)
BANES_LERG 6
VENE_USER 8
USER3 339
DBUS 106
VEL_USER 37
SYS 597
6 rows selected.Check it - Re: Error in nested group function used with column name.
and previous post -
Nested Group Function without Group By Problem
Hey everyone,
I have 3 tables as below:
TABLES
ITEM (Item_no, Item_price, desc)
DeliveryItem (delivery_no, item_no, quantity)
Delivery (delivery_no, delivery_date)
SELECT desc, MAX(SUM(quantity)) FROM DeliveryItem, Item, Delivery WHERE Item.item_no = DeliveryItem.item_no AND Delivery.delivery_no = deliveryitem.delivery_no;
And I'm trying to output description of most delivered item but I got an error like SQL Error: ORA-00978: nested group function without GROUP BY. Could you help me to fix my code?
ThanxHi,
DESC is not a good column name; you could get errors if the parser thinks it means DESCending. I used DESCRIPTION instead, below.
I think the best way is to do the SUM in a sub-query, lkike this:
WITH got_r_num AS
SELECT item_no
, SUM (quantity) AS total_quantity
, RANK () OVER (ORDER BY SUM (quantity) DESC) AS r_num
FROM deliveryitem
GROUP BY item_no
SELECT i.description
, r.total_quantity
FROM got_r_num r
JOIN item i ON r.item_no = i.item_no
WHERE r.r_num = 1
;If you want to do it without a sub-query:
SELECT MIN (i.description) KEEP (DENSE_RANK LAST ORDER BY SUM (di.quantity)
AS description
, MAX (SUM (quantity)) AS total_quantity
FROM deliveryitem di
JOIN item i ON d1.item_no = i.tiem_no
GROUP BY i.description
;If you do nested aggegate functions, then every column in the SELECT clause must be an aggregate applied to either
(a) another aggregate, or
(b) one of the GROUP BY expressions.
That's why you got the ORA-00937 error.
This second approach will only display one row of output, so If there is a tie for the item with the greatest total_quantity, only one description will be shown. The RANK method will show all items that had the highest total_quantity.
It looks like the delivery table plays no role in this problem, but it there's some reason for including it, you can join it tpo either query above.
Of course, unless you post test copies of your tables (CREATE TABLE and INSERT statements) I cn't test anything.
Edited by: Frank Kulash on Nov 6, 2010 10:57 AM
Maybe you are looking for
-
Error while calling BAPIs of DMS from Portal
Hi everybody, We are developing a portal with Web Dynpro and trying to call from our java code BAPIs that deals with DMS: BAPI_DOCUMENT_CREATE2 - to create a new DMS document and checkin an original. CVAPI_DOC_CHECKIN - to checkin an original to an e
-
13" MacBook Pro abruptly shut down, won't power on or take a charge
Today I was using my 13" MacBook Pro, bought March 2012 (I think it is running 10.7.5), it had been plugged in all day and the charger light was green. The screen abruptly went black and all sound stopped working. As this happens sometimes, I tried
-
FileVault Encryption STUCK after Yosemite upgrade
This is my problem. It stuck forever at 87%. How to revert back because I do not want to turn on FileVault. Below its a copy of my current status: Last login: Fri Oct 17 21:14:47 on ttys000 Abraham-Sudirmans-MacBook-Air:~ abrahamsudirman$ { diskutil
-
Can I put my DVD movies on to Itunes to move to my Iphone? like with cds (not home movies) compaq Windows XP
-
Smart Card on Elevated Permissions
I'm setting up a QA Web server on a virtual server and having trouble with the Smart Card (this is in order to upgrade from Win03 to Win12 in production). I've been able to bypass the log on with no issue. I've disabled UAC down to the registry level