带有"&"符号的查询在 Oracle 中有效,但在 MySQL 中无效?

mysqlmysqli database

"&"符号在 Oracle 中有效。要在 MySQL 中使用它,请使用 @,如以下语法所示−

SET @yourVariableName1 = yourValue, @yourVariableName2 = yourValue, @yourVariableName3 =yourValue,.........N;
insert into yourTableName values(@yourVariableName1,@yourVariableName2,@yourVariableName3,........N);

为了理解上述语法,让我们创建一个表。创建表的查询如下 −

mysql> create table Student_Information
   -> (
   -> StudentId int,
   -> StudentName varchar(100),
   -> StudentAge int,
   -> StudentMarks int,
   -> StudentCountryName varchar(10)
   -> );
Query OK, 0 rows affected (0.75 sec)

这是以 @ 开头的值的查询。使用插入命令在表中插入一些记录。−

mysql> SET @Id = 10001, @Name = 'Carol', @Age =23 ,@Marks =89, @CountryName = 'US';
Query OK, 0 rows affected (0.00 sec)
mysql> insert into Student_Information values(@Id, @Name, @Age ,@Marks, @CountryName);
Query OK, 1 row affected (0.19 sec)

现在,您可以使用 select 语句显示表中的所有记录。查询如下 −

mysql> select *from Student_Information;

这是输出 −

+-----------+-------------+------------+--------------+--------------------+
| StudentId | StudentName | StudentAge | StudentMarks | StudentCountryName |
+-----------+-------------+------------+--------------+--------------------+
| 10001     | Carol       | 23         | 89           | US                 |
+-----------+-------------+------------+--------------+--------------------+
1 row in set (0.00 sec)

相关文章