example of model clause

I want to learn about the model clause, if everyone learned pls share your knowledge, it will be useful to everyone, the examples provided in the oracle documentation are really pathetic. pls share your knowledge with which any person can understand, as good examples

What is a measure, and what it does?
What is a size clause?
What is the rules how to use and what it does.

If oracle documentation is reading my post, hope that they will understand how it is difficult to understand the examples provided in the oracle documentation

If you are familiar with the OOPS concepts, I think it will be very easy to understand the concept of MODEL... I would try to explain with a simple example.

Think of a table, for example POPULATION_ARRAY, that allows to store the population for countries for different years. Means of the table are defined as

POPULATION_ARRAY (number of people) indexed by [COUNTRY_ID, YEAR]

Normally, we define the values as below for the tables...


    population_array[INDIA,2012].population := 130,000,000;

The ID of the country and the YEAR here are the dimensions. The POPULATION is a MEASURE.

Another element in the array will be

    population_array[CHINA,2012].population := 150,000,000;

Now suppose I want to do a calculation to know the population on 2022 on an explanation that the population will double (!) for these countries in 2022.
Will let you know how you can do this in EXCEL. Same thing can be done using the MODEL. (And much more...!)

For simplicity we will fill all these data in a single table.

SQL> create table country(country_id varchar2(30),
  2  year number,population number);

Table created.

SQL> insert into country values('INDIA',2012,130000000);

1 row created.

SQL> insert into country values('CHINA',2012,150000000);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from country;

COUNTRY_ID                           YEAR POPULATION
------------------------------ ---------- ----------
INDIA                                2012  130000000
CHINA                                2012  150000000

Here we do not have values for 2022.Now how to calculate and display the results using MODEL?

As mentioned, the dimensions are COUNTRY_ID, YEAR. The fatc that interests us is the POPULATION.

Thus, the application of the MODEL will be as follows, for INDIA

SQL> select *
  2  from country
  3  model
  4   dimension by (country_id,year)
  5   measures(population)
  6    rules upsert all
  7     (
  8      population['INDIA',2022] = population['INDIA',2012]*2
  9     );

COUNTRY_ID                           YEAR POPULATION
------------------------------ ---------- ----------
CHINA                                2012  150000000
INDIA                                2012  130000000
INDIA                                2022  260000000

So here we use MODEL as an EXCEL spreadsheet.

You will notice that us hard coded name of the country here, which can be avoided using ANY keyword and cv (present value) function.

SQL> select *
  2  from country
  3  model
  4   dimension by (country_id,year)
  5   measures(population)
  6    rules upsert all
  7     (
  8      population[ANY,2022] = population[cv(),2012]*2
  9     );

COUNTRY_ID                           YEAR POPULATION
------------------------------ ---------- ----------
INDIA                                2012  130000000
CHINA                                2012  150000000
CHINA                                2022  300000000
INDIA                                2022  260000000

Suppose now, I do not have the details of the USA for 2012. But I guess that the US population is half that of INDIA. That can be added as follows

SQL> select *
  2  from country
  3  model
  4   dimension by (country_id,year)
  5   measures(population)
  6    rules upsert all
  7     (
  8      population['USA',ANY] = population['INDIA',cv()]/2,
  9      population[ANY,2022] = population[cv(),2012]*2
 10     );

COUNTRY_ID                           YEAR POPULATION
------------------------------ ---------- ----------
INDIA                                2012  130000000
CHINA                                2012  150000000
USA                                  2012   65000000
CHINA                                2022  300000000
INDIA                                2022  260000000
USA                                  2022  130000000

6 rows selected.

With this basis, go gold http://docs.oracle.com/cd/B28359_01/server.111/b28313/sqlmodel.htm and ask any doubts...

Published by: JAC on January 30, 2013 13:40
Please note: this is a very simple example, which may not require the MODEL clause as such...

Tags: Database

Similar Questions

  • XMLType and model Clause

    Hello-

    We face a problem which I hope I can explain clearly and concisely.

    We have a relational Oracle table with an XMLType column. the relational table has some fields in addition to the profiling XMLType column.

    CREATE TABLE 'CLAIM_OUTPUT_XML '.

    (NUMBER OF 'SEQ_NUM',

    NUMBER OF "BATCH_ID."

    VARCHAR2 (BYTE 9) "MEMBER_ID"

    NUMBER OF "MBR_COB_SFX."

    NUMBER OF "CLAIM_NBR."

    VARCHAR2 (3 BYTE) "CLAIM_SFX."

    DATE OF THE "PRINT_DATE."

    VARCHAR2 (30 BYTE) "DOC_TYPE."

    "CLAIM_OUTPUT" 'SYS '. "" XMLTYPE.

    DATE OF THE "CRTD_DT."

    VARCHAR2 (30 BYTE) "CRTD_BY".

    );

    INSERT INTO CLAIM_OUTPUT_XML (SEQ_NUM

    BATCH_ID

    MEMBER_ID

    MBR_COB_SFX

    CLAIM_NBR

    CLAIM_SFX

    PRINT_DATE

    DOC_TYPE

    CLAIM_OUTPUT)

    VALUES (1

    2015072015

    , "ABCDEF123".

    0

    61773667

    null

    TRUNC (SYSDATE)

    , "EOB".

    XMLTYPE ("< claim >

    < ClaimInfo >

    < claim >

    < CLAIM_NBR > 61773667 < / CLAIM_NBR >

    < CLAIM_SFX / >

    < MEMBER_ID > ABCDEF123 < / SSN >

    < MBR_COB_SFX > 0 < / SSN_COB_SFX >

    < > 00 DEP < / DEP >

    MEMBER of < UD_PATIENT_TYPE > < / UD_PATIENT_TYPE >

    the PATIENT NAME < UD_PATIENT_NAME > < / UD_PATIENT_NAME >

    < DOCTOR_PFX > T < / DOCTOR_PFX >

    < DOCTOR_NBR > 123123123 < / DOCTOR_NBR >

    < DOCTOR_SFX > 0 < / DOCTOR_SFX >

    < GRP_NBR > GRP_NBR < / GRP_NBR >

    P < INSURER > < / INSURER >

    < ClaimDetails >

    < ClaimDetail >

    < CLAIM_NBR > 61773667 < / CLAIM_NBR >

    < CLAIM_SFX / >

    < CLAIM_LINE > 1 < / CLAIM_LINE >

    < MEMBER_ID > ABCDEF123 < / SSN >

    < MBR_COB_SFX > 0 < / SSN_COB_SFX >

    < > 00 DEP < / DEP >

    < GRP_NBR > GRP_NBR < / GRP_NBR >

    P < INSURER > < / INSURER >

    C < PLAN_TYPE > < / PLAN_TYPE >

    < DOCTOR_PFX > T < / DOCTOR_PFX >

    < DOCTOR_NBR > 123123123 < / DOCTOR_NBR >

    < DOCTOR_SFX > 0 < / DOCTOR_SFX >

    < DOC_FEES > 116 < / DOC_FEES >

    < SCH_FEE > 0 < / SCH_FEE >

    < COB_AMT > 0.00 < / COB_AMT >

    < COB_COMPANY / >

    < PTX_COPAY > 0 < / PTX_COPAY >

    < DEDUCT_AMT > 0.00 < / DEDUCT_AMT >

    < OVER_AMT > 0 < / OVER_AMT >

    < ALLOW_AMT > 0 < / ALLOW_AMT >

    < ENTERED_BY > N < / ENTERED_BY >

    < PAY_IND > N < / PAY_IND >

    < EXPLAIN_CODE1 > AF < / EXPLAIN_CODE1 >

    < EXPL1_DESC > ORTHODONTICS COVERAGE AVAILABLE ONLY IF there IS a SERIOUS MEDICAL CONDITION < / EXPL1_DESC >

    < EXPL1_DEN_DESC / >

    P8 < EXPLAIN_CODE2 > < / EXPLAIN_CODE2 >

    < EXPL2_DESC > SERVICE a TREATY BASED ON THE CLAIM FORM DESCRIPTION < / EXPL2_DESC >

    < EXPL2_DEN_DESC / >

    < EXPLAIN_CODE3 / >

    < EXPL3_DESC / >

    < EXPL3_DEN_DESC / >

    < SERVICE_DATE / >

    < ADA_CODE > 8670 < / ADA_CODE >

    a TREATMENT ORTHODONTIQUE PERIODICAL < ADA_DESC > < / ADA_DESC >

    BRACES < ADA_SHORT_DESC > < / ADA_SHORT_DESC >

    < HPLX_CODE > 8420 < / HPLX_CODE >

    < HPLX_DESC / >

    < UD_AGE_LIMITATION / >

    < TEETH / >

    < SURFACE / >

    < COB_RES_CRD > 0 < / COB_RES_CRD >

    < PTX_RESP > 116.00 < / PTX_RESP >

    < PAY_CODE_PRT > N < / PAY_CODE_PRT >

    < UD_SHOW_PTX_RESP_MSG > Y < / UD_SHOW_PTX_RESP_MSG >

    < / ClaimDetail >

    < / ClaimDetails >

    < / claim >

    < EOB_Specific >

    < SendToInfo >

    COPY of PROVIDER < UD_COPY_TO > < / UD_COPY_TO >

    < UD_COPY_TO_FULL > COPY PROVIDER - assigned doctor benefits < / UD_COPY_TO_FULL >

    < / SendToInfo >

    < / EOB_Specific >

    < / ClaimInfo >

    (< / request > ')

    );

    INSERT INTO CLAIM_OUTPUT_XML (SEQ_NUM

    BATCH_ID

    MEMBER_ID

    MBR_COB_SFX

    CLAIM_NBR

    CLAIM_SFX

    PRINT_DATE

    DOC_TYPE

    CLAIM_OUTPUT)

    VALUES (2

    2015072015

    , "ABCDEF123".

    0

    61773667

    null

    TRUNC (SYSDATE)

    , "EOB".

    XMLTYPE ("< claim >

    < ClaimInfo >

    < claim >

    < CLAIM_NBR > 61773667 < / CLAIM_NBR >

    < CLAIM_SFX / >

    < MEMBER_ID > ABCDEF123 < / SSN >

    < MBR_COB_SFX > 0 < / SSN_COB_SFX >

    < > 00 DEP < / DEP >

    MEMBER of < UD_PATIENT_TYPE > < / UD_PATIENT_TYPE >

    the PATIENT NAME < UD_PATIENT_NAME > < / UD_PATIENT_NAME >

    < DOCTOR_PFX > T < / DOCTOR_PFX >

    < DOCTOR_NBR > 123123123 < / DOCTOR_NBR >

    < DOCTOR_SFX > 0 < / DOCTOR_SFX >

    < GRP_NBR > GRP_NBR < / GRP_NBR >

    P < INSURER > < / INSURER >

    < ClaimDetails >

    < ClaimDetail >

    < CLAIM_NBR > 61773667 < / CLAIM_NBR >

    < CLAIM_SFX / >

    < CLAIM_LINE > 1 < / CLAIM_LINE >

    < MEMBER_ID > ABCDEF123 < / SSN >

    < MBR_COB_SFX > 0 < / SSN_COB_SFX >

    < > 00 DEP < / DEP >

    < GRP_NBR > GRP_NBR < / GRP_NBR >

    P < INSURER > < / INSURER >

    C < PLAN_TYPE > < / PLAN_TYPE >

    < DOCTOR_PFX > T < / DOCTOR_PFX >

    < DOCTOR_NBR > 123123123 < / DOCTOR_NBR >

    < DOCTOR_SFX > 0 < / DOCTOR_SFX >

    < DOC_FEES > 116 < / DOC_FEES >

    < SCH_FEE > 0 < / SCH_FEE >

    < COB_AMT > 0.00 < / COB_AMT >

    < COB_COMPANY / >

    < PTX_COPAY > 0 < / PTX_COPAY >

    < DEDUCT_AMT > 0.00 < / DEDUCT_AMT >

    < OVER_AMT > 0 < / OVER_AMT >

    < ALLOW_AMT > 0 < / ALLOW_AMT >

    < ENTERED_BY > N < / ENTERED_BY >

    < PAY_IND > N < / PAY_IND >

    < EXPLAIN_CODE1 > AF < / EXPLAIN_CODE1 >

    < EXPL1_DESC > ORTHODONTICS COVERAGE AVAILABLE ONLY IF there IS a SERIOUS MEDICAL CONDITION < / EXPL1_DESC >

    < EXPL1_DEN_DESC / >

    P8 < EXPLAIN_CODE2 > < / EXPLAIN_CODE2 >

    < EXPL2_DESC > SERVICE a TREATY BASED ON THE CLAIM FORM DESCRIPTION < / EXPL2_DESC >

    < EXPL2_DEN_DESC / >

    < EXPLAIN_CODE3 / >

    < EXPL3_DESC / >

    < EXPL3_DEN_DESC / >

    < SERVICE_DATE / >

    < ADA_CODE > 8670 < / ADA_CODE >

    a TREATMENT ORTHODONTIQUE PERIODICAL < ADA_DESC > < / ADA_DESC >

    BRACES < ADA_SHORT_DESC > < / ADA_SHORT_DESC >

    < HPLX_CODE > 8420 < / HPLX_CODE >

    < HPLX_DESC / >

    < UD_AGE_LIMITATION / >

    < TEETH / >

    < SURFACE / >

    < COB_RES_CRD > 0 < / COB_RES_CRD >

    < PTX_RESP > 116.00 < / PTX_RESP >

    < PAY_CODE_PRT > N < / PAY_CODE_PRT >

    < UD_SHOW_PTX_RESP_MSG > Y < / UD_SHOW_PTX_RESP_MSG >

    < / ClaimDetail >

    < / ClaimDetails >

    < / claim >

    < EOB_Specific >

    < SendToInfo >

    MEMBER COPY < UD_COPY_TO > < / UD_COPY_TO >

    < UD_COPY_TO_FULL > COPY MEMBER - benefits assigned to doctor < / UD_COPY_TO_FULL >

    < / SendToInfo >

    < / EOB_Specific >

    < / ClaimInfo >

    (< / request > ')

    );

    The generated XML is used to provide raw data to third-party documents generation software. Before send us the data to the third party software, we need to predetermine the number of documents that are part of a shipment (as part of the requirements for other third party software, we use). This is determined by the number of forms to be printed and how many services it has. The caution in our requirements is that, for example, if 3 members of the same family turn on the same doctor on the same day, we want to combine broadcast of each Member of the family. Each envelope can have up to 10 sheets of paper, then regroup according to this as well. I was able to design it by using the SQL type clause, but the problem that I am up against accessing values retrieved via XQuery.

    Here's a simple example of data extracted from XML is not not available. I can share the data file - I did not know how to attach to this issue.

    If I run this query:

    Select *.

    of claim_output_xml x 1

    , XMLTable (' for $z in/Claim/ClaimInfo)

    return $z '

    PASSAGE claim_output

    COLUMNS

    grp_id varchar2 (30) PATH "claim/GRP_NBR.

    , path of varchar2 (30) copy_To ' EOB_Specific/SendToInfo/UD_COPY_TO.

    ) y ;

    I see all the columns of x 1 as well as the columns that I extracted using xquery.

    SEQ_NUMBATCH_IDMEMBER_IDMBR_COB_SFXCLAIM_NBRCLAIM_SFXDOCTOR_NBRDOCTOR_PFXDOCTOR_SFXPRINT_DATEDOC_TYPECLAIM_OUTPUTCRTD_DTCRTD_BYCOPY_TOGRP_IDCOPY_TO_1
    18012015072015ABCDEF12306177366720 JULY 15EOB(XMLTYPE)GRP_NBRCOPY OF PROVIDER
    18022015072015ABCDEF12306177366720 JULY 15EOB(XMLTYPE)GRP_NBRMEMBER COPY

    If I now add the clause type (no rules applied) for the same query:

    Select *.

    of claim_output_xml x 1

    , XMLTable (' for $z in/Claim/ClaimInfo)

    return $z '

    PASSAGE claim_output

    COLUMNS

    grp_id varchar2 (30) PATH "claim/GRP_NBR.

    , path of varchar2 (30) copy_To ' EOB_Specific/SendToInfo/UD_COPY_TO.

    ) y

    model

    dimension (x1.seq_num)

    measures (cast (x 1. MEMBER_ID as varchar2 (30)) mbr_id

    y.copy_to)

    Rules();

    y.copy_to is null:

    SEQ_NUMMBR_IDCOPY_TO
    1801ABCDEF123
    1802ABCDEF123

    I also share the actual query, that we are working on. The query has a few clauses, which allows access to the XML xquery data. In one case, the extracted value of the XML is coming through, but I can't get the others to work.

    Version information:

    Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    PL/SQL Release 11.2.0.3.0 - Production

    "CORE 11.2.0.3.0 Production."

    AMT for Solaris: 11.2.0.3.0 - Production Version

    NLSRTL Version 11.2.0.3.0 - Production

    Hello

    Your test scenario has not been 'tested '.

    Two examples of XML documents are not correct.

    On the real problem, it works:

    SQL> select *
      2  from (
      3    select /*+ no_merge */
      4           x1.seq_num
      5         , x1.member_id
      6         , y.copy_to
      7    from claim_output_xml x1
      8       , XMLTable(
      9           'for $z in /Claim/ClaimInfo return $z'
     10           PASSING claim_output
     11           COLUMNS
     12             grp_id  varchar2(30) PATH 'Claim/GRP_NBR'
     13           , copy_To varchar2(30) path 'EOB_Specific/SendToInfo/UD_COPY_TO'
     14         ) y
     15  )
     16  model
     17  dimension by (seq_num)
     18  measures(
     19    cast(MEMBER_ID as varchar2(30)) as mbr_id
     20  , copy_to
     21  )
     22  rules();
    
       SEQ_NUM MBR_ID                         COPY_TO
    ---------- ------------------------------ ------------------------------
             1 ABCDEF123                      PROVIDER COPY
             2 ABCDEF123                      MEMBER COPY
    

    In some cases, the CBO messes things.

    This is a recurring problem when the XMLTABLE projections are used in predicates or as the source for subsequent transformations.

    The workaround is to set mode of line no-that can be merged.

    That being said, maybe you can share your needs more explaining the logic (sample input/output required).

    There might be a way to avoid the MODEL - is not that I do not use it, but I usually prefer to pull out of my hat as a last resort.

  • Helps the model clause. Date field in the Dimension

    Hello, all.

    I'm having a problem with the clause type in my query. In my view, it may be a misunderstanding on my part, but I can't find any documentation that is opposed to the use of the date fields in the dimensions of my model.

    Given these data;
    LOGDATE               SHIFTNAME  BUILDING  UNIT  DOORNUMBER  INOUT    EVENTCOUNT
    2012-02-01 06:00:00      A        1800      R      Door 4     Out         14
    2012-02-01 06:00:00      A        1800      R      Door 4     In          15
    2012-02-01 18:00:00      D        1800      R      Door 4     Out         17
    2012-02-01 18:00:00      D        1800      R      Door 4     In          19
    2012-02-02 06:00:00      A        1800      R      Door 4     Out         14
    2012-02-02 06:00:00      A        1800      R      Door 4     In          14
    ...
    I write my SQL like this:
    SELECT logdate, shiftname, building, unit, doornumber, inout, eventcount
      FROM door_events
     WHERE building='1800' AND unit='R' AND doornumber=4
     MODEL DIMENSION BY (logdate, shiftname, building, unit, doornumber, inout)
           MEASURES (eventcount)
          RULES ()
    And I get the expected result. (The same table as above) But when I try to add rows using rules, I get no new line until the LOGDATE field is a date. For example, by using this code, I expect to get a new line, with a 100 EVENTCOUNT (and other fields as written) but I stiill get the same set of data (no line is added)
    SELECT logdate, shiftname, building, unit, doornumber, inout, eventcount
      FROM door_events
     WHERE building='1800' AND unit='R' AND doornumber=4
     MODEL DIMENSION BY (logdate, shiftname, building, unit, doornumber, inout)
           MEASURES (eventcount)
           RULES (eventcount[SYSDATE,'X','1800','R',4,'In'=100)
    However, when I turn the LOGDATE field in a CHAR data type (and make the SYSDATE a TANK in the same way) with the code below, all of a sudden I get the line I was expecting!
    SELECT TO_CHAR(logdate,'YYYY-MM-DD HH24:MI:SS') logdate, shiftname, building, unit, doornumber, inout, eventcount
      FROM door_events
     WHERE building='1800' AND unit='R' AND doornumber=4
     MODEL DIMENSION BY (logdate, shiftname, building, unit, doornumber, inout)
           MEASURES (eventcount)
           RULES (eventcount[TO_CHAR(SYSDATE,'YYYY-MM-DD HH24:MI:SS'),'X','1800','R',4,'In'=100)
    
    
    LOGDATE               SHIFTNAME  BUILDING  UNIT  DOORNUMBER  INOUT    EVENTCOUNT
    2012-02-01 06:00:00      A        1800      R      Door 4     Out         14
    2012-02-01 06:00:00      A        1800      R      Door 4     In          15
    2012-02-01 18:00:00      D        1800      R      Door 4     Out         17
    2012-02-01 18:00:00      D        1800      R      Door 4     In          19
    2012-02-02 06:00:00      A        1800      R      Door 4     Out         14
    2012-02-02 06:00:00      A        1800      R      Door 4     In          14
    ...
    2012-02-07 15:18:33      X        1800      R      Door 4     In          100
    Can someone explain this behavior? I intend to do some calculations on the LOGDATE dimension and I would like to keep it as a date. Thanks in advance for any help!

    I do not get the same result. When I use SYSDATE, I don't get the extra line. When I use TO_CHAR (SYDATE...) as you say, I still don't get the extra line.

    However, when I use a constant date, such as TO_DATE (' 2012/02/07 02:00 ',' YYYY-MM-DD HH24:MI:SS'), then I get the extra line.

    This behavior is described in http://docs.oracle.com/cd/E11882_01/server.112/e25554/sqlmodel.htm#BEIGGGFJ

    «Using UPSERT creates a new cell corresponding to that referenced on the left-hand side of the rule when the cell is absent, and the cell reference contains only positional references * qualified constants *.»

    Best regards, stew Ashton

    P.S. "Oracle Database 11g Enterprise Edition Release 11.2.0.2.0.

    Published by: stew Ashton on 7 February 2012 23:03

  • Using advanced MODEL clause

    I have a fairly complex series of calculations that my client wants done. I decided to use the TYPE clause as this data between the rows.

    Essentially, I need data as

    NAME of CC by year_ DT Meas value
    6K 29 300010 11 2008 1 1 12
    6K 29 300007 5 2008 1 1 1
    6K 29 300049 6 2008 1 1 300.58
    6K 29 300119 9 2008 1 1 - 120.67
    6K 29 300022 2 2008 1-1 - 53098.25
    6K 29 300008 2 2008 1 1 390.59
    6K 29 110310 3 2009 1 1 0
    6K 29 115020 5 2009 1 1 199.04
    6K 29 300022 2 2009 1-1 - 77706.88
    6K 29 300003 6 2009 1 1 23.90
    6K 29 300010 11 2009 1 1 10
    6K 29 300035 10 2009 1 1 0

    And turn them into
    NAME of CC by year_ DT Meas value
    6K 29 300010 11 2008 1 1 12
    6K 29 300007 5 2008 1 1 1
    6K 29 300049 6 2008 1 1 300.58
    6K 29 300119 9 2008 1 1 - 120.97
    6K 29 300022 2 2008 1-1 - 53098.25
    6K 29 300008 2 2008 1 1 390.59
    6K 29 110310 3 2009 1 1 0
    6K 29 115020 5 2009 1 1 199.04
    6K 29 300007 5 2009 1 1-1
    6K 29 300022 2 2009 1-1 - 77706.88
    6K 29 300003 6 2009 1 1 23.90
    6K 29 300049 6 2009 1 1 - 300.58
    6K 29 300010 11 2009 1 1 10
    6K 29 300035 10 2009 1 1 0
    6K 29 300119 9 2009 1 1 120.67
    6K 29 300008 2 2009 1 1 390.59

    As you can see there are now additional lines in 2009. I would then perform a calculation
    2008 2009. who is Annul_val = 2009_value - (2008_value(PER=13)/13). -which is why
    I want to use the TYPE clause.

    My problem is the new lines in 2009 (or for that matter, 2010, 2011 and so forth). This is just a small sample of the lines of 2 M table. So far I was only able to use a full as outer join...


    Select nvl (cc, T2, T1, cc) CC... nvl (T1.value, t2.value) of
    Join data complete external T1 T2 data on
    T1. CC = T2. CC and... T1.year_ = T2. Year-1 and T1.meas = T2.meas

    and then she sucks in the clause type... like this

    Select CC, name, per, year_, dt, soul, nval value of
    (select nvl (cc, T2, T1, cc) CC... nvl (T1.value, t2.value) of)
    Join data complete external T1 T2 data on
    T1. CC = T2. CC and... T1.year_ = T2. Year - 1 and T1.meas = T2.meas)
    model
    partition (CC, NAME, SOUL)
    dimension of (year_, by, dt)
    measures (val, nval 0 value) ignore nav
    rules)
    nVal [everything, everything, 1] = val [cv (year_), cv (period_id), 1]-(val [cv (year_)-1, 13, 1] / 13)
    );

    My question is how can I get the lines of a year in order to operate in the following years. While in this space of lines "fill" example 2008 2009, 2010 so on until 2015. And as for 2009 and other years. Is this possible with TEMPLATE rules? It does not seem possible from what I've read, but then I'm not a guru.

    Can it be done with analytical queries. My only other possibility I can think of is function in pipeline.

    Thanks, for any questions do not hesitate to ask...

    SAL

    chameeya S S wrote:
    Quite a nice solution.

    Indeed, but with two table scans... :-)

    Kind regards
    Rob.

  • Question of model clause

    Hello

    I was looking oracle documentation but can't find a clear answer. Question under works properly - existing lines are updated, no new documents created.
    With T as (
         Select 1 As Person_Id, 'Andrew' As Person_Name, 'HR' As Department From Dual union all
            Select 2 As Person_Id, 'John' As Person_Name, 'SALES' As Department From Dual     
    )
    Select Person_Id, Department, Person_Name, Salary
    From T
    Model          
         Dimension By (Person_id)
         Measures (Department, Person_Name, Cast(null As number) Salary)
         Rules upsert(         
              Salary [1] = 5000,
              Salary [2] = 7000       
         )
    Order By Person_id;
    The same query when person_id is changed to digital text form rather than update the existing lines, creates new ones.

    With T as (
         Select '1' As Person_Id, 'Andrew' As Person_Name, 'HR' As Department From Dual union all
            Select '2' As Person_Id, 'John' As Person_Name, 'SALES' As Department From Dual     
    )
    Select Person_Id, Department, Person_Name, Salary
    From T
    Model          
         Dimension By (Person_id)
         Measures (Department, Person_Name, Cast(null As number) Salary)
         Rules upsert(         
              Salary ['1'] = 5000,
              Salary ['2'] = 7000       
         )
    Order By Person_id;
    The only remedy is to throw the person_id as varchar2. Below query works correctly again (without new records created).

    With T as (
         Select cast('1' as varchar2(1)) As Person_Id, 'Andrew' As Person_Name, 'HR' As Department From Dual union all
            Select cast('2' as varchar2(1)) As Person_Id, 'John' As Person_Name, 'SALES' As Department From Dual     
    )
    Select Person_Id, Department, Person_Name, Salary
    From T
    Model          
         Dimension By (Person_id)
         Measures (Department, Person_Name, Cast(null As number) Salary)
         Rules upsert(         
              Salary ['2'] = 5000,
              Salary ['1'] = 7000       
         )
    Order By Person_id;
    If anyone knows the reason for this behavior, please let me know.

    Thanks in advance

    MJ

    Given that this has worked properly for me in the same version, can guess us maybe it could be something like a settiing parameter.
    For example, something like OPTIMIZER cursor_sharing, query_rewrite_enabled or query_rewrite_expression?

  • Iteration in a model clause...

    Hello
    I try a few tests using iterations in a clause of simple model...
    Here's one of them...
    select
      key ,
      m_1,
      itn
    from
      dual
    model
      ignore nav
      dimension by ( 0 as key )
      measures     ( 0 as m_1 ,
                     0 as itn)
      rules
        upsert
        sequential order
        iterate (10)
        (
          m_1[2]=ITERATION_NUMBER
          ,itn[iteration_number] =iteration_number
        )
    order by
      key
    ;

    The results are ...

            KEY     M_1     ITN
         0     0     0
         1          1
         2     9     2
         3          3
         4          4
         5          5
         6          6
         7          7
         8          8
         9          9
    I just can't justify the cell value to the value of dimension 2 (aka the value 9). Can you help me... ???

    Note: I use db 10g v.2
    Thank you
    SIM

    Hello

    sgalaxy wrote:
    As a matter of fact I rushed back upward to post this question... (sorry)...
    I realized the answer when I put:

    ......m_1[3]=ITERATION_NUMBER ....the result set is the same....!!!!
    

    Really? When I do the same change, in other words, if I change the line that says initially

    m_1[2]=ITERATION_NUMBER 
    

    TO

    m_1[3]=ITERATION_NUMBER 
    

    then the following 2 rows are different:

    `      KEY        M_1        ITN
    ---------- ---------- ----------
     ...
             2                     2
             3          9          3
    

    Look at your results and see if the 9 column m_1 is really on the same line.

  • table problem model clause / dual?

    Hi all, just experiment with the model using clause:

    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production

    this:
    with t as (select 1 num, 1 lvl from dual)
    select num, f1
      from t
    MODEL
       dimension by (lvl)
       measures (num f1, num f2)
       rules iterate(3)
           (f1[any] = f1[cv()] + f2[cv()]);
    works very well

    this:
    with t as (select 1 num, 1 lvl from dual connect by level <= 1)
    select num, f1
      from t
    MODEL
       dimension by (lvl)
       measures (num f1, num f2)
       rules iterate(3)
           (f1[any] = f1[cv()] + f2[cv()]);
                  
    results in
    ORA-32614: illegal MODEL SELECT expression
    32614. 00000 -  "illegal MODEL SELECT expression"
    *Cause:    An expression other than MODEL aliases, constants,
               or expressions of the two is specified in the
               MODEL SELECT clause.
    *Action:   Reformulate the query, perhaps nesting inside another SELECT.
    Error at Line: 2 Column: 7
    What is going on?

    Hello

    In fact, the first query should have failed with the same error because the Digital projection is not defined anywhere in the TYPE clause (it defines only LVL, F1 and F2).

    But what happens here is that the subquery of the DOUBLE is merged into the main and constant query are used instead.
    This is confirmed by a 10053 trace:

    Final query after transformations:******* UNPARSED QUERY IS *******
    SELECT 1 "NUM","F1" "F1"
    FROM "SYS"."DUAL" "DUAL"
    MODEL
      DIMENSION BY (1 "LVL")
      MEASURES (1 "F1",1 "F2")
      UNIQUE  DIMENSION
      RULES  UPSERT  ITERATE (3)(
        UPDATE "F1"["LVL"IS ANY]=("F1"[( CURRENTV("LVL"))])+("F2"[( CURRENTV("LVL"))]))
    

    (formatted)

  • Use the bind variable in example of a clause giving questions

    create or replace procedure pr_mbk (p_val in number)
    is
    CROR type is ref cursor;
    REF CROR;
    type numbertype is the table of index number of pls_integer;
    numtype numbertype.
    v_str varchar2 (2000): = 'select empno from emp sample(:val) ";
    Start
    Open ref for v_str using p_val;
    Close ref;
    end;
    /

    Successfully compiled.

    But when I run the same

    Exec pr_mbk (10);

    ERROR on line 1:
    ORA-00933: SQL not correctly completed command.
    ORA-06512: at "SCOTT. PR_MBK', line 9
    ORA-06512: at line 1

    My question is can use us Bind variables within a sample clause.

    Receive your answer.

    Thank you
    Madhu K.

    I guess that SAMPLE is considered as a special case, and is not considered as something that takes a 'value' in the same way as values in where clause or values in the query itself.
    Let's face it, the SAMPLE is not the standard SQL syntax and is probably something Oracle implements in a separate thread for processing SQL itself i.e. engine Oracle saying to herself... "I will remember this bit of the sample until I questioned the data using the SQL engine, so I'll take a suitable sample of the results," but it's the SQL engine treats the binding of values and the Oracle process that awaits the results taste, knows nothing of the binding values in it's special EXAMPLE of keyword.

  • model clause [10gr 2]

    I'm trying to rotate the EMP organization:

    Select (level 1, 2, level3, level4
    SELECT "nom_org" Organization, LEVEL AS org_level, ename
    WCP
    CONNECT BY PRIOR empno = mgr
    START WITH ename = 'KING')
    model
    to return the rows updated
    partition (Organization)
    dimension (org_level)
    measures (lpad (' ', 10) level1, lpad (' ', 10) level2, lpad (' ', 10) level3, lpad (' ', 10) level4)
    update rules
    (level 1 [0] = ename [1],)
    level 2 [0] = ename [2],
    Level3 [0] = ename [3],
    Level4 [0] = ename [4].
    )

    But something is wrong with the type clause... It is not the ename column.

    Any suggestions?

    Ename be a measure to be treated as a cell in the column. Note also that level uniquely identifies each measure.
    Not sure I understand your needs correctly, but:

    SQL> select organisation, level1,level2,level3,level4 from (
      2  SELECT 'org_name' AS organisation, LEVEL AS org_level, ename
      3  FROM emp
      4  CONNECT BY PRIOR empno = mgr
      5  START WITH ename = 'KING')
      6  model
      7  return updated rows
      8  partition by (organisation)
      9  dimension by (rownum rn)
     10  measures (lpad(' ',10) level1, lpad(' ',10) level2, lpad(' ',10) level3,lpad(' ',10) level4, org_level, ename)
     11  rules update
     12  ( level1[any] = case when org_level[cv()] = 1 then ename [cv()] end,
     13    level2[any] = case when org_level[cv()] = 2 then ename [cv()] end,
     14    level3[any] = case when org_level[cv()] = 3 then ename [cv()] end,
     15    level4[any] = case when org_level[cv()] = 4 then ename [cv()] end
     16  )
     17  ;
    
    ORGANISA LEVEL1     LEVEL2     LEVEL3     LEVEL4
    -------- ---------- ---------- ---------- ----------
    org_name KING
    org_name            JONES
    org_name                       SCOTT
    org_name                                  ADAMS
    org_name                       FORD
    org_name                                  SMITH
    org_name            BLAKE
    org_name                       ALLEN
    org_name                       WARD
    org_name                       MARTIN
    org_name                       TURNER
    org_name                       JAMES
    org_name            CLARK
    org_name                       MILLER
    
    14 rows selected.
    

    Kind regards
    Dima

  • What happened to the examples of models in CS4?

    In CS3, there were many examples of pages that were already completed... When you mention first CS3, you select:

    New...

    More...

    Sample page...

    Start page (theme)...

    And then, you can select items such as Restaurants, health and Nutrition, personal training... etc.

    They seem to have disappeared in CS4.  Is there a more robust elsewhere in Adobe that contains these examples?  Starting with a blank page is so much longer.

    Ideas?

    Thank you

    Rich Locus, Logicwurks, LLC

    Yes I think you're correct in your statement that they no longer exist in CS4.  If you have CS3 still on your computer, you can save as templates and then import them into CS4.  It seems that DW does that people now page blank CSS based layouts.

  • Are there plans to provide upgrades to Pages with more features like MS Word, for example the models?

    Of course the Pages not the functionality of the MS Word has.  Are there plans to provide similar functionality, such as the creation of forms/templates?

    I don't know what you mean. But Pages can create templates very well...

    Pages for Mac: create custom templates

  • Clause type SQL how can the others cannot?

    Hi all

    I met a topic called the type Clause when I was reading Pro Oracle SQL by Karen Morton, Kerry Osborne, Robyn SandsRiyaj Ntanguand Jared still. I just read the chapter and did some practice on my local machine. It is obvious that it is a very powerful feature. And I also reachered on the web and found out that it is used for spreadsheets (excel etc.). Can someone please give me a simple example which, in which case one must use the clauses types SQL Analytic Functions or group Advanced functions cannot cure?

    Either said by the way, I recommend strongly Pro SQL Oracle book to all who want to learn the knowledge of SQL.

    Thanks in advance

    Hello

    In short Yes, the TYPE clause allows you to perform calculations of "spreadsheet-like". With the help of the clause TYPE is quite rare. Now with the introduction of the WITH recursive clause in 11g 2, you can almost everything in SQL, do not even talk about the pattern match feature introduced in 12 c.

    You can probably do now with analytical functions / recursive clause the clause of MODEL can do. And I must say that it is a shame that the TYPE clause has never been improved since its introduction in 10g.

    In my view, the clause TYPE can come in handy when you need cross reference calculations (typically dealing with periods such as dates, years, weeks). For example, I personally used a MODEL clause for an analysis of sales time, where I watch the sales of previous years to find a pattern for the current. References of cells in a MODEL clause allows to easily, something like [my_year, my_week] model = local_pattern [(y ENTRE CV()-2 ET CV) (-1, w BETWEEN (CV-2) RESUME AND () + 2)]

  • How to use the clause type conditionally create new lines

    This question is just for learning - no object other than to start real world to create versions of some queries known to learn how to measure the performance of the MODEL clause clause of the MODEL versions.

    The question is: How can you write a STANDARD clause that pivots (updates) ONLY the lines that actually need to rotate and do NOT change the lines that have no value and cannot be rotated.

    I found a good site that has about two dozen example articles on different pieces. This first link is the beginning of the series.

    SQL features tutorials - Clause TYPE

    http://www.sqlsnippets.com/en/topic-11663.html

    This link is to a clause of FAQ of BluShadow MODEL version "how to convert rows to columns."

    Line - MODEL method string

    http://www.sqlsnippets.com/en/topic-11987.html

    The solution to this link uses this line of source:

    POSITION KEY VAL

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

    R08 0 v1, v2, v3,.

    and this result set:

    POSITION KEY VAL

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

    R08 1 v1

    R08 2 v2

    R08 3 v3

    The reason why it produces that result set is this clause of the statement of MODEL

    RETURN THE UPDATED LINES

    If you comment on this article, you will see that the original lines are all in position 0. This means that the solution reproduced EACH SOURCE LINE even if there is only one item in the list of values.

    Thus, even a line source with a single value (for example, the r01 'a') will be updated and updated this line is returned.

    For a large number of data sources with only a few lines that actually need to rotate it would be a great performance of infringement.

    This is the sample data source

    with t as (button 1, 'a' value 'abc' col2, col3 'def' of the double
    Select Union all 2, 'b', 'ghi', 'jkl' from dual
    Union all select 3, 'c, d, e, 'mno', 'pqr' from dual.
    Union all select 4, 'f', 'stu', 'vwx' from dual
    )
    Select the key, value, col2, col3
    t

    KEY, VALUE, COL2, COL3
    1, a, abc, def
    2, b, GHI, jkl
    3, "c, d, e, mno, pqr.
    4, f, stu, vwx

    Lines 1, 2 and 4 only have a value of (a, b, c respectively.

    Only line 3 must rotate. It contains "c, d, e" and which must become 3 lines in the result set

    Value of the key, col2 col3
    1 an abc def
    2B ghi jkl
    3 c mno, pqr
    3 d mno, pqr
    3 e mno, pqr
    4 f stu vwx

    The nut of the problem is that if the clause 'RETURN UPDATED ROWS' is used, then the lines 1, 2 and 4 must be updated in order to be returned in the result set. And if this clause is NOT used, then line 3 must be updated by 'c', d, e 'c' and two new product lines: one line for a ' and one for 'e '.

    How can you do this with the TYPE clause without the help of the clause "Return LINES UPDATE"? I don't have a solution to sample showing what I tried because I can't understand what it takes to even try.

    I have a solution that uses "RETURN UPDATED ROWS" but I want to compare this performance to the exercise, when this clause is NOT used.

    We ask BluShadow to add the solution of MODEL clause to this FAQ with other similar solutions.

    Like this?

    SQL > with t as
    () 2
    3 select the 1 key, 'a' val, 'abc' col2, col3 'def' of the double


    Select 4 Union all 2, 'b', 'ghi', 'jkl' from dual
    5 union all select 3, 'c, d, e, 'mno', 'pqr' from dual.
    Select 6 Union all the 4 'f', 'stu', 'vwx' from dual
    7)
    8. Select the key
    9, key_1
    10, val
    11, regexp_substr (val, ' [^,] +', 1, key_1) val_new
    12, col2
    13, col3
    14 t
    model 15
    16 partition by (key)
    dimension (1 key_1) 17
    18 measures (val, col2, col3, (length (val) - length (replace (val, ",")) + 1) as len)
    19 rules
    (20)
    21 val [for 1 to increment of len key_1 [1] 1] = val [1]
    22, col2 [for 1 to increment of len key_1 [1] 1] = col2 [1]
    23, col3 [for 1 to increment of len key_1 [1] 1] = col3 [1]
    24)
    25 order
    26 by key
    27, key_1;

    KEY KEY_1 VAL VAL_N NECK NECK
    ---------- ---------- ----- ----- --- ---
    1 1 has an abc def
    2 b 1 b ghi jkl
    3 1 c, d, e c mno pqr
    3 2 c, d, e d mno pqr
    3 3 c, d, e e mno pqr
    4 1 f f stu vwx

    6 selected lines.

  • Analytical functions, model indexes and multiple dimensions.

    I don't understand the notion of analytic functions (windowing clause) in the regulation of a model clause. I discovered an ordinary table as one-dimensional, and I can understand the concept of window, just like a line on a segment line. However with the models, there are several dimensions, so I guess that the window to become a kind of cube, instead of a line segment. But I'm not.

    For example, I have a matrix sparse 2D, with 5 values non-zero:
    select * from field
      where f is not null
    
    X     Y     F
    -----------------
    5     8     X
    6     6     X
    6     8     X
    7     7     X
    7     8     X
    I guess that the following clause of the model
    with t as(
      select *
        from field
       model
         reference old_field
           on
           (
             select * from field
           )
           dimension by (x, y)
           measures     (f)
         main new_field
           dimension by (x, y)
           measures     (cast(f as varchar2(3)) f)
           rules
           (
             f[x,y] = max(old_field.f) over (order by old_field.y range between 1 preceding and 1 following)
           ))
    select * from t
      where f is not null
    to assign for each cell up among its neighbors vertical 2. Just like
    0 0 0      0 X 0
    0 X 0  ->  X X 0
    X 0 0      X X 0
    But the real result is all NULL values.

    Hello

    with a as
    (
    select
    level L
    from
    dual
    connect by level < 4
    )
    
    select
         X
         ,Y
         ,Z
         ,X*3+Y
    
    from
         a          A1
         ,A     A2
    
    model
         dimension by ( A1.L X, A2.L Y )
         MEASURES (0 Z)
         RULES
         (
         Z[X,Y] = COUNT(Z) OVER (ORDER BY X * 3 + Y RANGE BETWEEN 1 PRECEDING AND 1 FOLLOWING)
         )
    
    X Y Z X*3+Y
    - - - -----
    1 1 2     4
    1 2 3     5
    1 3 3     6
    2 1 3     7
    2 2 3     8
    2 3 3     9
    3 1 3    10
    3 2 3    11
    3 3 2    12 
    
     9 rows selected 
    

    for x, y = 1.1, there is no previous rank if it is not counted. current line + line = 2
    for x, y = 1, 2, the previous line + line current + more rank = 3
    for x, y = 1.3 the previous line + line current + more rank = 3
    for x, y = 2, 1, the previous line + line current + more rank = 3
    ...
    for x, y = 3, 2 the previous line + line current + more rank = 3
    for x, y = 3, 3 the stored previous + current line = 2. There is no next line.

    What exectly not understand you?

    Kind regards
    Peter

  • on the Clause type

    Hi all
    I read some documents oracle and and some examples
    I understand that this model is used to create the table multidimensional and for the prediction of the future.

    but I am not able to write the query using the type clause.
    Please someone help me to understand the clause type base.
    I want everything clause type to start from scratch.

    Please guide me.

    Links: http://rwijk.blogspot.in/2007/10/sql-model-clause-tutorial-part-one.html.
    http://rwijk.blogspot.in/2007/10/SQL-model-clause-tutorial-part-two.html

    There is a post over here in the OTN forum. Please do a search.

    Concerning
    Biju

    Edited by: biju2012 1 Sep 2012 16:02
    (The link for part 2 is provided)

    Published by: biju2012 on Sep 2, 2012 02:45

Maybe you are looking for

  • Hi my browser Crash: Crash ID: bp-86ce85fa-6ce7-45e0-8ef1-9fa652140914 ID of Crash: Crash ID bp-a6741f31-c188-4e59-9612-ac6f62140912: bp-3cee8af1-3f9e-43

    Identifying full crash:Crash ID: bp-86ce85fa-6ce7-45e0-8ef1-9fa652140914Crash ID: bp-a6741f31-c188-4e59-9612-ac6f62140912Crash ID: bp-3cee8af1-3f9e-430f-b17b-7ae8f2140909Crash ID: bp-2325f9d9-df93-4d04-9432-72c312140905Crash ID: bp-cf760ccc-dc42-4fbd

  • Text imported from Motion pixelated

    I create a text on the video in movement 5. The project settings are The video is superb in motion and I use the behavior of the jet and the 3D text. When I import in FCPX it is pixelated as it grows. I use the Helvetica font because that's what I se

  • New H535s with Win 8.1

    I just bought a new H535s with Win 8.1 - do you know if there is a recovery already integrated into the system section or do I have to back up the system myself (using a lot of space) Thank you in anticipation

  • Price loop request?

    I am a loop in my stock and I am asking each those prices. The problem is, only the most recent in the loop is back with a price. Is there something wrong with my code? I checked that the loop runs through correctly, here is the code of the loop call

  • Table FLOW_INSTANCE SOA 12 c not found

    According to the noted id:- Doc-ID 2065869.1 Tables COMPOSITE_INSTANCE and MEDIATOR_INSTANCE does not apply to 12 c.Tables CUBE_INSTANCE, DLV_MESSAGE and DLV_TYPE have no any change.The FLOW_INSTANCE is available only in 12g.When I looked at my diagr