The Oracle PL/SQL CHAR data type is used to store character data.
Syntax
The syntax for declaring a CHAR variable is:
CHAR(size)
where size is the number of characters that can be stored in the variable. For example, a CHAR(10) variable can store up to 10 characters.
Examples
To convert a number, date or varchar to char, you can use the TO_CHAR function. For example:
select TO_CHAR(123) from dual;-- returns '123' select TO_CHAR(SYSDATE) from dual; -- returns 'DD-MON-YYYY HH24:MI:SS' select TO_CHAR('abc') from dual;-- returns 'abc'
You can also use the CONCAT function to concatenate two or more CHAR variables. For example:
select CONCAT(' abc', 'def ') from dual;-- returns 'abcdef'
You can also use the SUBSTR function to extract a substring from a CHAR variable. For example:
declare v_string char(100); begin select SUBSTR('abcdef', 3, 2) into v_string from dual; DBMS_OUTPUT.PUT_LINE('v_string = '||v_string); end;
You can also use the INSTR function to find the position of a substring within a CHAR variable. For example:
declare v_string char(100); begin select INSTR('abcdef', 'cde') into v_string from dual; DBMS_OUTPUT.PUT_LINE('v_string = '||v_string); end;
Oracle PL/SQL also provides a set of built-in functions for working with CHAR data. For more information, see the Oracle documentation.