SQL Server 中存储过程参数使用单引号2025年2月2日 | 阅读6分钟 引言首先,让我们了解一下最受追捧的 SQL 软件,即 SQL(结构化查询语言)Server。这款服务器由一家备受追捧的公司推出和开发。这家公司名为微软。 这是一个关系型数据库服务器。该产品旨在执行其他应用程序所需的数据存储和检索的基本任务。它可以在单台计算机或连接到网络的多台计算机上运行。 这款 SQL Server 于 1989 年 4 月 24 日发布。可以轻松下载。SQL Server 也是一款开源软件。 现在,让我们来了解一下 SQL Server 中用于存储过程的单引号。 字符串只用单引号 (' ') 括起来。 如果字符串不是用单引号括起来,或者用了双引号,编译器就会抛出运行时错误,告知我们犯了错误。 我正在执行 SQL 操作的服务器是 SQL SERVER 2019。 Stored Procedure可被保存并重复使用的 SQL 预编译代码称为存储过程。 因此,如果您经常开发 SQL 查询,请将它们保存为存储过程,然后直接调用它们来运行。 此外,您可以向存储过程传递参数,使其能够根据传入参数的值执行操作。 语法 示例程序 在学习示例程序之前,让我们先了解一下这些过程在 SQL Server 上是如何执行的。 语法 这是该过程的语法。现在,让我们直接开始看示例。 示例 1 代码 输出 Result _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Believe Become (1 rows affected) 示例 2 代码 输出 Result _ _ _ _ _ 269 (1 rows affected) 示例 2 代码 输出 Result _ _ _ _ _ 269 (1 rows affected) 示例 3 代码 输出 Result _ _ _ _ _ _ _ _ _ _ 829.17894999999999 (1 rows affected) 示例 4 代码 输出 Result _ _ _ c (1 rows affected) 示例 5 代码 输出 Result _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ I am lost for words. My mouth is probably dry out of emotions (1 rows affected) 示例 6 代码 输出 Result Msg 102, Level 15, State 1, Server DESKTOP-Q5M2SGA, Line 2 Incorrect syntax near 'am'. 示例 7 代码 输出 Result Msg 156, Level 15, State 1, Server DESKTOP-Q5M2SGA, Line 2 Incorrect syntax near the keyword 'not'. 以上是关于单引号的案例研究。现在,让我们转到过程参数部分。但在进入之前,让我们先了解一下什么是过程。 过程它类似于其他编程语言中的函数或方法。每个过程中都包含一些参数。这些参数在调用过程时会接收一些值。参数的数据类型已经在过程中指定。 即使是对于存储过程,输入也必须用单引号括起来。 我们正在 MS SQL Server 中执行此操作。它也被称为 SQL Server。 过程 1现在使用该过程 代码 1 输出 Result _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ THINK (1 rows affected) 代码 2 输出 Result _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ a b c d e f g h I j k l m n o p q r s t u v w x y z (1 rows affected) 代码 3 输出 Result _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ I had goosebumps, one of the greats of this game talking about Zimbabwe and in particular me (1 rows affected) Result _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ He just seems to know exactly what to do, when to do it. (1 rows affected) 代码 4 输出 Msg 102, Level 15, State 1, Server DESKTOP-Q5M2SGA, Line 1 Incorrect syntax near 'just'. 代码 5 输出 Result _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ This product is designed to perform the fundamental task of data storage and retrieval as needed by other applications (1 rows affected) 代码 6 输出 Result _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Online Python DebBugger. Code, Run and Debug Python program online. Please Compile Your Codes (1 rows affected) 代码 7 输出 Result _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Like Raza, he was also full of praise for the fast bowlers for setting the tone early (1 rows affected) 以上是关于 SQL Server 中存储过程参数使用单引号的主题。 下一主题什么是 SQL |
我们请求您订阅我们的新闻通讯以获取最新更新。