Какая функция позволяет преобразовать все буквы в выбранном столбце в верхний регистр sql
Перейти к содержимому

Какая функция позволяет преобразовать все буквы в выбранном столбце в верхний регистр sql

  • автор:

SQL Server функция UPPER

В SQL Server (Transact-SQL) функция UPPER преобразует все буквы указанной строки в верхний регистр. Если в строке есть символы, которые не являются буквами, они не зависят от этой функции.

Синтаксис

Синтаксис функции UPPER в SQL Server (Transact-SQL):

Параметры или аргументы

string — строка для преобразования в верхний регистр.

Примечание

См. Также функцию LOWER.

Применение

Функция UPPER может использоваться в следующих версиях SQL Server (Transact-SQL):
SQL Server vNext, SQL Server 2016, SQL Server 2015, SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, SQL Server 2005

Пример

Рассмотрим некоторые примеры SQL Server функции UPPER, чтобы понять, как использовать функцию UPPER в SQL Server (Transact-SQL). Например:

SQL UPPER: Convert a String into Uppercase

Summary: this tutorial shows you how to use the SQL UPPER function to convert a string into uppercase.

Introduction to the SQL UPPER function

The SQL UPPER function converts all the letters in a string into uppercase. If you want to convert a string to lowercase, you use the LOWER function instead.

The syntax of the UPPER function is as simple as below.

If the input string is NULL , the UPPER function returns NULL , otherwise, it returns a new string with all letters converted to uppercase.

Besides the UPPER function, some database systems provide you with an additional function named UCASE which is the same as the UPPER function. It is “there is more than one way to do it”.

SQL UPPER function examples

The following statement converts the string sql upper to SQL UPPER :

Let’s take a look at the employees table in the sample database.

employees table

The following query uses the UPPER function to convert last names of employees to uppercase.

The query just read the data from the employees table and convert them on the fly. The data in the table remains intact.

To convert data to uppercase in the database table, you use the UPDATE statement. For example, the following statement updates the emails of employees to uppercase.

SQL UPPER exmaple

Querying data case insensitive using the UPPER function

When you query the data using the WHERE clause, the database systems often match data case sensitively. For example, the literal string Bruce is different from bruce .

The following query returns no result.

To match data case insensitively, you use the UPER function. For example, the following query will return a row:

SQL UPPER function example

Notice that the query above scans the whole table to find the matching rơ. In case the table is big, the query will be very slow.

To overcome this, some database systems provide the function-based index that allows you to define an index based on a function of one or more columns that results in a better query performance.

In this tutorial, you have learned how to use the SQL UPPER function to convert a string to uppercase.

Функция SQL UCASE()

Оператор SQL UCASE() — функция, возвращающая значения столбца или столбцов в верхнем регистре букв.

Функция SQL UCASE() имеет следующий синтаксис:

В СУБД MS SQL Server аналогом оператора SQL UCASE() является функция UPPER с тем же синтаксисом.

Примеры оператора SQL UCASE. Имеется следующая таблица Planets :

ID PlanetName Radius SunSeason OpeningYear HavingRings Opener
1 Mars 3396 687 1659 No Christiaan Huygens
2 Saturn 60268 10759.22 Yes
3 Neptune 24764 60190 1846 Yes John Couch Adams
4 Mercury 2439 115.88 1631 No Nicolaus Copernicus
5 Venus 6051 243 1610 No Galileo Galilei

Пример 1. Вывести названия планет в верхнем регистре, у которых нет колец, используя оператор SQL UCASE:

PlanetName
MARS
MERCURY
VENUS

Пример 2. Пример для MS SQL Server. Вывести названия планет в верхнем регистре, радиус которых больше 20000, используя оператор SQL UCASE:

Convert all records in postgres to Titlecase, first letter uppercase

I have a simple table in PostgreSQL called keywords with a simple text field called name. I want to convert all names of keywords in first letter uppercase. Is there a way to do it from psql console?

4 Answers 4

There is an initcap() function, if you’re meaning to uppercase the first letter of each keyword and to lowercase the following characters:

Else combine substring() and upper() :

This does give the correct answer (R. López Viña Tondonia Rioja White Viña) in our version of Postgres (9.0.7).

Scott Pritchett's user avatar

@denis, Gave the Right Answer!

But in my case I use PgAdmin3 , so after selecting the database there is SQL query Options , So there we can directly add the above query in it.

I had a table called subcategory_subcategory(name of table) in that i wanted to change a column values whose name was Item_name(name of column ) , so my query was like this

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *