Define and use char value : CHAR « Data Type « Oracle PL / SQL






Define and use char value

  

SQL>
SQL> -- Using IF...ELSIF to determine a grade.
SQL> DECLARE
  2     variable_Score Number := 85;
  3     variable_LetterGrade Char(1);
  4  BEGIN
  5     IF variable_Score >= 90 THEN
  6          variable_LetterGrade := 'A';
  7     ELSIF variable_Score >= 80 THEN
  8          variable_LetterGrade := 'B';
  9     ELSIF variable_Score >= 70 THEN
 10          variable_LetterGrade := 'C';
 11     ELSIF variable_Score >= 60 THEN
 12          variable_LetterGrade := 'D';
 13     ELSE
 14          variable_LetterGrade := 'E';
 15     END IF;
 16          DBMS_OUTPUT.PUT_LINE('Your Letter Grade is: ' || variable_LetterGrade);
 17  END;
 18  /
Your Letter Grade is: B

PL/SQL procedure successfully completed.

SQL>
SQL>
           
         
    
  








Related examples in the same category

1.The CHAR data type is used for storing fixed-length character strings.
2.char type with 50 characters
3.Define varchar2 type variable
4.Comparison of CHAR with VARCHAR2
5.set column width by setting char number
6.CHAR() and VARCHAR2()
7.'' represents a zero length character string BUT NOT a null value
8.No equality comparison between two '' strings
9.Compare char value without knowing the case
10.Convert string to clob
11.char type and varchar2 type
12.Memory allocation differences between the CHAR and VARCHAR2 datatypes