Tutorial MySQL

MySQL HOME Introdução ao MySQL MySQL RDBMS

MySQL SQL

MySQL SQL MySQL SELECIONAR MySQL ONDE MySQL E, OU, NÃO MySQL ORDER BY MySQL INSERT INTO Valores NULL do MySQL ATUALIZAÇÃO DO MySQL MySQL EXCLUIR MySQL LIMIT MySQL MIN e MAX MySQL COUNT, AVG, SUM MySQL LIKE Caracteres curinga do MySQL MySQL IN MySQL ENTRE Aliases do MySQL Junções do MySQL MySQL INNER JOIN MySQL LEFT JOIN MySQL RIGHT JOIN MySQL CROSS JOIN Auto-ingresso do MySQL MySQL UNION MySQL GROUP BY MySQL TENDO O MySQL EXISTE MySQL QUALQUER, TODOS MySQL INSERT SELECT CASO MySQL Funções Nulas do MySQL Comentários do MySQL Operadores MySQL

Banco de dados MySQL

MySQL Criar banco de dados MySQL Drop DB MySQL Criar Tabela Tabela de descarte do MySQL Tabela de alteração do MySQL Restrições do MySQL MySQL não nulo MySQL exclusivo Chave primária do MySQL Chave estrangeira do MySQL Verificação do MySQL Padrão do MySQL MySQL Criar Índice Incremento automático do MySQL Datas do MySQL Visualizações do MySQL

Referências do MySQL

Tipos de dados MySQL Funções do MySQL

Exemplos MySQL

Exemplos MySQL Teste do MySQL Exercícios do MySQL

Função MySQL SUBSTR()

❮ Funções do MySQL

Exemplo

Extraia uma substring de uma string (comece na posição 5, extraia 3 caracteres):

SELECT SUBSTR("SQL Tutorial", 5, 3) AS ExtractString;

Definição e uso

A função SUBSTR() extrai uma substring de uma string (começando em qualquer posição).

Nota: As funções SUBSTR() e MID() equivalem à função SUBSTRING() .

Sintaxe

SUBSTR(string, start, length)

OU:

SUBSTR(string FROM start FOR length)

Valores de parâmetro

Parameter Description
string Required. The string to extract from
start Required. The start position. Can be both a positive or negative number. If it is a positive number, this function extracts from the beginning of the string. If it is a negative number, this function extracts from the end of the string
length Optional. The number of characters to extract. If omitted, the whole string will be returned (from the start position)

Detalhes técnicos

Trabalha em: Do MySQL 4.0

Mais exemplos

Exemplo

Extraia uma substring do texto em uma coluna (comece na posição 2, extraia 5 caracteres):

SELECT SUBSTR(CustomerName, 2, 5) AS ExtractString
FROM Customers;

Exemplo

Extraia uma substring de uma string (comece do final, na posição -5, extraia 5 caracteres):

SELECT SUBSTR("SQL Tutorial", -5, 5) AS ExtractString;

❮ Funções do MySQL