如何仅将我的 sqlplus 查询的输出提供给 powershell 变量?
How to give to a powershell variable only the output of my sqlplus query?
$a = 'select 2 from dual' | sqlplus user/password@database.
预期结果:2
实际结果:
SQL*Plus: Release 19.0.0.0.0 - Production on Tue May 31 08:29:43 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Last Successful login time: Tue May 31 2022 08:24:55 +02:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL> 2
SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
我只想得到我查询的内容 returns。我该怎么做?
@vonPrynz
$a = 'select 2 from dual' | sqlplus -S user/password@database.
结果为空
您需要添加';'
PS C:\> 'select 2 as result from dual;' | sqlplus -s user/password@DEV19
RESULT
----------
2
如果您只需要“2”,则添加以下行:
'SET FEEDBACK OFF
set heading off
set termout OFF
SET FEEDBACK OFF
SET TAB OFF
set pause off
set verify off
SET UNDERLINE OFF
set trimspool on
set timing off
set echo off
set linesize 1000
set pagesize 100
select 2 as result from dual;' | sqlplus -s user/password@DEV19
2
$a = 'select 2 from dual' | sqlplus user/password@database.
预期结果:2
实际结果:
SQL*Plus: Release 19.0.0.0.0 - Production on Tue May 31 08:29:43 2022 Version 19.3.0.0.0 Copyright (c) 1982, 2019, Oracle. All rights reserved. Last Successful login time: Tue May 31 2022 08:24:55 +02:00 Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.3.0.0.0 SQL> 2 SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.3.0.0.0
我只想得到我查询的内容 returns。我该怎么做?
@vonPrynz
$a = 'select 2 from dual' | sqlplus -S user/password@database.
结果为空
您需要添加';'
PS C:\> 'select 2 as result from dual;' | sqlplus -s user/password@DEV19
RESULT
----------
2
如果您只需要“2”,则添加以下行:
'SET FEEDBACK OFF
set heading off
set termout OFF
SET FEEDBACK OFF
SET TAB OFF
set pause off
set verify off
SET UNDERLINE OFF
set trimspool on
set timing off
set echo off
set linesize 1000
set pagesize 100
select 2 as result from dual;' | sqlplus -s user/password@DEV19
2