Can analytic functions be used  in a cursor ?

The following pl/sql code gives out the error as given below the code. However when the select staement in the cursor if run alone gives the results. Can someone tell me why. Can't analytic functions be used in cursors
declare
cursor cur1 is
SELECT
col1,
col2,
REGR_SLOPE(col1, LOG(10,col2))
OVER(PARTITION BY col1 ORDER BY col2
ROWS BETWEEN 2 PRECEDING AND UNBOUNDED FOLLOWING)
from datatab;
OVER(PARTITION BY col1 ORDER BY col2
ERROR at line 7:
ORA-06550: line 7, column 5:
PLS-00103: Encountered the symbol "(" when expecting one of the following:
, from

Since it is a cursor, you can put the select statement in quotes which will execute the statement as dynamic SQL and allow the analytical function reference:
open c for
  'SELECT col1, col2, REGR_SLOPE(col1, LOG(10,col2))
                      OVER(PARTITION BY col1 ORDER BY col2
                      ROWS BETWEEN 2 PRECEDING AND UNBOUNDED FOLLOWING)
     from datatab';
loop
  fetch c into v_col1, v_col2, v_col3;
  exit when c%notfound;
  -- do something with values
end loop;
close c;

Similar Messages

  • Can stored function return record type or cursor type?

    Hi everybody,
    I am working with a stored function now.
    Can the function output more that ONE result? i.e. cursor or record type.
    Thanks.
    Brigitta.

    Brigitta,
    If you are calling the stored function from SQL then the function can only return one of the base datatypes, as Murali has said. However, if you are calling the function from PLSQL you can return any complex datatype, eg:
    package test_package is
    type rec_test is
      ( col_a number
      , col b varchar2(30) );
    type tab_test is
      table of rec_test
      index by binary ineteger;
    function test_function (.....)
    return tab_test;
    end test_package;and to call this function:
    declare
    l_table test_package.tab_test;
    begin
    l_table := test_package.test_function(....);
    end;Hope that helps!

  • Can DAQmxRegisterEveryNSamplesEvent function be used for the Counter Input Channels

    Hi, All,
    I have an application to count the digitial pulse number. I want to know the time of the coming pulses which start from 1 and increased 4 later, like 1, 5, 9, 13..... The time interval between each pulse is not a fixed value. So I tried to use  DAQmxRegisterEveryNSamplesEvent and DAQmxCreateCICountEdgesChan functions. But afterI called the DAQmxStartTask function, it always failed.  The board I used is the NI-PCIe-6320. Here is part of my code.
    DAQmxErrChk (DAQmxCreateTask("",&m_taskhandle));
    DAQmxErrChk (DAQmxCreateCICountEdgesChan(m_taskhandle,"Dev1/ctr0","",DAQmx_Val_Rising, 0, DAQmx_Val_CountUp));
    DAQmxErrChk(DAQmxRegisterEveryNSamplesEvent(m_taskhandle, DAQmx_Val_Acquired_Into_Buffer, 4, 0, EveryNSamplesCallback, this) );
    DAQmxErrChk (DAQmxStartTask(m_taskhandle));
    I don't know the reason. Can Anyone give me some help. Thanks.
    Yang
    Solved!
    Go to Solution.

    Hi, John,
    What's I what to do is that I have an external digital signal, when the signal goes from low to high, I need do some operations. So I just want to know the time when the digital signal goes from low to high.  The frequency of the digital signal is from 0 - 20000Hz. My first plan is to use a counter to count the pulse rising edges. When the number of edge increases one, I do the designed operations. In this method, I can't guarantee I can catch each pulse rising point. Because sometimes the counter will increase more than one in the on-demand mode. For example, the previous content of the counter is xxxx4, but the next reading the content may become xxxx6.
    After I learned some ANSI C  codes, I found that the ChangeDetectionEvent can help me found time when the signal goes from low to high. So I wrote the following code: (I set the digital signal to P0.0)
    DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
    DAQmxErrChk (DAQmxCreateDIChan(taskHandle,"Dev1/port0/line0","",DAQmx_Val_ChanPerLine));
    DAQmxErrChk (DAQmxCfgChangeDetectionTiming(taskHandle,"Dev1/port0/line0","",DAQmx_Val_ContSamps, 1));
    DAQmxErrChk (DAQmxRegisterSignalEvent (taskHandle, DAQmx_Val_ChangeDetectionEvent, 0, Callback , dialog));
    DAQmxErrChk (DAQmxStartTask(taskHandle));
    int32 CVICALLBACK Callback (TaskHandle taskHandle, int32 signalID, void *callbackData){
    CNIPCIE6320Dlg* dialog = static_cast<CNIPCIE6320Dlg*>(callbackData);
    dialog->m_event_num++;  // Here is to calculate how many events has been triggered
    return 0;
    Yesterday I used this method to get the pulse rising time. I found the m_event_num is close to the ground truth (In the simulation, I know how may rising pulse I generated).  In one two hours test, the offset is almost 400 pulses. But today I did the same tests again. I found the m_event_num got a big difference from the ground truth. The voltage of the whole system today maybe smaller than yesterday, because today the power is from an invertor while yesterday the power is from the electricity supply. So will the lower voltage supply will causing some event missing. Or if PC system became busy will ignore some callings of the event callback function? That's two possible reason will affact the final result. I am not sure. Do you have any experience about this problem.  Or do you have some better suggestion to get the pulse rising time. Thanks again.
    Regards,
    Yang 

  • Can analytical function support this requirement?

    As a result of some Qry, I get the following result set.
    Column1 Column2
    A       100   
    A       200
    A       200
    A       100
    B       200
    B       200
    B       200
    C       100
    C       200
    D       200
    D       200
    E       200
    With this as input i had to take some decision like, For a particular Column1 value, if all the avaiable value of column2 is 200 (B, D & E in this case), i need to do one set of operations, if atleast one of the value for Column2 is non 200 (A & C in this case), i need to do another set of operation. How to frame the If clause or any other approach?
    By using Analytical count(*) function, is it possible to generate something like
    Column1 Column2   Column3(200_count)
    A       100       2
    A       200       2
    A       200       2
    A       100       2
    B       200       3
    B       200       3
    B       200       3
    C       100       1
    C       200       1
    D       200       3
    D       200       3
    E       200       3

    hi,
    Something lilke this?
    with data as (
    select 'A' column1,       100     column2 from dual union all
    select 'A' column1,       200 from dual union all
    select 'A' column1,       200 from dual union all
    select 'A' column1,       100 from dual union all
    select 'B' column1,       200 from dual union all
    select 'B' column1,       200 from dual union all
    select 'B' column1,       200  from dual union all
    select 'C' column1,       100 from dual union all
    select 'C' column1,       200 from dual union all
    select 'D' column1,       200 from dual union all
    select 'D' column1,       200 from dual union all
    select 'E' column1,       200 from dual
    select
    column1,column2,count(0) over (partition by column1,column2) cnt
    from data
    order by column1The above query will count the occuerence of column2 for every column1.
    If you want to count only 200 something like may help you.
    with data as (
    select 'A' column1,       100     column2 from dual union all
    select 'A' column1,       200 from dual union all
    select 'A' column1,       200 from dual union all
    select 'A' column1,       100 from dual union all
    select 'B' column1,       200 from dual union all
    select 'B' column1,       200 from dual union all
    select 'B' column1,       200  from dual union all
    select 'C' column1,       100 from dual union all
    select 'C' column1,       200 from dual union all
    select 'D' column1,       200 from dual union all
    select 'D' column1,       200 from dual union all
    select 'E' column1,       200 from dual
    select
    column1,column2,sum(
    case when column2=200 then
    1
    else
    0
    end
    ) over (partition by column1) cnt
    from data
    order by column1Regards,
    Bhushan
    Edited by: Buga added second query

  • Can EL functions be used???

    Workshop complains about the following line, saying that EL functions are not supported.
    <c:if test="${helper:collectionSize(events) > 0}">
    When I change the jstl.jar, standard.jar and c.tld to use the latest Apache version,
    workshop complains that the above type needs to return true or false.
    Is this a configuration problem or lack of support for the latest standards.
    TIA...

    Mike--
    EL functions are a JSP 2.0 feature that was not included when JSTL 1.0 introduced the expression
    language.
    WebLogic Server / Workshop 8.1 are built atop the J2EE 1.3 specifications, which includes JSP 1.2.
    The latest version of the JSTL runtime from Apache (Standard Tag Library 1.1) requires a JSP 2.0
    container, so those tags won't run correctly on older containers.
    A way to solve the problem you seem to be addressing with the "collectionSize" function with the
    JSTL 1.0 tags is described in the thread titled "JSTL Errors".
    Hope that helps...
    Eddie
    Mike Faulkner wrote:
    Workshop complains about the following line, saying that EL functions are not supported.
    <c:if test="${helper:collectionSize(events) > 0}">
    When I change the jstl.jar, standard.jar and c.tld to use the latest Apache version,
    workshop complains that the above type needs to return true or false.
    Is this a configuration problem or lack of support for the latest standards.
    TIA...

  • Can Analytical function give me this result?

    Hi Friends
    I have the following query:
    SELECT DISTINCT
          DATE_FIELD
          ,ACCT_ID
          ,CITY
          ,STATE
          ,ZIP
          ,UNIQUE_ID
          ,OPEN_DT
          ,TO_CHAR (ROW_NUMBER () OVER (PARTITION BY ACCT_ID ORDER BY ACCT_ID,OPEN_DT ) ) rn
    FROM TABLE1
    WHERE 1=1
    AND OPEN_DT IS NOT NULL This query gives me the following result:
    DATE_FIELD     | ACCT_ID     CITY | STATE | ZIP | UNIQUE_ID |OPEN_DT|RN
    1/02/2010|111|'CITY1'|'STATE1'|3333|2325|9/01/1987|1
    1/02/2010|111|'CITY2'|'STATE1'|3333|2090|19/01/1996|2
    1/02/2010|111|'CITY2'|'STATE1'|3333|2090|20/06/2002|3
    1/02/2010|111|'CITY2'|'STATE1'|3333|2090|20/06/2002|4
    1/02/2010|111|'CITY1'|'STATE1'|3333|2325|20/06/2002|5
    1/02/2010|222|'CITY3'|'STATE1'|3350|1270|9/08/1974|1
    1/02/2010|222|'CITY3'|'STATE1'|3350|1270|11/12/1980|2
    1/02/2010|222|'CITY3'|'STATE1'|3350|1270|5/12/1989|3
    1/02/2010|222|'CITY4'|'STATE1'|3350|8308|5/12/1989|4
    1/02/2010|222|'CITY4'|'STATE1'|3353|2278|5/12/1989|5
    1/02/2010|222|'CITY4'|'STATE1'|3353|2278|5/12/1989|6
    1/02/2010|222|'CITY4'|'STATE1'|3353|2278|4/08/1994|7
    1/02/2010|222|'CITY4'|'STATE1'|3353|2278|4/08/1994|8
    1/02/2010|222|'CITY4'|'STATE1'|3353|2278|4/08/1994|9
    1/02/2010|222|'CITY3'|'STATE1'|3350|1270|30/06/2000|10
    1/02/2010|222|'CITY4'|'STATE1'|3353|2278|4/12/2003|11
    1/02/2010|222|'CITY3'|'STATE1'|3350|9747|20/09/2004|12
    1/02/2010|222|'CITY4'|'STATE1'|3350|1794|22/10/2004|13
    1/02/2010|222|'CITY3'|'STATE1'|3350|1270|20/08/2009|14
    1/02/2010|222|'CITY4'|'STATE1'|3350|2278|17/09/2009|15
    1/02/2010|222|'CITY4'|'STATE1'|3350|2278|28/09/2009|16
    1/02/2010|222|'CITY3'|'STATE1'|3350|1270|1/10/2009|17
    1/02/2010|222|'CITY3'|'STATE1'|3350|1270|1/10/2009|18
    1/02/2010|222|'CITY4'|'STATE1'|3350|8308|2/10/2009|19
    1/02/2010|222|'CITY4'|'STATE1'|3353|2278|2/10/2009|20
    1/02/2010|333|'CITY5'|'STATE2'|5001|9905|17/06/2002|1
    1/02/2010|333|'CITY6'|'STATE2'|5016|3948|24/06/2002|2
    1/02/2010|333|'CITY5'|'STATE2'|5001|9905|3/09/2009|3
    1/02/2010|333|'CITY7'|'STATE2'|5020|6444|3/09/2009|4All I want is the rownumer having maximum rn value from abouve quey.
    How do I achieve this? Much appreciate a quick response.

    Hi,
    Not sure I understand what you mean by maximum rn value? Is it the same value in every row for each partition?
    If that's the case you could use count:
    SELECT DISTINCT
          DATE_FIELD
          ,ACCT_ID
          ,CITY
          ,STATE
          ,ZIP
          ,UNIQUE_ID
          ,OPEN_DT
          ,COUNT(*) OVER (PARTITION BY ACCT_ID) cnt
    FROM TABLE1
    WHERE 1=1
    AND OPEN_DT IS NOT NULLIf not, then perhaps can you post sample data showing what is it that you expect from the output, please? Something along the lines of what you have posted for the current output you're obtaining.

  • Analytic Functions in CONNECT BY Queries

    Can analytic functions be used in a CONNECT BY query? Are there limits?
    This problem occurs in Oracle 11.1.0.6.0, 10.2 and 10.1.
    Here is the presenting problem:
    Starting with data like this:
    CREATE TABLE     enrollment
    (      name          VARCHAR2 (10)
    ,      coursenumber     NUMBER
    INSERT INTO enrollment (name, coursenumber) VALUES ('Ted',      101);
    INSERT INTO enrollment (name, coursenumber) VALUES ('Ted',      102);
    INSERT INTO enrollment (name, coursenumber) VALUES ('Ted',      103);
    INSERT INTO enrollment (name, coursenumber) VALUES ('Mary',      102);
    INSERT INTO enrollment (name, coursenumber) VALUES ('Mary',      104);
    INSERT INTO enrollment (name, coursenumber) VALUES ('Hiro',      101);
    INSERT INTO enrollment (name, coursenumber) VALUES ('Hiro',      104);
    INSERT INTO enrollment (name, coursenumber) VALUES ('Hiro',      105);
    COMMIT;I'm trying to get cross-tab output like this:
    NAME       TXT
    Hiro         101            104  105
    Mary              102       104
    Ted          101  102  103without knowing before-hand what course numbers, or even how many course numbers, will be in the results.
    My strategy was to use LPAD to make the course numbers always occupy 5 spaces.
    If n "columns" needed to be left blank before the number, I wanted to add 5n extra spaces.
    I tried this:
    WITH     universe     AS
         SELECT     name
         ,     coursenumber
         ,     DENSE_RANK () OVER ( ORDER BY        coursenumber)     AS cnum
         ,     ROW_NUMBER () OVER ( PARTITION BY  name
                                   ORDER BY          coursenumber
                           )                         AS snum
         FROM     enrollment
    SELECT     name
    ,     REPLACE ( SYS_CONNECT_BY_PATH ( LPAD ( TO_CHAR (coursenumber)
                                              , 5 * (cnum - LAG (cnum, 1, 0)
                                                                   OVER ( PARTITION BY  name
                                                                             ORDER BY          coursenumber
              )     AS txt
    FROM     universe
    WHERE     CONNECT_BY_ISLEAF     = 1
    START WITH     snum     = 1
    CONNECT BY     snum     = PRIOR snum + 1
    AND          name     = PRIOR name
    ORDER BY     name
    ;but the txt column was always NULL.
    I tried showing some of the intermediate calculations:
    WITH     universe     AS
         SELECT     name
         ,     coursenumber
         ,     DENSE_RANK () OVER ( ORDER BY        coursenumber)     AS cnum
         ,     ROW_NUMBER () OVER ( PARTITION BY  name
                                   ORDER BY          coursenumber
                           )                         AS snum
         FROM     enrollment
    SELECT     name
    ,     REPLACE ( SYS_CONNECT_BY_PATH ( LPAD ( TO_CHAR (coursenumber)
                                              , 5 * (cnum - LAG (cnum, 1, 0)
                                                                   OVER ( PARTITION BY  name
                                                                             ORDER BY          coursenumber
              )     AS txt
    ,     coursenumber
    ,     cnum
    ,     LAG (cnum, 1, 0) OVER ( PARTITION BY  name
                                                ORDER BY          coursenumber
                         )      AS lag_cnum
    FROM     universe
    -- WHERE     CONNECT_BY_ISLEAF     = 1
    START WITH     snum     = 1
    CONNECT BY     snum     = PRIOR snum + 1
    AND          name     = PRIOR name
    ORDER BY     name
    ;and they all seemed reasonable:
    NAME       TXT                            COURSENUMBER       CNUM   LAG_CNUM
    Hiro                                               101          1          0
    Hiro                                               104          4          1
    Hiro                                               105          5          4
    Mary                                               102          2          0
    Mary                                               104          4          2
    Ted                                                101          1          0
    Ted                                                102          2          1
    Ted                                                103          3          2but txt was still NULL.
    I got around the problem by computing the LAG in a sub-query (see [this thread|http://forums.oracle.com/forums/message.jspa?messageID=3875566#3875566]), but I'd like to know why LAG didn't work in the CONNECT BY query, or at least within SYS_CONNECT_BY_PATH.
    I've had other problems before trying to use analytic functions in CONNECT BY queries. Sometimes, the presence of an analytic function woudl cause CONNECT BY to never work, sometimes it would destroy the order of the output. (Sorry, I don't have those examples handy now.)
    Are there limitations on using analytic functions in a CONNECT BY query?
    is there a work-around other than computing the analytic functions in a sub-query?
    Thanks.

    how about
    SQL> with temp as
      2  (select name
      3       , coursenumber
      4    from enrollment
      5  )
      6  , courses as
      7  (select distinct
      8          coursenumber
      9     from enrollment
    10  )
    11  select name
    12       , replace (sys_connect_by_path (case when t_course is not null
    13         then rpad (t_course, 8, ' ')
    14         else rpad (' ', 8, ' ')
    15         end, ';'), ';', ' ') scbp
    16    from (
    17  select t.name
    18       , t.coursenumber t_course
    19       , c.coursenumber c_course
    20       , row_number() over (partition by t.name
    21                                order by c.coursenumber
    22                           ) rn
    23    from temp  t partition by (name)
    24    right outer
    25    join courses c
    26      on c.coursenumber = t.coursenumber
    27  )
    28   where connect_by_isleaf = 1
    29   start with rn = 1
    30   connect by rn = prior rn + 1
    31   and name = prior name;
    NAME       SCBP
    Hiro        101                        104      105
    Mary                 102               104
    Ted         101      102      103

  • Analytic Functions in PL/SQL

    This procedure won't compile - the word PARTITION seems to be the problem - with this error...
    PLS-00103: Encountered the symbol "(" when expecting one of the following: , from
    The query in the cursor runs correctly as a stand-alone query. Can analytic functions not be used in PL/SQL cursors?
    Thanks.
    CREATE OR REPLACE
    PROCEDURE TestAnalyticFunction IS
    CURSOR GetAllTransTypes_Cursor IS
    select transaction_class.trans_desc,
    transaction_code.trans_type ,
    transaction_code.trans_code,
    transaction_code.trans_code_desc,
    sum(tr_tx_amt) as trans_sum,
    RATIO_TO_REPORT(sum(tr_tx_amt)) OVER
    (PARTITION BY transaction_code.trans_type) AS Percentage
    from transaction_code,
    transaction_class,
    transactions
    where TR_POST_DT IS NOT NULL
    AND TR_POST_DT >= '01-DEC-2000'
    AND TR_POST_DT <= '31-JAN-2001'
    AND TRANSACTION_CODE.TRANS_CLASS = TRANSACTION_CLASS.TRANS_CLASS_ID
    AND TRANSACTION_CODE.TRANS_CODE = TRANSACTIONS.TR_TX_CODE
    AND TRANSACTION_CODE.TRANS_TYPE in (1,2,3,4,5,8)
    group by transaction_code.trans_type,
    trans_class,
    trans_desc,
    trans_code,
    trans_code_desc
    order by transaction_code.trans_type, trans_code;
    TYPE TransClassDescType IS TABLE OF transaction_class.trans_desc%TYPE;
    TYPE TransCodeTypeType IS TABLE OF transaction_code.trans_type%TYPE;
    TYPE TransCodeCodeType IS TABLE OF transaction_code.trans_code%TYPE;
    TYPE TransCodeDescType IS TABLE OF transaction_code.trans_code_desc%TYPE;
    TYPE TotalType IS TABLE OF NUMBER(14,2);
    TYPE TotalPctType IS TABLE OF NUMBER(6, 2);
    TransClassDesc TransClassDescType;
    TransCodeType TransCodeTypeType;
    TransCodeCode TransCodeCodeType;
    TransCodeDesc TransCodeDescType;
    Total TotalType;
    TotalPct TotalPctType;
    BEGIN
    OPEN GetAllTransTypes_Cursor;
    FETCH GetAllTransTypes_Cursor BULK COLLECT INTO TransClassDesc,TransCodeType,TransCodeCode,TransCodeDesc,
    Total, TotalPct;
    CLOSE GetAllTransTypes_Cursor;
    END TestAnalyticFunction;
    null

    Some functions just don't seem to work in PL/SQL even though they work fine in SQL*Plus.
    Two such functions I found were NVL2 and RATIO_TO_REPORT.
    Have no clue why yet.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Dale Johnson ([email protected]):
    This procedure won't compile - the word PARTITION seems to be the problem - with this error...
    PLS-00103: Encountered the symbol "(" when expecting one of the following: , from
    The query in the cursor runs correctly as a stand-alone query. Can analytic functions not be used in PL/SQL cursors?
    Thanks.
    CREATE OR REPLACE
    PROCEDURE TestAnalyticFunction IS
    CURSOR GetAllTransTypes_Cursor IS
    select transaction_class.trans_desc,
    transaction_code.trans_type ,
    transaction_code.trans_code,
    transaction_code.trans_code_desc,
    sum(tr_tx_amt) as trans_sum,
    RATIO_TO_REPORT(sum(tr_tx_amt)) OVER
    (PARTITION BY transaction_code.trans_type) AS Percentage
    from transaction_code,
    transaction_class,
    transactions
    where TR_POST_DT IS NOT NULL
    AND TR_POST_DT >= '01-DEC-2000'
    AND TR_POST_DT <= '31-JAN-2001'
    AND TRANSACTION_CODE.TRANS_CLASS = TRANSACTION_CLASS.TRANS_CLASS_ID
    AND TRANSACTION_CODE.TRANS_CODE = TRANSACTIONS.TR_TX_CODE
    AND TRANSACTION_CODE.TRANS_TYPE in (1,2,3,4,5,8)
    group by transaction_code.trans_type,
    trans_class,
    trans_desc,
    trans_code,
    trans_code_desc
    order by transaction_code.trans_type, trans_code;
    TYPE TransClassDescType IS TABLE OF transaction_class.trans_desc%TYPE;
    TYPE TransCodeTypeType IS TABLE OF transaction_code.trans_type%TYPE;
    TYPE TransCodeCodeType IS TABLE OF transaction_code.trans_code%TYPE;
    TYPE TransCodeDescType IS TABLE OF transaction_code.trans_code_desc%TYPE;
    TYPE TotalType IS TABLE OF NUMBER(14,2);
    TYPE TotalPctType IS TABLE OF NUMBER(6, 2);
    TransClassDesc TransClassDescType;
    TransCodeType TransCodeTypeType;
    TransCodeCode TransCodeCodeType;
    TransCodeDesc TransCodeDescType;
    Total TotalType;
    TotalPct TotalPctType;
    BEGIN
    OPEN GetAllTransTypes_Cursor;
    FETCH GetAllTransTypes_Cursor BULK COLLECT INTO TransClassDesc,TransCodeType,TransCodeCode,TransCodeDesc,
    Total, TotalPct;
    CLOSE GetAllTransTypes_Cursor;
    END TestAnalyticFunction;<HR></BLOCKQUOTE>
    null

  • Having clause with Analytic function

    can you pls let me know if we can use HAVING clause with analytic function
    select eid,empno,sum(sal) over(partition by year)
    from employee
    where dept = 'SALES'
    having sum(sal) > 10000I m getting error while using the above,
    IS that we can use HAVING clause with partition by
    Thanks in advance

    Your having clause isn't using an analytical function, is using a regular aggregate function.
    You also can't use analytical functions in the where clause or having clause like that as they are windowing functions and belong at the top of the query.
    You would have to wrap the query to achieve what you want e.g.
    SQL> ed
    Wrote file afiedt.buf
      1  select deptno, total_sal
      2  from (
      3        select deptno,sum(sal) over (partition by deptno) as total_sal
      4        from   emp
      5       )
      6  group by deptno, total_sal
      7* having total_sal > 10000
    SQL> /
        DEPTNO  TOTAL_SAL
            20      10875
    SQL>

  • Alternate for analytic functions

    Hello All,
    I'm trying to write a query without using analytic functions.
    Using Analytic func,
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    "CORE     11.2.0.2.0     Production"
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    SELECT id, sal, rank() OVER (PARTITION BY ID ORDER BY SAL) rnk FROM
    (SELECT 10 AS id, 100 AS sal FROM DUAL
        UNION ALL
        SELECT 10, 300 FROM DUAL
        UNION ALL
        SELECT 10, 400 FROM DUAL
        UNION ALL
        SELECT 20, 200 FROM DUAL
        UNION ALL
        SELECT 20, 200 FROM DUAL
        UNION ALL
        SELECT 20, 300 FROM DUAL
        UNION ALL
        SELECT 30, 100 FROM DUAL
        UNION ALL
        SELECT 40, 100 FROM DUAL
        UNION ALL
        SELECT 40, 200 FROM DUAL
        ) Expected results. I want these results without analytic functions.
    10     100     1
    10     300     2
    10     400     3
    20     200     1
    20     200     1
    20     300     3
    30     100     1
    40     100     1
    40     200     2

    Hi,
    SamFisher wrote:
    Thank You Frank. That was simple.
    I was trying to get the reults without using analytical functions. Just trying to improve my SQL skills. Yes, I admit that practicising using the wrong tools can improve your SQL skills, but I think there's a lot to be said for practising using the right tools, too.
    I tried all sort of things. I thought hierarchical query would do it but hard luck for me.Do you want to use a CONNECT BY query for this? Here's one way:
    WITH     got_max_level            AS
         SELECT       id
         ,       sal
         ,       MAX (LEVEL)     AS max_level
         FROM       table_x
         CONNECT BY NOCYCLE  id        = PRIOR id
              AND          sal       >= PRIOR sal
              AND     (   sal       >  PRIOR sal
                   OR  ROWID > PRIOR ROWID
         GROUP BY  id
         ,            sal
    ,     got_cnt          AS
         SELECT       id
         ,       sal
         ,       COUNT (*)     AS cnt
         FROM       table_x
         GROUP BY  id
         ,            sal
    SELECT       x.id
    ,       x.sal
    ,       l.max_level + 1 - c.cnt     AS rnk
    FROM       table_x        x
    JOIN       got_max_level  l  ON   x.id     = l.id
                         AND      x.sal     = l.sal
    JOIN       got_cnt      c  ON      x.id     = c.id
                         AND      x.sal     = c.sal
    ORDER BY  x.id
    ,            x.sal
    ;This is even less efficient, as well as more complicated, than the scalar sub-query solution.

  • Can i use an analytic function instead of a group by clause?

    Can i use an analytic function instead of a group by clause? Will this help in any performance improvement?

    analytic can sometimes avoid scanning the table more than once :
    SQL> select ename,  sal, (select sum(sal) from emp where deptno=e.deptno) sum from emp e;
    ENAME             SAL        SUM
    SMITH             800      10875
    ALLEN            1600       9400
    WARD             1250       9400
    JONES            2975      10875
    MARTIN           1250       9400
    BLAKE            2850       9400
    CLARK            2450       8750
    SCOTT            3000      10875
    KING             5000       8750
    TURNER           1500       9400
    ADAMS            1100      10875
    JAMES             950       9400
    FORD             3000      10875
    MILLER           1300       8750
    14 rows selected.
    Execution Plan
    Plan hash value: 3189885365
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |    14 |   182 |     3   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE    |      |     1 |     7 |            |          |
    |*  2 |   TABLE ACCESS FULL| EMP  |     5 |    35 |     3   (0)| 00:00:01 |
    |   3 |  TABLE ACCESS FULL | EMP  |    14 |   182 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - filter("DEPTNO"=:B1)which could be rewritten as
    SQL> select ename, sal, sum(sal) over (partition by deptno) sum from emp e;
    ENAME             SAL        SUM
    CLARK            2450       8750
    KING             5000       8750
    MILLER           1300       8750
    JONES            2975      10875
    FORD             3000      10875
    ADAMS            1100      10875
    SMITH             800      10875
    SCOTT            3000      10875
    WARD             1250       9400
    TURNER           1500       9400
    ALLEN            1600       9400
    JAMES             950       9400
    BLAKE            2850       9400
    MARTIN           1250       9400
    14 rows selected.
    Execution Plan
    Plan hash value: 1776581816
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |    14 |   182 |     4  (25)| 00:00:01 |
    |   1 |  WINDOW SORT       |      |    14 |   182 |     4  (25)| 00:00:01 |
    |   2 |   TABLE ACCESS FULL| EMP  |    14 |   182 |     3   (0)| 00:00:01 |
    ---------------------------------------------------------------------------well, there is no group by and no visible performance enhancement in my example, but Oracle7, you must have written the query as :
    SQL> select ename, sal, sum from emp e,(select deptno,sum(sal) sum from emp group by deptno) s where e.deptno=s.deptno;
    ENAME             SAL        SUM
    SMITH             800      10875
    ALLEN            1600       9400
    WARD             1250       9400
    JONES            2975      10875
    MARTIN           1250       9400
    BLAKE            2850       9400
    CLARK            2450       8750
    SCOTT            3000      10875
    KING             5000       8750
    TURNER           1500       9400
    ADAMS            1100      10875
    JAMES             950       9400
    FORD             3000      10875
    MILLER           1300       8750
    14 rows selected.
    Execution Plan
    Plan hash value: 2661063502
    | Id  | Operation            | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT     |      |    14 |   546 |     8  (25)| 00:00:01 |
    |*  1 |  HASH JOIN           |      |    14 |   546 |     8  (25)| 00:00:01 |
    |   2 |   VIEW               |      |     3 |    78 |     4  (25)| 00:00:01 |
    |   3 |    HASH GROUP BY     |      |     3 |    21 |     4  (25)| 00:00:01 |
    |   4 |     TABLE ACCESS FULL| EMP  |    14 |    98 |     3   (0)| 00:00:01 |
    |   5 |   TABLE ACCESS FULL  | EMP  |    14 |   182 |     3   (0)| 00:00:01 |
    -----------------------------------------------------------------------------So maybe it helps

  • How can rewrite the Query using Analytical functions ?

    Hi,
    I have the SQL script as shown below ,
    SELECT cd.cardid, cd.cardno,TT.TRANSACTIONTYPECODE,TT.TRANSACTIONTYPEDESC DESCRIPTION,
    SUM (NVL (CASE tt.transactiontypecode
    WHEN 'LOAD_ACH'
    THEN th.transactionamount
    END, 0)
    ) AS load_ach,
    SUM
    (NVL (CASE tt.transactiontypecode
    WHEN 'FUND_TRANSFER_RECEIVED'
    THEN th.transactionamount
    END,
    0
    ) AS Transfersin,
    ( SUM (NVL (CASE tt.transactiontypecode
    WHEN 'FTRNS'
    THEN th.transactionamount
    END,
    0
    ) +
    SUM (NVL (CASE tt.transactiontypecode
    WHEN 'SEND_MONEY'
    THEN th.transactionamount
    END, 0)
    )) AS Transferout,
    SUM (NVL (CASE tt.transactiontypecode
    WHEN 'WITHDRAWAL_ACH'
    THEN th.transactionamount
    END, 0)
    ) AS withdrawal_ach,
    SUM (NVL (CASE tt.transactiontypecode
    WHEN 'WITHDRAWAL_CHECK'
    THEN th.transactionamount
    END, 0)
    ) AS withdrawal_check,
    ( SUM (NVL (CASE tt.transactiontypecode
    WHEN 'WITHDRAWAL_CHECK_FEE'
    THEN th.transactionamount
    END,
    0
    ) +
    SUM (NVL (CASE tt.transactiontypecode
    WHEN 'REJECTED_ACH_LOAD_FEE'
    THEN th.transactionamount
    END,
    0
    ) +
    SUM (NVL (CASE tt.transactiontypecode
    WHEN 'WITHDRAWAL_ACH_REV'
    THEN th.transactionamount
    END,
    0
    ) +
    SUM (NVL (CASE tt.transactiontypecode
    WHEN 'WITHDRAWAL_CHECK_REV'
    THEN th.transactionamount
    END,
    0
    ) +
    SUM
    (NVL (CASE tt.transactiontypecode
    WHEN 'WITHDRAWAL_CHECK_FEE_REV'
    THEN th.transactionamount
    END,
    0
    ) +
    SUM
    (NVL (CASE tt.transactiontypecode
    WHEN 'REJECTED_ACH_LOAD_FEE_REV'
    THEN th.transactionamount
    END,
    0
    ) +
    SUM (NVL (CASE tt.transactiontypecode
    WHEN 'OVERDRAFT_FEE_REV'
    THEN th.transactionamount
    END, 0)
    ) +
    SUM (NVL (CASE tt.transactiontypecode
    WHEN 'STOP_CHECK_FEE_REV'
    THEN th.transactionamount
    END,
    0
    ) +
    SUM (NVL (CASE tt.transactiontypecode
    WHEN 'LOAD_ACH_REV'
    THEN th.transactionamount
    END, 0)
    ) +
    SUM (NVL (CASE tt.transactiontypecode
    WHEN 'OVERDRAFT_FEE'
    THEN th.transactionamount
    END, 0)
    ) +
    SUM (NVL (CASE tt.transactiontypecode
    WHEN 'STOP_CHECK_FEE'
    THEN th.transactionamount
    END, 0)
    )) AS Fee,
    th.transactiondatetime
    FROM carddetail cd,
    transactionhistory th,
    transactiontype tt,
    (SELECT rmx_a.cardid, rmx_a.endingbalance prev_balance, rmx_a.NUMBEROFDAYS
    FROM rmxactbalreport rmx_a,
    (SELECT cardid, MAX (reportdate) reportdate
    FROM rmxactbalreport
    GROUP BY cardid) rmx_b
    WHERE rmx_a.cardid = rmx_b.cardid AND rmx_a.reportdate = rmx_b.reportdate) a
    WHERE th.transactiontypeid = tt.transactiontypeid
    AND cd.cardid = th.cardid
    AND cd.cardtype = 'P'
    AND cd.cardid = a.cardid (+)
    AND CD.CARDNO = '7116734387812758335'
    --AND TT.TRANSACTIONTYPECODE = 'FUND_TRANSFER_RECEIVED'
    GROUP BY cd.cardid, cd.cardno, numberofdays,th.transactiondatetime,tt.transactiontypecode,TT.TRANSACTIONTYPEDESC
    Ouput of the above query is :
    CARDID     CARDNO     TRANSACTIONTYPECODE     DESCRIPTION     LOAD_ACH     TRANSFERSIN     TRANSFEROUT     WITHDRAWAL_ACH     WITHDRAWAL_CHECK     FEE     TRANSACTIONDATETIME
    6005     7116734387812758335     FUND_TRANSFER_RECEIVED     Fund Transfer Received     0     3.75     0     0     0     0     21/09/2007 11:15:38 AM
    6005     7116734387812758335     FUND_TRANSFER_RECEIVED     Fund Transfer Received     0     272     0     0     0     0     05/10/2007 9:12:37 AM
    6005     7116734387812758335     WITHDRAWAL_ACH     Withdraw Funds via ACH     0     0     0     300     0     0     24/10/2007 3:43:54 PM
    6005     7116734387812758335     SEND_MONEY     Fund Transfer Sent     0     0     1     0     0     0     19/09/2007 1:17:48 PM
    6005     7116734387812758335     FUND_TRANSFER_RECEIVED     Fund Transfer Received     0     1     0     0     0     0     18/09/2007 7:25:23 PM
    6005     7116734387812758335     LOAD_ACH     Prepaid Deposit via ACH     300     0     0     0     0     0     02/10/2007 3:00:00 AM
    I want the output like for Load_ACH there should be one record etc.,
    Can any one help me , how can i rewrite the above query using analytical functions .,
    Sekhar

    Not sure of your requirements but this mayhelp reduce your code;
    <untested>
    SUM (
       CASE
       WHEN tt.transactiontypecode IN
          ('WITHDRAWAL_CHECK_FEE', 'REJECTED_ACH_LOAD_FEE', 'WITHDRAWAL_ACH_REV', 'WITHDRAWAL_CHECK_REV',
           'WITHDRAWAL_CHECK_FEE_REV', 'REJECTED_ACH_LOAD_FEE_REV', 'OVERDRAFT_FEE_REV','STOP_CHECK_FEE_REV',
           'LOAD_ACH_REV', 'OVERDRAFT_FEE', 'STOP_CHECK_FEE')
       THEN th.transactionamount
       ELSE 0) feeAlso, you might want to edit your post and use &#91;pre&#93; and &#91;/pre&#93; tags around your code for formatting.

  • Using Analytic functions in Cursors

    Hi,
    I am trying to use an analytic function as part of my select statement in a cursor declaration. However, i get a compilation error.
    Any idea?

    Hi,
    I am trying to use an analytic function as part of my select statement in a cursor declaration. However, i get a compilation error.
    Any idea?

  • How can I restrict the rows of a SELECT which uses analytical functions?

    Hello all,
    Can anyone please tell me how to restrict the following query:
    SELECT empno,
    ename,
    deptno,
    SUM(sal) over(PARTITION BY deptno) sum_per_dept
    FROM emp;
    I would need just the lines which have sum_per_dept>100, without using a SUBSELECT.
    Is there any way which is specific for analytical functions?
    Thank you in advance,
    Eugen
    Message was edited by:
    misailescu

    SQL> select empno,
      2  ename,
      3  deptno,sum_per_dept
      4  from
      5  (
      6  SELECT empno,
      7  ename,
      8  deptno,
      9  SUM(sal) over(PARTITION BY deptno) sum_per_dept
    10  FROM emp
    11  )
    12  where sum_per_dept>1000;
    EMPNO ENAME      DEPTNO SUM_PER_DEPT
    7839 KING           10         8750
    7782 CLARK          10         8750
    7934 MILLER         10         8750
    7902 FORD           20         6775
    7369 SMITH          20         6775
    7566 JONES          20         6775
    7900 JAMES          30         9400
    7844 TURNER         30         9400
    7654 MARTIN         30         9400
    7521 WARD           30         9400
    7499 ALLEN          30         9400
    7698 BLAKE          30         9400
    12 rows selected
    SQL>
    SQL> select empno,
      2  ename,
      3  deptno,sum_per_dept
      4  from
      5  (
      6  SELECT empno,
      7  ename,
      8  deptno,
      9  SUM(sal) over(PARTITION BY deptno) sum_per_dept
    10  FROM emp
    11  )
    12  where sum_per_dept>9000;
    EMPNO ENAME      DEPTNO SUM_PER_DEPT
    7900 JAMES          30         9400
    7844 TURNER         30         9400
    7654 MARTIN         30         9400
    7521 WARD           30         9400
    7499 ALLEN          30         9400
    7698 BLAKE          30         9400
    6 rows selected
    SQL> Greetings...
    Sim

  • Can you use a custom cursor with drag and drop?

    Hi there! I'm a newbie flash user and working on a simulation for a graduate course in instructional design. I'm using Flash Professional CC on Mac. Here's what I'm trying to do. I have several draggable sprites on the stage and three target sprites. I have specified the original x,y locations of the sprites and have set the end x,y locations as those of each of the three targets. Items must be dragged to one of the three targets.
    Some questions:
    1. Can I specify more than one End x,y location for a draggable sprite? I'm creating a lesson to teach kindergartners how to sort lunchroom waste. If they have a napkin, for example, it could either go into the compost OR into the recycling. In cases like this where an item could really be placed into more than one bin, I want them to get it right if they do either of those things, rather than forcing them to choose which one.
    2. To make my project more "fun" for kids, I wanted to customize the cursor with a graphic of  hand. When I tried this in the flash file it works perfectly until I add the drag and drop functionality for the wasted items. Then the cursor will more around  but not pick up any items. Once I revert back to the standard pointer, the correct drag and drop functionality is restored.
    3. I have it set to snap back to the original location if learner attempts to drop the item on the wrong target. I want to be able to play a sound file when that happens, as well as play a sound file when it lands on the correct target, as well as shrink the item and change its opacity so that it appears invisible. I want to give the illusion of it being placed into the bin. I have no idea as to the proper way to code these events so that they happen.
    4. I've watched dozens of hours of youtube tutorials before coming here. I'm a quick study, but am very new to action script. In one of the videos the developer showed referencing an external action script file which I don't think is an option in CC. The coding method he used seemed much more streamlined and "clean" than the chunks I'm working with now. Is there an easy way for me to code information about these objects  than the way I've got it here now? I hate starting new things with bad habits. The perils of self-teaching.
    Thanks!
    I'm pasting my code from the actions panel below so you can see what's going on:
    stop();
    /* Custom Mouse Cursor
    Replaces the default mouse cursor with the specified symbol instance.
    stage.addChild(customcursor);
    customcursor.mouseEnabled = false;
    customcursor.addEventListener(Event.ENTER_FRAME, fl_CustomMouseCursor);
    function fl_CustomMouseCursor(event:Event)
      customcursor.x = stage.mouseX;
      customcursor.y = stage.mouseY;
    Mouse.hide();
    //To restore the default mouse pointer, uncomment the following lines:
    customcursor.removeEventListener(Event.ENTER_FRAME, fl_CustomMouseCursor);
    stage.removeChild(customcursor);
    Mouse.show();
    //set up variables and objects for dragging
    var offset:int = 10;
    var appleStartX:int = 243;
    var appleStartY:int = 156;
    var appleEndX:int = 522;
    var appleEndY:int = 22;
    apple.buttonMode = true;
    apple.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
    apple.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
    var cupStartX:int = 39;
    var cupStartY:int = 266;
    var cupEndX:int = 520;
    var cupEndY:int = 175;
    cup.buttonMode = true;
    cup.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
    cup.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
    var barStartX:int = 178;
    var barStartY:int = 234;
    var barEndX:int = 522;
    var barEndY:int = 22;
    bar.buttonMode = true;
    bar.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
    bar.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
    var orangeStartX:int = 284;
    var orangeStartY:int = 102;
    var orangeEndX:int = 522;
    var orangeEndY:int = 22;
    orange.buttonMode = true;
    orange.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
    orange.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
    var bottleStartX:int = 172;
    var bottleStartY:int = 303;
    var bottleEndX:int = 520;
    var bottleEndY:int = 175;
    bottle.buttonMode = true;
    bottle.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
    bottle.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
    var bananaStartX:int = 113;
    var bananaStartY:int = 123;
    var bananaEndX:int = 522;
    var bananaEndY:int = 22;
    banana.buttonMode = true;
    banana.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
    banana.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
    var napkinStartX:int = 248;
    var napkinStartY:int = 271;
    var napkinEndX:int = 520;
    var napkinEndY:int = 175;
    napkin.buttonMode = true;
    napkin.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
    napkin.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
    var yogurtStartX:int = 27;
    var yogurtStartY:int = 136;
    var yogurtEndX:int = 518;
    var yogurtEndY:int = 329;
    yogurt.buttonMode = true;
    yogurt.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
    yogurt.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
    var strawberryStartX:int = 120;
    var strawberryStartY:int = 285;
    var strawberryEndX:int = 522;
    var strawberryEndY:int = 22;
    strawberry.buttonMode = true;
    strawberry.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
    strawberry.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
    var sandwichStartX:int = 7;
    var sandwichStartY:int = 364;
    var sandwichEndX:int = 522;
    var sandwichEndY:int = 22;
    sandwich.buttonMode = true;
    sandwich.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
    sandwich.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
    var juiceStartX:int = 88;
    var juiceStartY:int = 347;
    var juiceEndX:int = 518;
    var juiceEndY:int = 329;
    juice.buttonMode = true;
    juice.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
    juice.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
    var foilStartX:int = 39;
    var foilStartY:int = 416;
    var foilEndX:int = 520;
    var foilEndY:int = 175;
    foil.buttonMode = true;
    foil.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
    foil.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
    var waxbagStartX:int = 235;
    var waxbagStartY:int = 342;
    var waxbagEndX:int = 522;
    var waxbagEndY:int = 22;
    waxbag.buttonMode = true;
    waxbag.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
    waxbag.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
    function startDragging (e:MouseEvent) {
      e.currentTarget.startDrag();
    function stopDragging (e:MouseEvent) {
      e.currentTarget.stopDrag();
      switch (e.currentTarget) {
      case apple:
      if (apple.x < appleEndX - offset || apple.x > appleEndX + offset || apple.y < appleEndY - offset || apple.y > appleEndY + offset) {
      apple.x = appleStartX;
      apple.y = appleStartY;
      else {
      apple.x = appleEndX;
      apple.y = appleEndY;
      //checkGame();
      break;
      case sandwich:
    if (sandwich.x < sandwichEndX - offset || sandwich.x > sandwichEndX + offset || sandwich.y < sandwichEndY - offset || sandwich.y > sandwichEndY + offset) {
      sandwich.x = sandwichStartX;
      sandwich.y = sandwichStartY;
      else {
      sandwich.x = sandwichEndX;
      sandwich.y = sandwichEndY;
      //checkGame();
      break;
      case orange:
    if (orange.x < orangeEndX - offset || orange.x > orangeEndX + offset || orange.y < orangeEndY - offset || orange.y > orangeEndY + offset) {
      orange.x = orangeStartX;
      orange.y = orangeStartY;
      else {
      orange.x = orangeEndX;
      orange.y = orangeEndY;
      //checkGame();
      break;
      case strawberry:
    if (strawberry.x < strawberryEndX - offset || strawberry.x > strawberryEndX + offset || strawberry.y < strawberryEndY - offset || strawberry.y > strawberryEndY + offset) {
      strawberry.x = strawberryStartX;
      strawberry.y = strawberryStartY;
      else {
      strawberry.x = strawberryEndX;
      strawberry.y = strawberryEndY;
      //checkGame();
      break;
      case napkin:
    if (napkin.x < napkinEndX - offset || napkin.x > napkinEndX + offset || napkin.y < napkinEndY - offset || napkin.y > napkinEndY + offset) {
      napkin.x = napkinStartX;
      napkin.y = napkinStartY;
      else {
      napkin.x = napkinEndX;
      napkin.y = napkinEndY;
      //checkGame();
      break;
      case bar:
    if (bar.x < barEndX - offset || bar.x > barEndX + offset || bar.y < barEndY - offset || bar.y > barEndY + offset) {
      bar.x = barStartX;
      bar.y = barStartY;
      else {
      bar.x = barEndX;
      bar.y = barEndY;
      //checkGame();
      break;
      case juice:
    if (juice.x < juiceEndX - offset || juice.x > juiceEndX + offset || juice.y < juiceEndY - offset || juice.y > juiceEndY + offset) {
      juice.x = juiceStartX;
      juice.y = juiceStartY;
      else {
      juice.x = juiceEndX;
      juice.y = juiceEndY;
      //checkGame();
      break;
      case foil:
    if (foil.x < foilEndX - offset || foil.x > foilEndX + offset || foil.y < foilEndY - offset || foil.y > foilEndY + offset) {
      foil.x = foilStartX;
      foil.y = foilStartY;
      else {
      foil.x = foilEndX;
      foil.y = foilEndY;
      //checkGame();
      break;
      case banana:
    if (banana.x < bananaEndX - offset || banana.x > bananaEndX + offset || banana.y < bananaEndY - offset || banana.y > bananaEndY + offset) {
      banana.x = bananaStartX;
      banana.y = bananaStartY;
      else {
      banana.x = bananaEndX;
      banana.y = bananaEndY;
      //checkGame();
      break;
      case bottle:
    if (bottle.x < bottleEndX - offset || bottle.x > bottleEndX + offset || bottle.y < bottleEndY - offset || bottle.y > bottleEndY + offset) {
      bottle.x = bottleStartX;
      bottle.y = bottleStartY;
      else {
      bottle.x = bottleEndX;
      bottle.y = bottleEndY;
      //checkGame();
      break;
      case waxbag:
    if (waxbag.x < waxbagEndX - offset || waxbag.x > waxbagEndX + offset || waxbag.y < waxbagEndY - offset || waxbag.y > waxbagEndY + offset) {
      waxbag.x = waxbagStartX;
      waxbag.y = waxbagStartY;
      else {
      waxbag.x = waxbagEndX;
      waxbag.y = waxbagEndY;
      //checkGame();
      break;
      case cup:
    if (cup.x < cupEndX - offset || cup.x > cupEndX + offset || cup.y < cupEndY - offset || cup.y > cupEndY + offset) {
      cup.x = cupStartX;
      cup.y = cupStartY;
      else {
      cup.x = cupEndX;
      cup.y = cupEndY;
      //checkGame();
      break;
      case yogurt:
    if (yogurt.x < yogurtEndX - offset || yogurt.x > yogurtEndX + offset || yogurt.y < yogurtEndY - offset || yogurt.y > yogurtEndY + offset) {
      yogurt.x = yogurtStartX;
      yogurt.y = yogurtStartY;
      else {
      waxbag.x = waxbagEndX;
      waxbag.y = waxbagEndY;
      //checkGame();

    Some questions:
    1. Can I specify more than one End x,y location for a draggable sprite?
    yes, use an if-else statement
    I'm creating a lesson to teach kindergartners how to sort lunchroom waste. If they have a napkin, for example, it could either go into the compost OR into the recycling. In cases like this where an item could really be placed into more than one bin, I want them to get it right if they do either of those things, rather than forcing them to choose which one.
    2. To make my project more "fun" for kids, I wanted to customize the cursor with a graphic of  hand. When I tried this in the flash file it works perfectly until I add the drag and drop functionality for the wasted items. Then the cursor will more around  but not pick up any items. Once I revert back to the standard pointer, the correct drag and drop functionality is restored.
    assign your cursor's mouseEnabled property to false:
    yourcursor.mouseEnabled=false;
    3. I have it set to snap back to the original location if learner attempts to drop the item on the wrong target. I want to be able to play a sound file when that happens, as well as play a sound file when it lands on the correct target, as well as shrink the item and change its opacity so that it appears invisible. I want to give the illusion of it being placed into the bin. I have no idea as to the proper way to code these events so that they happen.
    use the sound class to create a sound:
    // initialize your correct sound once with
    var correctSound:Sound=new CorrectSound();  // add an mp3 sound to your library and assign it class = CorrectSound
    // apply the play() method everytime you want your sound to play:
    correctSound.play();
    // change an object's opacity:
    someobject.alpha = .3;  // partially visible
    someobject.alpha = 1;  // fully visible
    someobject.visible=false;  // not visible, at all.
    // change an object's scale
    someobject.scaleX=someobject.scaleY=.5;  // shink width and height by 2
    someobject.scaleX=someobject.scaleY=1;  // resize to original
    4. I've watched dozens of hours of youtube tutorials before coming here. I'm a quick study, but am very new to action script. In one of the videos the developer showed referencing an external action script file which I don't think is an option in CC. The coding method he used seemed much more streamlined and "clean" than the chunks I'm working with now. Is there an easy way for me to code information about these objects  than the way I've got it here now? I hate starting new things with bad habits. The perils of self-teaching.
    you could google: 
    actionscript 3 class coding
    actionscript 3 object oriented programming
    p.s.  you can simplify and streamline your coding by learning about arrays and using hitTestObject.

Maybe you are looking for

  • Unable to connect offcard terminal with jcop simulator

    Hi all, I have made a JavaCard applet, called DisplayApplet. I am using Eclipse with the JCOP tools plugin. But now I want to make use of an own Terminal that connects to the applet and communicates to it using APDUs. I don't have a smart card reader

  • My iPhone displays "Restore Needed" but won't stay up long enough to connect. A log shows CRC ERR

    My 2 year old iphone 4 was around 38% battery when I closed my eyes. (TV nap) When I opened my eyes, the apple logo was showing.  It repeatedly reboots.   If I use a wall power adapter I can get logged in and look around for maybe a minute before it

  • Installing LEGO NXT-G 1.1 or 2.0 on mac OSX 10.6

    Hello LabView,  I recently did a fresh install of Mac OSX 10.6 Snow Leopard Since then i'm unable to install the LEGO Mindstorms NXT-G 1.1 software (by LabView) It appears that the same is true for the latest version of NXT-G 2.0  In both cases, a di

  • Create a PDF Form and Email the entire form w/ responses

    I created a form in PDF and I want to e-mail the form with the responses in the fields... like a file-->send to-->mail reciepents as attachment... I want to e-mail the form with responses not just email the data file of the form...any suggestions..pl

  • ORA-00210: cannot open the specified control file

    Hi all, Initially we faced the following error: ORA-00214: control file '+DBDG/dws/controlfile/current.256.638648487' version 75647 inconsistent with file '+FLASHDG/dws/controlfile/current.256.638648489' version 75645 Then the following action: RMAN>