Help need  for  PL/SQL  collections

Hi All,
Please help me to solve the following Error.
Error # ORA-06533: Subscript beyond count.
I am using Oracle 10g.
I have data in the Test_table
id_col stat_col reason_col
101 A          HPQ
101 A NULL
101 NULL EDU
101 P NULL
102 P NULL
102 NULL HEN
103 R NULL
103 Q NULL
Ny requirement is like:
id_col stat_col_ reason_col
101 A|P HPQ|EDU
102 P HEN
103 R|Q NULL
step1- Type tab_type as table of varchar2(32767);
step2 - I have written a function which returns the pl/sql table type
create or replace function fn_get_val(id in VARCHAR2)
return tab_type
cursor my_cur is
select id_col,stat_col,reason_col
from test_table WHERE ID_COL = ID;
lv_status VARCHAR2(100);
LV_reason varchar2(200);
lv_sep CHAR(1);
lv_disp_stat varchar2(200);
lv_disp_reason varchar2(200);
LN_STR NUMBER;
BEGIN
lv_tab_data:= tab_type();
lv_tab_data.extend;
open my_cur;
loop
fetch my_cur into lv_status,lv_reason;
exit when my_cur%notfound;
--dbms_output.put_line('my_curr.rowcount'|| my_curr.rowcount);
lv_disp_stat:= lv_disp_stat||lv_sep||lv_status;
lv_disp_reason:= lv_disp_reason||lv_sep||lv_reason;
lv_sep:= '|';
end loop;
-- To remove first occurance of (|) pipeline in the string.
LN_STR := INSTR(lv_str1,'|',1,1);
IF LN_STR = 1 THEN
lv_disp_stat := SUBSTR(lv_disp_stat ,2 );
END IF;
LN_STR := INSTR(lv_str2,'|',1,1);
IF LN_STR = 1 THEN
lv_disp_reason := SUBSTR(lv_disp_reason ,2 );
END IF;
lv_tab_data(1) := lv_disp_stat;
lv_tab_data.extend;
lv_tab_data(2) := lv_disp_reason;
return lv_tab_data;
EXCEPTION
DBMS_OUTPUT.PUT_LINE('Error in function fn_get_val # '||SQLERRM||' - '||dbms_utility.format_error_backtrace);
END fn_get_val;
STEP-3
I have created one procedure where the above function is called
CREATE OR REPLACE PROCEDURE my_proc (p_emp_id in Varchar2)
AS
lv_tab_ty tab_type;
CURSOR DET_CUR IS
SELECT EMP_ID_C,NAME_C,LOCATION
FROM DETAILS_TABLE
WHERE EMP_ID_C = p_emp_id;
type det_tab_ty is table of det_cur%type index by pls_integer;
lv_det_rec det_tab_ty;
BEGIN
     lv_tab_ty := fn_get_val(p_emp_id);
     dbms_output.put_line('lv_tab_ty.count is : '||lv_tab_ty.count);
     OPEN DET_CUR;
     LOOP
     FETCH DET_CUR BULK COLLECT INTO lv_det_rec;
     EXIT WHEN DET_CUR%NOTFOUND;
     END LOOP;
     CLOSE DET_CUR;
     IF lv_det_rec.COUNT > 0 THEN
     FOR i IN lv_det_rec.FIRST .. lv_det_rec.LAST
     LOOP
     INSERT INTO other_tab (emp_id_c,name_c,Loc_c,status_c,reason_c) values(lv_det_rec(i).emp_id_c,lv_det_rec(i).NAME_C,lv_det_rec(i).LOCATION,lv_tab_ty(1),lv_tab_ty(2) );
     END LOOP;
     END IF;
COMMIT;
EXCEPTIONS
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error in procedure my_proc # '||SQLERRM||' - '||dbms_utility.format_error_backtrace);
END my_proc ;
After exucting the above procedure i am getting the following error.
lv_tab_ty.count is : 1
Error # ORA-06533: Subscript beyond count.
This error is occured when my_curr.rowcount is equal to 0 (cursor defined in the function fn_get_val() ).
The function fn_get_val() does return null to the pl/sql table variable (lv_tab_ty).
AND another schenario:
If
lv_tab_data.count = 1
Then how can i handle this situation in the above procedure,because i need both
lv_tab_data(1)
and lv_tab_data(2)
to insert to the OTHER_TABLE in the procedure.
Please help me to solve this issue.
Thanks in Advance!!!
PKM

You can do it with one query with Tom Kyte's stragg function:
http://asktom.oracle.com/pls/asktom/f?p=100:11:3431223221768118::::P11_QUESTION_ID:15637744429336
with test_table(id_col,stat_col,reason_col) as (
select 101,'A','PQ' from dual union all
select 101,'A',NULL from dual union all
select 101,NULL,'EDU' from dual union all
select 101,'P',NULL from dual union all
select 102,'P',NULL from dual union all
select 102,NULL,'HEN' from dual union all
select 103,'R',NULL from dual union all
select 103,'Q',NULL from dual
select id_col,replace(stragg(stat_col),',','|'),replace(stragg(reason_col),',','|')
from test_table tt
group by id_colRegards,
Sayan M.

Similar Messages

  • Help need for PL/SQL procedure

    Hi guys,
    I have scenario like this
    Schema     T     LOGTABLENAME          TDIRECTORY
    DEV          DEV.ABC_LOG                    import-abc
    DEV          DEV.GBTSLOG          import-gbts
    DEV          DEV.CLSSBOG     import-cls
    QA          QA.TransactionlOG          import-transaction
    QA1 QA1.tlog import-ess
    QA2 QA2.translog import-trnals
    I have to write a procedure to get the log table data from schema Dev.I have to take Shcema dev and go to DEv.abc_log table and get the record from the dev.abc_logtable. The same way for other schema also with respective logtables .
    I would appreciate your help or suggestions.
    Reards,
    User
    Edited by: user1758353 on Dec 5, 2008 11:43 AM

    hello,
    im also not sure if i get the point but maybe you need sth. like that...
    create table schema_logtable as
    select 'dev' schema, 'dev.abc_log' tlogtable, 'import-abc' tdirectory from dual union all
    select 'dev', 'dev.gbtslog', 'import-gpts' from dual union all
    select 'dev', 'dev.clssbog', 'import-cls' from dual );
    declare
       v_slt_row schema_logtable%rowtype;
       type log_description_table is table of varchar2(1000char);
       v_log_description log_description_table := log_description_table();
    begin
       for v_slt_row in ( select * from schema_logtable )
       loop
          execute immediate 'select log_description from ' || v_slt_row.tlogtable bulk collect into v_log_description;
          for i in v_log_description.first .. v_log_description.last
          loop
             dbms_output.put_Line( 'log_desc: ' || v_log_description(i) );
          end loop;
       end loop;
    end;
    /this reads for every schema in table schema_logtable the name of the logtable.
    for each logtable you fetch all rows of that table into a variable and you can do what-ever you want with that...
    -mario

  • Help needed for SCCM SQL query

    Hello.
    I have the below query to extract the workstations build date as well as the hardware info. This works fine. 
    Select distinct
    v_R_System.Name0,
    v_GS_COMPUTER_SYSTEM.Manufacturer0,
    v_GS_COMPUTER_SYSTEM.Model0,
    v_GS_COMPUTER_SYSTEM_PRODUCT.Version0,
    v_GS_OPERATING_SYSTEM.Caption0,
    v_GS_OPERATING_SYSTEM.CSDVersion0,
    v_GS_OPERATING_SYSTEM.InstallDate0
    From v_R_System
    LEFT JOIN v_GS_OPERATING_SYSTEM ON v_GS_OPERATING_SYSTEM.ResourceID=v_R_System.ResourceID
    LEFT JOIN v_GS_COMPUTER_SYSTEM_PRODUCT ON v_GS_COMPUTER_SYSTEM_PRODUCT.ResourceID=v_R_System.ResourceID
    LEFT JOIN v_GS_COMPUTER_SYSTEM ON v_GS_COMPUTER_SYSTEM.ResourceID=v_R_System.ResourceID
    LEFT JOIN v_GS_SYSTEM_CONSOLE_USAGE ON v_R_System.ResourceID=v_GS_SYSTEM_CONSOLE_USAGE.ResourceID
    Where v_GS_OPERATING_SYSTEM.Caption0 = 'Microsoft Windows 7 Enterprise' and v_R_System.Is_Virtual_Machine0 =0
    order by v_GS_OPERATING_SYSTEM.InstallDate0 desc
    Now, I want a report of count of machines built based on "v_GS_COMPUTER_SYSTEM_PRODUCT.Version0" against every month and year of "v_GS_OPERATING_SYSTEM.InstallDate0".
    For example, I want to know the number of machines under a particular model (which appears under  v_GS_COMPUTER_SYSTEM_PRODUCT.Version0) built in June 2014. In this fashion I want a report for every model count for every month and year available under
    InstallDate0 column)
    Example:
    Jan 2013 ->  ThinkCentre M92p -> 55
    Jan 2013 ->  ThinkCentre M93 -> 40
    Feb 2013 ->  ThinkCentre M92p -> 10
    Feb 2013 ->  ThinkCentre M93 -> 39
    Jan 2014 ->  ThinkCentre M92p -> 20
    Jan 2014 ->  ThinkCentre M93 -> 25
    Feb 2014 ->  ThinkCentre M92p -> 12
    Feb 2014 ->  ThinkCentre M93 -> 35
    Can anyone help?

    After scratching my head a bit, I came up with the below. Do you find any flaw in it?
    Select
    v_GS_COMPUTER_SYSTEM.Manufacturer0 as Manufacturer,
    v_GS_COMPUTER_SYSTEM.Model0 as Model,
    v_GS_COMPUTER_SYSTEM_PRODUCT.Version0 as "Model Info",
    COUNT(*) as "No. of machines built",
    CASE WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '1' THEN 'January'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '2' THEN 'February'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '3' THEN 'March'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '4' THEN 'April'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '5' THEN 'May'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '6' THEN 'June'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '7' THEN 'July'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '8' THEN 'August'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '9' THEN 'September'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '10' THEN 'October'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '11' THEN 'November'
    WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '12' THEN 'December'END as "Month",
    YEAR(v_GS_OPERATING_SYSTEM.InstallDate0) as "Year"
    From v_GS_COMPUTER_SYSTEM
    LEFT JOIN v_GS_OPERATING_SYSTEM ON v_GS_OPERATING_SYSTEM.ResourceID=v_GS_COMPUTER_SYSTEM.ResourceID
    LEFT JOIN v_GS_COMPUTER_SYSTEM_PRODUCT ON v_GS_COMPUTER_SYSTEM_PRODUCT.ResourceID=v_GS_COMPUTER_SYSTEM.ResourceID
    Where v_GS_OPERATING_SYSTEM.Caption0 = 'Microsoft Windows 7 Enterprise' Group By v_GS_COMPUTER_SYSTEM.Manufacturer0,
    v_GS_COMPUTER_SYSTEM.Model0,
    v_GS_COMPUTER_SYSTEM_PRODUCT.Version0,
    Month(v_GS_OPERATING_SYSTEM.InstallDate0),
    YEAR(v_GS_OPERATING_SYSTEM.InstallDate0)
    Order by v_GS_COMPUTER_SYSTEM_PRODUCT.Version0 desc

  • Help needed for writing query

    help needed for writing query
    i have the following tables(with data) as mentioned below
    FK*-foregin key (SUBJECTS)
    FK**-foregin key (COMBINATION)
    1)SUBJECTS(table name)     
    SUB_ID(NUMBER) SUB_CODE(VARCHAR2) SUB_NAME (VARCHAR2)
    2           02           Computer Science
    3           03           Physics
    4           04           Chemistry
    5           05           Mathematics
    7           07           Commerce
    8           08           Computer Applications
    9           09           Biology
    2)COMBINATION
    COMB_ID(NUMBER) COMB_NAME(VARCHAR2) SUB_ID1(NUMBER(FK*)) SUB_ID2(NUMBER(FK*)) SUB_ID3(NUMBER(FK*)) SUBJ_ID4(NUMBER(FK*))
    383           S1      9           4           2           3
    384           S2      4           2           5           3
    ---------I actually designed the ABOVE table also like this
    3) a)COMBINATION
    COMB_ID(NUMBER) COMB_NAME(VARCHAR2)
    383           S1
    384           S2
    b)COMBINATION_DET
    COMBDET_ID(NUMBER) COMB_ID(FK**) SUB_ID(FK*)
    1               383          9
    2               383          4
    3               383          2
    4               383          3
    5               384          4
    6               384          2          
    7               384          5
    8               384          3
    Business rule: a combination consists of a maximum of 4 subjects (must contain)
    and the user is less relevant to a COMB_NAME(name of combinations) but user need
    the subjects contained in combinations
    i need the following output
    COMB_ID COMB_NAME SUBJECT1 SUBJECT2      SUBJECT3      SUBJECT4
    383     S1     Biology Chemistry      Computer Science Physics
    384     S2     Chemistry Computer Science Mathematics Physics
    or even this is enough(what i actually needed)
    COMB_ID     subjects
    383           Biology,Chemistry,Computer Science,Physics
    384           Chemistry,Computer Science,Mathematics,Physics
    you can use any of the COMBINATION table(either (2) or (3))
    and i want to know
    1)which design is good in this case
    (i think SUB_ID1,SUB_ID2,SUB_ID3,SUB_ID4 is not a
    good method to link with same table but if 4 subjects only(and must) comes
    detail table is not neccessary )
    now i am achieving the result by program-coding in C# after getting the rows from oracle
    i am using oracle 9i (also ODP.NET)
    i want to know how can i get the result in the stored procedure itsef.
    2)how it could be designed in any other way.
    any help/suggestion is welcome
    thanks for your time --Pradeesh

    Well I forgot the table-alias, here now with:
    SELECT C.COMB_ID
    , C.COMB_NAME
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID1) AS SUBJECT_NAME1
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID2) AS SUBJECT_NAME2
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID3) AS SUBJECT_NAME3
    , (SELECT SUB_NAME
    FROM SUBJECTS
    WHERE SUB_ID = C.SUB_ID4) AS SUBJECT_NAME4
    FROM COMBINATION C;
    As you need exactly 4 subjects, the columns-solution is just fine I would say.

  • Color management help needed for adobe CS5 and Epson printer 1400-Prints coming out too dark with re

    Color management help needed for adobe CS5 and Epson printer 1400-Prints coming out too dark with reddish cast and loss of detail
    System: Windows 7
    Adobe CS5
    Printer: Epson Stylus Photo 1400
    Paper: Inkjet matte presentation paper with slight luster
    Installed latest patch for Adobe CS5
    Epson driver up to date
    After reading solutions online and trying them for my settings for 2 days I am still unable to print what I am seeing on my screen in Adobe CS5. I calibrated my monitor, but am not sure once calibration is saved if I somehow use this setting in Photoshop’s color management.
    The files I am printing are photographs of dogs with lots of detail  I digitally painted with my Wacom tablet in Photoshop CS5 and then printed with Epson Stylus 1400 on inkjet paper 20lb with slight luster.
    My Printed images lose a lot of the detail & come out way to dark with a reddish cast and loss of detail when I used these settings in the printing window:
    Color Handling: Photoshop manages color, Color management -ICM, OFF no color adjustment.
    When I change to these settings in printer window: Color Handling:  Printer manages color.  Color management- Color Controls, 1.8 Gamma and choose Epson Standard it prints lighter, but with reddish cast and very little detail and this is the best setting I have used so far.
    Based on what I have read on line, I think the issue is mainly to do with what controls are set in the Photoshop Color Settings window and the Epson Printer preferences. I have screen images attached of these windows and would appreciate knowing what you recommend I enter for each choice.
    Also I am confused as to what ICM color management system to use with this printer and CS5:
    What is the best ICM to use with PS CS5 & the Epson 1400 printer? Should I use the same ICM for both?
    Do I embed the ICM I choose into the new files I create? 
    Do I view all files in the CS5 workspace in this default ICM?
    Do I set my monitor setting to the same ICM?
    If new file opens in CS5 workspace and it has a different embedded profile than my workspace, do I convert it?
    Do I set my printer, Monitor and PS CS5 color settings to the same ICM?
    Is using the same ICM for all devices what is called a consistent workflow?
    I appreciate any and all advice that can be sent my way on this complicated issue. Thank you in advance for your time and kind help.

    It may be possible to figure out by watching a Dr.Brown video on the subject of color printing. Adobe tv
    I hope this may help...............

  • File missing (file\BCD error code 0Xc0000034 help need for work!

    file missing (file\BCD  error code 0Xc0000034 help need for work!    what can i do?
    have an p 2000 notebook pc

     Hi bobkunkle, welcome to the HP Forums. I understand you cannot boot passed the error you are receiving.
    What is the model or product number of your notebook? What version of Windows is installed?
    Guide to finding your product number
    Which Windows operating system am I running?
    TwoPointOh
    I work on behalf of HP
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos, Thumbs Up" on the bottom to say “Thanks” for helping!

  • Help need for force to signout All session ! how...

    hi
         help need for force to  signout All session !  how ??
    Solved!
    Go to Solution.

    Hi and welcome to the Skype Community,
    To force a signout of all instances your Skype is signed into please change your password: https://support.skype.com/en/faq/FA95/how-do-i-change-my-password
    Follow the latest Skype Community News
    ↓ Did my reply answer your question? Accept it as a solution to help others, Thanks. ↓

  • Need help with querying pl/sql collections

    hi all,
    i have a requirement wherein i look thru a number of records and then updates. then i need to check if these records were successfully updated. i have the following code but it doesn't work on the part where i query the collection.
    declare
      type ap_invoices_all_tbl is table of ap_invoices_all%rowtype;
      ap_invoices_all_rec ap_invoices_all_tbl;
      cursor cai is
        select *
          from ap_invoices_all ai
         where source = 'XXX';
    begin
      open cai;
      fetch cai bulk collect into ap_invoices_all_rec;
      for i in 1..ap_invoices_all_rec.count loop
        begin
        dbms_output.put_line('Invoice Status: ' || ap_invoices_pkg.get_approval_status( ap_invoices_all_rec(i).invoice_id, ap_invoices_all_rec(i).invoice_amount, ap_invoices_all_rec(i).payment_status_flag, ap_invoices_all_rec(i).invoice_type_lookup_code));
        exception
          when no_data_found then
            null;
        end;
      end loop;
      for j in ( select * from ap_invoices_all ai
                  where invoice_id in ( select invoice_id
                                          from ap_invoices_all_rec ))
      loop
        dbms_output.put_line('Invoice Number: ' || j.invoice_num);
      end loop;
    end;i do understand that i cannot use select statement directly on a collection but i just wanted to show what i'm trying to achieve.
    any suggestions on what i should do?
    thanks
    allen

    You can not use locally defined collection(pl/sql) in SELECT statement directly, instead use Objects defined in schema.
    For example:
    SQL> CREATE OR REPLACE TYPE emp_rec IS OBJECT (
      2                      v_sal    NUMBER(7,2),
      3                      v_name   VARCHAR2(35),
      4                      v_empno  NUMBER(4),
      5                      v_deptno NUMBER(2)
      6                      )
      7  ;
      8  /
    Type created.
    SQL> CREATE OR REPLACE TYPE emp_tab IS TABLE OF emp_rec;
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE dept_rec IS OBJECT (
      2                      v_deptno NUMBER,
      3                      v_dname VARCHAR2(50)
      4                      )
      5  ;
      6  /
    Type created.
    SQL> CREATE OR REPLACE TYPE dept_tab IS TABLE OF dept_rec;
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE emp_dept_rec IS
      2                     OBJECT (
      3                      v_sal     NUMBER,
      4                      v_name     VARCHAR2(35),
      5                      v_deptname VARCHAR2(30)
      6                      );
      7  /
    Type created.
    SQL> CREATE OR REPLACE TYPE emp_dept_tab_type IS TABLE OF emp_dept_rec;
      2  /
    Type created.
    SQL> set serverout on
    SQL> DECLARE
      2    l_emp_dept_tab emp_dept_tab_type; --emp_dept_tab_type declared in database
      3    l_emp_tab      emp_tab; --emp_tab declared in database
      4    l_dept_tab     dept_tab; --dept_tab declared in database
      5 
      6    CURSOR e1 IS
      7      SELECT emp_rec(sal, ename, empno, deptno) FROM emp; --Note the type casting here
      8 
      9    CURSOR d1 IS
    10      SELECT dept_rec(deptno, dname) FROM dept; --Note the type casting here
    11  BEGIN
    12    OPEN e1;
    13 
    14    FETCH e1 BULK COLLECT
    15      INTO l_emp_tab;
    16 
    17    OPEN d1;
    18 
    19    FETCH d1 BULK COLLECT
    20      INTO l_dept_tab;
    21 
    22    SELECT CAST(MULTISET (SELECT em.v_sal, em.v_name, dep.v_dname
    23                   FROM TABLE(l_emp_tab) em, TABLE(l_dept_tab) dep
    24                  WHERE em.v_deptno = dep.v_deptno) AS emp_dept_tab_type)
    25      INTO l_emp_dept_tab
    26      FROM DUAL;
    27    FOR i IN 1 .. l_emp_dept_tab.COUNT LOOP
    28      dbms_output.put_line(l_emp_dept_tab(i)
    29                           .v_sal || '--' || l_emp_dept_tab(i)
    30                           .v_name || '--' || l_emp_dept_tab(i).v_deptname);
    31    END LOOP;
    32 
    33  END;
    34  /
    1300--MILLER--ACCOUNTING
    5000--KING--ACCOUNTING
    2450--CLARK--ACCOUNTING
    3000--FORD--RESEARCH
    1100--ADAMS--RESEARCH
    3000--SCOTT--RESEARCH
    2975--JONES--RESEARCH
    800--SMITH--RESEARCH
    950--JAMES--SALES
    1500--TURNER--SALES
    2850--BLAKE--SALES
    1250--MARTIN--SALES
    1250--WARD--SALES
    1600--ALLEN--SALES
    PL/SQL procedure successfully completed.
    SQL>

  • Help needed in framing SQL query.

    Hi,
    I have table having following schema:
    PRODUCT_ID         INT
    DATE                   DATETIME
    ITEMS_SOLD         INT
    This table contains data for a week (sunday to saturday). I want to write an SQL query to get (filter out) PRODUCT_ID of products which has same no. of ITEMS_SOLD for all 7 days. Also for given PRODUCT_ID I need to find the longest period of successive days where the no. of ITEMS_SOLD is same for all days in this period. Eg.(PRODUCT_ID 23 was sold as following along the week in no. of units sold: 4,6,6,6,6,7,4 .So the longest period is *4 days* from Monday to Thursday.) The first condition is special case of second condition where no. of days is 7.
    Any help to get the SQL query will be appreciated.
    Thanks,
    Akshay.

    PRODUCT_ID      DATE           ITEMS_SOLD
    1          10/10/2011     3
    1          11/10/2011     3
    1          12/10/2011     3
    1          13/10/2011     3
    1           16/10/2011     5
    2          10/10/2011     4
    2           11/10/2011     4
    2          12/10/2011     4
    2          13/10/2011     4
    2           14/10/2011     4
    2          15/10/2011     4
    2          16/10/2011     4
    Output:
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    1          3                4     
    2          4               7
    Explanation of results:
    The table to be queried contains data for 1 week: from 10/10/2011(Sunday) to 16/10/2011(Saturday). Now, product with PRODUCT_ID '1' was sold on dates 10,11,12,13,16. Out of these 5 days 3 units were sold on 4 successive days (from 10-13). So output should be like :
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    1          3               4     
    as longest period of successive days is 4 where same no. of units were sold i.e 3 units (other period is of 1 day on 16th ).
    For PRODUCT_ID 2 we have only one period of 7 days where 4 units were sold each day. So we output :
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    2           4               7
    Other case where same PRODUCT_ID have different units sold on each day should be ignored.
    I hope that clarifies the problem more. Let me know in case I have missed out anything which should have been mentioned.
    -Akshay.

  • Help Needing in optimizing SQL

    I need help optimizing the following SQL.
    Following are the schema elements -
    cto_xref_job_comp - Contains the Job Data
    cto_mast_component - Contains component
    cto_mast_product - Contains product info
    cto_mast_model - Contains model info
    cto_xref_mod_prod - Contains model and product assoiciation
    cto_mast_model_scan - Contain the Scan order for each model family (the mod_id(should be renamed) refers to mod_fam_id on the cto_mast_model table).
    Here is what I am trying to achieve
    I want all the ATP components whose Travel card order (on cto_mast_model_scan > 0 ) and in addition I need the Phantoms that do not have any ATP components under them if they do not appear on ATP component list.
    SELECT f.travelcard_order, b.job_number,
    b.product_code,
    b.line_number,
                   b.component_type,
    b.component_item_number,
    b.parent_phantom,
    b.item_type,
    a.comp_id,
    a.comp_type_id,
    a.comp_desc_short,
    b.batch_id,
    b.quantity_per_unit,
    a.comp_notes,
                   b.COMPONENT_ITEM_DESCRPTION
    FROM      cto_xref_job_comp b,
                        cto_mast_component a,
                        cto_mast_product c,
    cto_xref_mod_prod d,
    cto_mast_model e,
                   cto_mast_model_scan f
    WHERE ( b.job_number = 'CTO2499814001' ) AND
    ( b.batch_id = 21 ) AND
    (b.item_type = 'ATP') AND
                   (b.parent_phantom = a.comp_desc_short ) and          
                   (b.product_code = c.prod_desc_short ) and
    (c.prod_id = d.prod_id ) and
    (d.mod_id = e.mod_id) and
    (e.mod_fam_id = f.mod_id) and
    (a.comp_type_id=f.comp_type_id) and
                                       (f.travelcard_order > 0)
    union
    SELECT distinct f.travelcard_order, b.job_number,
    b.product_code,
    b.line_number,
                   b.component_type,
    b.parent_phantom,
    b.item_type,
    a.comp_id,
    a.comp_type_id,
    a.comp_desc_short,
    b.batch_id,
    1,
    a.comp_notes,
    FROM      cto_xref_job_comp b,
                        cto_mast_component a,
                        cto_mast_product c,
    cto_xref_mod_prod d,
    cto_mast_model e,
                   cto_mast_model_scan f
    WHERE ( b.job_number = 'CTO2499814001' ) AND
    ( b.batch_id = 21 ) AND (b.item_type is null) and
                   (substr(b.parent_phantom,1,1)='C') and
                   (b.parent_phantom = a.comp_desc_short )
    and (b.parent_phantom not in (select parent_phantom from cto_xref_job_comp where job_number=b.job_number and batch_id=b.batch_id and item_type='ATP')) and           
                   (b.product_code = c.prod_desc_short ) and
    (c.prod_id = d.prod_id ) and
    (d.mod_id = e.mod_id) and
    (e.mod_fam_id = f.mod_id) and
    (a.comp_type_id=f.comp_type_id) and (f.travelcard_order > 0)

    Here is a small example.
    DECLARE
         my_table VARCHAR2(10) := 'DUAL';
         my_value INTEGER;
    BEGIN
         EXECUTE IMMEDIATE 'SELECT 1 FROM ' || my_table INTO my_value;
         DBMS_OUTPUT.PUT_LINE(my_value);
    END;
    you can use your cursor value in the place of my_table.
    Thanks,
    Karthick.
    http://www.karthickarp.blogspot.com/

  • Help asked for a sql request - thanks

    Hello,
    I'm not a sql Guru... Who can help for this sql request ?
    First I have this:
    SELECT ADDINFO_ID, INFO, LANGUAGE_FK, ENGLISH_NAME
    FROM V_ADDINFOS
    WHERE LANGUAGE_FK = 'EN' (which is very simple...-)
    But now complicated... I have to add this in the same request:
    select sum(val) as nbrInfo
    from(
    select count(*) val from eccgis where addinfo1_fk = ADDINFO_ID
    union all
    select count(*) val from eccgis where addinfo2_fk = ADDINFO_ID
    union all
    select count(*) val from eccgis where addinfo3_fk = ADDINFO_ID
    union all
    select count(*) val from thirdgis where addinfo1_fk = ADDINFO_ID
    union all
    select count(*) val from thirdgis where addinfo2_fk = ADDINFO_ID
    In other words, for each row of the first select, I need to know how much it is linked in the tables eccgis and thirdgis...
    Hope is is clear... -)
    Thank you very very much,
    Michel

    Hi, Michel,
    Almost anywhere that SQL allows an expression (such as a column name, literal or function call) it also allows a scalar sub-query, a SELECT statement based on any table (or tables) that returns one column and (at most) one row. Like other sub-queries, scalar sub-queries can be corellated to the main query.
    To get the grand total you want on each row of your output:
    SELECT ADDINFO_ID, INFO, LANGUAGE_FK, ENGLISH_NAME
    , (select count(*) from eccgis where addinfo1_fk = ADDINFO_ID)
    + (select count(*) from eccgis where addinfo2_fk = ADDINFO_ID)
    + (select count(*) from eccgis where addinfo3_fk = ADDINFO_ID)
    + (select count(*) from thirdgis where addinfo1_fk = ADDINFO_ID)
    + (select count(*) from thirdgis where addinfo2_fk = ADDINFO_ID)
    AS nrbInfo
    FROM V_ADDINFOS
    WHERE LANGUAGE_FK = 'EN';VERY IMPORTANT: Each sub-query must be in parentheses. You'll get a run-time error if any scalar sub-query returns more than one row. (Returning no rows is okay: the value will be NULL).
    By the way, this looks like a bad table design. If each row in eccgis or thirdgis can be associated with more than one foreign key, they should be kept in a separate table. That's the standard way to handle many-to-many relationships.

  • Advice needed for pl/sql

    Hey guys,
    I am look out for book/ articles for learning pl/sql . I am new to pl/sql adn i want book/ articles that help me learn pl/sql from scratch. I have see many books oriented towards DBA. I dont want such type of books. Please let me know the books/ articles that beginner needs, preferably artcles// books with lot of developer examples. ALso let me know any books/artciles to learn forms, reports.
    Please advice me on this.
    The response will be highly appreciated.
    Thanks
    u can mail me at : [email protected]

    It depends what you mean when you call yourself 'new'. There are two main concepts to learn for pl/sql: the sql language, and procedural logic. If you have previously been a programmer in any 3GL, you will be familiar with the procedural part, which is pretty much the same principal in any programming language. If you have no experience with sql, you really need to become proficient with that, otherwise there is a danger of writing everything procedurally when you should be doing it with sql.
    I find the Steven Feuerstein book very good, combined with Oracle manuals.

  • Query help needed for querybuilder to use with lcm cli

    Hi,
    I had set up several queries to run with the lcm cli in order to back up personal folders, inboxes, etc. to lcmbiar files to use as backups.  I have seen a few posts that are similar, but I have a specific question/concern.
    I just recently had to reference one of these back ups only to find it was incomplete.  Does the query used by the lcm cli also only pull the first 1000 rows? Is there a way to change this limit somwhere?
    Also, since when importing this lcmbiar file for something 'generic' like 'all personal folders', pulls in WAY too much stuff, is there a better way to limit this? I am open to suggestions, but it would almost be better if I could create individual lcmbiar output files on a per user basis.  This way, when/if I need to restore someone's personal folder contents, for example, I could find them by username and import just that lcmbiar file, as opposed to all 3000 of our users.  I am not quite sure how to accomplish this...
    Currently, with my limited windows scripting knowledge, I have set up a bat script to run each morning, that creates a 'runtime' properties file from a template, such that the lcmbiar file gets named uniquely for that day and its content.  Then I call the lcm_cli using the proper command.  The query within the properties file is currently very straightforward - select * from CI_INFOOBJECTS WHERE SI_ANCESTOR = 18.
    To do what I want to do...
    1) I'd first need a current list of usernames in a text file, that could be read (?) in and parsed to single out each user (remember we are talking about 3000) - not sure the best way to get this.
    2) Then instead of just updating the the lcmbiar file name with a unique name as I do currently, I would also update the query (which would be different altogether):  SELECT * from CI_INFOOBJECTS where SI_OWNER = '<username>' AND SI_ANCESTOR = 18.
    In theory, that would grab everything owned by that user in their personal folder - right? and write it to its own lcmbiar file to a location I specify.
    I just think chunking something like this is more effective and BO has no built in back up capability that already does this.  We are on BO 4.0 SP7 right now, move to 4.1 SP4 over the summer.
    Any thoughts on this would be much appreciated.
    thanks,
    Missy

    Just wanted to pass along that SAP Support pointed me to KBA 1969259 which had some good example queries in it (they were helping me with a concern I had over the lcmbiar file output, not with query design).  I was able to tweak one of the sample queries in this KBA to give me more of what I was after...
    SELECT TOP 10000 static, relationships, SI_PARENT_FOLDER_CUID, SI_OWNER, SI_PATH FROM CI_INFOOBJECTS,CI_APPOBJECTS,CI_SYSTEMOBJECTS WHERE (DESCENDENTS ("si_name='Folder Hierarchy'","si_name='<username>'"))
    This exports inboxes, personal folders, categories, and roles, which is more than I was after, but still necessary to back up.. so in a way, it is actually better because I have one lcmbiar file per user - contains all their 'personal' objects.
    So between narrowing down my set of users to only those who actually have saved things to their personal folder and now having a query that actually returns what I expect it to return, along with the help below for a job to clean up these excessive amounts of promotion jobs I am now creating... I am all set!
    Hopefully this can help someone else too!
    Thanks,
    missy

  • Help needed for grouping.

    Hi,
        Help needed .
    I have an internal table having 6 .
    Ex :
    f1     f2    f3     f4    f5    f6
    a     aa    11    p1  10    10
    a     aa    12    p1  20    20
    b     aa    11    p2  30    30
    b     aa    12    p2  40    30
    Now i want to sum the fields f5 and f6 individually and need to display based upon the fields f1 and f4.
    To Display :
    f1     f2    f3     f4    f5    f6
    a     aa    11    p1  30    30.
    b     aa    11    p2  70    60.
    can anyone help me.How to do this..?
    Thanks

    Here you go
    DATA:
      BEGIN OF cur_tab OCCURS 0,
        f1        TYPE c,
        f2(2)     TYPE c,
        f3(2)     TYPE c,
        f4(2)     TYPE c,
        f5(2)     TYPE c,
        f6(2)     TYPE n,
      END OF cur_tab.
    DATA:
      BEGIN OF sum_tab OCCURS 0,
        f1        TYPE c,
        f4(2)     TYPE c,
        f5        TYPE p,
        f6        TYPE p,
      END OF sum_tab.
    DATA:
      BEGIN OF final_tab OCCURS 0,
        f1        TYPE c,
        f2(2)     TYPE c,
        f3(2)     TYPE c,
        f4(2)     TYPE c,
        f5(5)     TYPE c,
        f6(5)     TYPE c,
      END OF final_tab.
    START-OF-SELECTION.
      cur_tab-f1 = 'a'.
      cur_tab-f2 = 'aa'.
      cur_tab-f3 = '11'.
      cur_tab-f4 = 'p1'.
      cur_tab-f5 = '10'.
      cur_tab-f6 = '10'.
      APPEND cur_tab.
      cur_tab-f1 = 'a'.
      cur_tab-f2 = 'aa'.
      cur_tab-f3 = '11'.
      cur_tab-f4 = 'p1'.
      cur_tab-f5 = '20'.
      cur_tab-f6 = '20'.
      APPEND cur_tab.
      cur_tab-f1 = 'b'.
      cur_tab-f2 = 'aa'.
      cur_tab-f3 = '11'.
      cur_tab-f4 = 'p2'.
      cur_tab-f5 = '30'.
      cur_tab-f6 = '30'.
      APPEND cur_tab.
      cur_tab-f1 = 'b'.
      cur_tab-f2 = 'aa'.
      cur_tab-f3 = '11'.
      cur_tab-f4 = 'p2'.
      cur_tab-f5 = '40'.
      cur_tab-f6 = '30'.
      APPEND cur_tab.
      LOOP AT cur_tab.
        MOVE-CORRESPONDING cur_tab TO sum_tab.
        COLLECT sum_tab.
      ENDLOOP.
      LOOP AT sum_tab.
        READ TABLE cur_tab WITH KEY f1 = sum_tab-f1
                                    f4 = sum_tab-f4.
        IF sy-subrc NE 0.
          WRITE:/ 'Something went very wrong'.
          CONTINUE.
        ENDIF.
        MOVE-CORRESPONDING cur_tab TO final_tab.
        MOVE-CORRESPONDING sum_tab TO final_tab.
        APPEND final_tab.
      ENDLOOP.
      LOOP AT final_tab.
        WRITE:/1 final_tab-f1,
              AT 5 final_tab-f2,
              AT 10 final_tab-f3,
              AT 15 final_tab-f4,
              AT 20 final_tab-f5,
              AT 25 final_tab-f6.
      ENDLOOP.
    and the output
    a   aa   11   p1     30   30  
    b   aa   11   p2     70   60  

  • Help needed for using BASIC authentication through JDBCRealm

    Help needed.
    Hello,
    I am doing a degree project, so far it works fine in my local machine, I need to try it on my virtual hosting (as it is a live server).
    My project requires JDBCRealm, that is BASIC authentication loading access data from mysql database. Normally this setup can be done in Server.xml file, because my Tomcat hosting is a virtual one, I only have permission to access the web.xml file.
    My question is: is it possible to get it done in an alternative way? In web.xml? Some properties file maybe?
    Thank you very much.

    You can set this up for your context using META-INF/context.xml instead of working with server.xml.
    Make a directory called META-INF under your webapp ( it'll be at the same level as WEB-INF ). Under this, add a context.xml with all your context specific configuration including the realm. A sample is below
    <?xml version="1.0" encoding="UTF-8"?>
    <Context path="/myApp" reloadable="true">
        <Realm
            className="org.apache.catalina.realm.JDBCRealm"            
            driverName="com.microsoft.jdbc.sqlserver.SQLServerDriver"         
            connectionURL="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=myDB;SelectMethod=Cursor;"
            connectionName="username" connectionPassword="password"
            digest="MD5" userTable="users" userNameCol="userid" userCredCol="userpassword"
            userRoleTable="user_roles" roleNameCol="rolename"
        />
    </Context>Hope this helps.
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    ----------------------------------------------------------------

Maybe you are looking for

  • Xp doesn't recognize ipod touch

    Itunes shows the Itouch and when you sync, the Ipod lights up, but nothing is copied over.  The Itouch doesn't show up in device manager or computer.  I can not download anything.  it says no updates! 

  • Data pump issue for oracle 10G in window2003

    Hi Experts, I try to run data pump in oracle 10G in window 2003 server. I got a error as D:\>cd D:\oracle\product\10.2.0\SALE\BIN D:\oracle\product\10.2.0\SALE\BIN>expdp system/xxxxl@sale full=Y directory=du mpdir dumpfile=expdp_sale_20090302.dmp log

  • I phone discharges after sofwear upgrade

    I have read about others having this problem but no Apple fix. My phone with heavy use phone, email, texts etc always lasted over a full day on a charge and mort than a few days over weekends with little business activity Just upgraded phone soft wea

  • I get incomplete printing for anything in black ink. and test bars are also faint

    when printing documents the text in black comes out incomplete, some are fine, others are missing.  color images, printing are fine.  Test page comes out with extremely light for the black toner images as well as the black bars

  • Migration -actions=mkconn returns always Error: java.sql.SQLException: Inva

    Hi I'm migrate from MS SQL 2005 to Oracle 11g using SQL Developer V3.0.04 Trying to use the batch file migration.bat. Found the documentation with migration -help=guide Every action I start results in the SQLException below: D:\oracle\product\sqldeve