In Oracle lag function
Hi all
I want to understand the inner workings of the Lag function in Oracle, which could help to solve my problem.
I have the table as the structure below.
P_ID | ENTRY_TIMESTAMP | SIZE | C_ID |
---|---|---|---|
15287 | 1 NOVEMBER 15 05.45.00 PM | 30 | 92 |
15295 | 06.00.00 PM 1ST NOVEMBER 15 | 15 | 92 |
15306 | 06.00.00 PM 1ST NOVEMBER 15 | 1 | 92 |
Now, when I write a query as below:
Select the size, CURR_TIMESTAMP TO_TIMESTAMP (TO_CHAR (ENTRY_TIMESTAMP, 'YYYYMMDDHH24MI'), 'YYYYMMDDHH24MI'),
TO_TIMESTAMP (TO_CHAR (LAG (ENTRY_TIMESTAMP) OVER (PARTITION BY ORDER BY ENTRY_TIMESTAMP ASC C_ID), 'YYYYMMDDHH24MI'), 'YYYYMMDDHH24MI') LAG_TIMESTAMP
OF Entry_log
where ENTRY_TIMESTAMP BETWEEN to_date (1 November 15 18.00.00','DD-MON-YY HH24.MI.) SS') AND to_date (1 November 15 18.00.00','DD-MON-YY HH24.MI.) SS')
Query will lead to give Lag_timestamp as 06.00.00 PM for size = 1 but will be NULL for size = 15.
Why is that Oracle will never lag_timestamp = 06.00.00 PM for size = 15.
Could someone please explain this behavior.
I'm using Oracle 11 g.
Thank you
I had a small mistake in the above query. now, I fixed it
Tags: Database
Similar Questions
-
LAG function alternative queries
Dear all,
WITH t AS
(SELECT 1 AS num, "test1" AS status
OF THE DOUBLE
UNION ALL
SELECT 2 AS num, "test2" LIKE status
OF THE DOUBLE
UNION ALL
SELECT 3 AS num, "test3" LIKE status
OF THE DOUBLE
UNION ALL
SELECT the 4 ACEs num, "test4" LIKE status
OF THE DOUBLE
UNION ALL
SELECT 5 AS num, "test5" LIKE status
THE DOUBLE)
SELECT the State, LAG (status 1) OVER (ORDER BY num) AS previous_status
T
Please help me to write search above without LAG function like oracle forms10g unsupported feature LAG.
Hello, you can join the table itself for the results. This will work only if you have a number in ascending order.
WITH t AS
(SELECT 1 AS num, "test1" AS status
OF THE DOUBLE
UNION ALL
SELECT 2 AS num, "test2" LIKE status
OF THE DOUBLE
UNION ALL
SELECT 3 AS num, "test3" LIKE status
OF THE DOUBLE
UNION ALL
SELECT the 4 ACEs num, "test4" LIKE status
OF THE DOUBLE
UNION ALL
SELECT 5 AS num, "test5" LIKE status
THE DOUBLE)
T1.status, t2.status SELECT previous_status
T t1, t t2
where t2.num (+) = t1.num - 1
order of t1.status
Best regards, Andrei
-
Oracle version: 11.0.2.0.2.0
Dear all
I have a question where I am using tables Tab1 and Tab2
Struncture of tab1 is
Store_no NUMBER,
Sell_date DATE
Sell quantity number,
number of item_no
to tab2
Number of Item_no
date date1,
number of item_price
I need know the total price of the article sold for 2 days (current as previous)
Select the store, sell_date, item_no, sell_qty * item_price, lag (sell_qty * item_price, 1) on the partition by (store_no, item_no order of sell_date)
of tab1, tab2
where tab1.item_no = tab2.item_no
and sell_date = date1
Question1) tables have millions of lines... The lag function is causing the query to run for hours...
Could you please suggest if we capture these sorts of queries where Lag/lead are used.
Your query does not much sense. Analytical functions are applied to already recovered lines, and since you have sell_date = date1, all you get is one day sales. All you need is:
Select the store
Max (sell_date),
tab1.item_no,
sum (case sell_date when date1 then sell_qty * end item_price) day_sales_amount,.
sum (case sell_date when date1 - sell_qty then 1 * item_price end) prev_day_sales_amount
of tab1.
tab2
where tab1.item_no = tab2.item_no
and sell_date in the fields (date1, date1 - 1).
Store group,
tab1.item_no;
SY.
-
LAG function to get the value of the measurement for parent
Hello
I'm interested if there is no function in OLAP DML, which is similar to the function of TROLLING. LAG function returns the measured value for the previous dimension member (or a few members of the back dimension). I would like to know if this function exists which does not return a meaningless measurement for the dimension member value, but the measured value for the parent of the live dimension member.
Thanks in advance
Peter_parentrel relationship identifies the parent of each Member of the dimension of a hierarchy. use:
the time - dimension
time_parentrel - Member parent expression
time_parentrel (time_hierlist 'CALENDAR') - expression for parent along the CALENDAR hierarchySales - measure
Sales (Time time_parentrel) - expression returning sales for the parent of the current Member along the existing hierarchy.
sales (time time_parentrel (time_hierlist 'EXERCISE'))-expression returning the sales for the parent of the current Member along the FISCAL hierarchy.You can search the user's Guide the OLAP DML for many examples of the use of the OLAP DML commands/functions/objects in expressions.
All of these objects are automatically created/maintained while retaining the dimension from the front end (MN).For example:
(11g) OLAP DML users guide notions-> about-> OLAP DML objects given OLAP DML-> objects that support the use of hierarchical Dimensions section. -
Oracle 11.2.0.1.0 SE - one on OL 5.6 x 86-64
Still faced with a LAG.
Given a table like this
Table is added every day withcreate table emp_hist ( sample_date date, lname varchar2(10), dept varchar2(10), sal number ) ;
Of course, most of the time, most of the employees will have no change from the previous. What I'm trying to do is filtering all the records of 'no change' and get off at only changes... amount of change and when it appearedinsert into emp_hist (select sysdate, lname, dept, sal from emp) ;
Maybe this:
or (better)dept lname sample_date sal ---- ----- ----------- ------- 10 smith 1-Aug-2012 10000 2-Aug-2012 20000 10 jones 5-Aug-2012 50000 6-Aug-2012 60000 20 snuffy 4-Aug-2012 30000 5-Aug-2012 40000
Wish I could show what I tried so far, but I'm so stuck, I can't even that.dept lname change_date prev_sal curr_sal ---- ----- ----------- ------- -------- 10 smith 2-Aug-2012 10000 20000 10 jones 6-Aug-2012 50000 60000 20 snuffy 5-Aug-2012 30000 40000
Hello
Looks like:
WITH got_prev_sal AS ( SELECT dept , lname , sample_date AS change_date , LAG (sal) OVER ( PARTITION BY lname ORDER BY sample_date ) AS prev_sal , sal AS curr_sal FROM emp_hist ) SELECT * FROM got_prev_sal WHERE prev_sal != curr_sal ORDER BY lname , change_date ;
In any application data (or subquery), analytical functions are calculated after the clause WHERE this request has been applied. If you need to use the results of an analytic function in a WHERE clause, calculate the analytical function in a subquery (such as got_prev_sal, above). You can then use the value returned in the WHERE clause (or elsewhere) in the main query.
I hope that answers your question.
If not, post a small example data (instructions INSERT, to go with the CREATE TABLE statement, you have already published) and also publish outcomes from these data.
Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results in these places.
See the FAQ forum {message identifier: = 9360002}Published by: Frank Kulash, August 7, 2012 16:29
-
Using Oracle analytic function
Hi all
I use Oracle 10 g Release 10.0.2
Here's the situation:
I visited in my table of looks like this:
Cust_id beg_dt end_dt sg_cd
264321502 1 MAY 97 19 MARCH 98 1
264321502 21 MAY 98 15 OCTOBER 98 6
264321502 20 OCTOBER 98 22 APRIL 99 6
264321502 23 APRIL 99 25 APRIL 00 6
264321502 27 APRIL 00 20 JANUARY 02 6
264321502 25 JANUARY 02 15 MAY 02 6
264321502 MAY 21 02 27 MAY 02 6
264321502 31 MAY 02 17 FEBRUARY 03 6
264321502 21 FEBRUARY 06 03-7.-04 1
264321502 25 FEBRUARY 03 25 FEBRUARY 03 1
264321502 31 MARCH 03 30 APRIL 03 1
264321502 07 - SEP - 04 26 DECEMBER 04 6
264321502 29 DECEMBER 04 3 JANUARY 06 6
264321502 4 JANUARY 06 3 JANUARY 07 12
264321502 4 JANUARY 06 3 JANUARY 07 12
264321502 4 JANUARY 06 3 JANUARY 07 12
I need the results of the query as
Cust_id beg_dt end_dt sg_cd
264321502 1 MAY 97 19 MARCH 98 1
264321502 21 MAY 98 17 FEBRUARY 03 6
264321502 21 FEBRUARY 03 30 APRIL 03 1
264321502 07 - SEP - 04 3 JANUARY 06 6
264321502 4 JANUARY 06 3 JANUARY 07 12
Basically, I need take a min max (end_dt) of sg_cd for this cust id (beg_dt).
Any help is very much appreciated:
My query is like that
Select cust_id, end_dt, beg_dt, sg_cd,
min (beg_dt) more (partition of cust_id, sg_Cd) as new_beg_dt,
Max (end_dt) more (partition of cust_id, sg_cd) as end_Dt_nw
of cust_tab.
can be like that?
1 data
() 2
3 select Cust_id 264321502, to_date('01-MAY-97','dd-mon-rr') beg_dt, to_date('19-MAR-98','dd-mon-rr') end_dt, 1 sg_cd of all the double union
4. Select 264321502, to_date('21-MAY-98','dd-mon-rr'), to_date('15-OCT-98','dd-mon-rr'), 6 Union double all the
5 select 264321502, to_date('20-OCT-98','dd-mon-rr'), to_date('22-APR-99','dd-mon-rr'), 6 Union double all the
6. Select 264321502, to_date('23-APR-99','dd-mon-rr'), to_date('25-APR-00','dd-mon-rr'), 6 Union double all the
7. Select 264321502, to_date('27-APR-00','dd-mon-rr'), to_date('20-JAN-02','dd-mon-rr'), 6 Union double all the
8 select 264321502, to_date('25-JAN-02','dd-mon-rr'), to_date('15-MAY-02','dd-mon-rr'), 6 Union double all the
9. Select 264321502, to_date('21-MAY-02','dd-mon-rr'), to_date('27-MAY-02','dd-mon-rr'), 6 Union double all the
10. Select 264321502, to_date('31-MAY-02','dd-mon-rr'), to_date('17-FEB-03','dd-mon-rr'), 6 Union double all the
11. Select 264321502, to_date('21-FEB-03','dd-mon-rr'), to_date('06-SEP-04','dd-mon-rr'), 1 Union double all the
12 select 264321502, to_date('25-FEB-03','dd-mon-rr'), to_date('25-FEB-03','dd-mon-rr'), 1 Union double all the
13 select 264321502, to_date('31-MAR-03','dd-mon-rr'), to_date('30-APR-03','dd-mon-rr'), 1 Union double all the
14 select 264321502, to_date('07-SEP-04','dd-mon-rr'), to_date('26-DEC-04','dd-mon-rr'), 6 Union double all the
15 select 264321502, to_date('29-DEC-04','dd-mon-rr'), to_date('03-JAN-06','dd-mon-rr'), 6 Union double all the
16 select 264321502, to_date('04-JAN-06','dd-mon-rr'), to_date('03-JAN-07','dd-mon-rr'), 12 Union double all the
17 select 264321502, to_date('04-JAN-06','dd-mon-rr'), to_date('03-JAN-07','dd-mon-rr'), 12 Union double all the
18 select 264321502, to_date('04-JAN-06','dd-mon-rr'), to_date('03-JAN-07','dd-mon-rr'), 12 of the double
(19) - select * from data
20. Select Cust_id, beg_dt, max (end_dt) as end_dt, min (beg_dt), sg_cd
21 of
(22)
23 select x.*, sum (flg) over (order by end_dt Cust_id partition) as grp
24 of
(25)
26 select
27 wagneur, case when lag (sg_cd, 1-9) over (order by end_dt Cust_id partition)! sg_cd = 1 END so that flg
28 from data d
x 29)
x 30)
Group 31 by Cust_id, sg_cd, grp
32 * order of Cust_id, end_dt
CUST_ID BEG_DT END_DT SG_CD
---------- --------- --------- ----------
264321502 1 MAY 97 19 MARCH 98 1
264321502 21 MAY 98 17 FEBRUARY 03 6
264321502 21 FEBRUARY 06 03-7.-04 1
264321502 07 - SEP - 04 3 JANUARY 06 6
264321502 4 JANUARY 06 3 JANUARY 07 12
-
get my head wrapped around the LAG function
Oracle 11.2.0.4 Std Ed
drop table change_hist;
create table change_hist (file_name varchar2 (30),)
date of sample_date,
number of blocks
);
insert into change_hist values (to_date('2015-07-01','yyyy-mm-dd'), 'file1', 5);
insert into change_hist values (to_date('2015-07-02','yyyy-mm-dd'), 'file1', 5);
insert into change_hist values (to_date('2015-07-03','yyyy-mm-dd'), 'file1', 6);
insert into change_hist values (to_date('2015-07-04','yyyy-mm-dd'), 'file1', 6);
insert into change_hist values (to_date('2015-07-05','yyyy-mm-dd'), 'file1', 6);
insert into change_hist values (to_date('2015-07-01','yyyy-mm-dd'), 'file2', 5);
insert into change_hist values (to_date('2015-07-02','yyyy-mm-dd'), 'file2', 5);
insert into change_hist values (to_date('2015-07-03','yyyy-mm-dd'), 'file2', 5);
insert into change_hist values (to_date('2015-07-04','yyyy-mm-dd'), 'file2', 5);
insert into change_hist values (to_date('2015-07-05','yyyy-mm-dd'), 'file2', 5);
insert into change_hist values ('file3', to_date('2015-07-01','yyyy-mm-dd'), 5);
insert into change_hist values ('file3', to_date('2015-07-02','yyyy-mm-dd'), 6);
insert into change_hist values ('file3', to_date('2015-07-03','yyyy-mm-dd'), 6);
insert into change_hist values ('file3', to_date('2015-07-04','yyyy-mm-dd'), 6);
insert into change_hist values ('file3', to_date('2015-07-05','yyyy-mm-dd'), 6);
Desired result
file_name sample_date prev_value curr_value
File1 2015-07-03 5 6
File2 2015-07-02 5 6
My first attempt...
SQL > select file_name,.
2 sample_date,
3 lag (blocks, 1) (order sample_date) as prev_blocks
4 change_hist;
FILE_NAME SAMPLE_DA PREV_BLOCKS
------------------------------ --------- -----------
July 1, 15 file1
July 1, 15 5 file3
July 1, 15 5 File2
File2 2 July 15 5
File1 2 July 15 5
file3 2 July 15 5
File1 July 3, 15 6
File2 July 3, 15 6
file3 July 3, 15 5
File1 4 July 15 6
file3 4 July 15 6
FILE_NAME SAMPLE_DA PREV_BLOCKS
------------------------------ --------- -----------
File2 4 July 15 6
File2 July 5 15 5
File1 July 5 15 5
file3 5 July 15 6
15 selected lines.
SQL >
SQL > spo off
1 select * from (select file_name, sample_date, lag(blocks) over (partition by file_name order by sample_date) prev, blocks 2 from change_hist) 3* where prev != blocks SQL> / FILE_NAME SAMPLE_DA PREV BLOCKS ------------------------------ --------- ---------- ---------- file1 03-JUL-15 5 6 file3 02-JUL-15 5 6
You know... you need to partition the file name
Edit: in the interest of beat some people with a force equal regardless of their status, you didn't really know we tell how to achieve these results, so I could refer to the FAQ on how to ask a question
-
Oracle 10.2.0.4 SE - One on OL 5 x 86-64
Trying to write reports on statspack tables. In view of this query
Works perfectly. But I would like to delete the ' where... w1.event = 'db file sequential read' and get a report on all events. Of course, simply commenting on this condition means that the first occurrence of an event is "shifted" against the last occurrence of the previous event. Can not find a way to get the logic that do break and start the 'delay' all over again.select -- s1.ucomment w1.event , s1.snap_id , to_char(s1.snap_time,'dd-Mon-yyyy hh24:mi:ss') snap_time , lag(w1.total_waits) over (order by s1.snap_id) prev_val, w1.total_waits - lag(w1.total_waits) over (order by s1.snap_id) delta_val , lag(w1.time_waited_micro) over (order by s1.snap_id) prev_val, w1.time_waited_micro - lag(w1.time_waited_micro) over (order by s1.snap_id) delta_val from stats$snapshot s1 , stats$system_event w1 where s1.snap_id = w1.snap_id and w1.event = 'db file sequential read' order by w1.event , s1.snap_id ; EVENT SNAP_ID SNAP_TIME PREV_VAL DELTA_VAL PREV_VAL DELTA_VAL ---------------------------------------------------------------- ---------- -------------------- ---------- ---------- ---------- ---------- db file sequential read 1 25-Apr-2013 11:00:51 db file sequential read 2 25-Apr-2013 12:00:51 959235 39179 949588625 29088092 db file sequential read 3 25-Apr-2013 13:00:51 998414 29632 978676717 24938574 db file sequential read 4 25-Apr-2013 14:00:52 1028046 21547 1003615291 23101379 4 rows selected.
You use lag (...) over (partition by the order of the events of snap_id), i.e. "partition by the event" will do lag a ' star on "for each different event
-
Oracle Spatial function to find the closest channel line according to lat/long
Hello
Here's my scenario. I have a table that contains the geometries of type line (road network) channels. The line geomteries are of type Ohio state South (SRID 41104) plan.
I have a requirement - given a lat/long, find the string line that aligns with this lat/long or the nearest set of strings of line at 0.02 miles.
It is a typical example of an attempt to identify an accident on our road network situation. Accidents reported us in lat/long through the GPS system.
How can I achieve this through any space function?
Thanks for the help in advance.
Thank you
L.Hello L,
SELECT r.
FROM roadsegments r WHERE SDO_NN(r.geometry, sdo_geometry(2001, 41104, sdo_point_type(lat,lon,NULL), NULL, NULL), 'sdo_num_res=2 distance=0.02 unit=mile') = 'TRUE'; This will give you the two segments of road nearest you at 0.02 miles. See [url http://docs.oracle.com/cd/E11882_01/appdev.112/e11830/sdo_operat.htm#i78067] documentation on the operator SDO_NN, especially the bit about the use of the index indicator.
HTH,
Stefan -
Oracle form functions and procedures in the APEX, how?
I'm working to recreate in the APEX, already existing read only forms in Oracle Forms. Report features interactive APEX among other things, in fact worth as well as to target a different audience than utilizies versions of Oracle Form. Versions of Oracle Forms use a lot of pre and post query triggers, PLSQL functions.
In Oracle Forms that places, these functions can be found in the "Units of program" section of the form. A feature typical of this kind, based on a particular Mission ID route, collecting names of regular passengers, is shaped with a comma and a space after each of them, in a single string that is returned and displayed the list of passengers of a line.
I have all of this written code so I can move most of the main request of the Oracle form in an interactive report. These functions and triggers called in the form of the "Units of program" section of the Oracle form rather than stored in the database schema in a package, where they would go inside the APEX? Can I create a 'shortcut' in the APEX and call it from the interactive report "Source Région"? I can create the PLSQL function at the level of the region of the interactive report or page level? Or, my best bet creates a package that is stored in the database, all these functions and/or proecedures I might need the original form of Oracle?
Some advice would be greatly appreciated.RLBickham wrote:
I don't think I've been pretty clear in the description of the specific thing I want to do, simply, it does not reach the level of forms of conversion of the APEX. It is basically a problem of PLSQL function.I have an interactive report which is currently 90 percent of what I want however, each line, which represents a Mission may have several feet. Each arm has two places or ICAO codes attached to it. Based on the number of Mission, I want to loop through the array of leg, collect all the codes of ICAO for this Mission, put them together in 1 variable separated by a coma and add this variable to display the columns in this interactive report as the last column.
In Oracle Forms, I have a function registered in the database, which is called in the main query. Maybe I ask a question that does not need to be asked, but anyway my question is can I put this function currently in the database somewhere within the interactive report and somehow reference it via Http, or should I just stick with set of functions and procedures in the packages stored in the database and called the conventional way?
You could switch the function to the database and call it from the report query, but it sounds as if it were superfluous. In the report query using any form of Re: 4. How can I convert rows to columns? is appropriate for your version of the (unspecified) database.
-----
When you have a problem, you will get an answer faster, more efficient including information as much information as possible from the outset. This should include:
- Full version of APEX
- Complete operating system DB, version, edition, host
- Architecture of Web server (EPG, SST or APEX listener/host operating system)
- Browser (s) and version (s) used
- Theme
- Model (s)
- Region/section type (s) (particularly as to distinguish if a 'report' is a standard report, an interactive report, or indeed a 'update report' (i.e. a tabular presentation))
With APEX, we also had the chance to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproduce things is the best way to solve most of the questions, particularly those relating to the layout and Visual formatting. If you expect a detailed response it is appropriate that you take on an important part of the effort by getting as much as possible with an example of the problem on apex.oracle.com before asking for help on specific issues, then we can see firsthand.
-
No support for oracle sql functions
Hi all
Please can someone explain why the B-tree indexes are not capable of supporting SQL queries using the built-in functions of Oracle.
We have indexes of tree b on account_no column.
Select * from test_table where account_no = 11005208
the above query use the index on account_no
Select * from test_table where superior (account_no) = 11005208
But this query does not use the index on the account_no, going for the full table scan.
My question here is account_no is the numeric data type.
Then, there is no difference between the data in the columns account_no and upper (account_no) column data, so why he does not use index when using sql functions in an sql query?Hello
If you apply the upper function, Oracle implicitly converts its argument to a string, so your query is actually upper (to_char (account_no)).
There is none HAVE fully functional in the optimizer and you do not expect to know everything and do all the conclusions that a human being can do. Why should Oracle re - write this type of query analysis the data type of the columns and features when it seems more natural programmer write a correct query (without capital letters in this example) or, if necessary, create an index based on a function? -
Oracle to_number function pramaters
I have problems with TO_NUMBER function second and third parameters. One dependent on the other? How does the nls_params parameter? I don't understand how the result of the query
SELECT TO_NUMBER ('17,000, 23',
"999G999D99,"
' nls_numeric_characters = ",". ')
REFORMATTED_NUMBER
FROM DUAL;
can be 17000.23. Could someone please explain the above conversion process. I looked towards the top of the documentation, but it is not explanatory eneogh.
P.S. The query above is taken from a book of preperation certificate Expert Oracle database SQL. -
Hi all
I'm still reviewing the analytical functions and I was wondering if someone can help me with the LISTAGG function. If this has nothing to do with some school or as homework. It's just me discover Oracle.
So, here is some code to insert data of base. It's just a person table and an array of phone number.
The following query returns all the person with their different phone numbers into a single line.-- to avoid name conflicts ;-) DROP TABLE PERSONNES CASCADE CONSTRAINTS purge; DROP TABLE TELEPHONES CASCADE CONSTRAINTS purge; -- create a person table with an id and a name. CREATE TABLE PERSONNES ( ID_PERSONNE NUMBER(10) , NOM VARCHAR2(100) , CONSTRAINT PK_PERSONNES PRIMARY KEY(ID_PERSONNE) ); -- table with phone number for persons. CREATE TABLE TELEPHONES ( ID_TELEPHONE NUMBER(10) , ID_PERSONNE NUMBER(10) , NUMERO VARCHAR2(100) , ACTIF CHAR(1) DEFAULT '0' -- is the number active or not. , CONSTRAINT PK_TELEPHONES PRIMARY KEY(ID_TELEPHONE) , CONSTRAINT UK_NUMERO UNIQUE(ID_TELEPHONE, NUMERO) , CONSTRAINT C_ACTIF_BOOLEAN CHECK(ACTIF IN ('0', '1')) , CONSTRAINT FK_PERSONNE FOREIGN KEY(ID_PERSONNE) REFERENCES PERSONNES ); -- insert some data. BEGIN -- create a person with a random name. FOR i in 1 .. 10 LOOP INSERT INTO PERSONNES(ID_PERSONNE, NOM) VALUES (i, InitCap(DBMS_RANDOM.STRING('l', 5))); -- for each newly inserted person, insert 5 different phone numbers. FOR j in 1 .. 5 LOOP INSERT INTO TELEPHONES(ID_TELEPHONE, ID_PERSONNE, NUMERO, ACTIF) VALUES(((i-1)*10) + j, i, '+32.' || TRUNC(DBMS_RANDOM.VALUE(1, 9)) || '.' || TO_CHAR(DBMS_RANDOM.VALUE(1, 999), 'fm099') || '.' || TO_CHAR(DBMS_RANDOM.VALUE(1, 99), 'fm09') || '.' || TO_CHAR(DBMS_RANDOM.VALUE(1, 99), 'fm09'), CASE MOD(j, 2) WHEN 0 THEN '0' ELSE '1' END ); END LOOP; END LOOP; -- now insert two different person without any phone number. INSERT INTO PERSONNES(ID_PERSONNE, NOM) VALUES (100, InitCap(DBMS_RANDOM.STRING('l', 5))); INSERT INTO PERSONNES(ID_PERSONNE, NOM) VALUES (101, InitCap(DBMS_RANDOM.STRING('l', 5))); END;
But what I would like is to have numbers grouped by the flag of the ASSET.SELECT NOM, LISTAGG(NUMERO, ', ') WITHIN GROUP (ORDER BY NULL) FROM PERSONNES A LEFT JOIN TELEPHONES B ON A.ID_PERSONNE = B.ID_PERSONNE GROUP BY NOM ORDER BY 2 NULLS LAST;
I thought that maybe using the PARTITION CLAUSE but I couldn't understand it. So maybe one of you has a better idea? I want to do in a single query (without using the inline views or with clause). But all the tips are welcome. I just discover Oracle ;-)Name1 Actif=0 +32... , +3200000000 Name1 Actif=1 +32... , +........... Name2 Actif=0 +32... , +3200000000 Name2 Actif=1 +32... , +...........
Thank youHello
user13117585 wrote:
... But what I would like is to have numbers grouped by the flag of the ASSET.This is the solution! You want to have results grouped by asset, so add assets to the GROUP BY clause:
SELECT NOM , ACTIF -- New , LISTAGG(NUMERO, ', ') WITHIN GROUP (ORDER BY NULL) FROM PERSONNES A LEFT JOIN TELEPHONES B ON A.ID_PERSONNE = B.ID_PERSONNE GROUP BY NOM , ACTIF -- New ORDER BY 3 NULLS LAST -- Changed ;
If you want to display ACTIVE, you will need to add it to the SELECT clause.
Don't forget to change the ORDER BY clause, which changes what is in the column #2, as stated above (assuming that it is how you want the output sorted). However, a better way is to give this column alias, which can be used in the ORDER BY clause:SELECT NOM , ACTIF , LISTAGG(NUMERO, ', ') WITHIN GROUP (ORDER BY NULL) AS NUMEROS -- Alias defined FROM PERSONNES A LEFT JOIN TELEPHONES B ON A.ID_PERSONNE = B.ID_PERSONNE GROUP BY NOM , ACTIF ORDER BY NUMEROS NULLS LAST -- Alias used ;
-
Oracle analytic function setting
Hi all
Oracle Database 10 g Enterprise Edition release 10.2.0.3.0 - 64bi
PL/SQL version 10.2.0.3.0 - Production
CORE Production 10.2.0.3.0
AMT for IBM/AIX RISC System/6000: Version 10.2.0.3.0 - production
NLSRTL Version 10.2.0.3.0 - Production
I have a query that has analytic function uses space on temporary tablespace resulting in temp of direct path read and track direct writing temp waiting events taking too much time. Is it possible to set this query?
Thanks in advance.user9074365 wrote:
Hi all
Oracle Database 10 g Enterprise Edition release 10.2.0.3.0 - 64bi
PL/SQL version 10.2.0.3.0 - Production
CORE Production 10.2.0.3.0
AMT for IBM/AIX RISC System/6000: Version 10.2.0.3.0 - production
NLSRTL Version 10.2.0.3.0 - Production
I have a query that has analytic function uses space on temporary tablespace resulting in temp of direct path read and track direct writing temp waiting events taking too much time. Is it possible to set this query?With your version of Oracle and high-volumes of data through the analytical function, it is likely that this blog note applies. You may need a patch upgrade or special. http://jonathanlewis.WordPress.com/2009/09/07/analytic-agony/
Concerning
Jonathan Lewis -
Oracle Apps functional in finance career
Hi all
I would be grateful to you if someone can guide me to pursue a career in finance functional Oracle applications. For your information here is my path passed – I did BSc (Computer Science), MBA & MSc and currently I work as an Accounts Assistant in a company based in Scotland.
I'm going on vacation in Hyderabad, India. I need to know what will be the best way to learn the course above, in an Institute or under a personal instructor. Please suggest
Any suggestions will be appreciated kindly.
Thank you.
ImranI'm going on vacation in Hyderabad, India. I need to know what will be the best way to learn the course above, in an Institute or under a personal instructor. Please suggest
Please visit the following link:
Oracle authorized training in India
http://www.Oracle.com/global/in/education/maps/index.html
Maybe you are looking for
-
I want to transfer the 160 GB photo library on my iMac to my retina of MacBook Pro 13 "computer laptop. Can I assume that the connection via Thunderbolt (both have entries of Thunderbolt) would be the fastest and most effective way to do?
-
iPhone - call you once it rings busy. Good return resonates through her call.
iPhone - call you once it rings busy. Good return resonates through her call. We have an iPhone 5 c and 5 s in the family. I don't know if it's a phone number or a vendor number. When I call my girls, it sounds occupied first (never show on their
-
Installation of Bluetooth on XP2
Hi everybodies,.I moved my satellite 5100 603 to stop XP2 and bluetooth to work. I tried to reinstall with the latest bluetooth stack, but the installation procedure, says "installation has been arrested, no change has been filed. Previous versions h
-
I need to create a windows reinstallation disc
I need to create a disk to reinstall windows.I picked up a virus and mcafee are not able to remove it if you need to reinstall windows... The recovery disk create function coverage this?
-
a few questions about s650.
1. Hi, I bought my s650 yesterday and wanted to save some messages in the drafts, how can I do? and is it still an option to save drafts in s650? 2. how to save my downloads in my sd card? all downloads are going to the internal memory. 3. where are