Wednesday 15 July 2015

plsql - Rows into Columns Oracle pl sql -



plsql - Rows into Columns Oracle pl sql -

this question has reply here:

“pivoting” table in sql (i.e. cross tabulation / crosstabulation) 9 answers dynamically pivoting table oracle 1 reply

i using oracle 10g pl sql, want transpose rows columns columns should dynamic , not hard-coded.

select * "enumerationvalue" pivot (count("pkenumerationvalueid") "text" in (select "text" "enumerationvalue" "fkenumerationid"=6));

i found query searching giving me error.

ora-00933: sql command not ended 00933. 00000 - "sql command not ended"

then tried this

variable g_ref refcursor declare v_sql varchar2(32767); begin v_sql := 'select "text"'; rec in (select "text" "enumerationvalue" inner bring together "enumeration" on "enumeration"."pkenumerationid"="enumerationvalue"."fkenumerationid" "enumtable"='vehicle model') loop v_sql := v_sql || ',sum(case when "text" not null 1 else 0)' || rec."text"; end loop; v_sql := v_sql || ',"pkenumerationvalueid" "enumerationvalue" grouping "text","pkenumerationvalueid"'; open :g_ref v_sql; end;

it giving me error

ora-00905: missing keyword ora-06512: @ line 14 00905. 00000 - "missing keyword"

my table column "text" containing values "suzuki","ferrari","honda","ford" , can more (user can insert new values). want result this.

model suzuki ferrari honda ford ........ 2000 1 0 0 0 2001 5 2 5 0 2002 9 12 3 2

you should remove previous database , build new database in order solve problem

oracle plsql

No comments:

Post a Comment