Pivot in 11g Producing a Keyword Error
980877Dec 19 2012 — edited Dec 27 2012Hello everyone. :) I am a rookie at SQL and just so happen to be the one trail blazing the pivot function for the section of the company I work in. (Needless to say, a Sesame Street style answer will not be offensive.) We are literally in the process of upgrading to 11g (11.2.0.1.0). Sadly, none of our more experienced programmers now anything about the pivot function. Not really surprising to me since we've been working in 10g. Anyway, I am using SQL Developer version 3.0.04 which I know is not the newest but I don't yet have permission to upgrade. I used http://www.oracle-developer.net/display.php?id=506# to get me as far as I am on this function. Would someone PLEASE help me see what I'm missing?
The script I am having problems with is:
SELECT *
FROM
(SELECT
begin_month,
begin_yr,
uut_part_num,
uut_part_description
FROM
cris.serial_num_rpt_view
PIVOT (SUM(wonum) AS WO_Count
FOR begin_yr AS Year, begin_month IN
(01 AS January,
02 AS February,
03 AS March,
04 AS April,
05 AS May,
06 AS June,
07 AS July,
08 AS August,
09 AS September,
10 AS October,
11 AS November,
12 AS December))
WHERE
date_reported >= to_timestamp (:v_bDate,'MM/DD/YYYY')
AND date_reported <= to_timestamp (:v_eDate,'MM/DD/YYYY')
AND worktype = 'COR')
WHERE site LIKE UPPER (CASE WHEN :v_SITE IS NULL THEN '%' ELSE :v_SITE END)
AND TFA like UPPER (CASE WHEN :v_TFA IS NULL THEN '%' ELSE :v_TFA END)
AND SUBTFA like UPPER (CASE WHEN :v_SUBTFA IS NULL THEN '%' ELSE :v_SUBTFA END)
AND UUT_Part_Number like UPPER (CASE WHEN :v_Part_Number IS NULL THEN '%' ELSE :v_Part_Number END)
AND UUT_Serial_No like UPPER (CASE WHEN :v_Serial_No IS NULL THEN '%' ELSE :v_Serial_No END)
-- The following line is for counting WO's, since the WOs repeat the Case When counts only the last instance of a series of WO number repeats
(CASE WHEN Lead (WOs.WONUM,1,0) over (order by WOs.wonum) = WOs.WONUM THEN 0 ELSE 1 END);
The error I'm getting is:
ORA-01738: missing IN keyword
01738. 00000 - "missing IN keyword"
*Cause:
*Action:
Error at Line: 16 Column: 2
The error indication bounces between line 15 and 16. If I put IN at the end of 15 I then have a missing right parenthesis error...
Thank you in advance.