1
 $a = 'select 2 from dual' | sqlplus user/password@database.

expected result: 2

real result :

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

I would like to get only what my query returns. How do I do that?


@vonPrynz

$a = 'select 2 from dual' | sqlplus -S user/password@database.

result is empty

3
  • 1
    Try the -s[ilent] switch to tell sqlplus not to print banners and such. That being said, consider using ODA.NET for programmatic access instead of passing parameters to a client app. Commented May 31, 2022 at 7:05
  • @vonPryz I have tried your solution. No result is returned Commented May 31, 2022 at 7:16
  • 2
    Oracle (clients) requires a semicolon for DML statements, so add one to the select query. That is, 'select 2 from dual;' Commented May 31, 2022 at 7:23

1 Answer 1

3

You need add ';'

PS C:\> 'select 2 as result from dual;' | sqlplus -s user/password@DEV19

    RESULT
----------
         2

If you want only '2' then add this lines:

'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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.