简体   繁体   English

在SQL Developer 3.1.07中为用户输入提供消息提示

[英]Provide a message prompt for user input in SQL Developer 3.1.07

I am trying to get the user to input the date into a substitution variable but want the prompt message to prompt the user to input the date in the correct format. 我试图让用户将日期输入到替代变量中,但希望提示消息提示用户以正确的格式输入日期。

SELECT claimdate, assessmentid
FROM claimassessment
WHERE claimdate > to_date('&Date_as_yyyy_mm_dd', 'yyyy-mm-dd');

I keep reading that I should be using the ACCEPT and PROMPT keywords but I am using SQL Developer 3.1.07 and these keywords aren't recognised. 我一直在阅读我应该使用ACCEPT和PROMPT关键字,但是我使用的是SQL Developer 3.1.07,但这些关键字无法识别。 How would I get the pop up to display a prompt like 'Enter the effective date in the format 'yyyy-mm-dd'. 我将如何弹出显示“以yyyy-mm-dd格式输入生效日期”之类的提示。 The default prompt on the pop up just says 'Enter Substitution Variable' 弹出窗口上的默认提示仅显示“输入替代变量”

Option 1: Build it into your SUBSTITUTION Variable name 选项1:将其构建到您的SUBSTITUTION变量名称中

SELECT *
  FROM hr.employees
 WHERE hire_date > TO_DATE('&date_mm_dd_yyyy', 'MM-DD-YYYY');

在此处输入图片说明

The date format is kind of in the prompt - the user will at least know you want the 2 digit month then the 2 digit day and then the 4 digit year. 日期格式在提示中是一种-用户至少会知道您想要2位数字的月份,然后是2位数字的日期,然后是4位数字的年份。

Option 2: Use a report with bind variables. 选项2:使用带有绑定变量的报表。

在此处输入图片说明

For the report, instead of using a substitution variable, we're using a BIND. 对于报告,我们使用的是BIND,而不是使用替代变量。 Your query basically stays the same, it's just :X vs &X. 您的查询基本上保持不变,只是:X vs&X。 The benefit is that your query will be cached in the optimizer once vs multiple times, once for each query...although more recent copies of the database are smart enough to figure this out on it's own. 好处是您的查询将在优化器中缓存一次,而不是多次,对于每个查询一次。。。尽管数据库的最新副本足够聪明,所以可以自行解决。

You can define in the report how the prompt is labeled. 您可以在报告中定义提示的标记方式。

在此处输入图片说明

And the query behind the report 以及报告背后的查询

SELECT *
  FROM hr.employees
 WHERE hire_date > to_date(:user_date, 'MM-DD-YYYY')

The accept and prompt keywords are recognised in SQL Developer 3.1.07.42. 在SQL Developer 3.1.07.42中可以识别accept和提示关键字。

Here's a demo using this form: 这是使用此表单的演示:

accept Date_as_yyyy_mm_dd date format "YYYY-MM-DD" prompt "Enter the effective date in the format 'yyyy-mm-dd'" 

which creates the prompt window with the text you want (the double-quotes around the prompt value aren't necessary in 3.1 but I think they make it clearer; the single quotes aren't preserved either way though in 3.1, but they are in 18.3), and also checks the format of the supplied values; 这将使用您想要的文本创建提示窗口(在3.1中,提示值周围的双引号不是必需的,但我认为它们会变得更清晰;尽管在3.1中,单引号也不会保留任何一种方式,但是它们在18.3),并检查提供值的格式; and then uses the accepted value: 然后使用接受的值:

在此处输入图片说明

When run as a script (F5) the pop-up window appears with the specified text: 作为脚本(F5)运行时,将显示带有指定文本的弹出窗口:

在此处输入图片说明

If I enter a value that doesn't match the format it re-prompts: 如果输入的值与格式不匹配,则会重新提示:

在此处输入图片说明

and one it has an acceptable value it uses that substitution variable value in subsequent statements: 一个具有可接受值的值,它将在后续语句中使用该替换变量值:

在此处输入图片说明

And as long as you've run the accept in script mode, you can run your main query as a statement (control-enter) to get results in a grid in a 'Query results' window. 而且,只要您以脚本模式运行accept ,就可以将主查询作为语句(控制输入)运行,以在“查询结果”窗口的网格中获取结果。


As Jeff mentioned, 3.1 is very old - it seems to have been released in February 2012 - so you might want to consider getting a newer version. 正如Jeff所提到的,3.1很旧-它似乎已于2012年2月发布-因此您可能要考虑获取更新的版本。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM