简体   繁体   English

SQL中的“:1”,“:2”是什么意思?

[英]What does “:1”, “:2” in SQL mean?

I am looking at a sql statement that looks like this: 我正在看一个看起来像这样的sql语句:

...
AND col2_.col_date >= :1
AND col2_.col_date <= :2
...

and I have no idea what :1 and :2 does?? 我不知道:1和:2做什么?

Can someone enlighten me, 有人能启发我吗

Thanks, :) 谢谢, :)

它们是参数化查询中的占位符,等待程序出现并提供参数。

There are parameters, specified when running the query - rather than having the date as text directly in the query, they're parameters injected when the query is run. 有一些参数是在运行查询时指定的-它们不是在查询中直接以日期作为文本的,而是在运行查询时注入的参数。 What you're seeing are the first and second placeholders...the syntax varies between servers and providers. 您所看到的是第一和第二个占位符...语法在服务器和提供程序之间有所不同。 For example sometimes you'll see them names instead of numbered, etc. 例如,有时您会看到它们的名称而不是编号等。

These are placeholders, but not in SQL, only in your programming language that constructs the SQL-string. 这些是占位符,但不是SQL,仅占构造SQL字符串的编程语言中的占位符。 In SQL (PostgreSQL anyway) you have to use numbered placeholders $1, $2, etc. Check the PostgreSQL-manual for PREPARE or the PHP-manual for pg_query_params() . 在SQL(无论如何是PostgreSQL)中,您必须使用带编号的占位符$ 1,$ 2等。请检查PostgreSQL手册中的PREPARE或PHP手册中的pg_query_params()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM