Home Common Problem What are the data types of Oracle?

What are the data types of Oracle?

Jun 05, 2023 am 11:40 AM
oracle oracle database

Oracle’s data types include: 1. String type, char and varchar2, which can express any string; 2. Numeric type, number(m,n), can express any number; 3. Date type, date, stores date and time; 4. clob type, stores single-byte string or multi-byte string data; 5. blob type, stores unstructured binary data; 6. rowid type, stores records in tables in the database The physical address in; 7. Other data types.

What are the data types of Oracle?

#The operating environment of this article: Windows 10 system, Oracle version 19c, dell g3 computer.

Oracle’s data types include the following:

1. String types: char and varchar2, which can express any string.

2. Number type: number(m,n), which can express any number. m is the total length of the number, n is the number of digits after the decimal point. If n is 0, it means it is an integer.

3. Date type: date, which stores date and time, including year (yyyy), month (mm), day (dd), hour (hh24), minute (mi), and second (ss).

4. Clob type, which stores single-byte string or multi-byte string data, such as text files and xml files.

5. Blob type, which stores unstructured binary data, such as pictures, audio, video, office documents, etc.

6. Rowid type, which stores the physical address recorded in the database in the table.

7. Other data types.

1. String type

is used in C/C language. Strings are enclosed in double quotes. In Oracle database, strings are enclosed in single quotes. It's as follows:

'www.freecplus.net'

'The coder has a way'

'A silly bird'

1 , Fixed-length string

Fixed-length strings are represented by char. When the length of the stored data content is not enough, Oracle will automatically fill in spaces after the data content to reach its fixed length, such as char(10 ) always contains 10 bytes of information.

The char field can store up to 2000 bytes of content.

2. Variable-length strings

Variable-length strings are represented by varchar2. Unlike the char type, Oracle will not fill in anything after the data content.

The varchar2 field can store up to 4000 bytes of content. Starting from Oracle 12c version, it can store 32767 bytes of content.

3. Comparison of char and varchar2

char(10), if stored in 'freecplus', 'freecplus' will be stored in the database, with a space added at the end.

varchar2(10), if you store 'freecplus', 'freecplus' will be stored in the database and nothing will be added.

In practical applications, we do not want Oracle to add spaces after the string, so can the char type be abandoned? No, we generally use the char type to store fixed-size data content, such as ID number, which is always 18 bits, so char(18) is very suitable. Can I use varchar2(18) to store ID number? Of course you can, but the efficiency of char(18) is much higher than that of varchar2(18).

To summarize, if you are sure, sure, certain, and guaranteed that the length of the stored string is fixed, such as gender, ID number, mobile phone number, use char type, otherwise use varchar2 type, such as name , education, address, hobbies, etc. Although char is rigid, it is efficient.

4. Storage of Chinese characters

How many bytes each Chinese character occupies depends on the specific encoding method, such as UTF-8 (1-3 bytes), GB2312 (2 bytes), GBK (2 bytes), GB18030 (1, 2, 4 bytes).

2. Number type

Oracle uses the number type to store numbers. This type can store up to 38 digits of precision, which is much higher than the conventional long in programming languages. int and double types.

number(m,n), m represents the total length, n represents the precision of decimal places. If the precision of decimal places of the stored data exceeds n, the rounded value will be taken.

For example: number(10,3), 10 is the total length, 3 is the number of digits after the decimal, such as 123.456.

If you deposit 123.4567, the actual amount will be 123.457.

If 12345679.899 is stored and the total length exceeds 10, Oracle will prompt an error.

If you plan to store integers, just use number(m). m represents the maximum number of digits that can be stored in the data.

3. Date type

Oracle uses the date type to represent date and time. This is a 7-byte fixed-width data type with 7 attributes, including : Century, year in century, month, day of month, hours, minutes and seconds.

In programming languages, dates and times are displayed and written using strings. Oracle provides two functions, to_date and to_char, to convert between date types and string types.

For example:

insert into T_GIRL(name,birthday) values('西施',to_date('2000-01-01 01:12:35','yyyy-mm-dd hh24:mi:ss'));
select name,to_char(birthday,'yyyy-mm-dd hh24:mi:ss') from T_GIRL where name='西施';
Copy after login

4. Clob and blob types

clob type, variable-length string large object, up to 4GB, A clob can store single-byte string or multi-byte string data, and a clob is considered a larger string. When the database's character set is converted, the clob type is affected.

Blob type, variable-length binary large object, up to 4GB in length. Blob is mainly used to save formatted unstructured data, such as pictures, audio, video, Office documents, etc. When the database character set is converted, the blob type is not affected, and Oracle Database does not care what content is stored.

5. Rowid type

Each row of records in each table in the Oracle database has a storage physical location, that is, the rowid pseudo column of the table, using rowid as The where condition has the highest access efficiency.

Although rowid has the highest access efficiency, you must be cautious in practical applications and pay attention to two issues:

1) rowid stores the physical location of table records. During organization, data backup and migration, the physical location of the records will change;

2) rowid is a data type exclusive to Oracle database and is incompatible with other databases.

6. Other data types

In the above content, the most commonly used data types in Oracle are introduced, which can meet more than 99% of application scenarios.

Oracle provides 22 different SQL data types. Other data types may not be practical, but I still list them all so that you can understand them without going into depth. In twenty years, I have never used any other data type.

char: fixed-length string, padded with spaces to reach the maximum length. A non-null char(10) contains 10 bytes of information. A char field can store up to 2000 bytes of information.

nchar: A fixed-length string containing unicode format data. nchar fields can store up to 2000 bytes of information.

varchar2: It is a synonym for varchar. This is a variable-length string that, unlike the char type, does not pad fields or variables to the maximum length with spaces. varchar(10) may contain 0~10 bytes of information and can store up to 4000 bytes of information. Starting from 12c, 32767 bytes of information can be stored.

nvarchar2: A variable-length string containing unicode format data. Can store up to 4000 bytes of information. Starting from 12c, 32767 bytes of information can be stored.

raw: A variable-length binary data type. Data stored in this data type will not undergo character set conversion.

number: Can store numbers with a precision of up to 38 digits. This type of data will be stored in a variable-length format, with a length ranging from 0 to 22 bytes.

binary_float: 32-bit single-precision floating point number, which can support at least 6 digits of precision and occupies 5 bytes of storage space on the disk.

binary_double: 64-bit double-precision floating point number, which can support at least 15 digits of precision and occupies 9 bytes of storage space on the disk.

long: This type can store up to 2GB of character data

long raw: The long raw type can store up to 2GB of binary information

date: This is a 7 A fixed-width date/time data type in bytes, which contains 7 attributes: century, year in century, month, day of month, hour, minute, and second.

timestamp: This is a 7-byte or 11-byte fixed-width date/time data type that contains fractional seconds.

timestamp with time zone: This is a 13-byte timestamp that provides time zone support.

timestamp with local time zone: This is a 7-byte or 11-byte fixed-width date/time data type. Time zone conversion occurs when data is inserted and read.

interval year to month: This is a 5-byte fixed-width data type used to store a period.

interval day to second: This is an 11-byte fixed-width data type used to store a period. Store periods as days/hours/minutes/seconds, optionally with 9 fractional seconds.

blob: This type is capable of storing up to 4GB of data.

clob: This type is capable of storing up to 4GB of data. This type is affected when character sets are converted.

nclob: This type is capable of storing up to 4GB of data. This type is affected when character sets are converted.

bfile: This data type can store an oracle directory object and a file name in the database column, and we can read the file through it.

rowid: It is actually the address of the row in the database table. It is 10 bytes long.

urowid: It is a general rowid, there is no fixed rowid table.

The above is the detailed content of What are the data types of Oracle?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

What to do if the oracle log is full What to do if the oracle log is full Apr 12, 2025 am 06:09 AM

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.