Showing entries 11 to 20 of 1214
« 10 Newer Entries | 10 Older Entries »
Displaying posts with tag: sql (reset)
SQL Char Function Example | Char Function In SQL Tutorial

SQL Char Function Example | Char Function In SQL Tutorial is today’s topic. SQL CHAR function is used for converting a numeric value to a character. It is just the opposite of the ASCII function. A character or string function is a function which takes one or more characters or numbers as parameters and returns the character value.

SQL Char Function

The CHAR() function returns a character based on the ASCII code.

See the following syntax.

Select CHAR (number_code)

Number_code

The number from which character is to be retrieved. An integer outside the range 0 to 255 will return a NULL character.

See the following code.

SELECT CHAR (97);

See the output.

a

Explanation

As ASCII value of a is 97 so character a is printed when number 97 was given as an input to …

[Read more]
What’s Faster? COUNT(*) or COUNT(1)?

One of the biggest and undead myths in SQL is that COUNT(*) is faster than COUNT(1). Or was it that COUNT(1) is faster than COUNT(*)? Impossible to remember, because there’s really no reason at all why one should be faster than the other. But is the myth justified?

Let’s measure!

How does COUNT(…) work?

But first, let’s look into some theory. The two ways to count things are not exactly the same thing. Why?

  • COUNT(*) counts all the tuples in a group
  • COUNT(<expr>) counts all the tuples in a group for which <expr> evaluates to something that IS NOT NULL

This distinction can be quite useful. Most of the time, we’ll simply COUNT(*) for convenience, but there are (at least) two cases where we don’t want that, for example:

When outer joining

[Read more]
SQL ASCII FUNCTION Example | ASCII Function In SQL

SQL ASCII FUNCTION Example | ASCII Function In SQL is today’s topic. ASCII stands for American Standard Code for Information Interchange. SQL ASCII function is used to return the numeric value of a character which is given as an input to the function. This function just acts opposite to that of CHAR function.

SQL ASCII FUNCTION Example

The ASCII function accepts a character expression and returns the ASCII code value of the leftmost character of the character expression. See the following syntax.

Syntax

SELECT ASCII (single_character or string);

PARAMETERS

  1. Single_character: It is a specified character whose numeric value will be returned.
  2. String: If a sequence of characters is inserted in function as input then only the first character, the numeric value will be returned ignoring all the …
[Read more]
SQL STUFF Function Example | Stuff Function In SQL Tutorial

SQL STUFF Function Example | Stuff Function In SQL Tutorial is today’s topic. SQL STUFF Function is used to replace the sequence of characters from the source string of given length from the new string given at the time of input to the function. It is replaced from the index which is also specified at the time of input. The STUFF() function deletes the part of the string and then inserts another part into the string, starting at the specified position.

SQL STUFF Function Example

See the syntax of stuff() function.

SELECT STUFF (source_string, start, length, add_string);

PARAMETERS

  1. source_string: It is the string that is to be processed.
  2. Start: It is an integer that is used for identifying the position to start deletion and insertion. If start is negative, zero, or longer than the length of the source_string, then the …
[Read more]
SQL TRIM Function Example | trim() Function In SQL

SQL TRIM Function Example | trim() Function In SQL is today’s topic. The SQL TRIM function is used for removing spaces and characters from both ends of the string. The TRIM() function removes the space character OR other specified characters from the start or end of a string. By default, the TRIM() function removes leading and trailing spaces from a string.

SQL TRIM Function Example

The syntax of TRIM() Function is following.

TRIM ([removed_characters FROM] input_string)

See the parameters of TRIM() function.

  1. removed_characters: It is a literal, variable of any non-LOB character type contains characters which will be removed.
  2. input_string: It is an expression that depicts the kind of characters to be removed.

Examples

See the following query.

Select TRIM (‘   SQL TUTORIAL …
[Read more]
SQL Substring Function Example | Substring In SQL

SQL Substring Function Example | Substring In SQL is today’s topic. SQL SUBSTRING FUNCTION is used to extract part of the string from an original string given as an input to the function. Part of the string is known as a substring. The SUBSTRING functions allow you to extract a substring from a string.

SQL Substring Function

See the syntax of SUBSTRING FUNCTION.

SELECT SUBSTRING (input_string, start_position, length);

See the following parameters.

  1. input_string: The source string from which substring will be extracted. It can be a character, binary, text, or image expression.
  2. start_position: It is an integer that specifies the location where the returned substring starts. The first character in an input_string is 1, not zero as that of in C or C++.
  3. Length: It is a positive integer that specifies the …
[Read more]
SQL CONCAT Function Example | Concat In SQL Tutorial

SQL CONCAT Function Example | Concat In SQL Tutorial is today’s topic. SQL CONCAT function is used to concatenate two strings to form a single string. The SQL CONCAT function is used to join two or more strings. It takes up to 255 input strings which are further joined by the function. For, performing join operation CONCAT requires at least 2 strings. If it is provided with only one string, it will raise an error.

SQL CONCAT Function

If any non-character string values are passed in the function, it will be implicitly converted to strings before concatenating. If any NULL is added to the function, it converts it into an empty string with VARCHAR (1).

Syntax

SELECT CONCAT (string1, string2, ... string_n)

Parameters

CONCAT: This is the function that is used for concatenating.

string1, string2, … …

[Read more]
SQL Replace Function Example | Replace Function In SQL

SQL Replace Function Example | Replace Function In SQL is today’s topic. The REPLACE function is used for replacing a sequence of characters in a string with another set of characters, i.e. it is used for replacing all the occurrences of a substring within a present string taken from another new string. The replace function performs case sensitive replacement.

SQL Replace Function

SQL REPLACE() function replaces all the occurrences of the substring within the string, with a new substring.

See the following syntax.

REPLACE(string, old_string, new_string)
  1. string: The string will be used for replacing the set of characters by another set of characters.
  2. old_string: The substring which will be searched in the string.
  3. new_string: All occurrences of old_string will be replaced with new_string in the string.
[Read more]
How to limit the SQL query result set to Top-N rows only

Introduction In this article, we are going to see how we can limit the SQL query result set to the Top-N rows only. Limiting the SQL result set is very important when the underlying query could end up fetching a very large number of records, which can have a significant impact on application performance. Why limit the number of rows of a SQL query? Fetching more data than necessary is the number one cause of data access performance issues. When a given business use case is developed, the amount of data available... Read More

The post How to limit the SQL query result set to Top-N rows only appeared first on Vlad Mihalcea.

SQL Check Constraint Example | Check Constraint In SQL Tutorial

SQL Check Constraint Example | Check Constraint In SQL Tutorial is today’s topic. Check constraint is used for specifying the predicate that every tuple must satisfy in a relation i.e. it is used for limiting the values that a column can hold in a relation. It is used for giving a condition to check the value to be entered into a record. If the condition results in false then that value will not be added to the record.

SQL Check Constraint

The CHECK constraint is used to limit the value range that can be placed in a column.

If you define a CHECK constraint on a single column it allows only certain values for this column.

If you define a CHECK constraint on a table it can limit the values in certain columns based on values in other columns in the row.

Some key points of SQL Check Constraint are following.

  1. Check constraint cannot be defined inside the …
[Read more]
Showing entries 11 to 20 of 1214
« 10 Newer Entries | 10 Older Entries »