Chr 10 что это

от admin

Oracle CHR

The Oracle CHR() function converts an ASCII code, which is a numeric value between 0 and 225, to a character. The Oracle CHR() function is the opposite of the ASCII() function.

Syntax

Arguments

The CHR() function accepts one argument:

  • numeric_expression is a numeric value or an expression that returns a numeric value from 0 through 255.

Return values

  • If the numeric_expression is from 0 through 255, the CHR() function returns a character that represents the number in the ASCII table.
  • In case the numeric_expression is less than 0 or greater than 255, the CHR() function will issue an error of «ORA-01426: numeric overflow» .
  • The CHR() function returns NULL if the numeric_expresion is NULL .

Examples

The following statement returns characters of the ASCII code 65 and 97 :

The following statement illustrates passing NULL to the CHR() function:

Oracle CHR function - NULL Example

In this example, the CHR() function returns NULL as expected.

Remarks

You can use the CHR() function to insert control characters into a string. The following table illustrates the commonly used control characters:

Control character Value
Carriage return CHR(13)
Line feed CHR(10)
Tab CHR(9)

Let’s see the following employees table in the sample database:

The following statement uses the CHR() function to output the first five employees of the company:

In this tutorial, you have learned how to use the Oracle CHR() function to get the corresponding character of an ASCII code.

Name already in use

VBA-Docs / Language / Reference / User-Interface-Help / chr-function.md

  • Go to file T
  • Go to line L
  • Copy path
  • Copy permalink
  • Open with Desktop
  • View raw
  • Copy raw contents Copy raw contents

Copy raw contents

Copy raw contents

Returns a String containing the character associated with the specified character code.

Chr(charcode)
ChrB(charcode)
ChrW(charcode)

The required charcode argument is a Long that identifies a character.

Numbers from 0–31 are the same as standard, nonprintable ASCII codes. For example, Chr(10) returns a linefeed character. The normal range for charcode is 0–255. However, on DBCS systems, the actual range for charcode is -32768–65535.

[!NOTE] The ChrB function is used with byte data contained in a String. Instead of returning a character, which may be one or two bytes, ChrB always returns a single byte.

The ChrW function returns a String containing the Unicode character except on platforms where Unicode is not supported, in which case, the behavior is identical to the Chr function.

[!NOTE] Visual Basic for the Macintosh does not support Unicode strings. Therefore, ChrW(n) cannot return all Unicode characters for n values in the range of 128–65,535, as it does in the Windows environment. Instead, ChrW(n) attempts a «best guess» for Unicode values n greater than 127. Therefore, you should not use ChrW in the Macintosh environment.

The functions Asc(), AscB(), and AscW() are the opposite of Chr(), ChrB(), and ChrW(). The Asc() functions convert a string to an integer.

This example uses the Chr function to return the character associated with the specified character code.

SQL CHR, CHAR, ASCII, NCHR, NCHAR, and ASCIISTR Function Guide, FAQ, and Example

The SQL CHR, CHAR, ASCII, NCHR, NCHAR, and ASCIISTR functions are useful when translating between text characters and their ASCII codes. Learn all about these functions in this article.

Table of Contents

Purpose of the SQL CHR, CHAR, ASCII, NCHR, NCHAR, and ASCIISTR Functions

These functions are similar, which is why I have combined them into a single guide.

These functions will

  • ASCII function will allow you to convert a single character into a number that represents the character. It’s how you get an ASCII value of a CHAR in SQL.
  • CHR/CHAR function will allow you to enter a number code and return an ASCII character. It’s the opposite of the ASCII function.
  • NCHR/NCHAR function returns a character based on the specified number code in the national character set. It’s very similar to the CHR function, but it uses the national character set.
  • ASCIISTR function converts a string in any character set to a string in the database character set. If there are any characters that are not ASCII, they are converted to a format of \xxxx, where xxxx is the UTF-16 code.

These functions are only available in some databases:

Database CHR CHAR ASCII NCHR NCHAR ASCIISTR
Oracle Y N Y Y N Y
SQL Server N Y Y N Y N
MySQL N Y Y N N N
Postgres Y N Y N N N

SQL CHR and CHAR Function Syntax and Parameters

The syntax of the CHR function is:

The syntax of the CHAR function is:

The parameters of the CHR and CHAR function are:

  • number_code (mandatory): This is the number code to look up the ASCII character.
  • USING NCHAR_CS (optional): Adding this parameter means that you will use the national character set. This applies to Oracle only.

The return value is a single character that represents the supplied number.

SQL ASCII Function Syntax and Parameters

The syntax of the ASCII function is:

The return type of this function is a NUMBER.

The parameters of the ASCII function are:

  • charvalue (mandatory): This is a value that is to be converted into its ASCII code. It can be of type CHAR, NCHAR, VARCHAR2, or NVARCHAR2.

Some things to note about this function:

  • If more than one character is entered as the charvalue parameter, the function will return the value for the first character, and ignore all of the other characters.
  • If your database is in the EBCDIC character set, then this function returns the EBCDIC value (there is no EBCDIC character function).

For a list of the ASCII codes in SQL, you can refer to this page.

SQL NCHR and NCHAR Function Syntax and Parameters

The syntax of the NCHR function is:

The syntax of the NCHAR function is:

The parameters of the NCHR and NCHAR functions are:

  • number_code (mandatory): The numeric value that identifies a single character.

The number_code is a NUMBER value or anything that can be implicitly converted to a number.

The return value of the NCHR function is always an NVARCHAR2 data type, and for NCHAR it is NVARCHAR.

The NCHR function is the same as using the CHR function with the parameter USING NCHAR_CS.

SQL ASCIISTR Syntax and Parameters

The syntax of the ASCIISTR function is:

The parameters are:

  • charvalue (mandatory): This is the string value that is to be converted to an ASCII string.

The return type is an ASCII string. So this is how you convert a string to ASCII values in SQL.

What Does the SQL CHR(10) Function Mean?

This is often used to insert a line feed into a string.

The number 10 represents the line feed character, so using CHR(10) will return a line feed character to split a line of text.

  • CHR(9) is a horizontal tab.
  • CHR(10) is a line feed.
  • CHR(13) is a carriage return.

Is There A TO_ASCII In Oracle?

No, there is no function called TO_ASCII, but the ASCII function may be what you’re looking for.

Examples of the SQL CHR, ASCII, and NCHR Functions

Here are some examples of these functions.

Example 1

This example shows a single lower-case character.

The result is “a” because that is the character for the supplied value.

Example 2

This example shows a single upper-case character.

The result is “P” because that is the character for the supplied value.

Example 3

This example uses the concatenation of several characters

The result is “Yes” because that’s what the three characters translate to.

Example 4

This example uses CHR(10).

You can find a list of the ASCII codes here. The result is the letter S, then a line break, and then the letter T.

Example 5

This example uses a single character in the ASCII function.

Example 6

This example uses a special character.

Example 7

This example uses multiple characters as a parameter.

The function only shows the ASCII value for the first character, which is “C”.

Example 8

This example uses the ASCII function in the WHERE clause. I’ve used the SUBSTR function to consider only the first character of the last_name field.

FIRST_NAME LAST_NAME
Tom Capper
Andrew Cooper

You can see that there are two records, both with a last_name beginning with C. This is because the ASCII value of C is 67.

Example 9

This is a simple example of the NCHR function.

Example 10

This example uses different CHR functions and the NCHR function.

CHR_FN CHR_USING NCHR_FN
(null) ¡ ¡

As you can see, using CHR has shown a NULL value. However, using NCHR has shown a value.

Example 11

This is an example of ASCIISTR with a standard value.

Example 12

This is an example of ASCIISTR with some unicode characters.

Example 13

This is another example of ASCIISTR with unicode characters.

So, that’s how you can use the CHR, CHAR, ASCII, NCHR, NCHAR, and ASCIISTR functions in SQL.

You can find a full list of Oracle SQL functions here.

Lastly, if you enjoy the information and career advice I’ve been providing, sign up to my newsletter below to stay up-to-date on my articles. You’ll also receive a fantastic bonus. Thanks!

Leave a Comment Cancel Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Ben Brumm
Ben Brumm
DatabaseStar

What is the difference between ASCII Chr(10) and Chr(13)

typewriters have a carriage return

Writing this because I can never remember which ascii code is \n and which is \r . Usually I end up googling my ASCII Cheatsheet for the answer. So here it is fully explained in case you are curious:

What is Chr(10)

The ASCII character code 10 is sometimes written as \n and it is sometimes called a New Line or NL . ASCII character 10 is also called a Line Feed or LF .

On a UNIX based operating system such as Linux or Mac it is all you typically use to delineate a line in a file.

What is Chr(13)

The ASCII character code 13 is called a Carriage Return or CR . On windows based computers files are typically delimited with a Carriage Return Line Feed or CRLF . So that is a Chr(13) followed by a Chr(10) that compose a proper CRLF .

Things such as HTTP headers or MIME mail headers are also delimited with a CRLF .

If you have ever opened a file with notepad on windows and found that it appears that everything is on one line, but then open it in another editor to find that the lines appear, the reason for that is that the file is delimited with only LF Chr(10) and not CRLF . Notepad is not smart enough to know the difference and plops everything on one line. Most text editors on windows besides notepad have no problem with working on files that are only delimited with \n or Chr(10) .

This all dates back to the typewriter

The term Carriage Return actually dates back to when typewriters were commonly used. When you hit enter on a typewriter it will advance the paper to the next line (line feed!), however unless you return the carriage (that lever that you move to the left) you would keep typing, here’s an example:

So what should I use as a file line delimiter?

I tend to use only Chr(10) because it takes less space. Unless you have a use case where people will be opening the files you create with notepad, this should work fine.

Also if your file needs to be interfaced with a typewriter, I would make sure you are using a Carriage Return 😉

Is it Char(10) or Chr(10)?

The name of the function to return an ascii character from an integer character code is not consistent across programming languages. So it depends what language you are using, here is a handy table with some popular languages:

Like this? Follow me ↯

What is the difference between ASCII Chr(10) and Chr(13) was first published on May 17, 2019.

Comments

When writing English on paper with a pen by hand, the paper is stationary and ones hand moves to the right across the paper. When the righthand edge of the paper is reached ones hand moves down to the left edge to write the next line.

On a manual mechanical typewriter, the paper is mounted on a roller called a carriage. Between the paper and the key hammers is an ink ribbon. When typing, the key action moves the carriage to the left after the character is impressed on the paper through the ink ribbon. To return to the writing by hand analogy, it would be like keeping the pen hand still and moving the paper underneath to the left instead.

On a manual mechanical typewriter the carriage has a carriage return lever. The first part of its travel advances the paper on the carriage roller. That is the line feed. Continued pressure on the carriage return lever causes the carriage to slide to the right until the left edge of the paper is under the character key hammers. That is a carriage return.

As printing technology developed, the print head moved left to right and paper stayed in same place just moving up a line. However the terminology remained true to a mechanical typewriter.

Читать:
Как узнать количество ключей в словаре python

Похожие статьи