Oracle 11g My work so far on SQL Fiddle
I'm using lead() and lag() functions on varchar2 columns. Using the following rules, I'd like to generate the desired results.
- If lag_val is null then '('
- If lag_val is same as set_a then 'and'
- If lag_val != set_a then 'or'
- If lead_val is null then ')'
I get 'invalid number' when I use nvl() to convert null values so I can compare.
Desired Output
SEQNO SET_A LAG_VAL LEAD_VAL MENU_ENTRY
------------------------------------------
1 CAKE <null> CAKE (
2 CAKE CAKE BEER AND
3 BEER CAKE BRATS OR
4 BRATS BEER <null> )