Group by having count error

I have this code with an error:
SELECT (CASE id_type
WHEN 4 THEN companyid
ELSE nric
END) AS customerid
FROM customer
GROUP BY customerid HAVING COUNT (*customerid*) = 1
The error is at the bold word with the error: Invalid identifier. How should I rewrite my sql statement?

SELECT CUSTOMERID FROM
SELECT (CASE id_type
WHEN 4 THEN companyid
ELSE nric
END) AS customerid
FROM customer
GROUP BY customerid HAVING COUNT (customerid) = 1

Similar Messages

  • Group by Having Count(*)

    Hi...
    I'm back again and I'm ever hopeful that I will get some needed help.
    I'm trying to use the groupby and having Count(*) on a table, but I think
    I have my group by wrong...I keep getting the wrong output.
    Here's my code:
    Select Course_ID,Count(*),Department_ID,Class_ID,Class_Room
    from Class
    Group By Course_ID,Department_ID,Class_ID,Class_Room
    Having Count(*) >=1
    and this is the output:
    COURS COUNT(*) DEPARTMENT_ID CLASS_ID CLASS_ROOM
    50 1 MATH 103600 140
    101 1 BIO 109100 180
    101 1 ENGL 108300 150
    115 1 HIST 108400 200
    183 1 PSYCH 103400 150
    183 1 PSYCH 108600 240
    184 1 HIST 104500 200
    198 1 PHILO 104200 150
    199 1 ENG 110300 255
    199 1 ECON 120200 235
    Now, what should be happeing is that Count should give me 2*101,2*183,2*199 but I keep
    getting 1 of each...
    Any ideas about where I'm going Wrong?

    Drake,
    In short, you are grouping on too many things. You need to group on only course_id when looking for duplicates, and then join the duplicate courses back to the course table to get the rest of the data:
    select c.course_id, c.department_id,
    c.class_id, c.class_room
    from class c,
    (select course_id, count(*) howmany
    from class
    group by course_id
    having count(*) > 1) dups
    where c.course_id = dups.course_id;
    Hi...
    I'm back again and I'm ever hopeful that I will get some needed help.
    I'm trying to use the groupby and having Count(*) on a table, but I think
    I have my group by wrong...I keep getting the wrong output.
    Here's my code:
    Select Course_ID,Count(*),Department_ID,Class_ID,Class_Room
    from Class
    Group By Course_ID,Department_ID,Class_ID,Class_Room
    Having Count(*) >=1
    and this is the output:
    COURS COUNT(*) DEPARTMENT_ID CLASS_ID CLASS_ROOM
    50 1 MATH 103600 140
    101 1 BIO 109100 180
    101 1 ENGL 108300 150
    115 1 HIST 108400 200
    183 1 PSYCH 103400 150
    183 1 PSYCH 108600 240
    184 1 HIST 104500 200
    198 1 PHILO 104200 150
    199 1 ENG 110300 255
    199 1 ECON 120200 235
    Now, what should be happeing is that Count should give me 2*101,2*183,2*199 but I keep
    getting 1 of each...
    Any ideas about where I'm going Wrong?

  • Count(field) group by having changed to an analytic function

    Goal: Be able to show columns with data not in the group by clause.
    I couldn't find this on the 'net either by looking here or by googling for it (unless I'm looking for the wrong thing). I'm doing a regular:
    select fielda, count(fielda)
    from some_table
    group by fielda1
    having count(field1) > 1;
    to find out where I have duplicates in a table (fielda). I get fielda and the count of those records back (ie X, 2). However, I want to add several more fields that may or may not be different for each of those records.
    For example:
    1 record has fielda = X, field2 = Test, field3 = Oracle, field4 = Unix
    1 record has fielda = X, field2 = Testa, field3 = Sybase, field4 = Windows.
    I want to be able to have the following output:
    X, 2 (count of records with fieldA = X), Test, Oracle, Unix
    X, 2 (count of records with fieldA = X), Testa, Sybase, Windows
    I'm not sure if this is one of those where I have to do a subquery on or not. Any ideas?
    Thanks as always!
    Vic

    Sorry, I misread your statement - it is poorly formatted. Besides incorrect use of aliases you are referencing columns that are not in inline view, therefore you must include it there:
    select  nsn,
            item_type_name,
            item_type_id,
            date_time_added,
            function_name
      from  (
             select  it.nsn,
                     it.item_type_name,
                     it.item_type_id,
                     it.date_time_added,
                     fn.function_name,
                     count(*) over (partition by it.nsn) cnt,
                     it.item_type_cat_id,
                     ic.item_category_id,
                     ic.function_id ic_function_id,
                     fn.function_id fn_function_id
               from  item_types it,
                     item_categories ic, functions fn
               where it.nsn is not null
                 and it.item_type_cat_id = ic.item_category_id
                 and ic.function_id = fn.function_id
      where cnt > 1
        and nsn is not null
        and item_type_cat_id = item_category_id
        and ic_function_id = fn_function_id
    order by nsn;SY.

  • A method of grouping a total count of errors by date

    Dear SQL Gurus,
    Can anyone guide me (with the script below) as to how I'm can group a total count of error by DISTINCT(CREATION_DATE)?
    11g Enterprise Edition Release 11.2.0.2.0
    SCRIPT:
    select
    CREATION_DATE, request_id, rpad (regexp_substr(summary,'[^\.|^:]+'), 60, '_') as "iCash Dep Error Summary",count(*)
    from BKS_OM.bks_icash_dep_errors
    group by CREATION_DATE, request_id, regexp_substr(summary,'[^\.|^:]+');
    RESULTS:
    CREATION_DATE REQUEST_ID iCash Dep Error Summary COUNT(*)
    02-JUL-12 415967 Validation Failure__________________________________________ 1
    02-JUL-12 415967 Validation Failure__________________________________________ 1
    02-JUL-12 415967 Validation Failure__________________________________________ 1
    02-JUL-12 415967 Validation Failure__________________________________________ 1
    02-JUL-12 415967 Validation Failure__________________________________________ 2
    06-JUL-12 417699 Validation Failure__________________________________________ 1
    06-JUL-12 417699 Validation Failure__________________________________________ 1
    06-JUL-12 417773 Validation Failure__________________________________________ 16
    02-JUL-12 415967 Validation Failure__________________________________________ 1
    06-JUL-12 417773 Validation Failure__________________________________________ 1
    Regards,
    DIBS812
    Edited by: DIBS812 on Aug 3, 2012 10:51 AM

    That did the trick John. Thank you for providing me the solution.
    Thanks everyone for your response!
    select trunc(creation_date), request_id,
    rpad(regexp_substr(summary,'[^\.|^:]+'), 60, '_') as "iCash Dep Error Summary",
    count(*)
    from bks_om.bks_icash_dep_errors
    group by trunc(creation_date), request_id, regexp_substr(summary,'[^\.|^:]+');
    TRUNC(CREATION_DATE) REQUEST_ID iCash Dep Error Summary COUNT(*)
    19-JUL-12 422601 Validation Failure__________________________________________ 326
    19-JUL-12 423343 Validation Failure__________________________________________ 383
    20-JUL-12 423650 Validation Failure__________________________________________ 439
    02-JUL-12 415967 Validation Failure__________________________________________ 53
    16-JUL-12 421687 Validation Failure__________________________________________ 277
    06-JUL-12 417699 Validation Failure__________________________________________ 21
    10-JUL-12 419189 Validation Failure__________________________________________ 124
    06-JUL-12 417773 Validation Failure__________________________________________ 124
    18-JUL-12 422529 Validation Failure__________________________________________ 269
    19-JUL-12 422894 Validation Failure__________________________________________ 326
    19-JUL-12 422901 Validation Failure__________________________________________ 326
    18-JUL-12 422357 Validation Failure__________________________________________ 277
    19-JUL-12 422865 Validation Failure__________________________________________ 326

  • HAVING clause error in JPA 2 examples

    In Chapter 8: Query Language of the Pro JPA 2 Mastering the Java Persistence API book, the jpqlExamples WAR has this query:
    SELECT e, COUNT(p)
    FROM Employee e JOIN e.projects p
    GROUP BY e
    HAVING COUNT(p) >= 2
    When executed, the following error occurs:
    java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
    Exception Description: Error compiling the query [SELECT e, COUNT(p) FROM Employee e JOIN e.projects p GROUP BY e HAVING COUNT(p) >= 2], line 1, column 80: invalid HAVING expression [COUNT(p) >= 2] for query with grouping [GROUP BY e]. The HAVING clause must specify search conditions over the grouping items or aggregate functions that apply to grouping items.
    I bring this us because I have an application which is getting the same error and need a fix. If the query is indeed legal in JPA 2, then why the error? If if it is my setup however, then I would like suggestions on fixing it. I am using GlassFish v3 (build 74.2), updated regularly with the Update Tool.

    The bug has been reopened. Now it says:
    Reopening because there is some debate about whether this should be supported
    by the spec. Some people read the spec to say the above query is allowed - I
    am not convinced, but discussion can be appended to this bug if necessary.
    This is Bug 308482, and I assume at least a few might want to take a look.
    https://bugs.eclipse.org/bugs/show_bug.cgi?id=308482

  • Can I write merge SQL statement having count(*)?

    Hi this is a followup question of my previous post. I tried to use a merge SQL statement to solve my problem but now I bump into another problem.
    Now I have a table where the field I need to update is a partial PK
    when using a merge SQL statement, I have to put a where clause that check if count(*) = 1 because of the PK constraint
    Where can I put the count(*) = 1 clause?
    Here are the details:
    I have two tables TA and TB, where TA contains the fields ID, FULLNAME, TYPE and TB contains the fields ID, FIRSTNAME
    I want to update the firstnames in TB to be the firstnames from TA where TB.ID = TA.ID and TA.TYPE = 'ABC'
    {ID, FIRSTNAME} are PKs but for the same ID, there can be more than 1 firstname.
    e.g.
    TA
    ID | FULLNAME | TYPE
    1 Caroline T ABC
    2 Mary C DEF
    3 Peter J ABC
    TB
    ID | FIRSTNAME
    1 Caroline
    1 Carol
    1 C,
    3 Peter
    I need to update TB with the new firstnames from TA where type is 'ABC' but only for those fields that have count(TB.ID) = 1
    when I try to run this SQL statement
    merge into TB B using TA A
    on (A.ID = B.ID and A.TYPE = 'ABC')
    when matched then update set B.FIRSTNAME = substr(A.FULLNAME, 1, instr(A.FULLNAME, ',') - 1)
    I got this error SQL Error: ORA-00001: unique constraint (TEST.PK_TB) violated
    which I believe is because I updated those fields say ID = 1, all with 'Caroline'
    that means I will have to add a clause having count(TB.ID) = 1
    How would you do it?
    Server is Oracle 11g
    Thank you!

    Hi,
    One way is to join ta and tb in the USING clause, and eliminate the duplicates there.
    MERGE INTO     tb     dst
    USING   (
             SELECT    ta.id
             ,           REGEXP_SUBSTR ( MIN (ta.fullname)
                                    , '^[^,]*'
                            )     AS firstname
             FROM      ta
             JOIN      tb  ON  ta.id     = tb.id
             WHERE     ta.type      = 'ABC'
             GROUP BY  ta.id
             HAVING    COUNT (*)     = 1
         )                   src
    ON     (scr.id      = dst.id)
    WHEN MATCHED THEN UPDATE
    SET     dst.firstname     = src.firstname
    ;If you'd care to post CREATE TABLE and INSERT statements for your sample data, then I could test this.
    I used REGEXP_SUBST instead of SUBSTR and INSTR to find the firstname, because I find it a little cleaner, and becuase it returns something even when there is no ',' in fullname, which I'm guessing is what you really want. (None of the fullnames in your sample data have ','s.) You could use SUBSTR and INSTR instead.

  • Using Disc Utility to copy my hard drive to a brand new external drive and am having the error "Unable to create...(Cannot allocate memory)".

    I'm not very tech savvy but am trying my best to use Disc Utility to copy my hard drive to a brand new external drive and am having the error "Unable to create...(Cannot allocate memory)".
    Last night no problems, woke this morning and it was freezing so I forced a restart and got the grey screen with the folder and question mark. Ran off to best buy to get an external drive... Please help! Thank you!

    I have done both. When I hold down the "C" key it pauses for a few seconds while the cd spins and then the flashing folder icon appears.
    Could be you have the wrong cd/dvd.  The mac will only boot a supported cd/dvd for your machine. The flashing question mark indicdates your machine could not find a valid os.
    When I hold down the "option" key for the startup manager the cursor comes up and moves but the actually manager doesn't come up no matter how long I leave the laptop on.
    Not sure.  Could be your machine does not support the startup manager. You would think the machine would ignore the key.
    Where did you get the dvd?  What is the number on the DVD?
    What machine do you have anyway?
    This site provides more information, but lacks security.
    "A serial number is a unique, identifying number or group of numbers and letters assigned to an individual piece of hardware or software. It's used for various things depending on the product / brand but what is your Mac's serial number for and more importantly... what is it hiding and what can it do for you ?"
    http://www.appleserialnumberinfo.com/Desktop/index.php
    or
    This site provides more information, but lacks security too.
    "A serial number is a unique, identifying number or group of numbers and letters assigned to an individual piece of hardware or software. It's used for various things depending on the product / brand but what is your Mac's serial number for and more importantly... what is it hiding and what can it do for you ?"
    http://www.appleserialnumberinfo.com/Desktop/index.php
    http://www.chipmunk.nl/klantenservice/applemodel.html
        ( hint by K Shaffer  )

  • Select query having count function is returning null

    Hi Everyone,
    Please see the query and help me to get this solved.
    DB version
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
    PL/SQL Release 10.2.0.1.0 - Production
    "CORE     10.2.0.1.0     Production"
    TNS for Linux: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - ProductionQUERY
    SELECT COUNT(*) as V_COUNT
          FROM LAB_ORDER_TMPLT_TEST
          WHERE TEST_ID IN
          (SELECT WEST_TEST_ID
                  FROM TEST_CODE_CONVERSION TCC
                  WHERE TCC.EAST_TEST_ID = 2769)
          GROUP BY LAB_ORDER_TMPLT_ID
          HAVING COUNT(*) > 1;
    It's returning null. Is there any way I can get the value as zero instead of null? Please help.Regards,
    BS2012.

    Hi,
    BS2012 wrote:
    Hi Everyone,
    Please see the query and help me to get this solved.
    DB version
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
    PL/SQL Release 10.2.0.1.0 - Production
    "CORE     10.2.0.1.0     Production"
    TNS for Linux: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - ProductionQUERY
    SELECT COUNT(*) as V_COUNT
    FROM LAB_ORDER_TMPLT_TEST
    WHERE TEST_ID IN
    (SELECT WEST_TEST_ID
    FROM TEST_CODE_CONVERSION TCC
    WHERE TCC.EAST_TEST_ID = 2769)
    GROUP BY LAB_ORDER_TMPLT_ID
    HAVING COUNT(*) > 1;
    It's returning null.
    Really? COUNT never returns NULL; it always returns 0 or a positive integer.
    Do you mean the query results in "no rows selected"?
    Is there any way I can get the value as zero instead of null? Please help.Do you want a query that will produce the same output as the query above, but will produce a single row containing 0 when the query above does not produce anything? That sounds like a job for an outer join:
    WITH    original_query  AS
           SELECT  COUNT(*) AS v_count
           FROM    lab_order_tmplt_test
           WHERE   test_id IN
                       (   SELECT  west_test_id
                           FROM        test_code_conversion tcc
                           WHERE   tcc.east_test_id = 2769
           GROUP BY  lab_order_tmplt_id
    SELECT     NVL (o.v_count, 0)     AS v_count
    FROM               dual
    LEFT OUTER JOIN  original_query  o  ON  o.v_count > 0
    ;If you'd care to post CREATE TABLE and INSERT statements for the sample data, then I could test this.

  • Group by having clause problem

    Hi,
    I have a query like this:
    select a.id,a.first_nm,a.last_nm,a.subgroup_id
    from temp a
    where (a.subgroup_id like 'D%' or a.subgroup_id like 'G%')
    group by a.id,a.first_nm,a.last_nm,a.subgroup_id having
    count(*) >1
    union
    select b.id,b.first_nm,b.last_nm,b.subgroup_id
    from temp b
    where b. subgroup_id like 'F%'
    group by b.id,b.first_nm,b.last_nm,b.subgroup_id having count(*) > 2;
    I want the result like this:
    10001 Wendy Lin DAP
    10001 Wendy Lin GMP
    10002 Jim Davis FAD
    10002 Jim Davis FIP
    10002 Jim Davis FIAP
    My query above didn't give the right result, Can someone help me?
    Thank you very much!
    Wendy

    You may like to try this way...
    select id,name,sub_id
    from a
    where id in (select id
    from a
    group by id
    having count(id)>1)
    order by id,name, sub_id asc;
    results are..
    ID NAME CODE
    1 wendy DIA
    1 wendy LCA
    1 wendy PLA
    2 jim CPR
    2 jim DIA
    2 jim PLA
    Hope this helps.

  • Having count- count(count(1))

    I have two queries below- first of which outputs one record, the Second query doesn't.
    Can you explain why First query returns always records, at least one record? In explanation, can you say which process is runned after which (something like where is runned firstly, then group by, then...)?
    --First:
    select count(count(1)) from dual
    where 1=2
    group by dummy
    having count(dummy) > 0;--1 row, value: 0
    --Second:
    select count(1) from dual
    where 1=2
    group by dummy
    having count(dummy) > 0;--0 rows

    Hi,
    Aggregate queries with nested aggregate functions (such as "COUNT (COUNT (1))") always return exactly 1 row, even if there are no rows in the table (or, as in your first example, no rows survive the WHERE clause).
    The outer layer of nested aggreate functions is evaluated after the GROUP BY and HAVING clauses have been applied.
    If you have a GROUP BY clause, but no nested aggregate fucntions, then the output contains one row for every distinct group, subject to the WHERE- and HAVING clauses. In your second example, no rows are left after the WHERE clause, so there will be no rows in the output.
    You can think of things as happening in this order
    (1) WHERE
    (2) GROUP BY
    (3) (inner) aggregate fucntions
    (4) HAVING
    (5) Nested aggregate functions
    The optimizer may not actually follow the steps above, but you won't notice that.
    Edited by: Frank Kulash on Mar 25, 2010 11:51 AM
    The following thread may help you:
    Re: group function

  • Another group by having problem I think ...

    I have a table defined like so ...
    create table mytable (
    subcode number,
    name varchar2(10)
    I suspect that I have records in this table that look like so ...
    SUBCODE NAME
    123 Jim
    123 Mary
    ... this is bad.
    I ran a query like this ...
    select subcode, name, count(subcode) from mytable group by subcode, name having count(subcode) > 1
    ... and got back zero results.
    Does this mean I DO NOT have duplicates?
    Thanks

    You do have duplicates but your statement doesn't show that since you are grouping by SUBCODE and NAME. Since your have the same SUBCODE but a different NAME for the duplicate SUBCODE you get only 1 result with your group by statement. Here are two examples:
    select subcode, name, count(subcode)
    from mytable
    group by subcode, name
       SUBCODE COUNT(SUBCODE)
           123              2
    select subcode, name, count(subcode)
    from mytable
    group by subcode, name
       SUBCODE NAME       COUNT(SUBCODE)
           123 JIM                     1
           123 MARY                    1This statement will give you what you are looking for:
    select subcode, name
    from mytable
    where subcode = (select subcode
                        from mytable
                        group by subcode
                        having count(subcode) > 1);

  • Create Table  From a Having Count Select

    Hello Folks, any ideas here, I need to create a table using the below 'Select' as the criteria.
    I have the following table and its has duplicate records, identified by double Unique_seq. I want to create a table of these else where, then delete them from schema.tablename.
    Schmea.tablename
    field1
    field2
    field3
    field4
    Unique_Seq
    SELECT Unique_Seq,COUNT(Unique_Seq)
    FROM Schema.Tablename
    GROUP BY Unique_Seq
    HAVING ( COUNT(Unique_Seq) > 1
    I want to create the table using all the fields from schema.tablename
    Thanks

    Thanks for the table script and insert statement.
    here is what you are looking for
    select * from tester_c;
    AD_ID                                    CD_ID                               UNIQUE_SEQ Z_MASTER_KEY
    OP0021889/10                             OP0021889/10                            529832 NNCC00491362OP0021889/1025-JAN-10
                                             OP0021889/10                            529832 NNCC0049136225-JAN-10
                                             OP0022096/10                            539481 NNCC0060037812-JAN-10
    OP0022096/10                             OP0022096/10                            539481 NNCC00600378OP0022096/1012-JAN-10
    LI0192                                   IK735241                                 53925 PP54TH34120988
                                             KL1923836                                65478 BG7892534KL1923836
                                             KL1923836                                65478 BG7892534KL1923836
    PQ8712346                                BN27345236                               64877 7234723642
    8 rows selected.
    Elapsed: 00:00:00.01Pushing duplicate data into a new table tester_c_dup
    CREATE Table tester_c_dup as SELECT * FROM tester_c A WHERE a.rowid > ANY (SELECT  B.rowid FROM
            Tester_c B
         WHERE
            a.Unique_Seq = B.Unique_Seq)
    select * from tester_c_dup;
    AD_ID                                    CD_ID                               UNIQUE_SEQ Z_MASTER_KEY
                                             OP0021889/10                            529832 NNCC0049136225-JAN-10
    OP0022096/10                             OP0022096/10                            539481 NNCC00600378OP0022096/1012-JAN-10
                                             KL1923836                                65478 BG7892534KL1923836
    Elapsed: 00:00:00.01Deleting duplicate data from tester_c table
    DELETE FROM tester_c A WHERE a.rowid > ANY (SELECT  B.rowid FROM
            Tester_c B
         WHERE
            a.Unique_Seq = B.Unique_Seq)
    select * from tester_c;
    AD_ID                                    CD_ID                               UNIQUE_SEQ Z_MASTER_KEY
    OP0021889/10                             OP0021889/10                            529832 NNCC00491362OP0021889/1025-JAN-10
                                             OP0022096/10                            539481 NNCC0060037812-JAN-10
    LI0192                                   IK735241                                 53925 PP54TH34120988
                                             KL1923836                                65478 BG7892534KL1923836
    PQ8712346                                BN27345236                               64877 7234723642
    Elapsed: 00:00:00.00HTH,
    Prazy

  • Error loading Cache group but Cache group created with out error

    Hi
    I have created a cache group but when I load that cache group I get following error:
    Command> load cache group SecondCache commit every 1 rows;
    5056: The cache operation fails: error_type=<Oracle Error>, error_code=<972>, error_message:ORA-00972: identifier is too long
    5037: An error occurred while load TESTUSER.SECONDCACHE:Load failed (ORA-00972: identifier too long)
    The command failed.
    Please help.
    Looking forward for your reply.
    /Ahmad

    Hi Chris!
    Thanks for urgent response. I solved my problem to some extent but want to share.
    Acctualy I was having a column named # which is a primary key also. When I change that column name from # to some other name like some characters then the cahe group is loaded successfuly.
    Is there anyway in TimesTen to load columns names # .
    I read in the documentation of TimesTen that it allows columns names as # , so it is the reason it is creating the cache group but fails to load do not know the reason.
    The code for creating cache group is as follows:
    create cache group MEASCache from testuser."MEAS"("UPDATED" number not
    null,"UNOCCUPIEDRECORD" number not null,"VALUECURRENT" number not null,"EQSFREF
    " number not null,"IMPLEMENTED" number not null,"FORMAT" number not null,"#" number not null,primary key("#"))
    When I change the # column to like eg Identity it works fine.
    /Ahmad

  • Subscript beyond count error

    Hi I've tried the following code but getting the error subscript beyond count error
    create or replace procedure test(
                                       p_srrce               in   DIM_AD.DE%type,
                                       p_date         in   varchar2,
                                       p_asset_id       in   DISET.PE_ID%type,
                                      p_nt_id              in    FAT_T.DT_ID%type,
                                        chek_status                         out varchar2,
                                       logs_dat                        out varchar2
    IS
    TYPE da_list  IS  TABLE OF FAT_T.DT_ID%TYPE;
    TYPE pd_list  IS TABLE OF FAT_T.pd%TYPE;
    TYPE v_txt_list  IS TABLE OF FAT_T.v_txt%TYPE;
    TYPE ttime_list IS TABLE OF FAT_T.ttime%TYPE;
    type t_rowid IS TABLE OF rowid INDEX BY binary_INTEGER;
      v_d_srce             varchar2(222);
      v_prdat        date ;
    no_d_eep exception;
         v_da_list  da_list ;
         v_pd_list  pd_list ;
         v_v_txt_list  v_txt_list ;
         v_ttime_list  ttime_list ;
         v_rowid  t_rowid ;
    BEGIN
      v_d_srce             :=   trim(p_srrce);
      v_prdat       :=   to_date(trim(p_date),'mm/dd/yyyy');
        DBMS_OUTPUT.PUT_LINE ( 'value v_prdat '||v_prdat );   
    ------   After executing this procedure the output statemnt has come till here after the got the error subscript beyond count
      SELECT     
                     DT_ID,
                  pd,
                    v_txt,
                      ttime
                       fdp.ROWID
              bulk collect  into  v_da_list , v_pd_list ,v_v_txt_list , v_ttime_list,v_rowid            
                  FROM
                       FAT_T
                 WHERE   
                        pd = NVL(p_asset_id ,pd)
                       AND DT_ID = NVL(p_nt_id ,DT_ID)
                       AND pedt=v_prdat ;
      FOR i in    v_da_list.first .. v_da_list.last     LOOP
          DBMS_OUTPUT.PUT_LINE ( 'Values are '||v_da_list(i) );
      END LOOP ;  
         EXCEPTION
        END;
    Please help in this

    Hi,
    it's hard to reproduce without having your data at hand.
    Is it possible for you to reproduce the error with a table having few rows?
    Can you post CREATE TABLE and INSERT statement for FAT_T table?
    How many rows do you have in FAT_T table?
    The error 6533 literally has this explanation:
    The SUBSCRIPT_BEYOND_COUNT Exception (ORA-06533) occurs when a program references a nested table or varray element using an index number larger than the number of elements in the collection.
    So I can only think that it occurs if you are trying to use an index larger than your table.
    That's why I said your original code could have had a problem in the LOOP part in case the query was not returning any row.
    But actually in case the array was empty you would get another error in the loop (ORA-06502: PL/SQL: numeric or value error)
    I saw that your array type are all nested tables except t_rowid which is an associative array using BINARY_INTEGER as index.
    This index can be up to 2^32. So unless you have a very high number of rows (more than 2.15 billions) you should not get this error.
    I can suggest to check 2 things:
    How many rows does your SELECT statement returns?
    Comment the exception block to see exactly which line is throwing that error.
    Post some sample data to reproduce your problem
    Actually if I try to do something similar in my environment using EMP table I don't get any error (if my select returns rows):
    SQL*Plus: Release 11.2.0.1.0 Production on Thu Nov 7 12:22:28 2013
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL>
    SQL> DECLARE
      2     TYPE t_empno IS TABLE OF emp.empno%TYPE;
      3     TYPE t_ename IS TABLE OF emp.ename%TYPE;
      4     TYPE t_hiredate IS TABLE OF emp.hiredate%TYPE;
      5     TYPE t_sal IS TABLE OF emp.sal%TYPE;
      6     TYPE t_rowid IS TABLE OF ROWID
      7                        INDEX BY BINARY_INTEGER;
      8
      9     v_empno        t_empno;
    10     v_ename        t_ename;
    11     v_hiredate     t_hiredate;
    12     v_sal          t_sal;
    13     v_rowid        t_rowid;
    14
    15  BEGIN
    16     SELECT empno, ename, hiredate, sal
    17          , ROWID
    18       BULK COLLECT INTO v_empno, v_ename, v_hiredate, v_sal
    19          , v_rowid
    20       FROM emp;
    21
    22     FOR i IN v_empno.FIRST .. v_empno.LAST
    23     LOOP
    24        DBMS_OUTPUT.put_line ('Values are ' || v_empno (i));
    25     END LOOP;
    26  END;
    27  /
    Values are 7369
    Values are 7499
    Values are 7521
    Values are 7566
    Values are 7654
    Values are 7698
    Values are 7782
    Values are 7788
    Values are 7839
    Values are 7844
    Values are 7876
    Values are 7900
    Values are 7902
    Values are 7934
    PL/SQL procedure successfully completed.
    SQL>
    Regards.
    Alberto

  • How to display rows in PSA having count(wbs) 1

    Hi there BW gurus.
    I have a history in the SQL world, where it is quite easy to write a SQL code to get out the rows from a table with duplicates in one spesific field. (Beeing indexed or not)
    I have tried to search for this option where we diplays the content in an PSA. but not found it.
    Anyone having a good solution for this.
    (I am not an ABAP-er)
    Best Regards Ingrid

    Hi Ingrid,
    following ABAP returns all languages which more than one user is assigned to.
    data: l_langu type usr01-langu.
    data: l_Num type i.
    SELECT count( * ) langu
      into (l_Num, l_langu)
    FROM usr01
    GROUP BY langu
       having count( * ) GT 1.
      write: / l_langu, ' - ', l_num.
    endselect.
    e.g. language E is assigned to 27 users.
    Hope this gives you an idea.
    Regards,
    Jürgen

Maybe you are looking for