What are the data types of Oracle?
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.
#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='西施';
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The function in Oracle to calculate the number of days between two dates is DATEDIFF(). The specific usage is as follows: Specify the time interval unit: interval (such as day, month, year) Specify two date values: date1 and date2DATEDIFF(interval, date1, date2) Return the difference in days

The retention period of Oracle database logs depends on the log type and configuration, including: Redo logs: determined by the maximum size configured with the "LOG_ARCHIVE_DEST" parameter. Archived redo logs: Determined by the maximum size configured by the "DB_RECOVERY_FILE_DEST_SIZE" parameter. Online redo logs: not archived, lost when the database is restarted, and the retention period is consistent with the instance running time. Audit log: Configured by the "AUDIT_TRAIL" parameter, retained for 30 days by default.

The Oracle database startup sequence is: 1. Check the preconditions; 2. Start the listener; 3. Start the database instance; 4. Wait for the database to open; 5. Connect to the database; 6. Verify the database status; 7. Enable the service (if necessary ); 8. Test the connection.

The INTERVAL data type in Oracle is used to represent time intervals. The syntax is INTERVAL <precision> <unit>. You can use addition, subtraction, multiplication and division operations to operate INTERVAL, which is suitable for scenarios such as storing time data and calculating date differences.

The amount of memory required by Oracle depends on database size, activity level, and required performance level: for storing data buffers, index buffers, executing SQL statements, and managing the data dictionary cache. The exact amount is affected by database size, activity level, and required performance level. Best practices include setting the appropriate SGA size, sizing SGA components, using AMM, and monitoring memory usage.

To find the number of occurrences of a character in Oracle, perform the following steps: Get the total length of a string; Get the length of the substring in which a character occurs; Count the number of occurrences of a character by subtracting the substring length from the total length.

The method of replacing strings in Oracle is to use the REPLACE function. The syntax of this function is: REPLACE(string, search_string, replace_string). Usage steps: 1. Identify the substring to be replaced; 2. Determine the new string to replace the substring; 3. Use the REPLACE function to replace. Advanced usage includes: multiple replacements, case sensitivity, special character replacement, etc.

Oracle database server hardware configuration requirements: Processor: multi-core, with a main frequency of at least 2.5 GHz. For large databases, 32 cores or more are recommended. Memory: At least 8GB for small databases, 16-64GB for medium sizes, up to 512GB or more for large databases or heavy workloads. Storage: SSD or NVMe disks, RAID arrays for redundancy and performance. Network: High-speed network (10GbE or higher), dedicated network card, low-latency network. Others: Stable power supply, redundant components, compatible operating system and software, heat dissipation and cooling system.