PL/SQL Control Statement Exercises: Check whether a given character is letter or digit
PL/SQL Control Statement: Exercise-13 with Solution
Write a PL/SQL program to check whether a given character is letter or digit.
Sample Solution:
PL/SQL Code:
DECLARE
get_ctr CHAR(1) := '&input_a_character';
BEGIN
IF ( get_ctr >= 'A'
AND get_ctr <= 'Z' )
OR ( get_ctr >= 'a'
AND get_ctr <= 'z' ) THEN
dbms_output.Put_line ('The given character is a letter');
ELSE
dbms_output.Put_line ('The given character is not a letter');
IF get_ctr BETWEEN '0' AND '9' THEN
dbms_output.Put_line ('The given character is a number');
ELSE
dbms_output.Put_line ('The given character is not a number');
END IF;
END IF;
END;
/
Sample Output:
SQL> / Enter value for input_a_character: m old 2: get_ctr CHAR(1) := '&input_a_character'; new 2: get_ctr CHAR(1) := 'm'; The given character is a letter PL/SQL procedure successfully completed.
Sample Output:
SQL> / Enter value for input_a_character: 5 old 2: get_ctr CHAR(1) := '&input_a_character'; new 2: get_ctr CHAR(1) := '5'; The given character is not a letter The given character is a number PL/SQL procedure successfully completed.
Sample Output:
SQL> / Enter value for input_a_character: @ old 2: get_ctr CHAR(1) := '&input_a_character'; new 2: get_ctr CHAR(1) := '@'; The given character is not a letter The given character is not a number PL/SQL procedure successfully completed.
Flowchart:
Improve this sample solution and post your code through Disqus
Previous: Write a PL/SQL program to check whether a given number is positive, negative or zero.
Next: Write a PL/SQL program to convert a temperature in scale Fahrenheit to Celsius and vice versa.
What is the difficulty level of this exercise?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/plsql-exercises/control-statement/plsql-control-statement-exercise-13.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics