SELECT NULL,*,NULL,NULL中令人困惑的SQL错误 [英] Confusing SQL error in SELECT NULL, *, NULL, NULL

查看:541
本文介绍了SELECT NULL,*,NULL,NULL中令人困惑的SQL错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景
我试图解决hackthissite.org中的第四现实任务,但无法弄清楚确切地说,我应该在URL中注入什么SQL来检索电子邮件列表.浪费了几个小时后,我放弃了,看了一种解决方案,它给出了有趣的代码行,该行代码将在选择查询后注入:

The Background
I was trying to solve the fourth realistic mission in hackthissite.org, and couldn't figure out exactly what SQL I should inject into the URL to retrieve the list of emails. After wasting a few hours, I gave up and looked at a solution, which gave this interesting line of code, which was to be injected after a select query:

UNION ALL SELECT NULL, *, NULL, NULL FROM email

我了解这样做的原因以及原因;黑客需要创建一个与合并的查询具有相同列数的查询,并在*周围移动以确保显示电子邮件.那不是我的问题.

I understand what this does and why; the hacker needs to create a query that has the same number of columns as the query it's being merged with, and shifted around the * to make sure the emails are displayed. That's not my question.

问题
我的问题是为什么该代码在MySQL中引发语法错误.经过几次测试,我发现这显然是一个有效的查询:

The Question
My question is why that code throws a syntax error in MySQL. After doing a few tests, I've found that apparently this is a valid query:

SELECT *, NULL, NULL, NULL FROM email

就这样

SELECT NULL, text, NULL, NULL FROM email

但是由于某种原因,它不是:

but for some reason, this isn't:

SELECT NULL, *, NULL, NULL FROM email

并在"*,NULL,来自电子邮件的NULL"附近引发语法错误. 我不明白为什么会这样.似乎查询仅在*是请求的第一列时才有效,而与其他列无关.这是一个错误吗?它是MySQL独有的功能(任务使用了不同的SQL变体)吗?还是我完全误解了?

and throws a syntax error " near '*, NULL, NULL FROM email' ". I fail to understand why this is so. It seems like the query is only valid if * is the first column requested, regardless of what the other columns are. Is this a bug? Is it a feature unique to MySQL (and the mission uses a different variation of SQL)? Or am I misunderstanding this completely?

推荐答案

这是

将不合格*与选择列表中的其他项目一起使用 产生解析错误.为避免此问题,请使用合格的 tbl_name.*参考

Use of an unqualified * with other items in the select list may produce a parse error. To avoid this problem, use a qualified tbl_name.* reference

只需按照说明进行操作.这应该干净地解析:

Just following the instructions. This should parse cleanly:

 select NULL, email.*, NULL, NULL from email

这篇关于SELECT NULL,*,NULL,NULL中令人困惑的SQL错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆