[Oracle] The difference between varchar and nvarchar

1、varchar / varchar2 

  • The length of varchar is not fixed. For example, if you define varchar(20), when you insert abc, it only occupies 3 bytes in the database. 
  • Varchar also distinguishes between Chinese and English, which is the same as char. 
  • varchar2 is basically equivalent to varchar, which is a non-industry standard varchar defined by oracle itself. The difference is that varchar2 replaces varchar with null" https://www.baidu.com/s?wd=%E7%A9%BA % E5% AD% 97% E7% AC% A6% E4% B8% B2 & amp; tn = 44039180_cpr & amp; fenlei = mv6quAkxTZn0IZRqIHckPjm4nH00T1d9nAF-uW6YryDdPy7hujn40ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPHcsnHbYPH63nHmdPHTLn1cd & quot; target = & quot; _blank & quot; class = & quot; baidu-highlight & quot; & gt; air string 
  • varchar/varchar2 is suitable for cases where the length is not fixed and generally does not contain Chinese 

2.nvarchar / nvarchar2  

  • nvarchar and nvarchar2 are of variable length 
  • nvarchar does not distinguish between Chinese and English, for example: if you define nvarchar(20), you can store 20 English letters/Chinese characters or a combination of Chinese and English, this 20 defines the number of characters rather than the number of bytes 
  • nvarchar2 is basically equivalent to nvarchar, the difference is that the English letters stored in nvarchar2 also occupy two bytes 
  • nvarchar/nvarchar2 is suitable for storing Chinese 

 

char [ ( n ) ] 

Fixed-length, non-Unicode character data, n bytes long. The value range of n is 1 to 8,000, and the storage size is n bytes. 

 

varchar [ ( n | max ) ] 

Variable-length, non-Unicode character data. The value range for n is 1 to 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the input data plus 2 bytes to reflect the length of the stored data. The length of the entered data can be 0 characters. 

-- Use char if the column data items are of the same size. 

-- Use varchar if column data items vary considerably in size. 

-- Use varchar(max) if column data items vary widely in size and may exceed 8,000 bytes in size 

 

If n is not specified for the char or varchar data type in a data definition or variable declaration statement, the default length is 1.

If n is not specified for the char or varchar data type when using the CAST and CONVERT functions, the default length is 30. 

When executing CREATE TABLE or ALTER TABLE, if SET ANSI_PADDING is OFF, char columns defined as NULL are treated as varchar.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326032205&siteId=291194637