|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
PL/SQL If Statement Question
Hey guys, im relatively new to Oracle, and im caught in a bind.
I have a view with employee training data. I have a table with training course reviews. The training course reviews only contain records when someone fills out a course review form. I'm pulling all of the employee training data from the view and using it in a reporting system. Somehow, I need to find out whether each record (or employee / course record) has filled out a review and return a 1 or 0 so that I may search the view and sort by the value. I'm assuming this will involve some sort of if statement or while loop. Any help is greatly appreciated, thanks! |
|
#2
|
||||
|
||||
|
Post your table structure and some sample data (preferably as INSERT statements), I'm pretty shure it can be done with a query.
__________________
My blog Tutorials about OSS databases, DBMonster ... Contribute to OSS Development, fill bug reports! Developer Shed eSupport Commented my.ini/my.cnf (ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins Random data (with a bias) |
|
#3
|
||||
|
||||
|
Table PROJECT_USERS
- registration_id - person_id - class_id - last_name - first_name - org - title - vendor - instructor_name Insert into PROJECT_USERS (REGISTRATION_ID, CLASS_ID, PERSON_ID, LAST_NAME, FIRST_NAME, ORG, TITLE, VENDOR, INSTRUCTOR_NAME) Values (8, 65, 99, 'Doe', 'John', 'HR', 'Demostration Class', 'Dynadeen Corporation', 'Ryan Jackson'); COMMIT; That would be an example of the 'view' which is actually be created from 8 different tables. I have this table: Table PROJECT_REVIEWS - review_id - class_id - person_id - anonymous - comments - overall_rating Insert into PROJECT_REVIEWS (REVIEW_ID, CLASS_ID, PERSON_ID, ANONYMOUS, COMMENTS, OVERALL_RATING) Values (1, 64, 3738, '0', 'Good Course', '3'); COMMIT; Now, there are many instances of PROJECT_USERS who have not filled out a review, so there is no record in PROJECT_REVIEWS for their specific class_id and person_id. In this case, in the VIEW above, there would theoretically be a column titled "REVIEW_STATUS", and if someone hasn't filled out a review, it would return 0 for that. if someone has filled out a review, meaning there is a record in PROJECT_REVIEWS with the same person_id and class_id as a record in PROJECT_USERS, it would return 1 for that. Let me know if that made any sense |
|
#4
|
||||
|
||||
|
You need a left outer join to place nulls for missing reviews (review_id as review_status), then use a coalesce/case/decode to change the nulls into 0.
You've been kind enough to post inserts, why not posting create table also? |
|
#5
|
||||
|
||||
|
this should work:
Code:
CREATE TABLE PROJECT_USERS
(
REGISTRATION_ID INTEGER NOT NULL,
CLASS_ID INTEGER,
PERSON_ID INTEGER,
LAST_NAME VARCHAR2(20),
FIRST_NAME VARCHAR2(50),
ORG VARCHAR2(50),
TITLE VARCHAR2(4000),
VENDOR VARCHAR2(4000),
INSTRUCTOR_NAME VARCHAR2(4000)
)
TABLESPACE USERS
PCTUSED 40
PCTFREE 10
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 128K
NEXT 128K
MINEXTENTS 1
MAXEXTENTS 4096
PCTINCREASE 0
FREELISTS 1
FREELIST GROUPS 1
BUFFER_POOL DEFAULT
);
ALTER TABLE PROJECT_USERS ADD (
PRIMARY KEY
(REGISTRATION_ID)
USING INDEX
TABLESPACE USERS
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 128K
NEXT 128K
MINEXTENTS 1
MAXEXTENTS 4096
PCTINCREASE 0
FREELISTS 1
FREELIST GROUPS 1
));
CREATE TABLE MSL_REVIEWS
(
REVIEW_ID INTEGER NOT NULL,
CLASS_ID INTEGER,
PERSON_ID INTEGER,
ANONYMOUS CHAR(1),
COMMENTS VARCHAR2(4000),
OVERALL_RATING CHAR(1),
)
TABLESPACE USERS
PCTUSED 40
PCTFREE 10
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 128K
NEXT 128K
MINEXTENTS 1
MAXEXTENTS 4096
PCTINCREASE 0
FREELISTS 1
FREELIST GROUPS 1
BUFFER_POOL DEFAULT
);
ALTER TABLE MSL_REVIEWS ADD (
PRIMARY KEY
(REVIEW_ID)
USING INDEX
TABLESPACE USERS
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 128K
NEXT 128K
MINEXTENTS 1
MAXEXTENTS 4096
PCTINCREASE 0
FREELISTS 1
FREELIST GROUPS 1
));
thanks for your help, by the way |
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > PL/SQL If Statement Question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|