TO_CHAR
Sintassi
%%{init: {
'theme': 'base',
'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
'themeVariables': {
'fontSize': '11px',
'fontFamily': 'Arial'
}
}}%%
flowchart LR
Start((START)) --> TO_CHAR[TO_CHAR]:::quoted
TO_CHAR --> End((END))
Scopo
La funzione SQL TO_CHAR converte un valore in testo.
Parametri:
- Input (
ANY): valore da convertire. - Formato (facoltativo,
varchar2): maschera di formattazione per una data o un numero, ad esempioYYYY-MM-DD HH24:MIoFM999G990D00. Il valore predefinito è lo stile americano. Gli elementi di una maschera di formato sono descritti in Format Masks; un numero con una maschera di formato è disponibile a partire dalla versione 28.0.
Restituisce: l'input convertito in testo.
Esempi
L'esempio seguente converte una data in testo utilizzando una maschera di formato:
select to_char(to_date('20260703', 'YYYYMMDD'), 'DD-MM-YYYY')
-------------------
03-07-2026
L'esempio seguente converte un numero in testo:
select to_char(123.45)
-------------------
123.45
L'esempio seguente converte un timestamp in testo senza i secondi:
select to_char(timestamp '2026-08-13 12:34:56', 'YYYY-MM-DD HH24:MI')
-------------------
2026-08-13 12:34
L'esempio seguente converte un numero in testo utilizzando separatori di gruppo e decimali:
select to_char(1234567.891, 'FM999G999G990D00')
-------------------
1,234,567.89