I
I
ince2019-03-21 17:04:18
Oracle
ince, 2019-03-21 17:04:18

Why can't I create a procedure?

I create a procedure

CREATE OR REPLACE PROCEDURE UNPIVOT_TEMP_CRE AS 
BEGIN
    INSERT INTO test( DATETIME, QUARTER, "YEAR", ID_LOCATION, ID_TYPE, PRICE ) 
    Select
        p.DATETIME	
      , p.QUARTER	
      , p."YEAR"	
      , p.ID_LOCATION
      , t."ID"
      , p.PRICE 
      
    FROM
         ( SELECT DATETIME	
                , QUARTER	
                , "YEAR"	
                , ID_LOCATION
                , "TYPE"
                , PRICE          
          FROM TEMP
          UNPIVOT (
          PRICE FOR "TYPE" IN (OFFICES_BUSINESS_CENTER,
              OFFICES_OTHER,
              RETAIL_SHOPPING_CENTER,
              RETAIL_STREET,
              RETAIL_OTHER,
              WAREHOUSE_COMPLEX,
              WAREHOUSE_OTHER,
              LAND_LIVING,
              LAND_COMMERCIAL,
              LAND_INDUSTRIAL)
              )
          ) p
    JOIN  TYPES_RE t
      ON  LOWER(SUBSTR(p."TYPE", 1, INSTR(p."TYPE", '_')-1)) = LOWER(t.subtype1)
      AND LOWER(SUBSTR(p."TYPE", INSTR(p."TYPE", '_')+1))    = LOWER(t.subtype2);      
    --
    execute immediate 'DROP TABLE TEMP';
    --NULL;
END UNPIVOT_TEMP_CRE;

An error occurs on the line
INSERT INTO AVG_PRICE_HISTORY ( DATETIME, QUARTER, "YEAR", ID_LOCATION, ID_TYPE, PRICE )
and on the LAND_INDUSTRIAL)
Error line:
Error(3,5): PL/SQL: SQL Statement ignored
Error(30,15): PL/SQL: ORA-00904: "LAND_INDUSTRIAL": недопустимый идентификатор

What is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vapaamies, 2019-03-24
@vapaamies

The campaign in unpivot needs to specify string values ​​through as , which will replace the fields (and the fields, in turn, must be present in the expanded table):

unpivot price for "TYPE" in (
  OFFICES_BUSINESS_CENTER as 'OFFICES_BUSINESS',
  OFFICES_OTHER as 'OFFICES_OTHER',
  ...
  LAND_INDUSTRIAL as 'INDUSTRIAL'
)

Oracle parses SQL statements from the end, so errors are also thrown from the end.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question