Conversion
DuckDB
PRINTF
Format string dengan placeholder seperti C printf. Sangat fleksibel untuk formatting output.
Tipe hasil:
VARCHARDiperbarui: 6 Jan 2026Syntax
SQL
PRINTF(format_string, arg1, arg2, ...)Parameter
format_stringVARCHARwajib
Format string dengan placeholders (%d, %s, %f, etc.)
arg1, arg2, ...ANYwajib
Nilai untuk mengisi placeholders
Contoh Penggunaan
Basic Formatting
SQL
1 SELECT PRINTF('Hello %s, you have %d items', 'John', 5);
Simple string formatting.
Hasil
Hello John, you have 5 items
Number Formatting
SQL
1 SELECT PRINTF('Price: $%,.2f', 1234567.89);
Format currency dengan decimals.
Hasil
Price: $1234567.89
Padding dan Alignment
SQL
1 SELECT 2 PRINTF('|%10s|', 'hello') AS right_align, 3 PRINTF('|%-10s|', 'hello') AS left_align, 4 PRINTF('|%010d|', 42) AS zero_pad;
Different alignment options.
Hasil
| hello| | hello | | 0000000042|
Report Formatting
SQL
1 SELECT PRINTF( 2 '%s: %8.2f (%+.1f%%)', 3 product_name, 4 revenue, 5 growth_rate 6 ) AS report_line 7 FROM sales_summary;
Format untuk report line.