Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

multiple rows into one, with a separate column for each, dynamically

845198Mar 6 2011 — edited Mar 6 2011
CREATE TABLE "STAGE"
  (
    "STAGE_ID"    NUMBER NOT NULL ENABLE,
    "NAME"        VARCHAR2(200 BYTE));

CREATE TABLE "STAFF_STAGE"
  (
    "STAFF_STAGE_ID" NUMBER NOT NULL ENABLE,
    "PARENT_ID"  NUMBER,
    "CHILD_ID"    NUMBER,
    "STAGE_ID"       NUMBER,
    "COMPLETE"       VARCHAR2(1 BYTE));



REM INSERTING into STAFF_STAGE
Insert into STAFF_STAGE (STAFF_STAGE_ID,PARENT_ID,CHILD_ID,STAGE_ID,COMPLETE) values (1,1,2,1,'N');
Insert into STAFF_STAGE (STAFF_STAGE_ID,PARENT_ID,CHILD_ID,STAGE_ID,COMPLETE) values (2,1,2,2,'N');
Insert into STAFF_STAGE (STAFF_STAGE_ID,PARENT_ID,CHILD_ID,STAGE_ID,COMPLETE) values (3,1,3,1,'N');
Insert into STAFF_STAGE (STAFF_STAGE_ID,PARENT_ID,CHILD_ID,STAGE_ID,COMPLETE) values (4,1,3,2,'N');

REM INSERTING into STAGE
Insert into STAGE (STAGE_ID,NAME) values (1,'Stage 1');
Insert into STAGE (STAGE_ID,NAME) values (2,'Stage 2');
Given this, Im wondering if it is possible (without being too hacky) to have a single row for each child_id in the staff stage table, with a column for each stage, where column header would be stage name.

i.e.

child_id | stage1 | stage2
2 | 'N' | 'N'

I did see this post by justin when i searched - 9355316 - but not really certain how to adapt that, or if I can in my situation.

..

Eventually, I want to have an apex page so when a parent logs it they can check off which stages an employee has completed - so maybe also need each primary key before each stage value, so I can update easily. Perhaps my modelling is wrong, so feedback welcomed.

Thx.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 3 2011
Added on Mar 6 2011
3 comments
1,576 views