0

我的要求是——我需要从用户那里获取输入(将两个字段作为输入),然后我会将输入存储在一个符号中。但问题是——我无法在 SQL Query 中使用该符号。 .

$ start:
$ INQUIRE REF "Enter Emp_ID"
$ DEFINE/NOLOG Report_file 'REF'
$       if f$type (REF) .nes. "INTEGER"
$       then
$                       call error_menu "Error: Integer value Expected"
$               wait 0:0:0.15
$               set term/width=132
$               goto START
$       endif
$       if f$length (REF) .lt. 5 .and. f$length (REF) .gt. 5
$       then

$                       call error_menu "Error: emp_id Should be 5 digits"
$               wait 0:0:0.15
$               set term/width=132
$               goto START
$ INQUIRE FILE "Enter year"
$ DEFINE/NOLOG Report_file 'FILE'
$       if f$type (FILE) .nes. "INTEGER"
$       then
$                       call error_menu "Error: NON Integer Value..Please enter numeric value"
$               wait 0:0:0.15
$               set term/width=132
$               goto START
$       endif
$ call error_menu "Checking whether emp_id is present in Database !!!"
$ sqlplus/
   set feedback on
    define IEMP_ID = '&REF';
    define IYEAR = '&FILE'; 
select emp_id from employee where emp_id=&IEMP_ID and year = &IYEAR;
exit;

任何人都可以帮助我..简单地说,我只需要输入一次,然后我需要将它用于各种目的(主要是在许多 sql 查询中)。有这样做的可能性吗?

4

1 回答 1

1

可能sqlplus无法访问 DCL 符号。(数字命令语言,不要与数据库控制语言混淆。)另一种方法是将命令写入临时文件,然后将其用作sqlplus. 就像是:

$ ! Your code to get user input...
$ !
$ ! Generate a temporary file with the SQLplus commands.
$ open/write SQL Sys$Login:SQLCommands.tmp
$ write SQL "set feedback on"
$ write SQL "define IEMP_ID = '" + Ref + "';"
$ write SQL "define IYEAR = '" + File + "';"
$ write SQL "select emp_id from employee where emp_id=&IEMP_ID and year = &IYEAR;"
$ write SQL "exit;"
$ close SQL
$ !
$ ! Run the SQLplus commands.
$ assign/user_mode Sys$Login:SQLCommands.tmp Sys$Input
$ sqlplus
$ !
$ ! Houseclean the temporary file.
$ delete Sys$Login:SQLCommands.tmp;0
$ !
$ ! That is all.
$ exit
于 2017-09-13T18:46:01.443 回答