NESTED TABLE & Analytical functions [message #607604] |
Mon, 10 February 2014 04:13 |
|
rishwinger
Messages: 132 Registered: November 2011
|
Senior Member |
|
|
Hi Experts,
create or replace type lst_vc2 is table of varchar2(4000);
/
DECLARE
v1 lst_vc2:=lst_vc2('01','02','03','04','05','06','07');
v2 lst_vc2:=lst_vc2('03');
v3 VARCHAR2(20);
BEGIN
SELECT res
INTO v3
FROM
(SELECT lag(column_value)over(order by column_value) res
FROM TABLE(CAST (v1 AS lst_vc2))
WHERE column_value='04'
);
dbms_output.put_line('count='||v3);
v1.delete;
v2.delete;
END;
/
Expected Output: 03
Actual Output : NULL
I need to fetch a value from v1 nested table which is prior to value in nested table v2.
With above code I'm getting a NULL output , Please advise.
Regards
|
|
|
Re: NESTED TABLE & Analytical functions [message #607616 is a reply to message #607604] |
Mon, 10 February 2014 04:41 |
|
Michel Cadot
Messages: 68645 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
LAG applies to the result set of your query.
If you query only one row then LAG is NULL.
You have to retrieve all rows with the LAG you want and then restrict.
SQL> with data as (select level nb from dual connect by level<=5)
2 select prev_value
3 from (select nb, lag(nb) over (order by nb) prev_value from data)
4 where nb= 4
5 /
PREV_VALUE
----------
3
[Edit: typo]
[Updated on: Mon, 10 February 2014 05:44] Report message to a moderator
|
|
|
|