当我输入&在PL / SQL Developer中执行此查询:
select employee_id, first_name, last_name, job_id, &column_name
from employees WHERE &condition ORDER BY &order_column
我收到了错误消息:
ORA-00936:表达式缺失。
虽然当我执行此查询时,变量字段会在我的屏幕上提示,分别有三个字段名column_name
,condition
和order_column
。
分别输入上述三个字段中的值后 - salary, >10000, employee/-id
当我点击确定时,我收到上述错误信息。
有人可以帮忙解决这个问题吗?
答案 0 :(得分:1)
如果您尝试在SQLPlus中运行查询,它将通过使用您为变量赋予的值来向您显示查询的转换方式:
SQL> select employee_id, first_name, last_name, job_id, &column_name from employees WHERE &condition ORDER BY &order_column;
Enter value for column_name: salary
Enter value for condition: >1000
Enter value for order_column: employee/-id
old 1: select employee_id, first_name, last_name, job_id, &column_name from employees WHERE &condition ORDER BY &order_column
new 1: select employee_id, first_name, last_name, job_id, salary from employees WHERE >1000 ORDER BY employee/-id
select employee_id, first_name, last_name, job_id, salary from employees WHERE >1000 ORDER BY employee/-id
*
ERROR at line 1:
ORA-00936: missing expression
因此,您的查询将变为以下内容:
select employee_id, first_name, last_name, job_id, salary from employees
WHERE >1000 ORDER BY employee/-id
这显然是错误的。
您需要提供格式良好的条件(例如salary > 1000
)并为ORDER BY
子句使用正确的列标识符(例如employee_id
);例如:
SQL> select employee_id, first_name, last_name, job_id, &column_name from employees WHERE &condition ORDER BY &order_column;
Enter value for column_name: salary
Enter value for condition: salary > 10000
Enter value for order_column: employee_id
old 1: select employee_id, first_name, last_name, job_id, &column_name from employees WHERE &condition ORDER BY &order_column
new 1: select employee_id, first_name, last_name, job_id, salary from employees WHERE salary > 10000 ORDER BY employee_id
EMPLOYEE_ID FIRST_NAME LAST_NAME JOB_ID SALARY
----------- -------------------- ------------------------- ---------- ----------
100 Steven King AD_PRES 24000
101 Neena Kochhar AD_VP 17000
...
15 rows selected.
SQL>
答案 1 :(得分:0)
这是你的专栏名称吗? employee/-id
?这可能是你问题的一部分。
基本上使用不同的东西:
字母
数字(不在列名称的开头)
下划线(_)
建议不要使用,因为它不是命名字段的好方法,而某些数据源可能会在其他字符上引发错误。