Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Space Function In Sql in SQL

Space Function In Sql in SQL

The SPACE function in SQL is used to return a string of repeated space characters.


? Syntax

SPACE(integer_expression)
  • integer_expression: The number of space characters to return.


? Return Type

  • Returns a string (typically VARCHAR) consisting of the specified number of space characters.


? Example Usage

SELECT 'Hello' + SPACE(3) + 'World' AS Greeting;

Result:

Hello   World

(There are 3 spaces between "Hello" and "World")


? Use Cases

  • Formatting output strings (e.g., padding).

  • Creating fixed-width text data.

  • Generating indents or gaps for display in reporting systems.

  • Simulating tab spacing in plain text output.


? Notes

  • If the argument is 0, it returns an empty string.

  • If the argument is negative, it returns NULL.

  • Works with + string concatenation in SQL Server and some other dialects.


? More Examples

SELECT SPACE(5) AS FiveSpaces;SELECT 'Data' + SPACE(2) + 'Science' AS Combined;SELECT LEN(SPACE(10)) AS LengthOfSpaces;  -- Returns 10

Let me know if you'd like a custom function to generate formatted strings using SPACE for reports or exports.

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql