Report of update SQL query with line selector. Update process.

I have a report of update SQL query with the selectors in line.
How to identify line selector in a process update on the page.

I want to update some columns with a value of an area of selection on the page.

With the help of the base:

UPDATE table_name
SET Column1 = value
WHERE some_column = some_value

I would need to do:

UPDATE table_name
SET column1 =: P1_select
WHERE [line selector] =?

Now sure how to identify [line selector] and/or validate it is checked.
Thank you
Bob

Identify the name of the checkbox of the source of the page element, it should be of the fxx format (f01, f02... f50).
Suppose that we f01.

for i in 1 .. apex_application.g_f01.count
loop
  UPDATE CONTRACTS
  SET SIP_LOAD_FLAG = :P16_STATUS
  where  =  apex_application.g_f01(i); --i'th checked record' primary key
end loop;

Tags: Database

Similar Questions

  • (Editable report) SQL query with line selector

    I used this code to get the update of the records in a query SQL (editable report).
    Updates a value in a selection box.

    because me in 1... apex_application.g_f01. Count
    loop
    UPDATE CONTRACTS
    SET LOAD_FLAG =: P8_SELECT
    WHERE ID = apex_application.g_f01 (i); -i'the checked the file 'primary key '.
    end loop;

    Here's my dilemma.
    Line selector seems to be in a fixed position.
    By linking the line for identification number selector (1, 2, 3, etc.)
    Sort by ID (1, 2, 3, etc.)
    It works perfectly, as long as the ID is sorted in order. < <
    If it is sorted by another field with say ID 29 now in the 1st row, by checking the box and update, you update ID #1 located elsewhere on the page.
    Any ideas how to make the line selector literally equal to the line, it is displayed in?
    Thank you
    Bob

    I think I have an idea of what is wrong and, eventually, how to fix it. Try this:

    make your field primary key (NO ROWID!) in a column in a table column, either through the "wizard" (i.e. through the report attributes screen), or using the APEX_ITEM api (as described by Vee). I often have my primary key as a hidden; If you really need to see it, you can use "DISPLAY_AND_SAVE".

    So if your primary key 'ID' colum is now in the 2nd table as a table (i.e. f02 - adjust accordingly!), your PL/SQL process should look like this:

    for i in 1 .. apex_application.g_f01.count
    loop
       UPDATE CONTRACTS
          SET LOAD_FLAG = :P8_SELECT
        where ID = apex_application.g_f02(apex_application.g_f01(i)); 
    
    end loop;
    

    It of a little confusing at first but it it makes sense when you train how tabular tables work with check boxes. The length of this array represents only what is verified - so if you have 3 values checked, the cardinality of the table in a particular table 3. On the other hand, your other tabular berries (containing the 'normal' values) has a cardinality of the count of all the visible lines.

    In this case, the record selector (F01) contains the ID of the relevant line in your report - so passing this value in the array index 2 (F02) should give you the correct primary key for that particular line value. If you subsequently order the report by another field, it should work again.

    I should add that Vee method will work well - the difference is that, instead of organizing the rowid, f01 contains the actual key value. Hope this helps

    Published by: Joel_C on March 21, 2011 11:50

  • Write a SQL query with lines in columns

    All the

    I need help in writing a SQL query with lines in columns, let give u an example...

    drop table activity;

    CREATE TABLE 'ACTIVITY '.

    (

    "PROJECT_WID" NUMBER (22.0) NOT NULL,

    VARCHAR2 (150 CHAR) "PROJECT_NO."

    VARCHAR2 (800 CHAR) 'NAME '.

    );

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1683691, '10007', 12-121');

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1684994, '10008', 12-122');

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1686296, '10009', 12-123');

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (2225222, '9040', 12-124');

    drop table lonet;

    CREATE TABLE 'LONET.

    (

    VARCHAR2 (150 CHAR) "NAME."

    NUMBER OF THE "ROOT."

    VARCHAR2 (150 CHAR) "ENTRYVALUE".

    );

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("GAC", 1683691, "LDE");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('NAM', 1683691, 'LME');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('BAG', 1683691, 'ICE');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1683691, 'IKE');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('NAM', 1686291, "QTY");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1686291, 'MAX');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("GAC", 1684994, "MTE");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1684994, 'MAC');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('FMT', 1684994, 'NICE');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('FMR', 1684994, 'RAY');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('BAG', 1686296, "CAQ");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("PAP", 1686296, "QAQ");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("VANESSA", 1686296, "THEW");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("ANDR", 1686296, "REYL");

    commit;

    Link: activity.project_wid = lonet.root

    look like output

    Project_wid Project_no NAME GAC NAM BAG RAC
    16836911000712-121LDELMELCELKE
    16849941000812-122MTEnullnullMAC
    16862961000912-123nullnullCAQQAQ
    2225222904012-124nullnullnullnull

    two problems, in that I am running

    1. I dono how simply we can convert rows to columns

    2. for root = 1683691, there are double NAM and RAC in lonet table... ideally these data should not be there, but since its here, we can take a MAX so that it returns a value

    3. There are undesirables who should be ignored

    Once again my thought process is that we join the activity and 4 alias table lonet.

    ask for your help in this

    Thank you

    Hello

    This is called pivoting.

    Here's a way to do it:

    WITH relevant_data AS

    (

    SELECT a.project_wid, a.project_no, b.SID

    , l.name AS lonet_name, l.entryvalue

    Activity one

    LEFT OUTER JOIN lonet l.root = a.project_wid l

    )

    SELECT *.

    OF relevant_data

    PIVOT (MAX (entryvalue)

    FOR lonet_name IN ("GAC" IN the gac

    "NAM" AS nam

    'BAG' IN the bag

    "RAC" AS cars

    )

    )

    ORDER BY project_wid

    ;

    Output:

    PROJECT_WID PROJECT_NO GAC NAM BAG RAC NAME

    ----------- ---------- ---------- ---------- ---------- ---------- ----------

    1683691 12 - 10007 121 LDE LME LCE LKE

    1684994 MAC MTE 10008 12-122

    1686296 12 - 10009 123 QAC QAQ

    2225222 9040 12 - 124

    To learn more about swivel, see the FAQ in the Forum: Re: 4. How can I convert rows to columns?

    Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!

  • More than 1 SQL query with checkbox and error invalid number report

    Hi all

    I have two SQL query reports that each has an apex_item.checkbox and two processes for each report.  A report/process works very well.  It gives me an error of invalid number.

    In addition, another query SQL (editable report) gives me the following error when using the Multi line process, delete.

    ORA-06502: PL/SQL: digital or value error: character number conversion
    error ORA-06502: PL/SQL: digital or value error: character number conversion
    error
    Ok

    When I got a report from SQL query (with box and a process) and the query SQL (editable report) everything worked.  It stopped working when I added another SQL query report (with box and a process).

    A SQL query has the following in my query: apex_item.checkbox(3,email_id,'UNCHECKED') ""

    The other SQL query has the following: apex_item.checkbox(2,b.file_id,'UNCHECKED') ""

    Any help will be greatly appreciated,

    Sylvia

    Hi Reema,

    I've recreated the region and now it works!

    Thank you for this, looking at

    Sylvia

  • SDO_RELATE within PL/SQL query with rownum clause runs slowly on 12 c - works great on 10 g

    Hello

    I use the database 12.1.0.2 with a node 2 RAC on Windows.

    I am struck by a really weird performance problem with a particular query.  Bear with me while I try to explain...

    I have a chart with lines 30 sdo_geometry million, in 7 partitions with a local partitioned spatial index divided.  Called BIG_PARTITIONED_TABLE for this example.

    I query the table to search for one line with a geometry that is equal to the geometry of my request.  In this case I use sdo_relate with "mask = equal".  Instantly returns:

    SQL> select id, geometry
      2  from       BIG_PARTITIONED_TABLE o
      3  where      sdo_relate(o.geometry, sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1),
      4     SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272)), 'mask=equal') = 'TRUE'
      5  and rownum = 1;
    
            ID
    ----------
    GEOMETRY(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
    -------------------------------------------------------------------------------
    2.5405E+12
    SDO_GEOMETRY(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272))
    
    Elapsed: 00:00:00.10
    
    

    But if I put the same query in PL/SQL, so it takes 21 seconds:

    SQL> declare
      2     l_id number;
      3     l_geom sdo_geometry;
      4     l_window_geom sdo_geometry;
      5  begin
      6     l_window_geom := sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1),
      7             SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272));
      8
      9     select id, geometry
    10     into l_id, l_geom
    11     from    BIG_PARTITIONED_TABLE o
    12     where   sdo_relate(o.geometry, l_window_geom, 'mask=equal') = 'TRUE'
    13     and rownum = 1;
    14
    15  end;
    16  /
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:21.13
    
    

    If I remove the "rownum = 1", then it returns instantly:

    SQL> declare
      2     l_id number;
      3     l_geom sdo_geometry;
      4     l_window_geom sdo_geometry;
      5  begin
      6     l_window_geom := sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1),
      7             SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272));
      8
      9     select id, geometry
    10     into l_id, l_geom
    11     from    BIG_PARTITIONED_TABLE o
    12     where   sdo_relate(o.geometry, l_window_geom, 'mask=equal') = 'TRUE';
    13
    14  end;
    15  /
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:00.03
    
    

    If using sdo_equal instead of sdo_relate and keep the "rownum = 1", then it returns instantly.

    SQL> declare
      2     l_id number;
      3     l_geom sdo_geometry;
      4     l_window_geom sdo_geometry;
      5  begin
      6     l_window_geom := sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1),
      7             SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272));
      8
      9     select id, geometry
    10     into l_id, l_geom
    11     from    BIG_PARTITIONED_TABLE o
    12     where   sdo_equal(o.geometry, l_window_geom) = 'TRUE'
    13     and rownum = 1;
    14
    15  end;
    16  /
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:00.13
    
    

    Here is a comparison of the plans to explain.  First, here's the good thing, that is using the spatial index (BIG_PARTITIONED_TABLE_SPIND):

    select id, GEOMETRY
    FROM
    BIG_PARTITIONED_TABLE O WHERE SDO_EQUAL(O.GEOMETRY, :B1 ) = 'TRUE'
    AND ROWNUM = 1
    
    call     count       cpu    elapsed       disk      query    current        rows
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.01       0.02          0         39          0           0
    Fetch        1      0.00       0.01          0         31          0           1
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    total        3      0.01       0.04          0         70          0           1
    
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 263     (recursive depth: 1)
    Number of plan statistics captured: 1
    
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
    ---------- ---------- ----------  ---------------------------------------------------
             1          1          1  COUNT STOPKEY (cr=99 pr=0 pw=0 time=43307 us)
             1          1          1   PARTITION RANGE ALL PARTITION: 1 7 (cr=99 pr=0 pw=0 time=43297 us cost=0 size=66 card=1)
             1          1          1    TABLE ACCESS BY LOCAL INDEX ROWID BIG_PARTITIONED_TABLE PARTITION: 1 7 (cr=99 pr=0 pw=0 time=43280 us cost=0 size=66 card=1)
             1          1          1     DOMAIN INDEX  BIG_PARTITIONED_TABLE_SPIND (cr=98 pr=0 pw=0 time=43250 us)
    
    

    Then the slow that does not use the spatial index.

    select id, GEOMETRY
    FROM
    BIG_PARTITIONED_TABLE O WHERE SDO_RELATE(O.GEOMETRY, :B1 , 'mask=equal') = 'TRUE'
      AND ROWNUM = 1
    
    call     count       cpu    elapsed       disk      query    current        rows
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    Parse        1      0.01       0.00          0          0          0           0
    Execute      1      0.03       0.03          0       1123          0           0
    Fetch        1     24.25      24.25          0     499429          0           1
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    total        3     24.30      24.29          0     500552          0           1
    
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 263     (recursive depth: 1)
    Number of plan statistics captured: 1
    
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
    ---------- ---------- ----------  ---------------------------------------------------
             1          1          1  COUNT STOPKEY (cr=499532 pr=0 pw=0 time=24289612 us)
             1          1          1   HASH JOIN RIGHT SEMI (cr=499532 pr=0 pw=0 time=24289586 us cost=32 size=144 card=1)
             1          1          1    VIEW  VW_NSO_1 (cr=103 pr=0 pw=0 time=31110 us cost=29 size=98016 card=8168)
             1          1          1     COLLECTION ITERATOR PICKLER FETCH SDO_PQRY (cr=103 pr=0 pw=0 time=31104 us cost=29 size=16336 card=8168)
      16914892   16914892   16914892    PARTITION RANGE ALL PARTITION: 1 7 (cr=499429 pr=0 pw=0 time=28678375 us cost=3 size=6600 card=100)
      16914892   16914892   16914892     TABLE ACCESS FULL BIG_PARTITIONED_TABLE PARTITION: 1 7 (cr=499429 pr=0 pw=0 time=23406547 us cost=3 size=6600 card=100)
    
    

    I tried adding an indication / * + index (o BIG_PARTITIONED_TABLE_SPIND) * / but that did not help.

    I am struck this issue during testing of upgrade 10.2.0.5 to 12.1.0.2.  The query works perfectly on 10g - we note only that this question on 12 c.

    I can't use sdo_equal as the real mask that we want is equal + dommagescausdspar + covers.  I'm just using equal here to simplify the test.

    I use "rownum = 1" because I want to just the first result.  In practice I can rewrite probably is a FOR LOOP, I get out after the first result, but that seems all just awful.

    Any ideas?  If anyone has seen anything like this before?  Its an optimizer delivers really so I'm going to cross post the SQL Forum after a certain time, but thought I would post it here first.

    Thank you

    John

    Hi John,.

    Can you please try the following before your slow queries event?

    "ALTER session set events ' trace 54669 name context forever."

    Thank you

    Ying

  • SQL query with the troubleshooting Subselects

    I have a query with the 3 Subselects. Each of the Subselects works very well on its own. I run the query in Oracle SQL Developer and get ORA 933 "sql command not completed successfully" at 47 48 line pass. I am unable to say what is causing the error. The pointers you know sincerely!

    Here is the code:
    SELECT 
      adjud.country,
      adjud.site,
      adjud.prodtype,
      sum(adjud.acount) + sum(denied.dcount) as TotalClosed,
      case when adjud.adtype = 'Paid' then adjud.acount End as NumPaid,
      case when adjud.adtype = 'Paid' then adjud.totalpaid End as AmtPaid,
      count(adjud.contest) + count(denied.contest) + count(pend.contest) as CntContestable,
      sum(pend.pcount) as PendingCount,
      Case when pend.overunder = 'Over' Then count(pend.pcount) End as Over90Count,
      sum(pend.facevalue) as PendingAmount
    From 
    ( select 
        count(clm.clm_nbr) as acount, 
        sum(clm.rsrv_amt) as facevalue,
        sum(clm.tot_pd_amt) as totalpaid,
        clm.prdt_type_nm as prodtype,
        clm.cntsbl_indc as contest,
        case when clm.exam_co_cd in ('107','134')
          then 'Hong Kong'
          else 
            case when clm.exam_co_cd = '234'
              then 'Singapore'
              else 'US'
            End
        End as country,
        clm.exam_admin_site_cd as site,
        Case when clm.rmk_cd in ('R00', 'R01', 'R02') then 'Denied' Else 'Paid' End as adtype
      from afp_cds.claim_vw clm
      where 
        clm.adjud_dt is not null and 
        clm.adjud_dt > :startDate and
        clm.adjud_dt < :EndDate
      group by 
        clm.prdt_type_nm,
        clm.cntsbl_indc,
        case when clm.exam_co_cd in ('107','134') 
          then 'Hong Kong'
          else 
            case when clm.exam_co_cd = '234'
              then 'Singapore'
              else 'US'
            End
        End,
        clm.exam_admin_site_cd,
        Case when clm.rmk_cd in ('R00', 'R01', 'R02') then 'Denied' Else 'Paid' End
    ) as adjud, 
    ( select 
        count(clm.clm_nbr) as dcount,
        sum(clm.rsrv_amt) as facevalue,
        clm.prdt_type_nm as prodtype,
        case when clm.exam_co_cd in ('107','134') 
          then 'Hong Kong'
          else 
            case when clm.exam_co_cd = '234'
              then 'Singapore'
              else 'US'
            End
        End as country,
        clm.exam_admin_site_cd as site,
        clm.cntsbl_indc as contest
      from afp_cds.claim_vw clm
      where 
        clm.deny_dt is not null and
        clm.deny_dt > :startDate and
        clm.deny_dt < :EndDate
      group by
        clm.prdt_type_nm,
        case when clm.exam_co_cd in ('107','134') 
          then 'Hong Kong'
          else 
            case when clm.exam_co_cd = '234'
              then 'Singapore'
              else 'US'
            End
        End,
        clm.exam_admin_site_cd,
        clm.cntsbl_indc
    ) as denied,
    ( select 
        count(clm.clm_nbr) as pcount, 
        sum(clm.rsrv_amt) as facevalue,
        clm.prdt_type_nm as prodtype,
        case when clm.exam_co_cd in ('107','134') 
          then 'Hong Kong'
          else 
            case when clm.exam_co_cd = '234'
              then 'Singapore'
              else 'US'
            End
        End as country,
        clm.exam_admin_site_cd as site,
        clm.cntsbl_indc as contest,  
        case when sysdate - clm.regtrtn_dt > 90 then 'Over' else 'Under' End as overunder
      from afp_cds.claim_vw clm
      where
        clm.adjud_dt is null and
        clm.deny_dt is null
      group by
        clm.prdt_type_nm,
        case when clm.exam_co_cd in ('107','134') 
          then 'Hong Kong'
          else 
            case when clm.exam_co_cd = '234'
              then 'Singapore'
              else 'US'
            End
        End,
        clm.exam_admin_site_cd,
        clm.cntsbl_indc,  
        case when sysdate - regtrtn_dt > 90 then 'Over' else 'Under' End
    ) as pend
    
    where
      adjud.prodtype = denied.prodtype and
      adjud.country = denied.country and
      adjud.site = denied.site and
      adjud.contest = denied.contest and
      adjud.prodtype = pend.prodtype and
      adjud.country = pend.country and
      adjud.site = pend.site and
      adjud.contest = pend.contest 
    group by
      adjud.country,
      adjud.site,
      adjud.prodtype,
      case when adjud.adtype = 'Paid' then adjud.acount End,
      case when adjud.adtype = 'Paid' then adjud.totalpaid End,
      Case when pend.overunder = 'Over' Then count(pend.pcount) End

    Do not use "Sub" with the table alias.

    Change this stmt type:

    ) as adjud,
    

    TO

    ) adjud,
    
  • SQL query with terms and calculations?

    Hello
    How do I create a query with terms and calculations?
    For example, I have this table


    Start | End |     At work |     Mandatory
    ------------------------------------------------------------------------------------
    1ST JANUARY 13 | JANUARY 11, 13.     Office |          1
    JANUARY 14, 13. 25 JANUARY 13 |     Ministry of the Interior.     0
    04-MRZ-13 | 15-MRZ-13 |     Office |          0
    FEBRUARY 11, 13. FEBRUARY 22, 13.     Office |          1


    Now, if the workplace of the column = office and required column = 0
    the new 'price' column should calculate: (end-start) * $25.00
    and if workplace = Office and required column = 1
    the 'price' column must calculate: (end-start) * $20.60
    any other $0.00

    I tried with the case statement, but I didn't know how
    to calculate my values and display in the virtual column 'price '.

    Something like
    case
    When Working_Place = 'Office' and mandatory = 1
    then...
    else ' 0.00'. "
    end PRICE
    ?????


    Or is that not possible?

    Published by: DB2000 on 12.03.2013 05:09

    Use CASE:

    select  start_dt,
            end_dt,
            working_place,
            mandatory,
            case
              when working_place = 'Office' and mandatory = 0 then (end_dt - start_dt) * 25
              when working_place = 'Office' and mandatory = 1 then (end_dt - start_dt) * 20.60
              else 0
            end price
      from  tbl
    /
    
    START_DT  END_DT    WORKING_PLA  MANDATORY      PRICE
    --------- --------- ----------- ---------- ----------
    01-JAN-13 11-JAN-13 Office               1        206
    14-JAN-13 25-JAN-13 Home Office          0          0
    04-MAR-13 15-MAR-13 Office               0        275
    11-FEB-13 22-FEB-13 Office               1      226.6
    
    SQL> 
    

    SY.

  • SQL query with dynamic exercise

    Hello

    I wrote this query with static exercise and exercise, I need info on making the dynamic variables

    Exercise: starts from July1st. This year up to June 30 is "2011" and July ' 1's '2012'
    Exercise: July1st his '1' and June ' 1 his '12'

    Query:

    Select distinct o.c_num, o.ac_num, s.sub_ac_num, o.fiscal_year, o.ac_exp_date, s.sub_ac_ind
    of org_account o
    outer join left sub_account s
    on o.c_num = s.c_num and o.ac_num = s.ac_num
    where (o.ac_exp_date > = CURRENT_DATE or o.ac_exp_date is null)
    and o.fiscal_year = * '2011' * -> need to be dynamic
    and o.fiscal_period = * '12' * -> need to be dynamic

    Thank you
    Mano

    Published by: user9332645 on June 2, 2011 18:55

    Hi, Mano,

    Welcome to the forum!

    Whenever you have a question, please post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data.
    Always tell what version of Oracle you are using.

    Since this is your first thread, I will post some examples of data for you:

    CREATE TABLE     table_x
    (     dt     DATE
    );
    
    INSERT INTO table_x (dt) VALUES (DATE '2010-12-31');
    INSERT INTO table_x (dt) VALUES (DATE '2011-01-01');
    INSERT INTO table_x (dt) VALUES (DATE '2011-06-02');
    INSERT INTO table_x (dt) VALUES (DATE '2011-06-30');
    INSERT INTO table_x (dt) VALUES (DATE '2011-07-01');
    

    What is the output you can from these data?

    DT          FISCAL_YEAR     FISCAL_PERIOD
    ----------- --------------- ---------------
    31-Dec-2010 2011            06
    01-Jan-2011 2011            07
    02-Jun-2011 2011            12
    30-Jun-2011 2011            12
    01-Jul-2011 2012            01
    

    If so, here's a way to get it:

    SELECT       dt
    ,       TO_CHAR ( ADD_MONTHS (dt, 6)
                , 'YYYY'
                )     AS fiscal_year
    ,       TO_CHAR ( ADD_MONTHS (dt, 6)
                , 'MM'
                )     AS fiscal_period
    FROM       table_x
    ORDER BY  dt
    ;
    

    Since your exercise begins 6 months prior to the calendar year, you must add 6 months to the actual date for the fiscal year and month.

    The above query produces strings for fiscal_year and fiscal_period. If you prefer to have the numbers, then use EXTRACT instead of TO_CHAR:

    SELECT       dt
    ,       EXTRACT (      YEAR
                FROM     ADD_MONTHS (dt, 6)
                )     AS fiscal_year
    ,       EXTRACT (      MONTH
                FROM     ADD_MONTHS (dt, 6)
                )     AS fiscal_period
    FROM       table_x
    ORDER BY  dt
    ;
    

    The first query will work in Oracle 6 (and more).
    I don't know when EXTRACT was introduced. Certainly, it works in Oracle 10 and may be available in older versions too.

  • Help setting up a SQL query with poor performance

    Hi all

    Database version: 10.2.0.5

    I'm working on a new report to view the top users by the number of calls. The table is truncated and filled again every month with records for the previous month; It contains approximately 400 000 records.

    I created a view with the columns needed for the report; also, the two functions of view calls to determine if a phone number is assigned to multiple staffs or several departments.

    It's full again table every month:

     CREATE TABLE "VOIP"."MONTHLY_BILLING_DETAILS" 
       (    "ID" NUMBER NOT NULL ENABLE, 
        "CDRRECORDTYPE" NUMBER, 
        "G_CALLMANAGERID" NUMBER, 
        "G_CALLID" NUMBER, 
        "O_LEGCALLIDENTIFIER" NUMBER, 
        "DATETIMEORIGINATION" NUMBER, 
        "O_NODEID" NUMBER, 
        "O_SPAN" NUMBER, 
        "O_IPADDR" NUMBER, 
        "CALLINGPARTYNUMBER" VARCHAR2(50 BYTE) NOT NULL ENABLE, 
        "CALLINGPARTY_USERID" VARCHAR2(128 BYTE), 
        "O_CAUSE_LOCATION" NUMBER, 
        "O_CAUSE_VALUE" NUMBER, 
        "O_PRECEDENCELEVEL" NUMBER, 
        "O_MEDIATRANSPORTADDR_IP" NUMBER, 
        "O_MEDIATRANSPORTADDR_PORT" NUMBER, 
        "O_MCAP_PAYLOADCAPABILITY" NUMBER, 
        "O_MCAP_MAXFRAMESPERPACKET" NUMBER, 
        "O_MCAP_G723BITRATE" NUMBER, 
        "O_VCAP_CODEC" NUMBER, 
        "O_VCAP_BANDWIDTH" NUMBER, 
        "O_VCAP_RESOLUTION" NUMBER, 
        "O_VIDEOTRANSPORTADDR_IP" NUMBER, 
        "O_VIDEOTRANSPORTADDR_PORT" NUMBER, 
        "O_RSVPAUDIOSTAT" VARCHAR2(64 BYTE), 
        "O_RSVPVIDEOSTAT" VARCHAR2(64 BYTE), 
        "DESTLEGIDENTIFIER" NUMBER, 
        "DESTNODEID" NUMBER, 
        "DESTSPAN" NUMBER, 
        "DESTIPADDR" NUMBER, 
        "ORIGINALCALLEDPARTYNUMBER" VARCHAR2(50 BYTE), 
        "FINALC_PARTYNUMBER" VARCHAR2(50 BYTE), 
        "FINALC_PARTY_USERID" VARCHAR2(128 BYTE), 
        "DESTCAUSE_LOCATION" NUMBER, 
        "DESTCAUSE_VALUE" NUMBER, 
        "DESTPRECEDENCELEVEL" NUMBER, 
        "DESTMEDIATRANSPORTADDR_IP" NUMBER, 
        "DESTMEDIATRANSPORTADDR_PORT" NUMBER, 
        "DESTMCAP_PAYLOADCAPABILITY" NUMBER, 
        "DESTMCAP_MAXFRAMESPERPACKET" NUMBER, 
        "DESTMCAP_G723BITRATE" NUMBER, 
        "DV_CAP_CODEC" NUMBER, 
        "DV_CAP_BANDWIDTH" NUMBER, 
        "DV_CAP_RESOLUTION" NUMBER, 
        "DV_TRANSPORTADDR_IP" NUMBER, 
        "DV_TRANSPORTADDR_PORT" NUMBER, 
        "DESTRSVPAUDIOSTAT" VARCHAR2(64 BYTE), 
        "DESTRSVPVIDEOSTAT" VARCHAR2(64 BYTE), 
        "DATETIMECONNECT" NUMBER, 
        "DATETIMEDISCONNECT" NUMBER, 
        "LASTREDIRECTDN" VARCHAR2(50 BYTE), 
        "PKID" VARCHAR2(4000 BYTE), 
        "O_INALCALLEDPARTYNUM_PARTITION" VARCHAR2(50 BYTE), 
        "CALLINGPARTYNUM_PARTITION" VARCHAR2(50 BYTE), 
        "FINALC_PARTYNUM_PARTITION" VARCHAR2(50 BYTE), 
        "LASTREDIRECTDNPARTITION" VARCHAR2(50 BYTE), 
        "DURATION" NUMBER, 
        "O_DEVICENAME" VARCHAR2(129 BYTE), 
        "DESTDEVICENAME" VARCHAR2(129 BYTE), 
        "O_CALLTERMINATION_BEHALF" NUMBER, 
        "DESTCALLTERMINATION_BEHALF" NUMBER, 
        "O_CALLEDPARTYREDIRECT_BEHALF" NUMBER, 
        "LASTREDIRECTREDIRECT_BEHALF" NUMBER, 
        "O_CALLEDPARTYREDIRECTREASON" NUMBER, 
        "LASTREDIRECTREDIRECTREASON" NUMBER, 
        "DESTCONVERSATIONID" NUMBER, 
        "G_CALLID_CLUSTERID" VARCHAR2(50 BYTE), 
        "JOIN_BEHALF" NUMBER, 
        "COMMENTS" VARCHAR2(2048 BYTE), 
        "AUTHCODEDESCRIPTION" VARCHAR2(50 BYTE), 
        "AUTHORIZATIONLEVEL" NUMBER, 
        "CLIENTMATTERCODE" VARCHAR2(32 BYTE), 
        "O_DTMFMETHOD" NUMBER, 
        "DESTDTMFMETHOD" NUMBER, 
        "CALLSECUREDSTATUS" NUMBER, 
        "O_CONVERSATIONID" NUMBER, 
        "O_MCAP_BANDWIDTH" NUMBER, 
        "DESTMCAP_BANDWIDTH" NUMBER, 
        "AUTHORIZATIONCODEVALUE" VARCHAR2(32 BYTE), 
        "OUTPULSEDCALLINGPARTYNUMBER" VARCHAR2(50 BYTE), 
        "OUTPULSEDCALLEDPARTYNUMBER" VARCHAR2(50 BYTE), 
        "O_IPV4V6ADDR" VARCHAR2(64 BYTE), 
        "DESTIPV4V6ADDR" VARCHAR2(64 BYTE), 
        "O_VCAP_CODEC_CHAN2" NUMBER, 
        "O_VCAP_BANDWIDTH_CHAN2" NUMBER, 
        "O_VCAP_RESOLUTION_CHAN2" NUMBER, 
        "O_V_TRANSPORTADDR_IP_CHAN2" NUMBER, 
        "O_V_TRANSPORTADDR_PORT_CHAN2" NUMBER, 
        "O_V_OCHANNEL_ROLE_CHAN2" NUMBER, 
        "DV_CAP_CODEC_CHAN2" NUMBER, 
        "DV_CAP_BANDWIDTH_CHAN2" NUMBER, 
        "DV_CAP_RESOLUTION_CHAN2" NUMBER, 
        "DV_TRANSPORTADDR_IP_CHAN2" NUMBER, 
        "DV_TRANSPORTADDR_PORT_CHAN2" NUMBER, 
        "DV_CHANNEL_ROLE_CHAN2" NUMBER, 
        "DATE_CREATED" DATE, 
        "DATETIME_CONNECT" DATE, 
        "DATETIME_DISCONNECT" DATE, 
        "USERID_EMAIL_ADDRESS" VARCHAR2(100 BYTE), 
        "FROM_FULL_TELEPHONE" VARCHAR2(20 BYTE), 
        "TO_FULL_TELEPHONE" VARCHAR2(20 BYTE), 
        "FROM_EXCHANGE" VARCHAR2(7 BYTE), 
        "TO_EXCHANGE" VARCHAR2(20 BYTE), 
        "FROM_CITY" VARCHAR2(200 BYTE), 
        "FROM_STATE" VARCHAR2(2 BYTE), 
        "TO_CITY" VARCHAR2(200 BYTE), 
        "TO_STATE" VARCHAR2(2 BYTE), 
        "CALL_TYPE" VARCHAR2(10 BYTE), 
         CONSTRAINT "MONTHLY_BILLING_PK" PRIMARY KEY ("ID")
      USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA"  ENABLE
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 75497472 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX1" ON "VOIP"."MONTHLY_BILLING_DETAILS" (TRUNC("DATETIME_CONNECT")) 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX10" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("CALL_TYPE") 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX2" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("FROM_EXCHANGE") 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX3" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("FROM_FULL_TELEPHONE", TRUNC("DATETIME_CONNECT")) 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX4" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("DATETIME_CONNECT", NVL("FROM_FULL_TELEPHONE","CALLINGPARTYNUMBER")) 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 5242880 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX5" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("DATETIME_CONNECT", NVL("TO_FULL_TELEPHONE","ORIGINALCALLEDPARTYNUMBER")) 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 5242880 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX6" ON "VOIP"."MONTHLY_BILLING_DETAILS" (TO_CHAR("DATETIME_CONNECT",'fmMONTH YYYY')) 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX7" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("TO_EXCHANGE") 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX8" ON "VOIP"."MONTHLY_BILLING_DETAILS" (NVL("FROM_FULL_TELEPHONE","CALLINGPARTYNUMBER")) 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    
    
      CREATE INDEX "VOIP"."MONTHLY_BILL_INDEX9" ON "VOIP"."MONTHLY_BILLING_DETAILS" ("DATETIME_CONNECT") 
      PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
      STORAGE(INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "VOIPDATA" ;
    

    These are the functions to determine if a phone number is assigned to multiple staffs or departments:

    FUNCTION GET_EMPLOYEE_NAME (P_FROM_FULL_TELEPHONE IN VARCHAR2)
    RETURN VARCHAR2
    AS
      L_NAME EMPLOYEES.NAME%TYPE;
    BEGIN
      SELECT NAME
      INTO L_NAME
      FROM EMPLOYEES
      WHERE WORK_PHONE_1_FORMAT = P_FROM_FULL_TELEPHONE;
      
      RETURN L_NAME;
    EXCEPTION
      WHEN TOO_MANY_ROWS THEN
        L_NAME := 'Multiple Employees';
        RETURN L_NAME;
      WHEN NO_DATA_FOUND THEN
        L_NAME := 'No Employee Assigned';
        RETURN L_NAME;
      WHEN OTHERS THEN
        NULL;
    END;
    

    FUNCTION GET_DEPARTMENT_NAME (P_FROM_FULL_TELEPHONE IN VARCHAR2)
    RETURN VARCHAR2
    AS
      L_DEPT_DESCR EMPLOYEES.DEPT_DESCR%TYPE;
    BEGIN
      SELECT DEPT_DESCR
      INTO L_DEPT_DESCR
      FROM EMPLOYEES
      WHERE WORK_PHONE_1_FORMAT = P_FROM_FULL_TELEPHONE;
      
      RETURN L_DEPT_DESCR;
    EXCEPTION
      WHEN TOO_MANY_ROWS THEN
        L_DEPT_DESCR := 'Multiple Departments';
        RETURN L_DEPT_DESCR;
      WHEN NO_DATA_FOUND THEN
        L_DEPT_DESCR := 'No Department Assigned';
        RETURN L_DEPT_DESCR;
      WHEN OTHERS THEN
        NULL;
    END;
    

    This is the point of view that I'll use in the report:

    CREATE OR REPLACE FORCE VIEW "VOIP"."TOP_USERS_BY_CALLS_V" ("TOP_NO", "EMPLOYEE_NAME", "EMPLOYEE_DEPARTMENT", "PHONE_NUMBER", "QUANTITY_CALLS") AS 
      SELECT
      ROWNUM,
      VOIP_PKG.GET_EMPLOYEE_NAME(FROM_FULL_TELEPHONE),
      VOIP_PKG.GET_DEPARTMENT_NAME(FROM_FULL_TELEPHONE),
      FROM_FULL_TELEPHONE,
      QUANTITY_CALLS
    FROM (
    SELECT
      MBD.FROM_FULL_TELEPHONE,
      COUNT(1) QUANTITY_CALLS
    FROM
      MONTHLY_BILLING_DETAILS MBD
    WHERE
      MBD.FROM_FULL_TELEPHONE IS NOT NULL                                     AND
      MBD.FROM_FULL_TELEPHONE <> '000-000-0000'                               AND
      LENGTH(MBD.FROM_FULL_TELEPHONE) = 12                                    AND
      LENGTH(MBD.TO_FULL_TELEPHONE) = 12                                      AND
      SUBSTR(MBD.TO_FULL_TELEPHONE,1,3) NOT IN (SELECT AREA_CODE
                                                FROM NYNJ_METRO_AREA_CODES)   AND
      SUBSTR(MBD.TO_FULL_TELEPHONE,1,3) NOT IN ('800','822','833','844',
                                                '855','866','877','888')
    GROUP BY
      MBD.FROM_FULL_TELEPHONE
    ORDER BY
      QUANTITY_CALLS DESC
    )
    WHERE ROWNUM <= 100;
    

    Explain Plan output and Extended SQL Trace:


    SQL> 
    SQL> show parameter user_dump_dest
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    user_dump_dest                       string      D:\ORACLEHOMES\ADMIN\RTS9\UDUM
                                                     P
    SQL> 
    SQL> show parameter optimizer
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    optimizer_dynamic_sampling           integer     2
    optimizer_features_enable            string      10.2.0.5
    optimizer_index_caching              integer     0
    optimizer_index_cost_adj             integer     100
    optimizer_mode                       string      ALL_ROWS
    optimizer_secure_view_merging        boolean     TRUE
    SQL> 
    SQL> show parameter db_file_multi
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    db_file_multiblock_read_count        integer     16
    SQL> 
    SQL> show parameter db_block_size
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    db_block_size                        integer     8192
    SQL> 
    SQL> show parameter cursor_sharing
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    cursor_sharing                       string      EXACT
    SQL> 
    SQL> column sname format a20
    SQL> column pname format a20
    SQL> column pval2 format a20
    SQL> 
    SQL> select
      2  sname
      3  , pname
      4  , pval1
      5  , pval2
      6  from
      7  sys.aux_stats$;
    
    SNAME                PNAME                     PVAL1 PVAL2
    -------------------- -------------------- ---------- --------------------
    SYSSTATS_INFO        STATUS                          COMPLETED
    SYSSTATS_INFO        DSTART                          02-09-2009 15:46
    SYSSTATS_INFO        DSTOP                           02-09-2009 15:46
    SYSSTATS_INFO        FLAGS                         1
    SYSSTATS_MAIN        CPUSPEEDNW            1259.6206
    SYSSTATS_MAIN        IOSEEKTIM                    10
    SYSSTATS_MAIN        IOTFRSPEED                 4096
    SYSSTATS_MAIN        SREADTIM
    SYSSTATS_MAIN        MREADTIM
    SYSSTATS_MAIN        CPUSPEED
    SYSSTATS_MAIN        MBRC
    SYSSTATS_MAIN        MAXTHR
    SYSSTATS_MAIN        SLAVETHR
    
    13 rows selected.
    
    Elapsed: 00:00:00.03
    SQL> 
    SQL> explain plan for
      2  SELECT
      3    TOP_NO,
      4    EMPLOYEE_NAME,
      5    EMPLOYEE_DEPARTMENT,
      6    PHONE_NUMBER,
      7    QUANTITY_CALLS
      8  FROM
      9    TOP_USERS_BY_CALLS_V
     10  ORDER BY
     11    QUANTITY_CALLS DESC;
    
    Explained.
    
    Elapsed: 00:00:00.18
    SQL> 
    SQL> select * from table(dbms_xplan.display);
    
    PLAN_TABLE_OUTPUT
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Plan hash value: 826236322
    
    ----------------------------------------------------------------------------------------------------------------
    | Id  | Operation                          | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                   |                           |     1 |  4042 |  1313   (1)| 00:00:16 |
    |   1 |  SORT ORDER BY                     |                           |     1 |  4042 |  1313   (1)| 00:00:16 |
    |   2 |   VIEW                             | TOP_USERS_BY_CALLS_V      |     1 |  4042 |  1312   (1)| 00:00:16 |
    |*  3 |    COUNT STOPKEY                   |                           |       |       |            |          |
    |   4 |     VIEW                           |                           |     1 |    25 |  1312   (1)| 00:00:16 |
    |*  5 |      SORT ORDER BY STOPKEY         |                           |     1 |    26 |  1312   (1)| 00:00:16 |
    |   6 |       HASH GROUP BY                |                           |     1 |    26 |  1312   (1)| 00:00:16 |
    |*  7 |        FILTER                      |                           |       |       |            |          |
    |*  8 |         TABLE ACCESS BY INDEX ROWID| MONTHLY_BILLING_DETAILS   |     1 |    26 |  1310   (1)| 00:00:16 |
    |*  9 |          INDEX FULL SCAN           | MONTHLY_BILL_INDEX3       |   934 |       |   449   (1)| 00:00:06 |
    |* 10 |         INDEX FULL SCAN            | NYNJ_METRO_AREA_CODES_UK1 |     1 |     4 |     1   (0)| 00:00:01 |
    ----------------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       3 - filter(ROWNUM<=100)
       5 - filter(ROWNUM<=100)
       7 - filter( NOT EXISTS (SELECT 0 FROM VOIP."NYNJ_METRO_AREA_CODES" "NYNJ_METRO_AREA_CODES" WHERE
                  LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3))))
       8 - filter(LENGTH("MBD"."TO_FULL_TELEPHONE")=12 AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'800' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'822' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'833' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'844' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'855' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'866' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'877' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'888')
       9 - filter(LENGTH("MBD"."FROM_FULL_TELEPHONE")=12 AND "MBD"."FROM_FULL_TELEPHONE"<>'000-000-0000'
                  AND "MBD"."FROM_FULL_TELEPHONE" IS NOT NULL)
      10 - filter(LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3)))
    
    33 rows selected.
    
    Elapsed: 00:00:00.82
    SQL> 
    SQL> rollback;
    
    Rollback complete.
    
    Elapsed: 00:00:00.00
    SQL> 
    SQL> set autotrace traceonly arraysize 100
    SQL> 
    SQL> alter session set tracefile_identifier = 'mytrace1';
    
    Session altered.
    
    Elapsed: 00:00:00.01
    SQL> 
    SQL> alter session set events '10046 trace name context forever, level 8';
    
    Session altered.
    
    Elapsed: 00:00:00.15
    SQL> 
    SQL> SELECT
      2    TOP_NO,
      3    EMPLOYEE_NAME,
      4    EMPLOYEE_DEPARTMENT,
      5    PHONE_NUMBER,
      6    QUANTITY_CALLS
      7  FROM
      8    TOP_USERS_BY_CALLS_V
      9  ORDER BY
     10    QUANTITY_CALLS DESC;
    
    100 rows selected.
    
    Elapsed: 00:10:37.68
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 826236322
    
    ----------------------------------------------------------------------------------------------------------------
    | Id  | Operation                          | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                   |                           |     1 |  4042 |  1313   (1)| 00:00:16 |
    |   1 |  SORT ORDER BY                     |                           |     1 |  4042 |  1313   (1)| 00:00:16 |
    |   2 |   VIEW                             | TOP_USERS_BY_CALLS_V      |     1 |  4042 |  1312   (1)| 00:00:16 |
    |*  3 |    COUNT STOPKEY                   |                           |       |       |            |          |
    |   4 |     VIEW                           |                           |     1 |    25 |  1312   (1)| 00:00:16 |
    |*  5 |      SORT ORDER BY STOPKEY         |                           |     1 |    26 |  1312   (1)| 00:00:16 |
    |   6 |       HASH GROUP BY                |                           |     1 |    26 |  1312   (1)| 00:00:16 |
    |*  7 |        FILTER                      |                           |       |       |            |          |
    |*  8 |         TABLE ACCESS BY INDEX ROWID| MONTHLY_BILLING_DETAILS   |     1 |    26 |  1310   (1)| 00:00:16 |
    |*  9 |          INDEX FULL SCAN           | MONTHLY_BILL_INDEX3       |   934 |       |   449   (1)| 00:00:06 |
    |* 10 |         INDEX FULL SCAN            | NYNJ_METRO_AREA_CODES_UK1 |     1 |     4 |     1   (0)| 00:00:01 |
    ----------------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       3 - filter(ROWNUM<=100)
       5 - filter(ROWNUM<=100)
       7 - filter( NOT EXISTS (SELECT 0 FROM VOIP."NYNJ_METRO_AREA_CODES" "NYNJ_METRO_AREA_CODES" WHERE
                  LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3))))
       8 - filter(LENGTH("MBD"."TO_FULL_TELEPHONE")=12 AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'800' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'822' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'833' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'844' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'855' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'866' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'877' AND
                  SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'888')
       9 - filter(LENGTH("MBD"."FROM_FULL_TELEPHONE")=12 AND "MBD"."FROM_FULL_TELEPHONE"<>'000-000-0000'
                  AND "MBD"."FROM_FULL_TELEPHONE" IS NOT NULL)
      10 - filter(LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3)))
    
    
    Statistics
    ----------------------------------------------------------
            365  recursive calls
              0  db block gets
         689543  consistent gets
         212906  physical reads
              0  redo size
           5984  bytes sent via SQL*Net to client
            400  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              2  sorts (memory)
              0  sorts (disk)
            100  rows processed
    
    SQL> 
    SQL> disconnect
    

    Part of the automatic trace output:

    SELECT
      TOP_NO,
      EMPLOYEE_NAME,
      EMPLOYEE_DEPARTMENT,
      PHONE_NUMBER,
      QUANTITY_CALLS
    FROM
      TOP_USERS_BY_CALLS_V
    ORDER BY
      QUANTITY_CALLS DESC
    
    call     count       cpu    elapsed       disk      query    current        rows
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    Parse        1      0.00       0.43          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        2     24.70     635.81     212587     631823          0         100
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    total        4     24.70     636.25     212587     631823          0         100
    
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 148  
    
    Rows     Row Source Operation
    -------  ---------------------------------------------------
        100  SORT ORDER BY (cr=689531 pr=212900 pw=0 time=636823070 us)
        100   VIEW  TOP_USERS_BY_CALLS_V (cr=689531 pr=212900 pw=0 time=642681672 us)
        100    COUNT STOPKEY (cr=631823 pr=212587 pw=0 time=635667026 us)
        100     VIEW  (cr=631823 pr=212587 pw=0 time=635666810 us)
        100      SORT ORDER BY STOPKEY (cr=631823 pr=212587 pw=0 time=635666493 us)
       2512       HASH GROUP BY (cr=631823 pr=212587 pw=0 time=635666125 us)
      27112        FILTER  (cr=631823 pr=212587 pw=0 time=519230237 us)
     315563         TABLE ACCESS BY INDEX ROWID MONTHLY_BILLING_DETAILS (cr=381523 pr=212587 pw=0 time=580209555 us)
     394473          INDEX FULL SCAN MONTHLY_BILL_INDEX3 (cr=2679 pr=2679 pw=0 time=26793918 us)(object id 206675)
     226627         INDEX FULL SCAN NYNJ_METRO_AREA_CODES_UK1 (cr=250300 pr=0 pw=0 time=3575488 us)(object id 206605)
    
    
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       2        0.00          0.00
      db file sequential read                    212587        0.20        611.67
      SQL*Net message from client                     2        0.00          0.00
      SQL*Net more data to client                     2        0.00          0.00
    ********************************************************************************
    

    DBMS_XPLAN. Output DISPLAY_CURSOR:

    SQL> 
    SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
    
    PLAN_TABLE_OUTPUT
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    SQL_ID  1ut636vt58jdw, child number 0
    -------------------------------------
    SELECT /*+ gather_plan_statistics */   TOP_NO,   EMPLOYEE_NAME,   EMPLOYEE_DEPARTMENT,   PHONE_NUMBER,   QUANTITY_CALLS FROM   TOP_USERS_BY_CALLS_V
    ORDER BY   QUANTITY_CALLS DESC
    
    Plan hash value: 826236322
    
    --------------------------------------------------------------------------------------------------------------------------------------------------------------
    | Id  | Operation                          | Name                      | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  |  OMem |  1Mem | Used-Mem |
    --------------------------------------------------------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                   |                           |      1 |        |    100 |00:09:56.06 |     689K|    210K|       |       |          |
    |   1 |  SORT ORDER BY                     |                           |      1 |      1 |    100 |00:09:56.06 |     689K|    210K| 13312 | 13312 |12288  (0)|
    |   2 |   VIEW                             | TOP_USERS_BY_CALLS_V      |      1 |      1 |    100 |00:10:04.98 |     689K|    210K|       |       |          |
    |*  3 |    COUNT STOPKEY                   |                           |      1 |        |    100 |00:09:54.89 |     631K|    210K|       |       |          |
    |   4 |     VIEW                           |                           |      1 |      1 |    100 |00:09:54.89 |     631K|    210K|       |       |          |
    |*  5 |      SORT ORDER BY STOPKEY         |                           |      1 |      1 |    100 |00:09:54.88 |     631K|    210K|  6144 |  6144 | 6144  (0)|
    |   6 |       HASH GROUP BY                |                           |      1 |      1 |   2512 |00:09:54.88 |     631K|    210K|   821K|   821K| 1153K (0)|
    |*  7 |        FILTER                      |                           |      1 |        |  27112 |00:08:58.57 |     631K|    210K|       |       |          |
    |*  8 |         TABLE ACCESS BY INDEX ROWID| MONTHLY_BILLING_DETAILS   |      1 |      1 |    315K|00:08:57.07 |     381K|    210K|       |       |          |
    |*  9 |          INDEX FULL SCAN           | MONTHLY_BILL_INDEX3       |      1 |    934 |    394K|00:00:23.02 |    2679 |   2679 |       |       |          |
    |* 10 |         INDEX FULL SCAN            | NYNJ_METRO_AREA_CODES_UK1 |    250K|      1 |    226K|00:00:03.47 |     250K|      0 |       |       |          |
    --------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       3 - filter(ROWNUM<=100)
       5 - filter(ROWNUM<=100)
       7 - filter( IS NULL)
       8 - filter((LENGTH("MBD"."TO_FULL_TELEPHONE")=12 AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'800' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'822'
                  AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'833' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'844' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'855'
                  AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'866' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'877' AND SUBSTR("MBD"."TO_FULL_TELEPHONE",1,3)<>'888'))
       9 - filter((LENGTH("MBD"."FROM_FULL_TELEPHONE")=12 AND "MBD"."FROM_FULL_TELEPHONE"<>'000-000-0000' AND "MBD"."FROM_FULL_TELEPHONE" IS NOT NULL))
      10 - filter(LNNVL("AREA_CODE"<>SUBSTR(:B1,1,3)))
    
    
    35 rows selected.
    
    Elapsed: 00:00:00.50
    SQL> 
    SQL> spool off
    
    

    Any help will be greatly appreciated. Please let me know if you need additional information.

    Thank you

    Erick

    ediazjorge wrote:

    Please let me know if you need additional information or do additional tests.

    Thanks again!

    Erick

    It's to you if you are satisfied or interested in improvements (if possible).

    If so the first thing I would like if you had your refreshed perspective as advised. According to expected area_code table cardinalities I doubt.

    So, if not cool off with dbms_stats.gather_table_stats on two tables, area_codes and MONTHLY_BILLING_DETAILS.

    Bottlenecks are now obviously the full table of MONTHLY_BILLING_DETAILS as well as the ANTI of LOOPS IMBRIQUEES scan.

    At the moment I don't think that an index of MONTHLY_BILLING_DETAILS will help a lot, because most of the lines will pass filter predicates, and because we need some columns in it, I have now I there will be gain a full index scan.

    I was surprissed that the optimizer pushes the substr <> predicates to both tables.

    So depending on your data, you might try

    1 make a factory of subquery select the two MONTHLY_BILLING_DETAILS columns that all directly apply predicates of membership and use it directly in the join instead of the table.

    or

    2. If all subtr to so are part of the table area_code choose in it using a subquery (or inline view) plant excluding these values.

    Both are attempts to get rid of the substr excluding as filters of join predicates.

    In fact, I was expecting a hash join anti as shown in the plan to explain instead of the nested loops anti, I expect to be more effective in this case.

    Perhaps with correct cardinalities the optimizier would understand himself.

    Just to test it, you can try the use_hash hint in the join:

    Select / * + USE_HASH (MBD, one) * /.

    ..

    OF MONTHLY_BILLING_DETAILS MBD,.

    NYNJ_METRO_AREA_CODES one

    (It's a good habit anyway usually use aliases and precede the names of columns. In the, it is easier to read queries are only trivial).

  • pl - sql query with index by table errors

    Hello once again

    I'm stuck again with the following query

    I want to display the name of the Department, employee id name count and avg sal

    rec type is rendered
    (
    not a number (8.0).
    DNAME varchar2 (40),
    mgr_nm varchar2 (55),
    d_hc number (8.0).
    SAL number (8.2)
    );
    rec1 is the rec index table directory.
    Start
    for rec1 in)
    Select a1.dnm, a1.nm, b.did, b.hc, b.sal
    Of
    (
    Select d.department_id as did e1.first_name |' '|| E1.last_name like nm, d.department_name as dnm
    of hr.employees e1, hr.departments d
    where e1.department_id = d.department_id) a1.
    (
    Select d.department_id as did, count (e1.employee_id) as hc, avg (e1.salary) as sal
    of hr.employees e1, hr.departments d
    where e1.department_id = d.department_id
    D.department_id group) b
    where a1.did = b.did)
    loop
    dbms_output.put_line (REC1);
    end loop;
    end;
    /

    my error is

    ORA-00900: invalid SQL statement

    Help, please

    Thank you!!!

    Try this:

    begin
      for rec1 in ( select a1.dnm
                    ,      a1.nm
                    ,      b.did
                    ,      b.hc
                    ,      b.sal
                    from ( select d.department_id as did
                           ,      e1.first_name||' '||e1.last_name as nm
                           ,      d.department_name as dnm
                           from   hr.employees e1
                           ,      hr.departments d
                           where  e1.department_id=d.department_id
                         ) a1
                    ,    ( select d.department_id as did
                           ,      count(e1.employee_id) as hc
                           ,      avg(e1.salary)as sal
                           from   hr.employees e1
                           ,      hr.departments d
                           where  e1.department_id=d.department_id
                           group by d.department_id
                          ) b
                    where a1.did=b.did
                  )
      loop
        dbms_output.put_line(rec1.dnm||' - '||rec1.nm||' - '||rec1.did||' - '||rec1.hc||' - '||rec1.sal);
      end loop;
    end;
    /
    

    Edit
    Use code tags when you post for example, keep formatting and indenting.
    See: http://wiki.oracle.com/page/Oracle+Discussion+Forums+FAQ (scroll down a bit)

    Published by: hoek on November 24, 2009 16:01

  • pl - sql query with indexes per table

    Hello again,

    I'm stuck with this query, I want to display the full name of all employees, using the HR schema table.

    DECLARE
    Employee_table_struct TYPE IS an ARRAY OF
    HR. Employees.first_name%type
    INDEX OF DIRECTORY;

    employee_table employee_table_struct;

    Employee_cursor CURSOR IS
    SELECT first_name
    OF hr.employees;


    v_row NUMBER: = 1;
    BEGIN

    OPEN employee_cursor;

    LOOP
    OUTPUT WHEN employee_cursor % NOTFOUND;

    DBMS_OUTPUT. Put_line (employee_table (v_row));

    -populated the next time the loop * /.
    v_row: = v_row + 1;
    END LOOP;

    CLOSE Employee_cursor;
    END;
    /

    Its gives me error saying:

    ORA-01403: no data found
    ORA-06512: at line 21

    Help, please
    Thank you

    Why not use a clear FOR the loop?
    It allows you to save saying stuff and it does the same thing, showing first_name for all employees:

    begin
      for rec in ( select first_name
                   from   hr.employees
                 )
      loop
        dbms_output.put_line(rec.first_name);
      end loop;
    end;
    /
    
  • Question - create a field in a SQL query with the status not nullable

    I want to create a field that is not nullable char (2) length

    If I do CREATE TEMPORARY TABLE X

    SELECT

    "AH" AS CDTYPE

    or

    SELECT

    CAST ('AH' AS CHAR (2)) CDTYPE

    Or

    CAST (NVL(' ','AH') AS CHAR (2)) CDTYPE

    The field is always created as a nullable field of Char (2)

    Without creating a special field type, how can I dow it

    You cannot set the projections have NOT null SQL, you can only put your query clauses so that NULL values are filtered out or by default set to another value results.

    NO NULL only applies to the columns of the table (or PL/SQL parameters/variables).

  • SQL Query search line differences

    Hi all!

    It will probably be a super easy question and a solution for someone.  Here's my scenario.

    • 2 tables (Table_1, Table_2)
    • 3 columns (A, B, C)
    • Table_1 unless Table_2 records, if I want to find records in Table_2 who aren't in Table_1
      • I don't like to find the records that are in Table_1 and Table_2
    • I'll do the comparison with column a.

    For simplicity, lets say a 10 lines total Table_1 and Table_2 15 total of lines.  He must only find 5 rows that are not in Table_1 and Table_2.  So, if I add the number of records found in Table_2 Table_1 total records, then I would have at least the same amount of records in Table_1 and Table_2, if not more.  Also, is there a way where I can insert the differences between the lines found in a 3rd table "to stop"?

    The example is provided below.

    Table_1

    A | B | C

    1. Bonneau | something

    2. Bonneau | something

    3. Bonneau | something

    4. Bonneau | something

    5. Bonneau | something

    Table_2

    A | B | C

    1. Bonneau | something

    3. Bonneau | something

    5. Bonneau | something

    6. Bonneau | something < = difference

    7. Bonneau | something < = difference

    In fact, there are millions of records in both tables.  I have a solution for this, but it would require me to do... Export results from Table_1 and Table_2.  Open the two results in Excel and run a macro to know the difference.  Once I found the difference, I save and import the results into the 3rd table 'intermediate '.

    Any help would be great!  Thank you!

    Hello

    You can use a subquery NOT EXISTS or NOT IN the for.

    For example, scott.dept and scott.emp are assimilated by deptno.  To find all the rows in the dept who do not have a corresponding row in the emp:

    SELECT *- or all of the columns that you want to

    OF scott.dept

    WHERE deptno NOT IN ((in English only)

    SELECT DeptNo

    FROM scott.emp

    WHERE deptno IS NOT NULL - if necessary

    )

    ;

    When you use a NOT IN subquery, check that the subquery cannot produce NULL values.

    I hope that answers your question.

    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.  Include an example where the column has is identical in the two tables, but columns B and C are not.

    Post your best attempt (use one of the solutions of publication) and specify where it's getting incorrect results, explain, using specific examples, how you get the right results from data provided in these places.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • SQL query with multiple conditions

    Here is the sample table

    ID RATE DATE ORGAMNT PAYAMOUNT

    1 3.45 23/12/2012 23000,45 19060.23

    2 5.50 12/04/2013 45000,00 36000.54

    3. 6.44 16/04/200 60000,00 20000.00

    Select a table with the highest rate, Orgamnt with date more closely to current events.

    Sorry, Marwin

    Sorry to put it very verbose and making this request get unnecessarily complex. I hope that this time, it makes sense. At the bottom of table, I have to

    Select (buy) properties so that

    1. I will get maximum profit out of it when buying this property

    Columns PROPERTIES important to maximize interest income:

    FURIOUS, interest rates

    -Interest rates high = interest income higher

    OMA, original mortgage amount

    -Large amount income = total interest, higher

    FPAY, Date of the first payment

    -The latest date of the first payment = income higher interest

    -Influence of ready depreciation on interest paid

    2. I have a budget of 50 million (PDB column is the amount that I should pay for each property)

    HNUM OMA FURIOUS HNAME PDB FPAY

    11186 5,51 10580934.67 11607400 2/1/2006

    4801800 9/1/2006 6.3 4326951.51 11188 PNC BANK, NATIONAL ASSOCIATION

    11189 1236100 8/1/2006 6.15 1147108.9 HEARTLAND BANK

    11192 5.82 1470926.86 1578400 4/1/2007

    11193 8150400 12/1 / 2008 6.75 7828776.28 OPPENHEIMER MULTIFAMILY HSG &

    11195 3898000 5/1/2009 6.5 3752154.96 BERKADIA MORTGAGE COMMERCIAL

    11196 8040000 6/1/2009 7 7775734.57 OPPENHEIMER MULTIFAMILY HSG &

    11197 37315000 12/1 / 2009 5.5 35851362.87 RED MORTGAGE CAPITAL LLC

    11199 WALKER 3673760.35 2/1/2010 3824000, 5.25 AND DUNLOP LLC

    11200 26927000 7/1/2010 4.7 25186682.65 OAK GROVE MORTGAGE COMMERCIAL

    11201 7208600 10/1 / 2010 4.59 BERKADIA COMMERCIAL MORTGAGE 6949026.64 L

    11204 9300000 2/1/2011 3,41 8927064.51 PNC BANK, NATIONAL ASSOCIATION

    11205 5200000 2/1/2011 3.56 4997518.18 LOVE FUNDING CORPORATION

    11206 3.88 6576635.57 6800000 5/1/2011

    11208 3.84 11879882.17 12240000 8/1/2011

    11209 12911500 10/1 / 2011 3.55 12542199.51 M & T REALTY CAPITAL CORPORA

    11210 9596900 7/1/2011 5.38 LANCASTER POLLARD 9323421.23 MORTGAGE COM

    11211 19951600 9/1/2011 3.88 19393524.45 DEUTSCHE BANK BERKSHIRE QUÉDÉ

    11183 4230000 4/1/2009 6.55 BERKADIA COMMERCIAL MORTGAGE 4069938.75 L

    11212 50475000 1/1/2013 2.37 49852632.51 LOVE FUNDING CORPORATION

    11213 3.1 5377541.15/5496000 5/1/2012

  • A query with line numbers and colum?

    Hello
    I have my java code divided into if conditions and each if the article I need to select a certain field in a table. Is it somehow possible to select a table field that for example is in the third row and the fifth column? So basically, how to choose a certain element of the matrix?

    Thanks :)

    Published by: user10956166 on April 5, 2009 06:09

    Hello

    Assuming that you have a table called Distance:

    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    
    SQL> DESCRIBE DISTANCE;
    Name    Type         Nullable Default Comments
    ------- ------------ -------- ------- --------
    LINN    VARCHAR2(30) Y
    TALLINN NUMBER       Y
    TARTU   NUMBER       Y
    P2RNU   NUMBER       Y                         
    
    SQL> select * from distance;
    
    LINN                              TALLINN      TARTU      P2RNU
    ------------------------------ ---------- ---------- ----------
    TALLINN                                 0        186        128
    TARTU                                 186          0        174
    P2RNU                                 128        174          0
    
    SQL>
    SQL> SET SERVEROUTPUT ON
    SQL> DECLARE
      2     v_sql         VARCHAR2(4000);
      3     v_column_name VARCHAR2(30):= 'TARTU';
      4     v_to          VARCHAR2(30):= 'P2RNU';
      5     v_distance    NUMBER;
      6  BEGIN
      7     v_sql := 'SELECT ' || v_column_name || ' FROM DISTANCE d WHERE d.LINN = ''' || v_to || '''';
      8     EXECUTE IMMEDIATE v_sql
      9        INTO v_distance;
     10
     11     dbms_output.put_line(v_distance);
     12
     13  EXCEPTION
     14     WHEN OTHERS THEN
     15        dbms_output.put_line(SQLERRM);
     16  END;
     17  /
    
    174
    
    PL/SQL procedure successfully completed
    
    SQL> 
    

    Kind regards

Maybe you are looking for

  • In mozilla firefox can not write anything in the E-mail body section

    I can just type in the toolbar and the toolbar object sender e-mail address, but nothing in the body section of the main text of the email in Firefox

  • A Wi-fi-no live connection connects

    network security weak shared - key not supported by windows -this is the error message I get. It worked fine for months. He doesn't want a security key 9which I) in the search for networks not supported, nothing appears. The router is in a closed off

  • Issue of QListDataModel

    I have a QListDataModel that stores a list of the classes, I want to be able to erase the model and then re - fill if necessary, but when I re - fill, it seems that the classes were not deleted when I called the clear() method. I tried to delete clas

  • 3rd party Plugins in Photoshop CC 2015

    HelloI wanted to know if the Plugins like Cup & cut my PNG Express or any other 3rd party plugins can be installed and if it is compatible with Photoshop CC 2015.

  • Double page numbers

    I have a large document in indesign all correctly page numbered, however, a single page and that page the page number has doubled.  It shows once again just below itself.  I can see the bounding box for the second number, but I can't click on it.  It