开发者

what is use of question mark in sql [duplicate]

This question already has answers here: What is the question mark's significance in MySQL at "WHERE column = ?"? (4 answers) What does a question mark represent in SQL queries? (6 answers) Closed 9 years ago.

I was just surfing the net and found a query something like:

sql  = "select milk_rate from special_milk_rate 
        where code_producer_id=? and effective_from <= ? 
        and effective_till >= ?"

what exactly this query means i means what is t开发者_如何学Gohe use of ? in this statement.

and one thing more what is use of & in sql.


This usually implies a prepared statement, where the parameters are filled in later. (see e.g. http://en.wikipedia.org/wiki/Prepared_statements#Parameterized_statements).


what exactly this query means i means what is the use of ? in this statement.

The question marks are for parameters.

and one thing more what is use of & in sql.

& is a bitwise AND operator in sql


The question marks are supposed to contain the actual parameters.

E.g.

"select milk_rate from special_milk_rate 
        where code_producer_id=2 and effective_from <= '20101231' 
        and effective_till >= '20110124'"


& usually denotes a variable or substitution value which you may be prompted for at run time


Here is nice article:

http://publib.boulder.ibm.com/infocenter/idshelp/v10/topic/com.ibm.sqls.doc/sqls610.htm#sii-02prep-18104

In some statements, parameters are unknown when the statement is prepared because a different value can be inserted each time the statement is executed. In these statements, you can use a question-mark ( ? ) placeholder where a parameter must be supplied when the statement is executed.


Question marks are found in prepared statements, meaning it is parametrized and can be called again and again without having to reconstruct the whole sql statement, just by changing the parameters. Some frameworks use those that together with SqlCommands. Those encapsulate escaping and prevent sql injection attacks.

Some frameworks also allow named parameters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜