char type and varchar2 type : CHAR « Data Type « Oracle PL / SQL






char type and varchar2 type

    


SQL> create table myTable(
  2      codeValue   char(2) not null,
  3      address     varchar2(30)
  4  );

Table created.

SQL>
SQL> desc myTable;
 Name                      Null?    Type
 ------------------------- -------- ------------------
 CODEVALUE                 NOT NULL CHAR(2)
 ADDRESS                            VARCHAR2(30)

SQL>
SQL> insert into myTable values ('AZ','Arizona');

1 row created.

SQL> insert into myTable (codeValue, address) values ('NJ','New Jersey');

1 row created.

SQL> insert into myTable (codeValue, address) values ('CA','California');

1 row created.

SQL> insert into myTable (codeValue, address) values ('TX','Texas');

1 row created.

SQL> insert into myTable (codeValue, address) values ('FL','Florida');

1 row created.

SQL> insert into myTable (codeValue, address) values ('MN','Maine');

1 row created.

SQL>
SQL> select * from myTable;



CO  ADDRESS
--  ------------------------------
AZ  Arizona
NJ  New Jersey
CA  California
TX  Texas
FL  Florida
MN  Maine

6 rows selected.

SQL>
SQL> select address from myTable;



ADDRESS
------------------------------
Arizona
New Jersey
California
Texas
Florida
Maine

6 rows selected.

SQL>
SQL>
SQL> drop table myTable;

Table dropped.

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.Define and use char value
6.set column width by setting char number
7.CHAR() and VARCHAR2()
8.'' represents a zero length character string BUT NOT a null value
9.No equality comparison between two '' strings
10.Compare char value without knowing the case
11.Convert string to clob
12.Memory allocation differences between the CHAR and VARCHAR2 datatypes