Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the colon sign ":" do in a SQL query?

What does : stand for in a query?

INSERT INTO MyTable (ID) VALUES (:myId)

How does it fetch the desired value?

Edit: Also what is that sign called? I wanted to search on google, but what's the name for :?

like image 210
Jla Avatar asked Feb 01 '10 15:02

Jla


People also ask

How do you insert a colon in SQL query?

CREATE TEMP FUNCTION InsertColons(s STRING) AS ( CONCAT(SUBSTR(s, 1, 2), ':', SUBSTR(s, 3, 2), ':', SUBSTR(s, 5, 2)) ); SELECT s, InsertColons(s) AS result FROM ( SELECT '123456' AS s UNION ALL SELECT '170519' );

What does the colon sign implies in the below given statement?

Colon : is used in HQL Hibernate Query Language to signify that there is a parameter involved. Hope this helps.

What means '%' in SQL?

The SQL LIKE Operator The percent sign (%) represents zero, one, or multiple characters. The underscore sign (_) represents one, single character.

What does double colon mean in SQL?

In MS SQL Server 2000: For built-in user-defined functions that return a table, the function name must be specified with a leading double colon (::) to distinguish it from user-defined functions that are not built-in. It also must be specified as a one-part name with no database or owner qualifications.


4 Answers

What does ":" stand for in a query?

A bind variable. Bind variables allow a single SQL statement (whether a query or DML) to be re-used many times, which helps security (by disallowing SQL injection attacks) and performance (by reducing the amount of parsing required).

How does it fetch the desired value?

Before a query (or DML) is executed by Oracle, your program will create a cursor. Your program issues the SQL to be parsed for that cursor, then it must bind values for each bind variable referred to by the SQL. How this is done depends on the language.

What is that sign called?

A colon.

like image 169
Jeffrey Kemp Avatar answered Oct 02 '22 16:10

Jeffrey Kemp


That's called a bind variable in Oracle.

what's the name for ":"?

Colon.

like image 21
OMG Ponies Avatar answered Oct 02 '22 17:10

OMG Ponies


Colon : is used in HQL Hibernate Query Language to signify that there is a parameter involved.

So what that means is: SQL SYNTAX:

SELECT * FROM EMPLOYEE WHERE EMP_ID = empID

is same as HQL SYNTAX:

SELECT * FROM EMPLOYEE WHERE EMP_ID = :empID

empID being local variable for parameters...

Hope this helps.

like image 40
RAHUL Avatar answered Oct 02 '22 15:10

RAHUL


This is a tag for a named query parameter, and is not part of the query's actual syntax. The tag is replaced with some value specified in the code that makes the query before it is actually run.

like image 20
Will Vousden Avatar answered Oct 02 '22 17:10

Will Vousden