×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

ORACLE DECODE FUNCTION...NEED HELP

ORACLE DECODE FUNCTION...NEED HELP

ORACLE DECODE FUNCTION...NEED HELP

(OP)
CREATE VIEW DECODE
AS SELECT STUDENT#,
DECODE ( GRADE,
'A', '4.0'
'A-', 3.67
'B+', 3.33
'B', 3.0
'B-', 2.67
'C+', 2.33
'C', 2.0
'C-', 1.67
'D', 1.33
'E', 1.0
'F', 0 )
FROM STUDENT_SCHEDULE;


This isn't working......it says it is missing a right parenthesis before the 'A'......I put one but it says it needs another one right after the 'A'...

RE: ORACLE DECODE FUNCTION...NEED HELP

Try:
CREATE VIEW GRADE_DECODE AS
SELECT STUDENT,
       DECODE ( GRADE,
       'A', 4.0,
       'A-', 3.67,
       'B+', 3.33,
       'B', 3.0,
       'B-', 2.67,
       'C+', 2.33,
       'C', 2.0,
       'C-', 1.67,
       'D', 1.33,
       'E', 1.0,
       'F', 0 )
FROM STUDENT_SCHEDULE;

You need commas after each parameter to decode, and all your decoded results should be of the same type (i.e. all numeric, or all varchar2).
Calling the view DECODE might cause problems too.

RE: ORACLE DECODE FUNCTION...NEED HELP

Calling the DECODE could not be any problem. But its a good practice not to use the reseverved word for objects.
Your query also create a problem as you haven't define a alias for the expression.
It shoould be
CREATE VIEW GRADE_DECODE AS
SELECT STUDENT,
       DECODE ( GRADE,
       'A', 4.0,
       'A-', 3.67,
       'B+', 3.33,
       'B', 3.0,
       'B-', 2.67,
       'C+', 2.33,
       'C', 2.0,
       'C-', 1.67,
       'D', 1.33,
       'E', 1.0,
       'F', 0 ) myExpr
FROM STUDENT_SCHEDULE;

RE: ORACLE DECODE FUNCTION...NEED HELP

I'm not sure if it's required, but I always add a final default value in case none of the DECODE values match:
       DECODE ( GRADE,
       'A', 4.0,
       'A-', 3.67,
       'B+', 3.33,
       'B', 3.0,
       'B-', 2.67,
       'C+', 2.33,
       'C', 2.0,
       'C-', 1.67,
       'D', 1.33,
       'E', 1.0,
       'F', 0,
         0 ) myExpr

RE: ORACLE DECODE FUNCTION...NEED HELP

The default value is optional - the DECODE() returns NULL if no values
matched.

RE: ORACLE DECODE FUNCTION...NEED HELP

There are several problems with your code:-

You need commas between all arguments, so you need them at each line end in the main body of you statement.

The third argument [  '4.0'  ] needs to be just 4   [ decode(grade,'A',4,'A-',3.67..... ) ]
so that the second of each pair is of the same datatype [here you are converting
a series of char values to numbers].  You could add a final default value to pick up stray grades, but this must also be of the NUMBER datatype to match the other returned values.

The column needs an alias for the [ create view ] to work.
Using DECODE as the view name is OK, but I would avoid key words as object names.

I hope this helps.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close