The Clause using SQL type
VersionSQL> select *
2 from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Productio
NLSRTL Version 10.2.0.4.0 - Production
My querywith tmp AS (
select 1 as num, 'karthik' as txt from dual UNION select 2 as num, 'john' as txt from dual UNION select 3 as num, '' as txt from dual UNION select 4 as num, '' as txt from dual UNION
select 14 as num, 'tom' as txt from dual UNION select 15 as num, '' as txt from dual UNION select 26 as num, 'sam' as txt from dual UNION
select 27 as num, '' as txt from dual UNION select 28 as num, '' as txt from dual
)
select *
from
(
select num,txt,rw,'G'||dense_rank() over(order by (num-rw)) grp_id
from
(
select
num, txt,row_number() over(order by num) rw
from tmp
)
)
model partition by(grp_id)
dimension by(num)
measures(txt,cast(null as varchar2(4000)) as last_row_col)
rules (last_row_col[(num)] = max(txt)[num < cv()])
GRP_ID NUM TXT LAST_ROW_COL
----------------------------------------- ---------- ------- --------------------------------------------------------------------------------
G1 1 karthik
G1 2 john karthik
G1 3 karthik
G1 4 karthik
G3 26 sam
G3 27 sam
G3 28 sam
G2 14 tom
G2 15 tom
Desired output:GRP_ID NUM TXT LAST_ROW_COL
G1 1 karthik karthik
G1 2 john
G1 3
G1 4 john
G3 26 sam
G3 27
G3 28 sam
G2 14 tom
G2 15 tom
i.e.within Group (GRP_ID) the LAST_ROW_COL column must have the most recent (order by num desc) not null not the value that is displayed in the last line of this group in particular.So, it should be 'john' for the rest of the null values in the group G1 (Kiss will remain as for num = 1) which should appear on the final line of this group in particular.
Thanks in advance.
Published by: RUSSO on January 2, 2012 04:18
RUSSO says:
I thought that this could be done easily using the power of the sql model clause
with tmp AS (
select 1 as num, 'karthik' as txt from dual UNION ALL
select 2 as num, 'john' as txt from dual UNION ALL
select 3 as num, '' as txt from dual UNION ALL
select 4 as num, '' as txt from dual UNION ALL
select 14 as num, 'tom' as txt from dual UNION ALL
select 15 as num, '' as txt from dual UNION ALL
select 26 as num, 'sam' as txt from dual UNION ALL
select 27 as num, '' as txt from dual UNION ALL
select 28 as num, '' as txt from dual
)
select grp_id,
num,
txt,
last_row_col
from tmp
model
dimension by(row_number() over(order by num) rw)
measures(num,txt,txt last_row_col,cast(null as varchar2(5)) grp_id)
rules(
grp_id[any] = 'G' || dense_rank() over(order by num[cv()] - cv(rw)),
last_row_col[rw > 1] order by rw = case
when last_row_col[cv()] is null then last_row_col[cv() - 1]
else last_row_col[cv()]
end,
last_row_col[rw > 1] order by rw = case last_row_col[cv() + 1]
when last_row_col[cv()] then null
else last_row_col[cv()]
end
)
/
GRP_I NUM TXT LAST_RO
----- ---------- ------- -------
G1 1 karthik karthik
G1 2 john
G1 3
G1 4 john
G2 14 tom
G2 15 tom
G3 26 sam
G3 27
G3 28 sam
9 rows selected.
SQL>
SY.
Published by: Solomon Yakobson January 2, 2012 09:35
Tags: Database
Similar Questions
-
Hi Experts,
I am trying to solve a problem. It is possible by other methods, but I want more precisely to explore and learn that using the Clause TYPE.
But facing some problem-
WITH t (i, col1, col2, col3) as)
SELECT 1,10,10,8 FROM dual UNION ALL
SELECT 2.15, null, 13 double UNION ALL
SELECT 4.20, null, 20 FROM dual UNION ALL
SELECT 3.7, null, 18 DOUBLE
)
---------------------------
-Samples above
---------------------------
SELECT *.
T
MODEL
dimension BY (i)
measures (col1, col2, col3)
rules
(
col2 [I > 1] = col2 [cv () - 1] - col3 [cv () - 1]
)
I ORDER
;
ORA-32637: Cyclic rudder automatically in sequential order MODEL
The ORA error is self-explanatory and so I guess the problem is use
col2 [I > 1] = col2 [cv () - 1]
The solution I want to achieve is-
col2 = (col2(previous row) - col3 (previous row)) + col1 (current row)
So my expected output should be-
1 10 10 8
2 15 17 13
3 20 24 20
4 7 11 18
and so on...
Please let me know if this can be achieved by using the type Clause.
Any response in this matter is appreciated.
Thank you and best regards,
-Nordine
(on Oracle 11.2.0.3.0)
Nordine include the ORDER BY clause in the RULES section
SQL > WITH t (i, col1, col2, col3) as)
2. SELECT 1,10,10,8 IN the dual UNION ALL
3 SELECT 2.15, null, 13 double UNION ALL
4 SELECT 4.20, null, 20 double UNION ALL
5 SELECT 3.7, null, 18 DOUBLE
6)
7 - Select * from t
8 ---------------------------
9 - sample data above
10 ---------------------------
11. SELECT *.
12 FROM t
MODEL 13
size 14 BY (i)
15 measures (col1, col2, col3)
16 rules
(17)
col2 18 [I > 1] i order = col2 [cv () - 1] - col3 [cv () - 1] + col1 [cv ()]
19)
20.
I HAVE COL1 COL2 COL3
---------- ---------- ---------- ----------
1 10 10 8
2 15 17 13
4 20 13 20
3 7 11 18
SQL >
-
XML data in the table using sql/plsql
Hi experts,
Could you please help with the following requirement. I have the tags xml (.xml on a server file) below. I need to access this file and read the XML and insert into the db table using sql and plsql. Is it possible with the cdata below? And there is a nested this table.
Could someone please guide me if you have a sample code file and xml.
<? XML version = "1.0" encoding = "UTF-8"? >
< generation_date > <! [CDATA [17/11/2015]] > < / generation_date >
< generated_by > <! [CDATA [Admin Admin]] > < / generated_by >
< year > <! [CDATA [2015]] > < / year >
< month > <! [CDATA [01]] > < / month >
< author >
< author > <! [CDATA [user author]] > < / author > < author_initial > <! [CDATA [user]] > < / author_firstname > < author_country > <! [CDATA [author]] > < / author_lastname >
< author_email > <! [CDATA [[email protected]]] > < / author_email >
< author_data_01 > <! [CDATA []] > < / author_data_01 >
< author_data_02 > <! [CDATA []] > < / author_data_02 >
< items >
< article_item >
< article_id > <! [CDATA [123456]] > < / article_id >
< publication > <! [CDATA [Al Bayan]] > < / publication >
< section > <! [CDATA [Local]] > < / section >
< issue_date > <! [CDATA [11/11/2015]] > < / issue_date >
< page > <! [CDATA [2]] > < / print this page >
< article_title > <! [CDATA [title.]] > < / article_title > < number_of_words > <! [CDATA [165]] > < / number_of_words >
< original_price > <! [CDATA [200]] > < / original_price >
< original_price_currency > <! [CDATA [DEA]] > < / original_price_currency >
< price > <! [CDATA [250]] > < / price >
< price_currency > <! [CDATA [DEA]] > < / price_currency >
< / article_item >
< / articles >
< total_amount > <! [CDATA [250]] > < / total_amount >
< total_amount_currency > <! [CDATA [DEA]] > < / total_amount_currency >
< / author >
< / xml >
Thanks in advance,
Suman
XMLTABLE using...
SQL > ed
A written file afiedt.buf1 with t (xml) as (select xmltype ('))
2 ") of the double)"
3
4
5
6
7
8
9
10
11
[[12[email protected]]] >
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34-
35 end of sample data
36-
37 - assumptions:
(38 - a) XML may have several tags
(39 - b) eachmay contain more
40-
41 select x.gen_by, x.gen_date, x.mn, x.yr
42, y.author, y.auth_fn, y.auth_ln, y.auth_cnt, y.auth_em, y.auth_d1, y.auth_d2
43, z.id, z.pub, z.sec, z.iss_dt, z.pg, z.art_ttl, z.num_wrds, z.oprice, z.ocurr, z.price, z.curr
44 t
45, xmltable ('/ authxml')
from $ 46 t.xml
path of 47 columns gen_date varchar2 (10) '. / generation_date'
48, path of varchar2 (15) of gen_by '. / generated_by'
49, path of varchar2 (4) year '. "/ year"
50 varchar2 (2) mn road '. "/ month"
51, path of xmltype authors '.'
52 ) x
53, xmltable ('/ authxml/authors ')
from $ 54 x.authors
author of 55 path of varchar2 columns (15) '. / author'
56, path of varchar2 (10) of auth_fn '. / author_firstname'
57, path of varchar2 (10) of auth_ln '. / author_lastname'
58 road of VARCHAR2 (3) auth_cnt '. / author_country'
59 road of varchar2 (20) of auth_em '. / author_email'
60 road of varchar2 (5) of auth_d1 '. / author_data_01'
61, path of varchar2 (5) of auth_d2 '. / author_data_02'
62, path of xmltype articles '. / Articles'
63 ) y
64, xmltable ('/ Articles/article_item ')
from $ 65 y.articles
path id 66 number columns '. / article_id'
67, path of varchar2 (10) pub '. ' / publication.
68 road of varchar2 (10) dry '. / section'
69, path of varchar2 (10) of iss_dt '. / issue_date'
70 road of VARCHAR2 (3) pg '. "/ print this page"
71, path of varchar2 (20) of art_ttl '. / article_title'
72, path of varchar2 (5) of num_wrds '. / number_of_words'
73, path of varchar2 (5) of oprice '. / original_price'
74 road to VARCHAR2 (3) ocurr '. / original_price_currency'
75, path of varchar2 (5) price '. "/ price"
76, path of VARCHAR2 (3) curr '. / price_currency'
77* ) z
SQL > /.GEN_DATE GEN_BY YEAR MN AUTHOR AUTH_FN AUTH_LN AUT AUTH_EM AUTH_ AUTH_ ID PUB DRY ISS_DT PG ART_TTL NUM_W OPRIC HEARTS PRICE OCU
---------- --------------- ---- -- --------------- ---------- ---------- --- -------------------- ----- ----- ---------- ---------- ---------- ---------- --- -------------------- ----- ----- --- ----- ---
17/11/2015 Admin Admin 2015 01 user author user author [email protected] 123456 UAE Al Bayan Local 11/11/2015 2 is the title. 165 200 AED AED 250Of course, you'll want to change the types of data, etc. as needed.
I assumed that the XML can contain several "
" sections and that each section can contain several entries. Thus the XMLTABLE aliasing as 'x' gives information of XML, and supplies the data associated with the XMLTABLE with alias 'y' which gets the multiple authors, which itself
section of the XMLTABLE with alias 'z' for each of the article_item. CDATA stuff are handled automatically by SQLX (XML functionality integrated into Oracle's SQL)
-
Unable to connect to the database using SQL * more
Hi, I have Oracle 10 g XE installed in my labtop, and I can't connect using SQL * more.
I can connect using the User Interface of navig however, I could do after the following procedure to change the password for the sys account:
-Open a command prompt
-type sqlplus
-On the line "Enter user name", enter the sysdba virtue
-On the SQL > prompt, type alter user sys identified by NewPassword;
But the thing is that even if I am able to connect using sys/NewPassword from my browser UI, I don't get the same result when do this using the SQL prompt.
What I try to do is the following:
SQL > connect sys/NewPassword
Can I get first a warming of the planet by saying I should use sysdba or sysoper to connect to the system account, but none of those who work.
Can anyone advice me on this subject?
Thanks in advanceDoes make sense at all?
You really need to Read The Fine Manual
http://download.Oracle.com/docs/CD/E11882_01/server.112/e16508/TOC.htmWhen you log in as USER "SYS" DB must be described as 'AS SYSDBA'
sqlplus
/ as sysdba
SHOW USER;
-line above indicates that you are now connected to the DB as "SYS"!SQL > CONNECT SYS / AS SYSDBA
-
If / then the Concepts using SQL not PL/SQL - avoid ORA-00942
Hello
Im trying to write a monitor which works in all of 80 db (where there is only applicable 7 db)-I want it simply returns the null value or no line on the DB is not required on as it is integrated into a model
A simplified version of the query "select col1, col2 from cat1.helptab.
It's very good for all the DB who actually have cat1.helpteb in their breast, but for those who are not obviously ORA-00942: table or view does not exist is returned.
I need to write a SQL statement that can move, * due to specific requirements, I can't use the PL/SQL for this *.
Any ideas how I can construct the statement above return null or 'no reurned lines' if cat1.helptab does not exist in the comic book?... instead of return ORA-00942
Any help would be appreciatedWhat is the interms impact of objects are created in the DB? nothing?
All operators/functions are generally available out of the box in a standard enterprise db installation.
Your admin could gave a restricted access to (or uninstalled) dbms_xmlgen well - one thing I would check beforehand.How this same method would work for the selection of a column that does not exist?
Almost the same:
SQL> select extract (x.column_value, 'ROW/DEPTNO/text()').getnumberval () deptno, extract (x.column_value, 'ROW/DNAME/text()').getstringval () dname, extract (x.column_value, 'ROW/ALERT/text()').getstringval () alert from all_tables, table ( xmlsequence ( dbms_xmlgen.getxmltype ('select deptno, dname, ''WARNING'' alert from ' || owner || '.' || table_name || ' where deptno > 30').extract ( 'ROWSET/ROW'))) x where owner = 'MICHAEL' and table_name = 'DEPT' / DEPTNO DNAME ALERT ---------- ------------------------------ ------------------------------ 40 OPERATIONS WARNING 50 SALES WARNING 2 rows selected.
-
Fire of process on click of the link using query type
APEX 3.2.0.0.27
I have a report region based on a qry with links. Each line has a link to separate the region on the same page. I want a process to fire (manual data select the process for the region linked) when the link is clicked. The link is displayed as a button change. I set the link for an application. How to identify the application that should fire when the user clicks on the link. I also defined a separate button named: QRY. The actual process (after submit process) it's fire is conditionial on the express request = 1 IN the expression 1 column, I entered the name of the button (QRY).
However the after submit the process is not fired.
So, how to correlate the process consisting in fires when the user clicks on the link. Do not confuse the link which is represented by a button here, but in fact I have this link button, but also a 'normal' button which bears the name of QRY. When I click on the actual button named QRY then my process is triggered. However, it did not when the user clicks on the link 'button '.
What I am doing wrong?So what you have is lines of report that can be presented in many ways, as well as the value of an other Item (Hidden)
Can think of two ways
- 1 concatenate the PK value with the request, use the PLSQL substr (substring) on demand to identify the type of demand but also to extract the value of the KP.
JavaScript: doSubmit('SAVE_#PK_COLUMN_ALIAS#');
Request: SUBSTR (: REQUEST, 1, INSTR(:REQUEST,'_')-1) and PK value is SUBSTR (: REQUEST, INSTR(:REQUEST,'_') + 1)
Then assign the item suitable in a bidding process - Another method is to assign the item directly
JavaScript: $s('
','#PK_COLUMN_ALIAS#'); doSubmit('SAVE_#DEPT_NAME#'); Replace the
with the name of the page to put element
Make sure that the item is not protected (this is the default option for the hidden items) -
To change the way of afficherdans the data using SQL
I have data as follows:
Name age
Tom 24
Harry 45
Mona 30
I want to convert these data in the way below
Name1, name2 Age1 Age2 Name3 3
24 45 30 Mona Harry Tom
How can I do the same thing using SQL?Why not try to search this forum of 'PIVOT' to make this small change yourself?
SQL> set line 1000 SQL> WITH t AS (SELECT 101 empid,45 marks,8 rank FROM dual UNION ALL 2 SELECT 101 empid,62 marks,7 FROM dual UNION ALL 3 SELECT 101 empid,80 marks,2 FROM dual UNION ALL 4 SELECT 102 empid,67 marks,5 FROM dual UNION ALL 5 SELECT 102 empid,56 marks,6 FROM dual UNION ALL 6 SELECT 103 empid,87 marks,7 FROM dual UNION ALL 7 SELECT 103 empid,55 marks,9 FROM dual UNION ALL 8 SELECT 103 empid,60 marks,6 FROM dual UNION ALL 9 SELECT 103 empid,70 marks,3 FROM dual 10 ) 11 ---End of Sample Data 12 ---Now the original query. 13 SELECT empid, MAX(DECODE(rn1,1,marks)) Marks1,MAX(DECODE(rn1,1,rank)) Rank1 14 , MAX(DECODE(rn1,2,marks)) Marks2,MAX(DECODE(rn1,2,rank)) Rank2 15 , MAX(DECODE(rn1,3,marks)) Marks3,MAX(DECODE(rn1,3,rank)) Rank3 16 , MAX(DECODE(rn1,4,marks)) Marks4,MAX(DECODE(rn1,4,rank)) Rank4 17 FROM 18 (SELECT empid,marks,rank, 19 ROW_NUMBER() OVER(PARTITION BY empid ORDER BY marks) rn1 20 FROM t) 21 GROUP BY empid; EMPID MARKS1 RANK1 MARKS2 RANK2 MARKS3 RANK3 MARKS4 RANK4 ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 101 45 8 62 7 80 2 102 56 6 67 5 103 55 9 60 6 70 3 87 7 SQL>
-
Hello guys,.
I have a PART_NEEDED table and a table function that returns the % ROWTYPE PART_NEEDED table. It works fine, but if I try to create new type defined by the user with the same attributes as PART_NEEDED and pipe lines in the table of this type, I get an inconsistency of error types - Error (30,16): PLS 00382: expression is of type.
Please see the below script. I appreciate any help!
CREATE TABLE 'LAUNCH '. "" PART_NEEDED ".
(
ACTIVATE THE "PART_NEEDED_ID" NUMBER NOT NULL,
NUMBER OF "TYPE_OF_PART_NEEDS_ID."
NUMBER OF "TYPE_OF_PART_IS_NEEDED_ID."
NUMBER IN THE 'QUANTITY '.
)
SEGMENT INITRANS PCTFREE, PCTUSED 40 10 IMMEDIATE CREATION 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
(
INITIALS 65536 THEN 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 USER_TABLES CELL_FLASH_CACHE DEFAULT FLASH_CACHE DEFAULT
)
TABLESPACE 'USERS ';
--
CREATE OR REPLACE TYPE 'TYPE_PART_NEEDED' AS AN OBJECT
(
IDENTIFICATION NUMBER,
NUMBER OF PART_ID,
NUMBER OF SUB_PART_ID
NUMBER AMOUNT
)
/
--
create or replace package KOLEV_ADMIN_PKG as
TYPE TYPE_PART_NEEDED_TBL IS TABLE OF THE DRAW. TYPE_PART_NEEDED; -If the type here is PART_NEEDED % ROWTYPE it works perfectly fine
FUNCTION GET_SUBPARTS (IN_PART_ID NUMBER)
TYPE_PART_NEEDED_TBL RETURN PIPELINE;
end;
--
CREATE OR REPLACE PACKAGE BODY 'KOLEV_ADMIN_PKG' AS
FUNCTION GET_SUBPARTS (IN_PART_ID NUMBER)
TYPE_PART_NEEDED_TBL RETURN PIPELINE
IS
R_TBL TYPE_PART_NEEDED_TBL; -Must be returned
BEGIN
FOR R IN)
WITH
SUBPARTS(ID, PART_ID, SUBPART_ID, AMOUNT) AS
(
SELECT PART_NEEDED_ID, TYPE_OF_PART_NEEDS_ID, TYPE_OF_PART_IS_NEEDED_ID, AMOUNT
OF PART_NEEDED
WHERE TYPE_OF_PART_NEEDS_ID = IN_PART_ID
UNION ALL
SELECT FN. PART_NEEDED_ID, PN. TYPE_OF_PART_NEEDS_ID, PN. TYPE_OF_PART_IS_NEEDED_ID, PN. AMOUNT
SUBPARTS SP, PART_NEEDED PN
WHERE PN. TYPE_OF_PART_NEEDS_ID = SP. SUBPART_ID
)
SELECT SP.ID, MS. PART_ID, MS. SUBPART_ID, MS. AMOUNT
THE SP SUBPARTS
ORDER BY PART_ID
)
LOOP
PIPE ROW (R); - Error (30,16): PLS 00382: expression is of the wrong type
END LOOP;
RETURN;
END GET_SUBPARTS;
END "KOLEV_ADMIN_PKG";
INSERT INTO 'TOSS '. "PART_NEEDED" (TYPE_OF_PART_NEEDS_ID, TYPE_OF_PART_IS_NEEDED_ID, PART_NEEDED_ID, AMOUNT) VALUES ('4 ', '2', '3', ' 2').
INSERT INTO 'TOSS '. "PART_NEEDED" (TYPE_OF_PART_NEEDS_ID, TYPE_OF_PART_IS_NEEDED_ID, PART_NEEDED_ID, AMOUNT) VALUES ('5', '3', '1', 2').
INSERT INTO 'TOSS '. "PART_NEEDED" (TYPE_OF_PART_NEEDS_ID, TYPE_OF_PART_IS_NEEDED_ID, PART_NEEDED_ID, AMOUNT) VALUES ('3', '2', '1', 4').
INSERT INTO 'TOSS '. "PART_NEEDED" (TYPE_OF_PART_NEEDS_ID, TYPE_OF_PART_IS_NEEDED_ID, PART_NEEDED_ID, AMOUNT) VALUES ('17', '3', '4', 1').
The 11.2.0.1.0 database release
I want this feature because I need to make some joins and add descriptions for each part. This PART_NEEDED table now contains only the IDs - many-to-many.
Kind regards!
Published by: Todor Kolev on March 3, 2012 12:47CREATE OR REPLACE PACKAGE BODY KOLEV_ADMIN_PKG AS FUNCTION GET_SUBPARTS (IN_PART_ID IN NUMBER) RETURN TYPE_PART_NEEDED_TBL PIPELINED IS BEGIN FOR R IN ( WITH SUBPARTS(ID, PART_ID, SUBPART_ID, AMOUNT) AS ( SELECT PART_NEEDED_ID, TYPE_OF_PART_NEEDS_ID, TYPE_OF_PART_IS_NEEDED_ID, AMOUNT FROM PART_NEEDED WHERE TYPE_OF_PART_NEEDS_ID = IN_PART_ID UNION ALL SELECT PN.PART_NEEDED_ID, PN.TYPE_OF_PART_NEEDS_ID, PN.TYPE_OF_PART_IS_NEEDED_ID, PN.AMOUNT FROM SUBPARTS SP, PART_NEEDED PN WHERE PN.TYPE_OF_PART_NEEDS_ID = SP.SUBPART_ID ) SELECT TYPE_PART_NEEDED( SP.ID, SP.PART_ID, SP.SUBPART_ID, SP.AMOUNT ) O FROM SUBPARTS SP ORDER BY PART_ID ) LOOP PIPE ROW(R.O); END LOOP; RETURN; END GET_SUBPARTS; END KOLEV_ADMIN_PKG; /
SY.
-
Create the view using SQL DEVELOPER
I'm new to this forum :)
11 GR 2, WIN2008 R2
SQL Developer Version 3.2.09
I am creating the data below view (view existing)
Table: Dovmarker
I try to describe the table and my goal :),MARKERBOREHOLE UWI MARKERSURFACE Z WELLXXX 65372643AAAA Cw -982,985619574516 WELLXXX 65372643AAAA Cn -1891,47401803955 WELLXXX 65372643AAAA J -674,989528816517 WELLXXX 65372643AAAA K3 20,00165000429 WELLXXX 65372643AAAA Tr 125,000317308153 WELLXXX 65372643AAAA K1 -658,989731894024 WELLXXX 65372643AAAA Q 149,999999999549 WELLYYY 56618334AAAA Jkm -715,071442105268 WELLYYY 56618334AAAA K3 36,9013966413975 WELLYYY 56618334AAAA J2 -976,056079257549 WELLYYY 56618334AAAA Tr 106,900507694299
each line describes wells, uwi(uniqe identifier), z (deppth), high (surface marker)
I try to merge all lines with the same MARKERBOREHOLE/UWI and MARKERSURFACE contact coresponding Z (ascending) as MARKERSURFACE = Z.
If it is posibble to reduce the number of decimals to 2.
My idea to solve the problem:
example: ' | ' is the delimiter
or better (not enough knowledge ;))WELLXXX Q=149,999999999549 | Tr=125,000317308153 | K3=20,00165000429 | K1=-658,989731894024 | J =-674,989528816517 | Cw=-982,985619574516 | Cn=-1891,47401803955 WELLYYY Tr=106,900507694299 | K3=36,9013966413975 | Jkm=-715,071442105268 | J2=-976,056079257549
Number of markersurface is different for each wellWELLXXX Q=149,999999999549 Tr=125,000317308153 K3=20,00165000429 K1=-658,989731894024 J =-674,989528816517 Cw=-982,985619574516 Cn=-1891,47401803955 WELLYYY Tr=106,900507694299 K3=36,9013966413975 Jkm=-715,071442105268 J2=-976,056079257549
I try to do it by the listagg function, but I have failled
result:select markerborehole, listagg(z, ' | ') within group (order by z) as new1 from dovmarker group by markerborehole;
When I tried to create new view in sql developer I occurred error;WELLZZZ -2575,95869465411 | -1891,47401803955 | -982,985619574516 | -674,989528816517 | -658,989731894024 | WELLRRR -2376,96975480605 | -2376,96975480605 | -2308,97180590009 | -2308,97180590009 | -2206,47428534641 | -2206,47428534641 | -2163,97522524171
Can you help me with this?Error(s) parsing SQL: unexpected token near *!* in the following: select markerborehole, listagg(z, ' | ') within *!*group (order by z) as new1 unexpected token near *!* in the following: select markerborehole, listagg(z, ' | ') within group *!*(order by z) as new1 missing expression near *!* in the following: select markerborehole, listagg(z, ' | ') within group (*!*order by z) as new1
Concerning
Jaroslaw961148 wrote:
I missed xWell Yes, my apologies, I has not changed all that.
It's a simple way to format the Z value to 2 decimal places?
Yes. It depends on if you want to use rounded, floor, ceiling, truncate or if you like a string always have 2 decimal places etc.
Make your choice and customize according to your needs...SQL> ed Wrote file afiedt.buf 1 with t as (select 'WELLXXX' as MARKERBOREHOLE, '65372643AAAA' as UWI, 'Cw' as MARKERSURFACE, -982.985619574516 as Z from dual union all 2 select 'WELLXXX', '65372643AAAA', 'Cn', -1891.47401803955 from dual union all 3 select 'WELLXXX', '65372643AAAA', 'J', -674.989528816517 from dual union all 4 select 'WELLXXX', '65372643AAAA', 'K3', 20.00165000429 from dual union all 5 select 'WELLXXX', '65372643AAAA', 'Tr', 125.000317308153 from dual union all 6 select 'WELLXXX', '65372643AAAA', 'K1', -658.989731894024 from dual union all 7 select 'WELLXXX', '65372643AAAA', 'Q', 149.999999999549 from dual union all 8 select 'WELLYYY', '56618334AAAA', 'Jkm', -715.071442105268 from dual union all 9 select 'WELLYYY', '56618334AAAA', 'K3', 36.9013966413975 from dual union all 10 select 'WELLYYY', '56618334AAAA', 'J2', -976.056079257549 from dual union all 11 select 'WELLYYY', '56618334AAAA', 'Tr', 106.900507694299 from dual) 12 -- 13 -- END OF TEST DATA - IGNORE ABOVE WITH CLAUSE 14 -- 15 select z 16 ,round(z,2) as round_z_2 17 ,floor(z*100)/100 as floor_z_2 18 ,ceil(z*100)/100 as ceil_z_2 19 ,trunc(z,2) as trunc_z_2 20 ,to_char(round(z,2),'fm9990.00') as string_z_2 21* from t SQL> / Z ROUND_Z_2 FLOOR_Z_2 CEIL_Z_2 TRUNC_Z_2 STRING_Z ------------------- ---------- ---------- ---------- ---------- -------- -982.9856195745160 -982.99 -982.99 -982.98 -982.98 -982.99 -1891.4740180395500 -1891.47 -1891.48 -1891.47 -1891.47 -1891.47 -674.9895288165170 -674.99 -674.99 -674.98 -674.98 -674.99 20.0016500042900 20 20 20.01 20 20.00 125.0003173081530 125 125 125.01 125 125.00 -658.9897318940240 -658.99 -658.99 -658.98 -658.98 -658.99 149.9999999995490 150 149.99 150 149.99 150.00 -715.0714421052680 -715.07 -715.08 -715.07 -715.07 -715.07 36.9013966413975 36.9 36.9 36.91 36.9 36.90 -976.0560792575490 -976.06 -976.06 -976.05 -976.05 -976.06 106.9005076942990 106.9 106.9 106.91 106.9 106.90 11 rows selected.
with above code I try to create a new view in SQL Developer, but I have error:
Error(s) parsing SQL: Unexpected token near *!* in the following: select markerborehole, listagg(z,chr(10)) within *!*group(order by rn) as z Unexpected token near *!* in the following: select markerborehole, listagg(z,chr(10)) within group*!*(order by rn) as z Missing expression near *!* in the following: select markerborehole, listagg(z,chr(10)) within group(*!*order by rn) as z
What are all the {noformat}! * * {noformat} in the code? Delete them.
Edit: or maybe your version of SQL Developer is not up-to-date and does not know the new LISTAGG function in 11g?
Published by: BluShadow on 26-Sep-2012 09:41
-
calculation of the average using sql
Hi all
My table structure is
--------------------------------------
ID name notes starting_date end_date
--------------------------------------
workingdays = end_date-starting_date
I had a query
Select name, max (case when remarks = remarks then end notes).
Max (case when id = id then end_date-starting_date end),
AVG(end_date-starting_date) average t_action_items
Rollup (name, end_date-starting_date) group;
who's out like that
Name of the average Workingdays remarks
--------------------------------
x 20 20 aaa
BBB 10 20 x
AAA 10 15
y ccc 19
DDD y 8
CCC 8 13.5
CCC 8 14.2
But I need output like this, how can I do that someone please guide me
Name of the remarks Workingdays
------------------------
aaa 20 x
BBB 10 x
15 > x average
y ccc 19
DDD y 8
13.5-> average for y
Forgive me, I can't able to align to the right format, I think that with data you can seggregate
Thanks in advance...
Published by: Paappu on March 20, 2009 09:50Hello
I have used WITH clause to show the result. You use just SELECT it with your table it will work.
SQL> SELECT * FROM T; NAME REMARK START_DT END_DT ------ ------------- --------- --------- Mark Design 15-FEB-09 15-FEB-09 Hendry Coding 08-JUN-08 15-JUN-08 steve Testing 29-OCT-08 04-NOV-08 JAMES POC 01-MAR-09 01-MAR-09 JAMES DOCUMENTATION 01-MAR-09 09-MAR-09 SQL> SELECT Name,Remark, SUM(work_hrs), AVG(work_hrs) FROM ( 2 SELECT name,remark ,start_dt,end_dt,SUM(end_dt-start_dt) OVER (PARTITI N BY name,remark ORDER by Name) work_hrs 3 FROM T) 4 GROUP BY ROLLUP(name,remark); NAME REMARK SUM(WORK_HRS) AVG(WORK_HRS) ------ ------------- ------------- ------------- Hendry Coding 7 7 Hendry 7 7 JAMES DOCUMENTATION 8 8 JAMES POC 0 0 JAMES 8 4 Mark Design 0 0 Mark 0 0 steve Testing 6 6 steve 6 6 21 4.2 10 rows selected. SQL>
Kind regards
-
How to get the path (using <; input type = "file" / >;)
Hello world
I create a HTML form that has an entry of type = "file". This will give you a dialog box browse for your user to search for a file on the operating system.
And my code:
function handleFileSelectForMyShop (evt)
{
var blnFileReaderSupported = false;Try
{Debug.log ("handleFileSelect", "start handleFileSelect");
reader of var = new FileReader();
blnFileReaderSupported = true;
var files = evt.target.files;
var size = files.length;Debug.log ("handleFileSelect", "handleFileSelect # selected files:" + size, debug.info);
for (var i = 0; i)< size;="">
{
Debug.log ("handleFileSelect", "in the handleFileSelect analysis the index file" + i, debug.info ");
var f = files [i];
Reader.OnLoad = (function (theFile)
{
Debug.log ("handleFileSelect", "start reader.onload", debug.info);
return Function
{
Debug.log ("handleFileSelect", "start Function", debug.info);Debug.log ("handleFileSelect", "reading file" + theFile.name + "(" + theFile.size + "") "" + theFile.type, debug.info);
If (theFile.type.match ('image.*')) {}
var path = e.target.result;
alert (path);
create the path} else {}
jAlert ("Please select photo!', 'Error'");
}
};
})(f);If ((f.type.match ('image.*')) |) (f.type.match ('audio.*')) | (f.type.match ('video.*')))
{
Debug.log ("handleFileSelect", "in handleFileSelect call reader.readAsDataURL for type" + f.type, debug.info);
Read in the media file in the form of a data URL.
reader.readAsDataURL (f);
}
}Debug.log ("handleFileSelect", "Complete", debug.info);
}
{} catch (e)
Debug.log ("handleFileSelect", e, debug.exception);
If (! blnFileReaderSupported)
{
Alert('Error.) The FileReader API is not supported. ") ;
}
}
}function doPageLoad()
{
Try
{
ELE var = document.getElementById ('txtFile_staffInfo');
If (ele)
{
ele.addEventListener ('change', handleFileSelectForMyShop, false);
}
imgSelectPictureClick = 0;
}
{} catch (e)
Debug.log ("doPageLoad", e, debug.exception);
}
}window.addEventListener ("load", doPageLoad, false);
Note: And alert (path) leads to a Base64 string! It is not a path of the image that I browse a Spain file on the operating system.
I want to have a full path of the file. For example: file:///accounts/1000/appdata/WebWorksAppTemplate.testa3NBcHBUZW1wbGF0ZSAgICA/shared/camera/image01.jpg
I hope to see your reply soon!
Thank you and best regards,
A Pham
A Pham
I think that you can not get the absolute path of a file due to browser security, when you use the
It's something that you need probably a PlayBook extension for.
-
How the group using SQL for the desired output.
Hi all
I am currently using oracle 10.2.0.4.0
Create a table script:
INSERT statement:CREATE TABLE FORTEST ( gpno VARCHAR2(10 BYTE), classnumber VARCHAR2(10 byte), age_min NUMBER, age_max NUMBER, amount NUMBER)
power required:insert into fortest (GPNO,classnumber,age_min,age_max,amount) values ('G123' , 01,0,29,1) insert into fortest (GPNO,classnumber,age_min,age_max,amount) values ('G123' , 01,30,35,2) insert into fortest (GPNO,classnumber,age_min,age_max,amount) values ('G123' , 01,36,40,3) insert into fortest (GPNO,classnumber,age_min,age_max,amount) values ('G123' , 02,0,29,1) insert into fortest (GPNO,classnumber,age_min,age_max,amount) values ('G123' , 02,30,35,2) insert into fortest (GPNO,classnumber,age_min,age_max,amount) values ('G123' , 02,36,40,5) insert into fortest (GPNO,classnumber,age_min,age_max,amount) values ('G123' , 03,0,29,1) insert into fortest (GPNO,classnumber,age_min,age_max,amount) values ('G123' , 03,30,35,2) insert into fortest (GPNO,classnumber,age_min,age_max,amount) values ('G123' , 03,36,40,3) insert into fortest (GPNO,classnumber,age_min,age_max,amount) values ('G124' , 01,0,29,1) insert into fortest (GPNO,classnumber,age_min,age_max,amount) values ('G124' , 01,30,35,2) insert into fortest (GPNO,classnumber,age_min,age_max,amount) values ('G124' , 01,36,40,3)
as for gpno g123, classnumber 1 and 3, the rates are the same in all the age_min and age_max they need to be grouped.gpno classnumber age_min age_max amount G123 1,3 0 29 1 G123 1,3 30 35 2 G123 1,3 36 40 3 G123 2 0 29 1 G123 2 30 35 2 G123 2 36 40 5 G124 1 0 29 1 G124 1 30 35 2 G124 1 36 40 3
even if gpno 123 classnumber 2 has the same rates as the classesnumber 1 and 3 for the age groups 0 to 29 and 30 to 35,
rates are different for ages 36 to 40. so it should not be placed together. How can I do this in SQL
any help is appreciated.
Thanks in advance.Hello
Thorny problem!
Unfortunately, LISTAGG was created to the Oracle 11.2. About half of the complexity here is the aggregation of chain, i.e. forming the list of the classnumbers, as '1.3', using only functions available in Oracle 10.2.
Here's a solution:
WITH got_gpno_classnumber_cnt AS ( SELECT gpno, classnumber, age_min, age_max, amount , COUNT (*) OVER ( PARTITION BY gpno , classnumber ) AS gpno_classnumber_cnt FROM fortest -- WHERE ... -- If you need any filtering, this is where it goes ) , pairs AS ( SELECT a.gpno , a.classnumber , MIN (b.classnumber) OVER ( PARTITION BY a.gpno , a.classnumber ) AS super_classnumber FROM got_gpno_classnumber_cnt a JOIN got_gpno_classnumber_cnt b ON a.gpno = b.gpno AND a.age_min = b.age_min AND a.age_max = b.age_max AND a.amount = b.amount AND a.gpno_classnumber_cnt = b.gpno_classnumber_cnt GROUP BY a.gpno , a.classnumber , b.classnumber HAVING COUNT (*) = MIN (a.gpno_classnumber_cnt) ) , got_rnk AS ( SELECT DISTINCT gpno, classnumber, super_classnumber , DENSE_RANK () OVER ( PARTITION BY gpno , super_classnumber ORDER BY classnumber ) AS rnk FROM pairs ) , got_classnumbers AS ( SELECT gpno, classnumber, super_classnumber , SUBSTR ( SYS_CONNECT_BY_PATH (classnumber, ',') , 2 ) AS classnumbers FROM got_rnk WHERE CONNECT_BY_ISLEAF = 1 START WITH rnk = 1 CONNECT BY rnk = PRIOR rnk + 1 AND gpno = PRIOR gpno AND super_classnumber = PRIOR super_classnumber ) SELECT DISTINCT g.gpno , c.classnumbers , g.age_min , g.age_max , g.amount FROM got_gpno_classnumber_cnt g JOIN got_classnumbers c ON c.gpno = g.gpno AND c.classnumber = g.classnumber ORDER BY g.gpno , c.classnumbers ;
Out (just as you requested):
GPNO CLASSNUMBERS AGE_MIN AGE_MAX AMOUNT ---------- --------------- ---------- ---------- ---------- G123 1,3 0 29 1 G123 1,3 30 35 2 G123 1,3 36 40 3 G123 2 0 29 1 G123 2 30 35 2 G123 2 36 40 5 G124 1 0 29 1 G124 1 30 35 2 G124 1 36 40 3
-
between the clause of sql query?
Hi all
After sql query using a report.
------------------------------------------------
Select trunc (m.spc_doc_date) prod_date, sum (nvl(d.req_qty,0)) order_qty, sum (nvl(d.spc_item_qty,0)) prod_qty
of spc_ppc_daily_m m, spc_ppc_daily_d d
where m.spc_doc_ # in (select spc_doc_ # to spc_ppc_daily_m)
- and d.blce_qty > 0
and m.spc_locn_code =: locn_code
and m.spc_doc_date between: TO_date and: FROM_date
and m.spc_locn_code = d.spc_locn_code
and m.spc_doc_ #= d.spc_doc_ #.
and (m.obu =: obu OR: OLGA IS NULL)
and (m.customer =: customer OR: CUSTOMER IS NULL)
Trunc Group (m.spc_doc_date)
order of trunc (m.spc_doc_date)
-----------------------------------------
"When I use to_date = 22 February 2012 ' from_date = February 22, 2012"
There is no pick up. (acually documents are there on February 22, 2012)
"When I use to_date = 22 February 2012 ' from_date = February 23, 2012"
now shows data of February 22, 2012.
I have replace between it of > = & < =, same result two cases respectively.
Why?
Thank you
Yoanndate you hours minutes and seconds
thenuse
trunc (m.spc_doc_date)or to: from_date in the parameter after form convert to February 23, 2012 23:59:59 '
-
How can I write an SQL to generate a square for a period of time? Using only the SQL (not PL SQL).
Assumption - two characters in the horizontal line is equal to a character vertically.
Example of
Suppose that if the length of the square is 7, then there will be a character in horizontal line 14 and 7 in vertical line.
Help, please.************** * * * * * * * * * * **************
Published by: user10681556 on 10 Sep, 2009 01:26Alex Nuijten wrote:
... but I don't know Rob could come up with a more elegant solution ;)Not really.
Only one rule less:
SQL> select s square 2 from dual 3 model 4 dimension by (0 i) 5 measures (cast(null as varchar2(100)) s) 6 rules 7 ( s[for i from 1 to :sz increment 1] = '*' || rpad (' ',2*:sz - 2) || '*' 8 , s[i in (1,:sz)] = replace(s[cv()],' ','*') 9 ) 10 / SQUARE ------------------------------------------------------------------------------------- ******************** * * * * * * * * * * * * * * * * ******************** 11 rijen zijn geselecteerd.
Kind regards
Rob. -
How to export the database and import the database using sql developer
Hello
I need to export the database to a server and import it on another server db using the export function of database under the Tools menu in SQLl developer. How to import it? This is for Oracle database 10g.
Thank youHello
I think it generates the file .sql containing all the objects that you are exported. Then you can simply open the target database file and run as a script. Also, there is another forum for sqldeveloper related issues.
Concerning
Maybe you are looking for
-
How can I cancel a subscription and get a refund? An application does not work, the "assistance of the developer page" link provided by itunes is broken, and email provided by the application developer's sole means of support, but no response in 3 we
-
HP Compaq 6000 Pro SFF: PCI Simple Communications Controller Driver Windows 7
Good afternoon everyone, I'm in the middle of installing Windows 7 on a 6000pro but I could not find the driver for the controller PCI of communication Simple. The hardware ID is: PCI\VEN_8086 & DEV_2E14 & SUBSYS_3048103C & REV_03 PCI\VEN_8086 & DEV_
-
Is it possible to sign our app customers?
Hello We are almost finished with the development of a Playbook application for one of our customers, but we are not sure of how it is to be signed. The customer is not technical and to be honest could not do through the RIM vendor, signing process.
-
Change the size of the text only does not work
Font size standard on most of the Windows I have open in Windows 8 is a 5 or 6. I'm in front of my computer, 6 to 8 hours per day (teacher online), and it's the single most annoying problem that I have ever met. "Change the size of the text only ' o
-
Use-business cases for Oracle JET
Dear team,Get your hands wet with Oracle JET and found it interesting. However, can you help me with the use case where it can be used effectively? Can you give us some specific use cases where Oracle JET is the ideal solution? (if possible with just