Diference bte fetch into statement fetch bulkcollect into statement.

hi,,
difference btw fetch into statement and bulk collect into statement.
differece btw for loop and forall loop.

Hi,
Syntax:
(Select)(Fetch)(execute immediate) … BULK COLLECT Into collection_name [,collection_name, …] [LIMIT max_lines] ;
LIMIT is used to limit the number of rows returned.
BULK COLLECT can also be used to retrieve the result of a DML statement that uses the RETURNING INTO clause:
SQL> Declare
2 TYPE TYP_TAB_EMPNO IS TABLE OF EMP.EMPNO%Type ;
3 TYPE TYP_TAB_NOM IS TABLE OF EMP.ENAME%Type ;
4 Temp_no TYP_TAB_EMPNO ;
5 Tnoms TYP_TAB_NOM ;
6 Begin
7 -- Delete rows and return the result into the collection --
8 Delete From EMP where sal > 3000
9 RETURNING empno, ename BULK COLLECT INTO Temp_no, Tnoms ;
10 For i in Temp_no.first..Temp_no.last Loop
11 dbms_output.put_line( 'Fired employee : ' || To_char( Temp_no(i) ) || ' ' || Tnoms(i) ) ;
12 End loop ;
13 End ;
14 /
Fired employee : 7839 KING
try to understand this example.i think it is sufficient.
Thanks,
Sanjeev.

Similar Messages

  • Reg: Diference between two Financial Statements(F.01)

    Hi,
    Documents have been posted in 31.03.2010 those have been updated in 2009 (FSV - F.01). Same documents amounts is showing
    in 2010  while checking FSV  through profit center.
    Can anybody give me solution how the balance is appear in 2010 FSV.
    Like Entry-        
    Posting date 31.03.2010  
    Salary paya a/c -100 Dr
    SBI Bank a/c     -100 CR
    Thanks &Reg
    Reddy

    Hi Reddy
    I dont know whether I understood your query correctly.
    But my response is that whenever you post any document in a Balance sheet account and if you have done a balance carryforward to next year using F.16, then it will appear in the subsequent year also.
    Regards

  • Problems with "Select Distinct" Statement

    Hi... I've a little problem with my SQL Statement...
    I've a Table in a DataBase with Solds of the Month... the fields are: vta_fecha, vta_prod, vta_total, vta_mesa.
    I've to Select only the distincts fields of vta_prod... selected by vta_fecha and vta_mesa...
    My code is like this:         try{
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                conec = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/POOL/Data/BaseDat.MDB");
                state = conec.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);try{
                rec = state.executeQuery("Select DISTINCT vta_prod, vta_fecha, vta_mesa from Ventas where vta_fecha = #" + Fecha_q + "# And vta_mesa = 0");           
                rec.first();
                int x = 0;
                while (rec.isAfterLast()==false){
                    x++;
                    rec.next();
                rec.first();
                if (x > 0){
                    Productos = new String[x];
                    Total_Vta = new int[x];
                    Cant_Prod = new int[x];
                    x = 0;
                    while (rec.isAfterLast() == false){
                        Productos[x] = rec.getString("vta_prod");
                        rec.next();
                        x++;
                else{
                    Productos = new String[0];
                    Total_Vta = new int[0];
                    Cant_Prod = new int[0];
            }catch(Exception e){JOptionPane.showMessageDialog(null,e.getMessage());}Now, in the Table I have only 3 diferents vta_prod, but this Statement returns 9 Rows... and I don't know why...
    Please help me...
    Regards...

    I don�t have a complete picture because I don�t know what values you are passing in the select and I don�t know your column types but this is what I think is happening from what you have shared.
    You may have misunderstood what the DISTINCT keyword does.
    The DISTINCT keyword applies to the full set of columns in the select (not just the first column). So in your case it would be equivalent to:
    SELECT vta_prod, vta_fecha, vta_mesa
    FROM Ventas
    WHERE ...
    GROUP BY by vta_prod, vta_fecha, vta_mesa
    So, it doesn't matter that you only have 3 distinct vta_prod values if you have multiple values being returned in the other columns. The vta_mesa column can only a return a single value as �0�. That leaves the vta_fecha column which is probably a date/time column and is probably the column that is returning the three other distinct values (one date with three distinct times).
    (3 vta_prod) x (3 vta_fecha) x (1 vta_mesa) or 3x3x1 = 9 rows
    So find a way to strip the time from vta_fecha in your select statement and your SQL should return the results you expect. I�m not an Access expect but I think I remember you can use something like the �Convert� or �DatePart� functions to make that happen (check your documentation to be sure)..
    A couple of asides;
    1) You should use a PreparedStatement and rarely if ever use Statement.
    2) You should start Java variable names with lower case.

  • Concat vs ||

    Hi,
    i am writing a some queries in SP which form dynamically. i do a lot of concatenation among strings and also numbers to prepare these queries.
    can somebody tell me that which approach is better to use in terms of performance.
    select concat(str,'popo') into str from dual ;
    or
    str:= str || 'popo';

    Although I agree with the most of the comments here, there will be a performance diference between the two statements in your original post.
    The first
    SELECT concat(str, 'popo') INTO str FROM dual;requires a context switch from PL/SQL to the SQL engine, and will be slower than the direct assignment. As far as I can tell, there is no difference between a direct assignment using CONCAT and the || operator.
    The following test shows that if you are going to do a lot of concatenation in a LOOP, then don't use SELECT INTO (good advice for almost anything in PL/SQL).
    SQL> DECLARE
      2     l_str   VARCHAR2(15);
      3     l_start NUMBER;
      4     l_end   NUMBER;
      5     l_elap  NUMBER;
      6  BEGIN
      7     l_start := DBMS_UTILITY.Get_Time();
      8     FOR i IN 1 .. 10000 LOOP
      9        l_str := 'HELLO';
    10        SELECT CONCAT(l_str, ' WORLD') INTO l_str
    11        FROM dual;
    12     END LOOP;
    13     l_end := DBMS_UTILITY.Get_Time();
    14     l_elap := l_end - l_start;
    15     DBMS_OUTPUT.Put_Line('Select used '||l_elap||' centi seconds');
    16
    17     l_start := DBMS_UTILITY.Get_Time();
    18     FOR i IN 1 .. 10000 LOOP
    19        l_str := 'HELLO';
    20        l_str := CONCAT(l_str, ' WORLD');
    21     END LOOP;
    22     l_end := DBMS_UTILITY.Get_Time();
    23     l_elap := l_end - l_start;
    24     DBMS_OUTPUT.Put_Line('Assign CONCAT '||l_elap||' centi seconds');
    25
    26     l_start := DBMS_UTILITY.Get_Time();
    27     FOR i IN 1 .. 10000 LOOP
    28        l_str := 'HELLO';
    29        l_str := l_str || ' WORLD';
    30     END LOOP;
    31     l_end := DBMS_UTILITY.Get_Time();
    32     l_elap := l_end - l_start;
    33     DBMS_OUTPUT.Put_Line('Operator used '||l_elap||' centi seconds');
    34  END;
    35  /
    Select used 96 centi seconds
    Assign CONCAT 0 centi seconds
    Operator used 1 centi seconds
    PL/SQL procedure successfully completed.TTFN
    John

  • Business Transaction Event  00001550

    Hi folks,
    Is there any possibility to include BTE 00001550 (Sample_Interface_00001550) in table TPS01 without creating a data element?
    I copied the function model Sample_Interface_00001550 to Z_Sample_Interface_00001550 including the function group. Next, via transaction FIBF, I defined a customer product FICR1550. While creating a new entry for this process via Menu->Settings->Process Modules ->of a customer the system requested that the entry for BTE must be included in table TPS01.
    At SE16 I tried to include the entry in TPS01. To do this, the system then requested that a new data element PR00001550 be created. Creating a data element in the system will result into modification.
    May I know if there is any possible way to include the BTE 1550 into TPS01 without creating a new data element?
    Regards,
    Joseph

    Hi,
    Thanx for the reply.
    But as earlier mentioned in the original message, the system requires me to <b>Create a new DataElement for PR00001550</b>.
    Since i do not want to modify the existing system, the question is whether there is a way to include this entry in via SM30 or SE16 into the table TPS01 without creating a dataElement to this effect?
    Regards,
    Joseph

  • Expression   cannot be used as an INTO-target of a SESELECT/FETCH Statement

    Hello guys
    Iam new to oracle and this my first post
    I have written this code in sql
    declare
    2 cursor madecursor is select bus_id ,bus_destination ,seat_no ,
    3 driver_name from bus for update of seat_no nowait ; myseat bus.seat_no%type
    4 ; begin
    5 for bus_id in madecursor loop
    6 select myseat into bus.bus_id from bus where
    7 bus_id = bus_id
    8 ; if
    9 myseat < 5 then
    10 update bus set seat_no = seat_no*2 WHERE CURRENT OF madecursor
    11 ; DBMS_OUTPUT.PUT_LINE('Updated');
    12 end if ;
    13 end loop;
    14 end;
    but I have the following errors:-
    ERROR at line 6:
    ORA-06550: line 6, column 27:
    PLS-00403: expression 'BUS.BUS_ID' cannot be used as an INTO-target of a SELECT/FETCH statement
    ORA-06550: line 6, column 2:
    PL/SQL: SQL Statement ignored
    please help me.
    Thanks in advance.
    user613283

    Firstly thank you for replies , I get use of your suggestions and change my code but still having errors please suggest.
    SQL> declare
    2 I_myseat bus.seat_no%type;
    3 begin
    4
    5
    6 select I_myseat into I_myseat from
    7 bus where
    8 bus_id = bus.bus_id
    9 ;
    10 if I_myseat < 5 then
    11 update bus set seat_no = seat_no*2
    12 where I_myseat<5
    13 ; DBMS_OUTPUT.PUT_LINE('Updated');
    14
    15 end if;
    16 end;
    17 / declare
    ERROR at line 1:
    ORA-01422: exact fetch returns more than requested number of rows
    ORA-06512: at line 6

  • How to specify dynamic cursorname in FETCH INTO statement

    Hi there,
    my pl/sql block is like below:
    LOOP
    FETCH pSnCur     INTO <variablevalue>
    EXIT WHEN pSnCur%NOTFOUND;
    end loop;
    here after INTO i want to specify variable for cursorname because my cursorname is changing dynamically. Is it possible to do this? If yes then how.
    Thanks,
    Meghna.

    Meghna,
    it seems that the solution is working.
    Here it is ->
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    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 - Production
    Elapsed: 00:00:00.02
    satyaki>
    satyaki>
    satyaki>declare
      2    v_str varchar2(1000);
      3  begin
      4    v_str := 'declare
      5                cursor cur is
      6                  select ename from emp where rownum <=3;
      7                v_ename varchar2(30);
      8              begin
      9                open cur;
    10                loop
    11                  fetch cur
    12                    into v_ename;
    13                  exit when cur%notfound;
    14                  dbms_output.put_line( v_ename );
    15                end loop;
    16              end;';
    17  
    18     Execute immediate v_str;
    19  end;
    20  /
    WARD
    MARTIN
    SCOTT
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.06
    satyaki>Can you post what you have tried so far?
    Regards.
    Satyaki De.

  • PLS-00386 when fetching into a previously declared type.

    I received error PLS-00386 when trying to fetch a cursor into a variable based on an object:
    SQL >-- Create type based on scott.emp
    SQL >CREATE OR REPLACE TYPE t_emp AS OBJECT
    2 (
    3 empno NUMBER(4),
    4 ename VARCHAR2(10),
    5 job VARCHAR2(9),
    6 mgr NUMBER(4),
    7 hiredate DATE,
    8 sal NUMBER(7, 2),
    9 comm NUMBER(7, 2),
    10 deptno NUMBER(2)
    11 );
    12 /
    Type created.
    SQL >
    SQL >show error
    No errors.
    SQL >
    SQL >-- Create a function that fetches records into t_emp:
    SQL >
    SQL >CREATE OR REPLACE FUNCTION emp_fn RETURN NUMBER IS
    2 l_emp t_emp;
    3 CURSOR c1 IS
    4 SELECT * FROM emp;
    5 BEGIN
    6 OPEN c1;
    7 LOOP
    8 FETCH c1
    9 INTO l_emp;
    10 EXIT WHEN c1%NOTFOUND;
    11 END LOOP;
    12 RETURN 0;
    13 END;
    14 /
    Warning: Function created with compilation errors.
    SQL >
    SQL >show error
    Errors for FUNCTION EMP_FN:
    LINE/COL ERROR
    8/5 PL/SQL: SQL Statement ignored
    9/12 PLS-00386: type mismatch found at 'L_EMP' between FETCH cursor
    and INTO variables
    SQL >
    Now when I declare the type exactly the same way inside the function, the function compiles and executes correctly:
    SQL >@test_emp2
    SQL >CREATE OR REPLACE FUNCTION emp_fn RETURN NUMBER IS
    2
    3 TYPE t_emp_rec IS RECORD(
    4 empno NUMBER(4)
    5 ,ename VARCHAR2(10)
    6 ,job VARCHAR2(9)
    7 ,mgr NUMBER(4)
    8 ,hiredate DATE
    9 ,sal NUMBER(7, 2)
    10 ,comm NUMBER(7, 2)
    11 ,deptno NUMBER(2));
    12
    13 l_emp t_emp_rec;
    14
    15 CURSOR c1 IS
    16 SELECT * FROM emp;
    17 BEGIN
    18 OPEN c1;
    19 LOOP
    20 FETCH c1
    21 INTO l_emp;
    22 EXIT WHEN c1%NOTFOUND;
    23 dbms_output.put_line( l_emp.empno);
    24 END LOOP;
    25 RETURN 0;
    26 END;
    27 /
    Function created.
    SQL >
    SQL >show error
    No errors.
    SQL >
    SQL >select emp_fn from dual;
    EMP_FN
    0
    1 row selected.
    Why can does the first function not compile and return PLS-00386?
    Thanks,
    Christoph

    Hi, Christoph,
    Christoph wrote:
    ... BTW: What do you do to format the code nicely like you did?This site normally doesn't display multiple spaces in a row.
    Whenever you post formatted text (such as query results) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Fetch x-number of rows into an array

    I have some code that selects out x-different number of rows (the number is related to different input data). Is there a good way to select into an array?
    Right now I'm doing it in a horrible way:
    -- finds out how many entries there are in the array
    v_i := v_array.last;
    open c_dyn_cursor for v_sql_stmt;
    loop
    -- There SHOULD be a better way to do this, but I've not found
    -- out how, this sucks!!
    if (v_i = 1) then
    fetch c_dyn_cursor into v_array(1);
    elsif (v_i = 2) then
    fetch c_dyn_cursor into v_array(1),v_array(2);
    elsif (v_i = 3) then
    fetch c_dyn_cursor into v_array(1),v_array(2),v_array(3);
    elsif (v_i = 4) then
    fetch c_dyn_cursor into v_array(1),v_array(2),v_array(3),v_array(4);
    end loop;
    I hope it's possible to do this a better way. Any suggestions?

    The problem though is that since I generate a dynamic sql I have no idea how to declare a variable to select into.
    If it wasn't a dynamic sql I could have done something like this I assume:
    Declare
    CURSOR c_emp IS
    select ename,sal,job from emp;
    r_emp c_emp%rowtype;
    Begin
    OPEN c_emp;
    Loop
    FETCH c_emp into r_emp;
    Exit when c_emp%NOTFOUND;
    Dbms_output.put_line(r_emp.ename || ', ' || r_emp.sal || ', ' || r_emp.job);
    End loop;
    CLOSE c_emp;
    End;
    But I Generate the SQL statement along the way.

  • Cursor fetch into

    I have a function, to which i pass a sql statement.In the function using the cursor i get the output of the sql statemnt into a output variable. This function works fine, but for one particular select statement it takes[u] over an hour to execute in the FETCH...INTO statement specifically. The same select statement when executed outside in sql editor returns in under 2 mins.
    The output of the sql is 5 records. Any ideas on why it is taking forever in the FETCH...INTO statment?
    FUNCTION getOutput(p_sql VARCHAR2)
    RETURN VARCHAR2
    AS
    TYPE extractlinecurtype IS REF CURSOR;
    cur_extract extractlinecurtype;
    v_oneextractline VARCHAR2 (32767);
    v_output VARCHAR2 (32767) := NULL;
    crlf CHAR (2) := CHR (10) || CHR (13);
    BEGIN
    OPEN cur_extract FOR p_sql;
    dbms_output.put_line(sysdate);
    LOOP
    FETCH cur_extract
    INTO v_oneextractline;
    EXIT WHEN cur_extract%NOTFOUND;
    v_output := v_output || CHR (10) || v_oneextractline;
    END LOOP;
    IF cur_extract%ISOPEN
    THEN
    CLOSE cur_extract;
    END IF;
    v_output := v_output || crlf || crlf;
    return v_output;
    EXCEPTION
    WHEN OTHERS
    THEN
    dbms_output.put_line('error in getoutput' || SQLCODE || SQLERRM);
    RETURN NULL;
    END getOutput;

    I cannot send the sql cause it uses our internal tables. My question is why does a query take under 2mins to run in sql editor and over an hr in pl/sql with cursor?
    Is there something wrong in declaration?

  • Fetch into object type

    Oracle 10.2.0.5.0
    Using Pl/SQL Developer
    Hi I'm new to collections, object types etc, so I aologize for any poor wording and missed concepts...
    I need to output a ref cursor from my package (for a summary report in SQL Server Reporting Services 2005). The summary report has two fields that come from the database table and 5 calculated fields. My idea for creating the ref cursor is as follows:
    1. Define an object type at the schema level
    2. Define a table (collection) type at the schema level
    3. Define a ref cursor at the package level
    4. Using dynamic SQL create a sql statement creating virtual columns for the 5 calculated fields
    5. Fetch cursor with dynamic sql into object type one record at a time
    6. Calculate the other five field values and update the object for each record processed
    7. Add the object 'record' to the table (collection) after each record is processed
    8. After the fetch is complete, convert the table to a ref cursor for returning to my application
    Here is what I have so far. I have cut out several of the calculated fields for simplicities sake. It is not complete and I don't know how to fetch the database row into the object, nor convert the collection to a ref cursor.
    Any help would be greatly appreciated.
    create or replace type dlyout.srvCtr_sum_rec_type as object (
                               zoneNo number,
                               zonetx varchar2(15),
                               distNo varchar2(4),
                               distTx varchar2(30),
                               numOccr number,
                               MEError varchar2(1));
    create or replace type dlyout.srvCtr_sum_tbl_of_recs is table of srvCtr_sum_rec_type;
    CREATE OR REPLACE PACKAGE DLYOUT.REPORTS_PKG is
      TYPE CUR IS REF CURSOR; 
    PROCEDURE testABC(startDate IN date,
                           endDate IN date,
                           startTime IN varchar2,
                           endTime IN varchar2,
                           zoneNo IN dlyout.loc.zone_no%type,
                           distNo IN dlyout.loc.dist_cd%type,
                           CUROUT OUT CUR);
    END;
    CREATE OR REPLACE PACKAGE BODY DLYOUT.REPORTS_PKG IS
      PROCEDURE testABC(startDate IN date,
                           endDate IN date,
                           startTime IN varchar2,
                           endTime IN varchar2,
                           zoneNo IN dlyout.loc.zone_no%type,
                           distNo IN dlyout.loc.dist_cd%type,
                           CUROUT OUT CUR) as
      startDateTimeStr varchar2(10) := to_Char(startDate, 'MM/DD/YYYY') ;     
      endDateTimeStr varchar2(10) := to_Char(endDate, 'MM/DD/YYYY');   
      startDateTime date := to_date(startDateTimeStr || ' ' || startTime, 'MM/DD/YYYY HH24:MI:SS');
      endDateTime date := to_date(endDateTimeStr|| ' ' || endTime, 'MM/DD/YYYY HH24:MI:SS');
      distClause varchar2(1000);
      sqls varchar2(2000);
      zoneClause varchar2(1000) :='';
      idx number :=0;
      curSrvCtr cur;
      srvCtrRec srvCtr_sum_rec_type;
      srvCtrTbl srvCtr_sum_tbl_of_recs :=srvCtr_sum_tbl_of_recs();
      BEGIN
        if zoneNo <> 9999 then
            zoneClause := ' and zone_no member of dlyout.reports_common_stuff_pkg.convert_to_collection(zoneNo)';
        end if;
        if distNo <> '9999' then
            distClause := ' and dist_cd member of dlyout.reports_common_stuff_pkg.convert_to_collection(distNo) ';
        end if;
        sqls := 'select distinct l.zone_no zoneNo, l.zone_tx zoneTx,
                l.dist_cd distCd , l.dist_tx distTx, 0 numOccr, '''' MEError       
                from dlyout.loc l
                where l.ts between  :startts and :endts ' ||
                zoneClause ||
                distClause ||
                ' order by l.zone_no, l.dist_tx ';
        open curSrvCtr for sqls using  startDateTime, endDateTime;
        LOOP
          FETCH curSrvCtr INTO srvCtrRec;      --ORA:00932 inconsistent datatype expected - got -
          EXIT WHEN curSrvCtr%NOTFOUND;
            --call other functions to get calculated fields
            srvCtrRec.numOccr := dlyout.reports_common_stuff_pkg.Num_Loc_Exc_Mom(startDateTimeStr, endDateTimeStr, starttime, endTime, srvctrRec.distno);
            srvCtrRec.MEError := dlyout.reports_common_stuff_pkg.ME_Error(startDateTimeStr, endDateTimeStr, starttime, endTime, srvCtrRec.distNo, null);
            dbms_output.put_line(srvCtrRec.distTx || ' ' || srvCtrRec.numoccr|| ' ' || srvCtrRec.MEError);
         end loop;
    end testABC;
    END;
      Then I need to add the object to the table. Something like this?
           -- add object 'record' to table
           srvCtrTbl.extend;
           srvCtrTbl.last := srvCtrRec;
    Then I am not sure how to do the cast to get the table to a ref cursor. Something like this?
    open curout for SELECT *
    FROM TABLE (CAST (srvCtrTbl AS srvCtr_sum_tbl_of_recs))
    ORDER BY zoneNo, distTx;

    Ok, so after more research if seems that in 10.2 you cannot assign an object (SQL) type to a ref cursor (PLSQL). SO i changed my direction and used a global temp table - created at the schema level.
    Create global temporary table dlyout.srvCtr_summary (
                               zoneNo number,
                               zonetx varchar2(15),
                               distNo varchar2(4),
                               distTx varchar2(30),
                               numOccr number,
                               MEError varchar2(1)
    ) on commit delete rows;Here is what the procedure looks like now.
    PROCEDURE testABC(startDate IN date,
                           endDate IN date,
                           startTime IN varchar2,
                           endTime IN varchar2,
                           zoneNo IN dlyout.location.zone_no%type,
                           distNo IN dlyout.location.dist_cd%type,
                           CUROUT OUT CUR) as
      startDateTimeStr varchar2(10) := to_Char(startDate, 'MM/DD/YYYY') ;     
      endDateTimeStr varchar2(10) := to_Char(endDate, 'MM/DD/YYYY');   
      startDateTime date := to_date(startDateTimeStr || ' ' || startTime, 'MM/DD/YYYY HH24:MI:SS');
      endDateTime date := to_date(endDateTimeStr|| ' ' || endTime, 'MM/DD/YYYY HH24:MI:SS');
      distClause varchar2(1000);
      sqls varchar2(2000);
      zoneClause varchar2(1000) :='';
      curSrvCtr cur;
    --Still need the PLSQL record type to put in the cursor for the dynamic SQL
    type srvCtr_sum_rec_type is record (zoneNo dlyout.location.zone_no%type,
                               zonetx dlyout.location.zone_tx%type,
                               distNo dlyout.location.dist_cd%type,
                               distTx dlyout.location.dist_tx%type,
                               numOccr number,
                               MEError varchar2(1));
      srvCtrRec srvCtr_sum_rec_type;
      BEGIN
        --create clauses for dynamic sql by calling other functions
        if zoneNo <> 9999 then
            zoneClause := ' and zone_no member of dlyout.reports_common_stuff_pkg.convert_to_collection(zoneNo)';
        end if;
        if distNo <> '9999' then
            distClause := ' and dist_cd member of dlyout.reports_common_stuff_pkg.convert_to_collection(distNo) ';
        end if;
        --here is the dynamic sql
        sqls := 'select distinct l.zone_no, l.zone_tx,
                l.dist_cd , l.dist_tx, 0, 0,
                0, 0, ''''       
                from dlyout.location l
                where l.enrgz_ts between  :startts and :endts ' ||
                zoneClause ||
                distClause ||
                ' order by l.zone_no, l.dist_tx ';
       open curSrvCtr for sqls using  startDateTime, endDateTime;
        LOOP
          --fetch in part of the record
          FETCH curSrvCtr INTO srvCtrRec;
          EXIT WHEN curSrvCtr%NOTFOUND;
          --do the calculations to get the other field values
            srvCtrRec.numOccr := dlyout.reports_common_stuff_pkg.Num_Loc_Exc_Mom(startDateTimeStr, endDateTimeStr, starttime, endTime, srvctrRec.distno);
             srvCtrRec.MEError := dlyout.reports_common_stuff_pkg.MEC_Error(startDateTimeStr, endDateTimeStr, starttime, endTime, srvCtrRec.distNo, null);
            dbms_output.put_line(srvCtrRec.distTx || ' ' || srvCtrRec.numoccr|| ' ' || srvCtrRec.MEError);
            --add record to GTT
            insert into dlyout.srvCtr_summary(zoneNo, zoneTx, distNo, distTX, numOccr, MEError )
            values(srvCtrRec.zoneNo, srvCtrRec.zoneTx, srvCtrRec.distNo, srvCtrRec.distTX, srvCtrRec.numOccr, srvCtrRec.MEError);
        end loop;
       --open GTT and return ref cursor to app
       open curout for SELECT *
           FROM srvCtr_summary
           ORDER BY zoneNo, distTx;
      end testABC;

  • How many records are  fetched my query into my internal tables

    Hi
    I am in the debugger, would like to know, how many records are  fetched my query into my internal tables. How do I  find out ?
    thanks
    siva

    Hi,
    Do the following,
    Step 1:
      Fill your internal table with select query.
    Step 2 : Use DESCRIBE statement with LINE addition to get the no of rows in the internal table.
    for further informations, check
    http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb3798358411d1829f0000e829fbfe/content.htm
    Regards,
    Anirban

  • Dynamic query and Open Cursor fetch into ??

    Hi;
    I think we took the wrong turn some were... because looks like a dead end...
    What I need to do:
    Create a procedure to compare two generic tables in diferente databases and find rows that have diferent data.
    (No restritions on what tables it might compare)
    What I have done:
    CREATE OR REPLACE PROCEDURE COMPARE_TABLES_CONTENT_V3(
    tableName_A IN VARCHAR2, tableName_B IN VARCHAR2, filter IN VARCHAR2) AS
    -- Get all collumns present in [TableName_A]
    -- This is necessary to create a dynamic query
    select column_name bulk collect
    into v_cols1
    from all_tab_columns
    where table_name = v_tab1
    and owner = nvl(v_own1, user)
    order by column_id;
    -- If there is no columns in table A ... them no need to proceed
    if v_cols1.count = 0 then
    dbms_output.put_line('[Error] reading table ' || tableName_A ||
    ' collumns information. Exit...');
    return;
    end if;
    -- Collect Collumns information by ',' separated, for the query
    for i in 1 .. v_cols1.count loop
    compareCollumns := compareCollumns || ',' || v_cols1(i);
    end loop;
    -- Create the query that gives the diferences....
    getDiffQuery := 'select ' || compareCollumns ||
    ' , count(src1) CNT1, count(src2) CNT2 from (select a.*, 1 src1, to_number(null) src2 FROM ' ||
    tableName_A ||
    ' a union all select b.*, to_number(null) src1, 2 src2 from ' ||
    tableName_B || ' b) group by ' || compareCollumns ||
    ' having count(src1) <> count(src2)';
    Whats the problem?
    I'm lost...I can access the query using debugging on the oracle procedure... and run it OK on a new SQL window. No problem here... its perfect.
    But I dont know how to access this information inside the procedure, I need to format the information a bit...
    I try a cursor...
    open vCursor for getDiffQuery;
    fetch vCursor into ??????? -- Into what... query, columns and tables is all dynamic...
    close vCursor;
    Any ideas..

    Making the issue more simple....
    At this point I have a oracle procedure that generates a dynamic sql query, based on the table names passed by parameter.
    getDiffQuery := 'select ' || compareCollumns || (.....)
    end procedure;
    This ''getDiffQuery'' contains a query that gets the diferences in the tables. (Working fine)
    I would like to access this information in the same procedure.
    I cant use cursor because the table, columns... actualy all is dynamic based on the generated query:( !

  • To fetch selective fields from DATABASETABLE into Internal TABLE

    Hi Friends,
    I have declared an internal table with fields for e.g. A , B , C , D.
    This does not have any records as of now.
    I have to fetch data from a DATABASE TABLE with fields A , B , X , Y , Z having records .
    I only need records for fields A B fron DB table.Can any one pls tell how can I do that with performance issues in mind as lots of records are there.
    I had written a query where:
    SELECT A B from dbtab
                        into CORRESPONDING FIELDS of table it_table.
    It_table i had defined with only two fields A B.
    Is this correct?
    Please tell wats the way to do it as I am new to ABAP.
    THANKS in ADVANCE..

    Hi.....
    What mentioned in all above answers is very helpful for ur requirement...
    and...
       Here some Steps to increase the performence of your programs...
    >Use Select Single when only one row is expected
    >Use Select Where rather than Selectu2026Check
    >Use Select with aggregate functions (SUM, MAX, MINu2026)
    >Use a View instead of nested Selects
    >Use Select column specific instead of select * for few fields
    >Use Selectu2026Into Table rather than Select...Move Corru2026Apend
    >Use Join extension with Select if possible
    >Use special operators (CO, CA, CS) rather than code your own
    >Use Delete Adjacent Duplicates rather than manual processing
    >Specify key fields for Readu2026Binary Search
    >Use Loop At Where rather than Loop Atu2026Check
    >Copy Internal Tables with TAB_DEST() = TAB_SRC()
    >Specify the sort key as restrictively as possible
    >Use Append To, Insert Into, Collect Into rather than Move
    >Compare tables with If Tab1() = Tab2()u2026
    >Use Delete ITAB Whereu2026 instead of Loop At ITAB Whereu2026Delete..
    >Use Case statements instead of If-constructions
    >Use Call Functions wisely, Performs use less memory
    >Use While instead of Do Exit
    >Use Type I for Indices
    >Keep Occurs clause realistic or use 0
    >Use COMMIT WORK as appropriate to free the Data Base and preserve work
    >
    >Avoid:
    >Using Shift inside a While-loop
    >Leaving unneeded declarations in your program
    >Using Move-corresponding for just a few fields
    >Excessive nested includes within function calls
    >Using DB field names if the value will be changed
    >Using Occurs clause if only the header is needed
    Thanks,
    Naveen.I

  • Fetch data into internal table

    Hi all,
    I want to fetch all the opbel records from erdk table into an intrnal table.
    Only opbel records.There are 100000000 records in erdk table.
    How can I fetch into internal table ? what statement can I use to fetch the data faster keepin performance into consideration ?
    Many thanks

    Hi,
    As far as data fetch is concerned you do the same as follows:
    Select * from erdk into table itab
    where..... < Your Where Condition if any>.
    But as the number of records are very high, first try to put all the primary keys in the where clause and also if possible, try to narrow down the selection criteria by fetching data from some other table or widening the conditions in where clause.
    Also try to fetch only thode fields which you actually need.
    else your program will give performance problems.
    Hope this helps!
    Regards,
    Lalit

Maybe you are looking for

  • I can not activate my iPhone 4S

    I can not activate my iPhone 4S.. Help me :/

  • TAXINN procedure - Key combination : Plant/Vendor/Service Activity?

    Hi FI experts, I wud like to have key combination for Tax conditions maintained at FV11, as per the following Plant / Vendor / Service Activity number Kindly revert whether the above is possible to configure or not. We are using Taxinn procedure. Ite

  • PdfMaker problem

    Dear the supporrt, AS I tried to create pdf from Adobe Acrobat Xi or Office 2010, they both gave me an error of "An Unexpected error occurred. PDFMaker was unable to produce the Adobe PDF" My computer is running in Win7 Professional with 64-bit offic

  • I am new to Motion and am going through the Lynda tutorials on how to use it...

    and there is a tutorial where the instructor is explaining text behaviors and he navigates to the text sequence folder in the library.  I have this folder, but there is nothing in it.  Is this something that I need to create or purchase? Thanks, C

  • HR Queries package

    Hi all, I downloaded HR Queries 50.2 business package and imported into EP6. I have created a system in EP called SAP_BW inorder to access BW data. Are there any more steps that I'm need to do inorder to view iviews? Moreover is there any installatio