In Oracle, there are various data types available to store different types of data. Here are some common data types in Oracle along with examples:
1. CHAR: Fixed-length character string with a maximum length of 2000 bytes.
DECLARE
v_char CHAR(10);
BEGIN
v_char := 'Hello';
DBMS_OUTPUT.PUT_LINE(v_char);
END;
/
2. VARCHAR2: Variable-length character string with a maximum length of 4000 bytes.
DECLARE
v_varchar VARCHAR2(20);
BEGIN
v_varchar := 'Hello';
DBMS_OUTPUT.PUT_LINE(v_varchar);
END;
/
3. NUMBER: Fixed-point or floating-point number with precision and scale.
DECLARE
v_number NUMBER(8,2);
BEGIN
v_number := 1234.56;
DBMS_OUTPUT.PUT_LINE(v_number);
END;
/
4. DATE: Date and time value with century, year, month, day, hours, minutes, and seconds.
DECLARE
v_date DATE := TO_DATE('2022-01-01', 'YYYY-MM-DD');
BEGIN
DBMS_OUTPUT.PUT_LINE(v_date);
END;
/
5. TIMESTAMP: Date and time value with fractional seconds precision.
DECLARE
v_timestamp TIMESTAMP := TO_TIMESTAMP('2022-01-01 12:34:56.789', 'YYYY-MM-DD HH24:MI:SS.FF');
BEGIN
DBMS_OUTPUT.PUT_LINE(v_timestamp);
END;
/
6. CLOB: Character large object for storing large text data.
DECLARE
v_clob CLOB;
BEGIN
v_clob := 'Large text data...';
DBMS_OUTPUT.PUT_LINE(v_clob);
END;
/
7. BLOB: Binary large object for storing large binary data.
DECLARE
v_blob BLOB;
BEGIN
v_blob := EMPTY_BLOB();
DBMS_OUTPUT.PUT_LINE(v_blob);
END;
/
8. BOOLEAN: Logical value representing TRUE, FALSE, or NULL.
DECLARE
v_boolean BOOLEAN := TRUE;
BEGIN
IF v_boolean THEN
DBMS_OUTPUT.PUT_LINE('TRUE');
ELSE
DBMS_OUTPUT.PUT_LINE('FALSE');
END IF;
END;
/
These are some commonly used data types in Oracle, and they can be used to define columns in tables or variables in PL/SQL blocks.
No comments:
Post a Comment