select id from contract where sap_code =$,sap_code sql语句哪里有问题
时间: 2024-03-05 10:50:38 浏览: 160
SQL 语句中的 `$` 是一个变量占位符,应该被具体的变量值替换掉,否则会导致 SQL 语法错误。你需要将 `$` 替换成具体的变量值,例如:
```
SELECT id FROM contract WHERE sap_code = 'ABC123';
```
上面的 SQL 语句中,`ABC123` 就是变量 `$` 应该替换的具体变量值,它表示需要查询 `contract` 表中 `sap_code` 列值为 `ABC123` 的记录,并返回这些记录的 `id` 列的值。如果你要查询其他 `sap_code` 值对应的记录,只需要将 `ABC123` 替换成具体的变量值即可。
相关问题
sql 语句报错 res := common.DB.Raw("SELECT * FROM(SELECT * FROM flaws WHERE facility_id = ? AND label LIKE '%?%' "+ "UNION SELECT * FROM issues WHERE facility_id = ? AND label = ? "+ "UNION SELECT * FROM records WHERE facility_id = ? AND label = ? "+ "UNION SELECT * FROM qualities WHERE facility_id = ? AND label = ? "+ "UNION SELECT * FROM inspections WHERE facility_id = ? AND label = ?)"+ "AS combined_tables LIMIT ? OFFSET ?", code, label, code, label, code, label, code, label, code, label, pageSize, offset).Find(&req)
这个 SQL 语句中有一些问题。首先,在查询中使用 `%?%` 这种方式是不正确的,正确的应该是使用 `?` 并在参数中加上 `%`。其次,在 SQL 语句中应该使用占位符 `?` 来代替参数,而不是直接写在字符串中。你可以尝试修改这个 SQL 语句如下:
```
res := common.DB.Raw("SELECT * FROM(SELECT * FROM flaws WHERE facility_id = ? AND label LIKE ? "+
"UNION SELECT * FROM issues WHERE facility_id = ? AND label = ? "+
"UNION SELECT * FROM records WHERE facility_id = ? AND label = ? "+
"UNION SELECT * FROM qualities WHERE facility_id = ? AND label = ? "+
"UNION SELECT * FROM inspections WHERE facility_id = ? AND label = ?) "+
"AS combined_tables LIMIT ? OFFSET ?", code, "%"+label+"%", code, label, code, label, code, label, code, label, pageSize, offset).Find(&req)
```
这样修改后,就可以正确地使用参数了。
select * from report_tt_storage_cost_record where customer_code = ADDS这条SQL语句写的对吗
这条SQL语句有问题。在SQL语句中,字符串需要使用单引号或双引号括起来,所以应该将ADDS用单引号或双引号括起来,例如:
```
select * from report_tt_storage_cost_record where customer_code = 'ADDS';
```
或者
```
select * from report_tt_storage_cost_record where customer_code = "ADDS";
```
阅读全文