Cannot perform an aggregate function on an expression containing an aggregate or a subquery.

I am getting "Cannot perform an aggregate function on an expression containing an aggregate or a subquery." error by executing below query, I need to calculate the percentage. Can you please help me on this by modifying the query.
select oe2.OrdSourceID,Count(oe2.OrdSourceID) as TotalOrders,
Percentage = Count(oe2.OrdSourceID) * 100.0 / SUM(Count(oe2.OrdSourceID))
  from OeOrders Oe 
  iNNER JOIN OeOrders2 AS oe2
       ON Oe.OrderID = oe2.OrderID
where
Oe.ProviderID = 'JOHN' and Oe.OrderDateTime between '10/07/2014' and '10/15/2014' and oe2.OrdSourceID is not null
  AND Oe.[Status] NOT IN ( 'CANCEL', 'CANC', 'CNC', 'UNVER', 'UNV' )
Group by oe2.OrdSourceID
Thanks..
Diddi

Hi,
please check this general solution using CTE. If you need a specific query help then pls post your DDL+DML :-) I hope you can get the idea from this example.
/************************************************ DDL+DML */
-- DDL
create table T (Num int, Name nvarchar(10))
-- DML
insert T values (1,'a'),(2,'a'),(3,'s'),(22,'s')
GO
/************************************************ Testing and solution */
select SUM(count(*))
from T
GO
--Msg 130, Level 15, State 1, Line 7
--Cannot perform an aggregate function on an expression containing an aggregate or a subquery.
;with MyCTE as (select count(*) C, Name from T group by Name)
--select * from MyCTE
select SUM(C), Name
from MyCTE
group by Name
GO
/************************************************ Clean */
drop table T
GO
  Ronen Ariely
 [Personal Site]    [Blog]    [Facebook]

Similar Messages

  • HT204406 help! cannot perform Itunes Match function

    I've owned a iMac for 2 years. Itunes match function used to perform correctly, until about a month ago. My softwares are up to date, including Lion I just installed successfully. Itunes version is the latest.
    When I try to perform Itunes match: Step 1 completes correctly, but NOT step 2. Step 2 stops, then loops back into step 1, and again and again ( loop..)
    Makes me a little sad...
    Anyone to help?

    never mind...just needed to restart the phone...seems to be working now...

  • How to Perform an Aggregate Function?

    Hi,
    I'm trying to define in Designer 6.5 an object with the following select: (example)
    sum (count (distinct REPORTING.table.object_name))
    the SQL parsing restitues me this error --> "The SQL can not perform an aggregate function on an expression containing an aggregate or a subquery".
    Can anyboby explain me the problem and above all how to solve it?
    Thanks
    Riccardo

    Hi,
    You cannot mix different aggregations functions in the same SQL expression: this is a SQL limitation for all databases.
    You need to use subselect to achieve your requirement.
    See the following example that works on SQL Server:
    Select sum(a._count) from
    (Select count (distinct cust_id) as _count from Club.dbo.Customer) a
    Regards,
    Didier

  • Analytic function and aggregate function

    What are analytic function and aggregate function. What is difference between them?

    hi,
    Analytic Functions :----------
    Analytic functions compute an aggregate value based on a group of rows. They differ from aggregate functions in that they return multiple rows for each group. The group of rows is called a window and is defined by the analytic_clause. For each row, a sliding window of rows is defined. The window determines the range of rows used to perform the calculations for the current row. Window sizes can be based on either a physical number of rows or a logical interval such as time.
    Analytic functions are the last set of operations performed in a query except for the final ORDER BY clause. All joins and all WHERE, GROUP BY, and HAVING clauses are completed before the analytic functions are processed. Therefore, analytic functions can appear only in the select list or ORDER BY clause.
    Analytic functions are commonly used to compute cumulative, moving, centered, and reporting aggregates.
    Aggregate Functions :----------
    Aggregate functions return a single result row based on groups of rows, rather than on single rows. Aggregate functions can appear in select lists and in ORDER BY and HAVING clauses. They are commonly used with the GROUP BY clause in a SELECT statement, where Oracle Database divides the rows of a queried table or view into groups. In a query containing a GROUP BY clause, the elements of the select list can be aggregate functions, GROUP BY expressions, constants, or expressions involving one of these. Oracle applies the aggregate functions to each group of rows and returns a single result row for each group.
    If you omit the GROUP BY clause, then Oracle applies aggregate functions in the select list to all the rows in the queried table or view. You use aggregate functions in the HAVING clause to eliminate groups from the output based on the results of the aggregate functions, rather than on the values of the individual rows of the queried table or view.
    let me know if you are feeling any problem in understanding.
    thanks.
    Edited by: varun4dba on Jan 27, 2011 3:32 PM

  • User-Defined Aggregate Function in oracle

    Somebody knows if in oracle 10g is possible to create a User-Defined Aggregate Function?
    Sometingh like my_sum, that aggregate the values in a way that i want...
    select manager, my_sum(salary)
    group by manager
    In internet i've found rellay notingh for oracle 10g...can somebody help me? Thank's in advance!

    Thank's to everybody!!! I've made my custom function sum_distinct
    create or replace type AggregateCD as object
    (  nb                   number,
         ListOfDistinctValue  clob,
        static               function ODCIAggregateInitialize(sctx IN OUT AggregateCD) return number,
        member               function ODCIAggregateIterate(self IN OUT AggregateCD, value IN VARCHAR2) return number,
         member               function ODCIAggregateTerminate(self IN AggregateCD, returnValue OUT number, flags IN number) return number,
        member               function ODCIAggregateMerge(self IN OUT AggregateCD, ctx2 IN AggregateCD) return number
    create or replace type body AggregateCD is
       static function ODCIAggregateInitialize(sctx IN OUT AggregateCD) return number is
         begin
             sctx := AggregateCD(0,null);
             return ODCIConst.Success;
        end;
        member function ODCIAggregateIterate(self IN OUT AggregateCD, value IN VARCHAR2) return number is
            ListOfValue CLOB:=self.ListOfDistinctValue ;
         begin
             self.nb:=self.nb+to_number(substr(value , INSTR(value, ';', 1, 1)+1 ,length(value)));
            return ODCIConst.Success;
        end;
        member function ODCIAggregateTerminate(self IN AggregateCD, returnValue OUT number, flags IN number) return number is
         begin
              returnValue := self.nb;
              return ODCIConst.Success;
        end;
         member function ODCIAggregateMerge(self IN OUT AggregateCD, ctx2 IN AggregateCD) return number is
         begin
             self.nb := ctx2.nb;
             return ODCIConst.Success;
        end;
      end;
    CREATE OR REPLACE FUNCTION sum_distinct (input VARCHAR2) RETURN number
      PARALLEL_ENABLE AGGREGATE USING AggregateCD;you can use so:
    select sum_distinct(distinct t.primary_key||';'||t.import)
    from table1 t, table2_with_bad_join
    it's the same of
    select sum(t.import)
    from table 1

  • Selecting both a aggregate function and another field

    I am trying to do something very simple but I am not sure of the syntax.
    I would like to select all of the petid's and find the count of the pets in a given city, both from the same table, Pets.
    Can somebody please help me with this?
    Thanks

    Hi,
    An aggregate function will give you one row of output per group.
    For example, if you use the aggregate COUNT function to get the total number of rows in a whole table, then you can only have one row of output, representing the whole table, so, if I understand the problem, you can't (easily) use an aggregate function.
    Almost all of the aggregate functions have analytic counterparts, that can produce the same results without collapsing the result set into one row per group.
    I think this is what you requested:
    SELECT  petid
    ,       COUNT (*) OVER (PARTITION BY 1)  AS total_cnt
    FROM    pets
    WHERE   city    = 'Paris'  -- or whatever
    ;Sorry, I'm not at a database now, so I can't check, but I think you don't need the PARTITION BY clause, so you can also say:
    ,       COUNT (*) OVER ()  AS total_cntThe keyword OVER marks this as an analytic, rather than an aggregate, function.

  • Aggregate functions cannot be used in group expressions

    Hi have report showing sales by Vendor. I need to list all the vendors with Monthly Total>5000 and combine the rest as "OTHER VENDORS"
    Vendor is a Group in my report, so I tried to put an expression as a Group on:
    =IIF(Sum(Fields!Mth_1_Sales.Value)>5000,Fields!Vendor_No.Value,"OTHER VENDORS")
    I've got an error: "aggregate functions cannot be used in group expressions"
    How do I get Vendors with Sales < 5000 into  "OTHER VENDORS" ?

    Hi,
    You need to group by Month on group expression,
    And you can use the same expression in the report column as 
    =IIF(Sum(Fields!Mth_1_Sales.Value)>5000,Fields!Vendor_No.Value,"OTHER VENDORS")
    Many Thanks
    ..................................................................................................................................................................Please
    mark the post as Please mark the post as answered if this post helps to solve the post.

  • My CS6 photoshop started showing cannot perform function programming error then it started freezing please help?

    My CS6 photoshop started showing {cannot perform function programming error}
    then it started freezing please help?

    Supply pertinent information for quicker answers
    The more information you supply about your situation, the better equipped other community members will be to answer. Consider including the following in your question:
    Adobe product and version number
    Operating system and version number
    The full text of any error message(s)
    What you were doing when the problem occurred
    Screenshots of the problem
    Computer hardware, such as CPU; GPU; amount of RAM; etc.

  • Cannot save any changes - Microsoft Forefront 2010 for exchange is unable to perform the requested function

    HI, I have Forefront 2010 for Exchange installed for an Exchange 2007 SP2 running on Windows 2003 x64 SP2. Exchange has all roles installed on the same server. 
    When I try to save any change on Forefront I got the following message:
    Microsoft Forefront 2010 for Exchange is unable to perform the requested function. This may be because Forefront services are unavailable. Ensure that all Microsoft Forefront services are running and that WindowsPower Shell is functional
    Well, our FF services are running and PowerShell is functional. I checked some forums and found some problems when there is entries in the IP Allow / Block lists in Exchange UI. I removed those entries but problem remains.
    Any ideas would be appreciated.
    Xavier Villafuerte

    In my case, I was able to work around this issue by using  PowerShell directly.  For example, to run an on-demand scan for all mailboxes, this worked:
    #open EMS
    $aliases = (get-mailbox -result unlimited).alias
    Add-PsSnapin FSSPSSnapin
    set-FseOnDemandScan -MailboxList $aliases
    Start-FseOnDemandScan -EnableVirusScan $true
    Windows 2008 R2 SP1
    Exchange 2010 SP3, RU9
    PowerShell 4.0 present on the machine (though EMS runs PS 2.0)
    Forefront PowerShell cmdlets:
    https://technet.microsoft.com/en-us/library/cc482986.aspx
    Mike Crowley | MVP
    My Blog --
    Baseline Technologies

  • SSRS - Interactive sorting based on aggregate function

    Hi,
    I'm trying to add interactive sorting to one of the columns in my tablix.
    The soring should be based on the LAST visit date of my child grouping. However interactive sorting is not compatible with aggregate functions apparently.
    I'm using the following expression to sort on the period since the last visit:
    =DateDiff(
    "d"
    ,LAST(CDate(Fields!Visit_date.Value))
    ,Today()
    Anyone an idea how to get this done?
    Regards,
    LiskieWhisky

    Thanks for the input,
    Qiuyun Yu: I already applied your method but my issues is that the visit dates are on de level of my
    child grouping and per child multiple visit dates are possible. Since I want to complute the days since the last visit I need to take the last visit date and subtract it from today's date.
    As you can see there are 2 dates. To compute the days since the last visit I take the last visit date (2015-04-17)
    and subtract it from today (2015-04-27). This gives me 10 days. That's ok, no problem there.
    But because I'm using the Last() function, I cannot use this expression in the Interactive sorting expression.
    LucasF: You are right, but if it's possible to do this in the report I'd prefer that. But ultimately if it's necessary I'll have to do it in MDX then.
    Kind regards,
    LiskieWhisky

  • Using Aggregate function in queries

    Hi all,
              Please take a look on this query and suggest me why i'm getting the error..
    This is my simple query using aggregate function in it..
    SELECT T1.NAME, T1.DESCRIPTION, SUM(T2.QUANTITY)
    FROM TABLE1 T1, TABLE2 T2
    WHERE T1.ID=T2.ID
    GROUP BY T1.NAME, T1.DESCRIPTION
    Above query added with a sub-query in the select segment..
    SELECT T1.NAME, T1.DESCRIPTION, SUM(T2.QUANTITY), (SELECT AVG(T3.PRICE) FROM TABLE1 TT1, TABLE3 T3 WHERE TT1.ID=T3.ID AND TT1.ID=T1.ID) AV_PRICE
    FROM TABLE1 T1, TABLE2 T2
    WHERE T1.ID=T2.ID
    GROUP BY T1.NAME, T1.DESCRIPTION
    When i add a sub-query which has aggregate function in it, i'm getting the 'ORA-00979: not a GROUP BY expression' error.

    What is your DB Version. Your query works without any issue in my DB. I used WITH clause to create the sample data. The query highlighted in BLUE is the actual query.
    SQL> select * from v$version where rownum = 1;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    SQL> with table1
      2  as
      3  (
      4    select 1 id, 'karthick' name, 'user name' description from dual
      5  ),
      6  table2
      7  as
      8  (
      9    select 1 id, 100 quantity from dual
    10  ),
    11  table3
    12  as
    13  (
    14    select 1 id, 10 price from dual
    15  )
    16  select t1.name
    17       , t1.description
    18       , sum(t2.quantity)
    19       , (
    20           select avg(t3.price)
    21             from table1 tt1
    22                , table3 t3
    23            where tt1.id = t3.id
    24              and tt1.id = t1.id
    25         ) av_price
    26    from table1 t1
    27       , table2 t2
    28   where t1.id = t2.id
    29   group
    30      by t1.name
    31       , t1.description;
    NAME     DESCRIPTI SUM(T2.QUANTITY)   AV_PRICE
    karthick user name              100         10
    SQL>

  • Cannot perform RFC lookup

    Hi All,
    We are getting below error in doing testing in PI mapping.
    Cannot perform RFC lookup com.sap.aii.mapping.api.StreamTransformationException: Cannot perform RFC lookup at com.sap.aii.mappingtool.flib7.RfcLookup.cacheMore(RfcLookup.java:105) at com.sap.aii.mappingtool.tf7.rt.AMultiResIterator$MultiOutIterator.gotoNextContext(AMultiResIterator.java:95) at com.sap.aii.mappingtool.tf7.rt.C2CFunctionWrapper.cacheContext(C2CFunctionWrapper.java:77) at com.sap.aii.mappingtool.tf7.rt.C2CFunctionWrapper.gotoNextContext(C2CFunctionWrapper.java:42) at com.sap.aii.mappingtool.tf7.AMappingProgram.processNode(AMappingProgram.java:317) at com.sap.aii.mappingtool.tf7.AMappingProgram.processNode(AMappingProgram.java:410) at com.sap.aii.mappingtool.tf7.AMappingProgram.processNode(AMappingProgram.java:410) at com.sap.aii.mappingtool.tf7.AMappingProgram.processNode(AMappingProgram.java:410) at com.sap.aii.mappingtool.tf7.AMappingProgram.processNode(AMappingProgram.java:410) at com.sap.aii.mappingtool.tf7.AMappingProgram.start(AMappingProgram.java:502) at com.sap.aii.mappingtool.tf7.Transformer.start(Transformer.java:133) at com.sap.aii.mappingtool.tf7.AMappingProgram.transform(AMappingProgram.java:632) at com.sap.aii.ibrep.server.mapping.exec.ExecuteXiMappingCommand.transformInternal(ExecuteXiMappingCommand.java:197) at com.sap.aii.ibrep.server.mapping.exec.ExecuteXiMappingCommand.execute(ExecuteXiMappingCommand.java:94) at com.sap.aii.ib.server.mapping.exec.CommandManager.execute(CommandManager.java:43) at com.sap.aii.ibrep.server.mapping.ServerMapService.execute(ServerMapService.java:40) at com.sap.aii.ibrep.server.mapping.MapServiceBean.execute(MapServiceBean.java:40) at sun.reflect.GeneratedMethodAccessor701.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at com.sap.engine.services.ejb3.runtime.impl.RequestInvocationContext.proceedFinal(RequestInvocationContext.java:46) at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:166) at com.sap.engine.services.ejb3.runtime.impl.Interceptors_StatesTransition.invoke(Interceptors_StatesTransition.java:19) at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Resource.invoke(Interceptors_Resource.java:71) at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Transaction.doWorkWithAttribute(Interceptors_Transaction.java:38) at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Transaction.invoke(Interceptors_Transaction.java:22) at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:189) at com.sap.engine.services.ejb3.runtime.impl.Interceptors_StatelessInstanceGetter.invoke(Interceptors_StatelessInstanceGetter.java:16) at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) at com.sap.engine.services.ejb3.runtime.impl.Interceptors_SecurityCheck.invoke(Interceptors_SecurityCheck.java:21) at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) at com.sap.engine.services.ejb3.runtime.impl.Interceptors_ExceptionTracer.invoke(Interceptors_ExceptionTracer.java:16) at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) at com.sap.engine.services.ejb3.runtime.impl.DefaultInvocationChainsManager.startChain(DefaultInvocationChainsManager.java:133) at com.sap.engine.services.ejb3.runtime.impl.DefaultEJBProxyInvocationHandler.invoke(DefaultEJBProxyInvocationHandler.java:164) at $Proxy1525.execute(Unknown Source) at sun.reflect.GeneratedMethodAccessor700.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at com.sap.engine.services.rmi_p4.P4DynamicSkeleton.dispatch(P4DynamicSkeleton.java:234) at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:355) at com.sap.engine.services.rmi_p4.server.ServerDispatchImpl.run(ServerDispatchImpl.java:69) at com.sap.engine.services.rmi_p4.P4Message.process(P4Message.java:67) at com.sap.engine.services.rmi_p4.P4Message.execute(P4Message.java:41) at com.sap.engine.services.cross.fca.FCAConnectorImpl.executeRequest(FCAConnectorImpl.java:977) at com.sap.engine.services.rmi_p4.P4Message.process(P4Message.java:57) at com.sap.engine.services.cross.fca.MessageReader.run(MessageReader.java:55) at com.sap.engine.core.thread.execution.Executable.run(Executable.java:115) at com.sap.engine.core.thread.execution.Executable.run(Executable.java:96) at com.sap.engine.core.thread.execution.CentralExecutor$SingleThread.run(CentralExecutor.java:314) Caused by: com.sap.aii.mapping.lookup.LookupException: Connection to system RUNTIME using application RUNTIME lost. Detailed information: Error accessing "http://sapdevpid01:51000/run/system/int?container=web" with user "PIREPUSER". Response code is 401, response message is "Unauthorized" at com.sap.aii.ibrep.server.lookup.LookupServiceProvider$RemoteClientDelegator.<init>(LookupServiceProvider.java:103) at com.sap.aii.ibrep.server.lookup.LookupServiceProvider$RemoteClientDelegator.<init>(LookupServiceProvider.java:86) at com.sap.aii.ibrep.server.lookup.LookupServiceProvider$RemoteClient.getSystemAccessor(LookupServiceProvider.java:73) at com.sap.aii.mapping.lookup.LookupService.getRfcAccessor(LookupService.java:258) at com.sap.aii.mappingtool.flib7.RfcLookup.cacheMore(RfcLookup.java:78) ... 52 more Caused by: com.sap.aii.utilxi.hmi.api.HmiCoreException: Connection to system RUNTIME using application RUNTIME lost. Detailed information: Error accessing "http://sapdevpid01:51000/run/system/int?container=web" with user "PIREPUSER". Response code is 401, response message is "Unauthorized" at com.sap.aii.utilxi.hmi.api.HmiCoreException.newCommunicationError(HmiCoreException.java:85) at com.sap.aii.utilxi.hmi.api.HmiHttpJDKClient.sendRequestAndReceiveResponse(HmiHttpJDKClient.java:184) at com.sap.aii.utilxi.hmi.api.HmiClientAdapter.invokeMethod(HmiClientAdapter.java:92) at com.sap.aii.ibrep.server.lookup.SystemAccessorHmiClient.<init>(SystemAccessorHmiClient.java:50) at com.sap.aii.ibrep.server.lookup.SystemAccessorHmiClient.getInstance(SystemAccessorHmiClient.java:71) at com.sap.aii.ibrep.server.lookup.LookupServiceProvider$RemoteClientDelegator.<init>(LookupServiceProvider.java:96) ... 56 more Root Cause: com.sap.aii.mapping.lookup.LookupException: Connection to system RUNTIME using application RUNTIME lost. Detailed information: Error accessing "http://sapdevpid01:51000/run/system/int?container=web" with user "PIREPUSER". Response code is 401, response message is "Unauthorized" at com.sap.aii.ibrep.server.lookup.LookupServiceProvider$RemoteClientDelegator.<init>(LookupServiceProvider.java:103) at com.sap.aii.ibrep.server.lookup.LookupServiceProvider$RemoteClientDelegator.<init>(LookupServiceProvider.java:86) at com.sap.aii.ibrep.server.lookup.LookupServiceProvider$RemoteClient.getSystemAccessor(LookupServiceProvider.java:73) at com.sap.aii.mapping.lookup.LookupService.getRfcAccessor(LookupService.java:258) at
    Thank you very much for advance.
    Ferran

    hi
    Check in SM59 the RFC destination is working fine
    Check the RFC communication channel is without error
    also
    Please check if the RFC is imported properly and you are using RFCLookup function in the mapping.
    Check if you have completd the parameter creation

  • "cannot perform a DML operation inside a query" error when using table func

    hello please help me
    i created follow table function when i use it by "select * from table(customerRequest_list);"
    command i receive this error "cannot perform a DML operation inside a query"
    can you solve this problem?
    CREATE OR REPLACE FUNCTION customerRequest_list(
    p_sendingDate varchar2:=NULL,
    p_requestNumber varchar2:=NULL,
    p_branchCode varchar2:=NULL,
    p_bankCode varchar2:=NULL,
    p_numberOfchekbook varchar2:=NULL,
    p_customerAccountNumber varchar2:=NULL,
    p_customerName varchar2:=NULL,
    p_checkbookCode varchar2:=NULL,
    p_sendingBranchCode varchar2:=NULL,
    p_branchRequestNumber varchar2:=NULL
    RETURN customerRequest_nt
    PIPELINED
    IS
    ob customerRequest_object:=customerRequest_object(
    NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
    condition varchar2(2000 char):=' WHERE 1=1 ';
    TYPE rectype IS RECORD(
    requestNumber VARCHAR2(32 char),
    branchRequestNumber VARCHAR2(32 char),
    branchCode VARCHAR2(50 char),
    bankCode VARCHAR2(50 char),
    sendingDate VARCHAR2(32 char),
    customerAccountNumber VARCHAR2(50 char),
    customerName VARCHAR2(200 char),
    checkbookCode VARCHAR2(50 char),
    numberOfchekbook NUMBER(2),
    sendingBranchCode VARCHAR2(50 char),
    numberOfIssued NUMBER(2)
    rec rectype;
    dDate date;
    sDate varchar2(25 char);
    TYPE curtype IS REF CURSOR; --RETURN customerRequest%rowtype;
    cur curtype;
    my_branchRequestNumber VARCHAR2(32 char);
    my_branchCode VARCHAR2(50 char);
    my_bankCode VARCHAR2(50 char);
    my_sendingDate date;
    my_customerAccountNumber VARCHAR2(50 char);
    my_checkbookCode VARCHAR2(50 char);
    my_sendingBranchCode VARCHAR2(50 char);
    BEGIN
    IF NOT (regexp_like(p_sendingDate,'^[[:digit:]]{4}/[[:digit:]]{2}/[[:digit:]]{2}$')
    OR regexp_like(p_sendingDate,'^[[:digit:]]{4}/[[:digit:]]{2}/[[:digit:]]{2}[[:space:]]{1}[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}$')) THEN
    RAISE_APPLICATION_ERROR(-20000,cbdpkg.get_e_m(-1,5));
    ELSIF (p_sendingDate IS NOT NULL) THEN
    dDate:=TO_DATE(p_sendingDate,'YYYY/MM/DD hh24:mi:ss','nls_calendar=persian');
    dDate:=trunc(dDate);
    sDate:=TO_CHAR(dDate,'YYYY/MM/DD hh24:mi:ss');
    condition:=condition|| ' AND ' || 'sendingDate='||'TO_DATE('''||sDate||''',''YYYY/MM/DD hh24:mi:ss'''||')';
    END IF;
    IF (p_requestNumber IS NOT NULL) AND (cbdpkg.isspace(p_requestNumber)=0) THEN
    condition:=condition|| ' AND ' || ' requestNumber='||p_requestNumber;
    END IF;
    IF (p_bankCode IS NOT NULL) AND (cbdpkg.isspace(p_bankCode)=0) THEN
    condition:=condition|| ' AND ' || ' bankCode='''||p_bankCode||'''';
    END IF;
    IF (p_branchCode IS NOT NULL) AND (cbdpkg.isspace(p_branchCode)=0) THEN
    condition:=condition|| ' AND ' || ' branchCode='''||p_branchCode||'''';
    END IF;
    IF (p_numberOfchekbook IS NOT NULL) AND (cbdpkg.isspace(p_numberOfchekbook)=0) THEN
    condition:=condition|| ' AND ' || ' numberOfchekbook='''||p_numberOfchekbook||'''';
    END IF;
    IF (p_customerAccountNumber IS NOT NULL) AND (cbdpkg.isspace(p_customerAccountNumber)=0) THEN
    condition:=condition|| ' AND ' || ' customerAccountNumber='''||p_customerAccountNumber||'''';
    END IF;
    IF (p_customerName IS NOT NULL) AND (cbdpkg.isspace(p_customerName)=0) THEN
    condition:=condition|| ' AND ' || ' customerName like '''||'%'||p_customerName||'%'||'''';
    END IF;
    IF (p_checkbookCode IS NOT NULL) AND (cbdpkg.isspace(p_checkbookCode)=0) THEN
    condition:=condition|| ' AND ' || ' checkbookCode='''||p_checkbookCode||'''';
    END IF;
    IF (p_sendingBranchCode IS NOT NULL) AND (cbdpkg.isspace(p_sendingBranchCode)=0) THEN
    condition:=condition|| ' AND ' || ' sendingBranchCode='''||p_sendingBranchCode||'''';
    END IF;
    IF (p_branchRequestNumber IS NOT NULL) AND (cbdpkg.isspace(p_branchRequestNumber)=0) THEN
    condition:=condition|| ' AND ' || ' branchRequestNumber='''||p_branchRequestNumber||'''';
    END IF;
    dbms_output.put_line(condition);
    OPEN cur FOR 'SELECT branchRequestNumber,
    branchCode,
    bankCode,
    sendingDate,
    customerAccountNumber ,
    checkbookCode ,
    sendingBranchCode
    FROM customerRequest '|| condition ;
    LOOP
    FETCH cur INTO my_branchRequestNumber,
    my_branchCode,
    my_bankCode,
    my_sendingDate,
    my_customerAccountNumber ,
    my_checkbookCode ,
    my_sendingBranchCode;
    EXIT WHEN (cur%NOTFOUND) OR (cur%NOTFOUND IS NULL);
    BEGIN
    SELECT requestNumber,
    branchRequestNumber,
    branchCode,
    bankCode,
    TO_CHAR(sendingDate,'yyyy/mm/dd','nls_calendar=persian'),
    customerAccountNumber ,
    customerName,
    checkbookCode ,
    numberOfchekbook ,
    sendingBranchCode ,
    numberOfIssued INTO rec FROM customerRequest FOR UPDATE NOWAIT;
    --problem point is this
    EXCEPTION
    when no_data_found then
    null;
    END ;
    ob.requestNumber:=rec.requestNumber ;
    ob.branchRequestNumber:=rec.branchRequestNumber ;
    ob.branchCode:=rec.branchCode ;
    ob.bankCode:=rec.bankCode ;
    ob.sendingDate :=rec.sendingDate;
    ob.customerAccountNumber:=rec.customerAccountNumber ;
    ob.customerName :=rec.customerName;
    ob.checkbookCode :=rec.checkbookCode;
    ob.numberOfchekbook:=rec.numberOfchekbook ;
    ob.sendingBranchCode:=rec.sendingBranchCode ;
    ob.numberOfIssued:=rec.numberOfIssued ;
    PIPE ROW(ob);
    IF (cur%ROWCOUNT>500) THEN
    CLOSE cur;
    RAISE_APPLICATION_ERROR(-20000,cbdpkg.get_e_m(-1,4));
    EXIT;
    END IF;
    END LOOP;
    CLOSE cur;
    RETURN;
    END;

    Now what exactly would be the point of putting a SELECT FOR UPDATE in an autonomous transaction?
    I think OP should start by considering why he has a function with an undesirable side effect in the first place.

  • Cannot perform RFC Look UP

    Hi All,
    When I executed the RFC Look up function in the mapping could see the following error.
    "Run time exception when processing target field mapping. Cannot perform RFC Look Up".
    I performed the below steps but still could find the same error again:
    1.In the test tab of the message mapping I have assined a channel which I configured in the Interface determination of the configuration and also assigned a value to that channel.
    2. Has given the values for the parameters in the operation mapping and also the binding is done successfully.
    3. The function module I assined is also existing and could test the same for output values for the given input values.
    Please help me resolve the error.
    Thanks & Regards,
    Kumar.

    Hi,
    This is the error I could see in the communication channel monitoring of RWB.
    "Error in processing caused by: com.sap.aii.adapter.rfc.afcommunication.RfcAFWException: error while processing message to remote system:com.sap.aii.adapter.rfc.core.client.RfcClientException: functiontemplate from repository was <null>"
    Help me with this error.
    Thanks,
    Kumar.

  • Microsoft forefront protection 2010 for exchange server is unable to perform the requested function

    I get the following error any time I try and change any setting:
    Microsoft Forefront Protection 2010 for Exchange Server is unable to perform the requested function. This may be becuase Microsoft ForeFront services are unavailable. Ensure that all Microsoft ForeFront services are running and that Windows Powershell is
    functional.
    I have installed the latest rollup for SEP. Rollup 5 I think. I have rebooted the server. I have checked the permissions and they are correct.
    Any thoughts?

    I posted a PowerShell-based workaround in the other thread:
    https://social.technet.microsoft.com/Forums/forefront/en-US/1ccb9a5e-4b08-4f6b-a4bd-32cf5f2cd2b0/cannot-save-any-changes-microsoft-forefront-2010-for-exchange-is-unable-to-perform-the-requested?forum=FSENext
    Mike Crowley | MVP
    My Blog --
    Baseline Technologies

Maybe you are looking for

  • Can I use iTunes Match to restore an iTunes Library on a MacBook?

    My son's 8 month old MacBook went horribly wrong on the upgrade to Mountain Lion and needed to be reinstalled from scratch, wiping his iTunes library as well. His music collection is on his iPhone 4 and I wondered if he subscribes to iTunes Match and

  • Can't boot my device OS or Bios

    hello .. First of all my deice is HP Pavilion 14-b109sx Ultrabook her's what happened .. well ... I just bought this new notebook ,Its really light and it booted really fast and the design is good ... problem is i wanted to make a second partition ou

  • Adding RAM to Macbook Pro

    Possibly a dumb question, but here goes: How do I determine the maximum RAM capacity on a Macbook Pro(specs below). I'd like to max out the RAM. Also-is it difficult to add RAM? Thanks.

  • Sharepoint 2013 bing search results

    I have integrated bing search to my sharepoint 2013. Its returning results but i am facing two issues. 1) The bing search is always returning only 8 results 2) I want to get results for only particular website and i have used following query. But its

  • 6.0.2 BUG: setting rating in smart playlists

    I created a smart playlist and wanted to match all songs that were not one star. When I click on the section with the stars, I can select any number (and the number of stars follow the mouse as I drag it - as expected). However, when I release the mo