Iteration in a model clause...
HelloI try a few tests using iterations in a clause of simple model...
Here's one of them...
selectI just can't justify the cell value to the value of dimension 2 (aka the value 9). Can you help me... ???
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
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.
Tags: Database
Similar Questions
-
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 documentationIf 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... -
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_NUM BATCH_ID MEMBER_ID MBR_COB_SFX CLAIM_NBR CLAIM_SFX DOCTOR_NBR DOCTOR_PFX DOCTOR_SFX PRINT_DATE DOC_TYPE CLAIM_OUTPUT CRTD_DT CRTD_BY COPY_TO GRP_ID COPY_TO_1 1801 2015072015 ABCDEF123 0 61773667 20 JULY 15 EOB (XMLTYPE) GRP_NBR COPY OF PROVIDER 1802 2015072015 ABCDEF123 0 61773667 20 JULY 15 EOB (XMLTYPE) GRP_NBR MEMBER 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_NUM MBR_ID COPY_TO 1801 ABCDEF123 1802 ABCDEF123 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;
I write my SQL like this: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 ...
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 ()
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 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)
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!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
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
-
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:
works very wellwith 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()]);
this:
results inwith 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()]);
What is going on?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
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)
-
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...
SALchameeya S S wrote:
Quite a nice solution.Indeed, but with two table scans... :-)
Kind regards
Rob. -
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 -
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.
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 '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;
If anyone knows the reason for this behavior, please let me know.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;
Thanks in advance
MJGiven 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? -
With the help of the Case clause with clause type
Hello PL SQL gurus
I used a few scripts I found on these forums to create an amortization of mortgage statement. What I'm trying to accomplish is to get the script to run a calculation or use a value in a table based on the value in this table.
Here are two tables:
CREATE TABLE mortgage_facts (customer VARCHAR2 (20), result VARCHAR2 (20),)
quantity NUMBER (10.3));
INSERT INTO mortgage_facts VALUES ('Smith', 'Ready', 131828.81);
INSERT INTO mortgage_facts VALUES ('Smith', 'Annual_Interest', 3,348);
INSERT INTO mortgage_facts VALUES ('Smith', 'Payments', 72);
INSERT INTO mortgage_facts VALUES ('Smith', 'PaymentAmt', 0);
Mortgage of CREATE TABLE (customer VARCHAR2 (20), pmt_num, no.4, principalp NUMBER (10.3), interestp NUMBER (10.3), mort_balance NUMBER (10.3));
INSERT INTO mortgage VALUES ('Smith', 0, 0, 0, 131828.81);
If the value in the mortgage_facts table is zero, I want the script runs a calculation to be used in a MODEL clause. If it is not zero, I would use this value instead of the calculation. Here is the script I am getting an error on (I have bolded the part in question):
SELECT c, p, to_char (round(m,2), 'fm$ 9999999.00') principal_balance,
TO_CHAR (Round(pp,2), 'fm$ 9999999.00') towards_principal,
TO_CHAR (Round(IP,2), 'fm$ 9999999.00') towards_interest,
TO_CHAR (Round(MP,2), 'fm$ 9999999.00') monthly_payment
MORTGAGE COMPANY
MODEL - see 1
IGNORE THE NAV
REFERENCES R ON
* (SOME customers, fact, amt - see 2 *)
FROM mortgage_facts
* MODEL SIZE (customer, done) MEASURES (amount amt) - see 3 *.
REGULATION SEQUENCE
*(*
CASE WHEN mortgage_facts.fact = 'PaymentAmt' AND mortage_facts.amt = 0 THEN
*(*
* amt [ALL, 'PaymentAmt'] = mortgage_facts.amt*
*)*
ON THE OTHER
*(*
* amt [everything, "PaymentAmt"] = (amt [CV (), "Ready"] *)
* Power (1 + (amt [CV (), 'Annual_Interest'] / 100/12), *)
(* AMT [CV (), 'Payments']) *.
(* AMT [CV (), 'Annual_Interest'] / 100/12)) / *.
* (Power (1 + (AMT [CV (), 'Annual_Interest'] / 100/12), *))
(* AMT [CV (), 'Payments'])-1) *.
*)*
END
*)*
*)*
SIZE OF (customer cust, made) measures (amt)
Amortization of PRINCIPAL
PARTITION BY (customer c)
DIMENSION (p) 0)
MEASURES (pp, interestp ip principalp, mort_balance m, mc, mp 0 customer)
REGULATION SEQUENCE
ITERATE (1000) UP TO (ITERATION_NUMBER + 1 =
r.AMT [MC [0], 'Payments'])
(ip [ITERATION_NUMBER + 1] = m [CV () - 1] *)
r.AMT [MC [0], 'Annual_Interest'] / 1200,.
MP [ITERATION_NUMBER + 1] = r.amt [mc [0], "PaymentAmt"],
pp [ITERATION_NUMBER + 1] = r.amt [mc [0], 'PaymentAmt']-ip [CV ()].
m [ITERATION_NUMBER + 1] = m [CV () - 1] - pp [CV ()]
)
ORDER BY c, p
Any help is very appreciated. Thank you!!OK, here we go, go with the iterative model:
select * from mortgage_facts model partition by (Customer) dimension by (1 p) measures(loan, payments, INTEREST, PAYMENTAMT, INTERESTPMT, PRINCIPALPMT, balance) rules iterate(1e9) until (iteration_number+2 >= payments[1]) (loan[iteration_number+2]=loan[1] ,payments[iteration_number+2]=cv(p)-1 ,interest[iteration_number+2]=interest[1] ,paymentamt[iteration_number+2]=ROUND( (LOAN[1] * (INTEREST[1]/12/100)*Power((1+INTEREST[1]/12/100), PAYMENTS[1])/(Power((1+INTEREST[1]/12/100),PAYMENTS[1])-1)), 2) ,INTERESTPMT[iteration_number+2]=round(balance[cv(p)-1]*interest[1]/1200, 2) ,PRINCIPALPMT[iteration_number+2]=paymentamt[cv()]-INTERESTPMT[cv()] ,balance[iteration_number+2]=balance[cv()-1]-PRINCIPALPMT[cv()] ) CUSTOMER P LOAN PAYMENTS INTEREST PAYMENTAMT INTERESTPMT PRINCIPALPMT BALANCE Smith 1 131828.81 72 3.348 0 0 0 131828.81 Smith 2 131828.81 1 3.348 2023.55 367.8 1655.75 130173.06 Smith 3 131828.81 2 3.348 2023.55 363.18 1660.37 128512.69 Smith 4 131828.81 3 3.348 2023.55 358.55 1665 126847.69 Smith 5 131828.81 4 3.348 2023.55 353.91 1669.64 125178.05 Smith 6 131828.81 5 3.348 2023.55 349.25 1674.3 123503.75 Smith 7 131828.81 6 3.348 2023.55 344.58 1678.97 121824.78 Smith 8 131828.81 7 3.348 2023.55 339.89 1683.66 120141.12 Smith 9 131828.81 8 3.348 2023.55 335.19 1688.36 118452.76 Smith 10 131828.81 9 3.348 2023.55 330.48 1693.07 116759.69 Smith 11 131828.81 10 3.348 2023.55 325.76 1697.79 115061.9 Smith 12 131828.81 11 3.348 2023.55 321.02 1702.53 113359.37 Smith 13 131828.81 12 3.348 2023.55 316.27 1707.28 111652.09 Smith 14 131828.81 13 3.348 2023.55 311.51 1712.04 109940.05 ....
-
I have a temp table as below
LOC X CNT
20 20 C
80 20 N
60 30 C
40 30 N
100 40 N
the rule is for each column of the LOC, there are 2 records of C, N and sum (NTC) must be = 100. If there is no value for C for a LOC (LOC = 40) then the value of the CNT corresponding to C should appear as null or 0 if the value of N is > 0.
I need a model clause to do this, see below,
LOC X CNT
20 20 C
80 20 N
60 30 C
40 30 N
100 40 N
0 TO 40 C
Why why why? I am not able to understand the model clause. How did you learn model clause?
-
Analytics / requirement model
It is a puzzle that I put myself after a discussion to make choices between SQL and PL/SQL - is not urgent not important and not serious.
If I query dba_extents for a given table (e.g. sys.source$) measure information looks like this:
Select file_id, block_id, blocks
from dba_extents
where owner = 'SYS '.
and nom_segment = '$SOURCE. '
order of file_id, block_id
;
FILE_ID, BLOCK_ID BLOCKS ---------- ---------- ----------
1 1504 8 1 8168 8 1 8176 8 1 8192 8 1 8288 8 1 8440 8 1 10072 8 ...
1 77568 128 1 77696 128 1 77824 128 1 78080 128 1 89984 128 ...
1 90752 1024 80 selected lines.
I have a piece of code that bed the exent list, joins a list of numbers to enumerate each block in each scope, sorts the blocks of file_id and block_id, applies to an ntile (12) for the result set, and then selects the first and the last block in each tile to produce an output which is essentially 12 rows (first_file_id first_block_id (, last_file_id, last_block_id)-which I can convert it to a set of coating lines for the table rowid. (This is essentially what dbms_parallel_execute when you create pieces of rowid - except that it uses the PL/SQL to do).
My SQL does exactly the necessary work, but is significantly slower than the equivalent PL/SQL - we're talking only a few seconds on the line for very large objects, so the difference is not relevant for the purposes of actual production - largely, I think, because I have to increase the size of the initial result set between the number of extensions and the number of blocks and then narrow down again so that the PL/SQL can simply browse the definitions of making simple arithmetic.
I'm sure that there is a way of MODEL clause to avoid explosion, and I'd like to see if anyone has the time, but I keep thinking I'm close an analytical solution, but can't quite get there. So if anyone can find a solution that would be even better than a solution of model - failing that someone proves that it can be done effectively in simple analytical SQL.
UPDATE: I forgot to declare explicitly that point to the explosion of the block and ntile() was that it was a simple strategy to get the same number (+ /-1) block in all ranges of rowid.
Concerning
Jonathan Lewis
Post edited by: Jonathan Lewis
The solution:
[Update: Please see https://stewashton.wordpress.com/2015/07/01/splitting-a-table-into-rowid-ranges-of-equal-size/ for an update solution, a bit cleaner.] Thanks Chris227, I learned for the function WIDTH_BUCKET]!
with data as ( select (select blocks / 12 from my_segments) blocks_per_chunk, object_id from my_objects ) , extents as ( select nvl(sum(blocks) over( order by file_id, block_id rows between unbounded preceding and 1 preceding ),0) cumul_start_blocks, sum(blocks) over(order by file_id, block_id) - 1 cumul_end_blocks, blocks, block_id, file_id, data.* from my_extents, data ) , extents_with_chunks as ( select trunc(cumul_start_blocks / blocks_per_chunk) first_chunk, trunc((cumul_end_blocks) / blocks_per_chunk) last_chunk, round(trunc(cumul_start_blocks / blocks_per_chunk)*blocks_per_chunk) first_chunk_blocks, round(trunc((cumul_end_blocks+1.0001) / blocks_per_chunk)*blocks_per_chunk)-1 last_chunk_blocks, e.* from extents e ) , expanded_extents as ( select first_chunk + level -1 chunk, cumul_start_blocks, file_id, block_id, case level when 1 then cumul_start_blocks else round((first_chunk + level -1)*blocks_per_chunk) end start_blocks, case first_chunk + level -1 when last_chunk then cumul_end_blocks else round((first_chunk + level)*blocks_per_chunk)-1 end end_blocks from ( select * from extents_with_chunks where first_chunk_blocks = cumul_start_blocks or last_chunk_blocks = cumul_end_blocks or first_chunk < last_chunk ) connect by cumul_start_blocks = prior cumul_start_blocks and first_chunk + level -1 <= last_chunk and prior sys_guid() is not null ) select chunk, min(file_id) first_file_id, max(file_id) last_file_id, min(block_id + start_blocks - cumul_start_blocks) keep (dense_rank first order by cumul_start_blocks) first_block_id, max(block_id + end_blocks - cumul_start_blocks) keep (dense_rank last order by cumul_start_blocks) last_block_id, max(end_blocks) + 1 - min(start_blocks) blocks from expanded_extents group by chunk order by chunk;
-
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
tKEY, VALUE, COL2, COL3
1, a, abc, def
2, b, GHI, jkl
3, "c, d, e, mno, pqr.
4, f, stu, vwxLines 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 vwxThe 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 vwx6 selected lines.
-
Addressing non-dimensional single MODEL?
Hi all
Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
Req:
I have a field with words in double as ' PRESIDENT; THE PRESIDENT OF THE EXECUTIVE; The "(séparés par deles de points-virgules) PRESIDENT, I need to remove duplicates from a line." I like 1 million rows to work on...
First time I use the model Dimension byORA-32638: Non unique addressing in MODEL dimensions 32638. 00000 - "Non unique addressing in MODEL dimensions" *Cause: The address space defined for the MODEL (partition by and dimension by expressions) do not uniquely identify each cell. *Action: Rewrite the MODEL clause. Using UNIQUE SINGLE REFERENCE option might help.
Any approach better to handle this kind of situation other than model Dimension bySELECT BIO, RTRIM (str_new, ';') new_str FROM db_temp MODEL DIMENSION BY (0 dim) MEASURES (BIO, BIO || ';' STR_NEW) RULES ITERATE (1000) UNTIL (STR_NEW[0] = PREVIOUS (STR_NEW[0])) (str_new [0] = REGEXP_REPLACE (str_new[0], '(^|;)([^;]+;)(.*?;)?\2+', '\1\2\3'));
Don't you have a unique ID column in the table?
In this case, all you have to do is to add a PARTITION clause:
... MODEL PARTITION BY (id) DIMENSION BY (0 dim) ...
If you do not have this column, you can also calculate an on-the-fly:
... MODEL PARTITION BY (rownum rn) DIMENSION BY (0 dim) ...
-
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:
I guess that the following clause of the modelselect * 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
to assign for each cell up among its neighbors vertical 2. Just likewith 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
But the real result is all NULL values.0 0 0 0 X 0 0 X 0 -> X X 0 X 0 0 X X 0
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
Maybe you are looking for
-
Can I update the graphics card in my iMac end 2012?
I am able to update the graphics card in my iMac end 2012? I know that this is not a gaming computer, but I want to be able to play low end games. Is this possible?
-
Most of my themes will disappear if I switch to FF4? I use 3.6.17
I used both of the themes and Personas. I want to talk about issues. My current version of FireFox is 3.6.17. I am very happy with some four years of use now! But I would be really frustrated if most of my themes disappeared! I did a backup using Moz
-
I can't connect to the Internet via the wireless network. It shows that I have local access only. I can't connect even in SafeMode with network. I have Ping www.microsoft.com and the answer is "ping request could not find host www.microsoft.com. I
-
How to set the regional settings of the control panel for the Dates
original title: Control Panel regional settings for Dates I've already put the regional settings in Control Panel to date as follows: DD/MM/yy. But whenever I turn on my PC again, it goes back to this format: DD/MM/YYYY. How can I get there like JJ/M
-
What is the difference between OP_READY and SECURE status?
I put ISD status of my java SECURE of the status card. I want to know what capacity card lost in this new status compared to OP_READY?Note: I try, I can download and install new map .cap files and delete them successfully still [in this new ISD statu