0

How to pass Linux variable in Oracle code?

I need to pass it in below format and it should not ask for "enter a value for 1:"

Please advise.

mount='/u08/dbname/'
sqlplus -s "/ as sysdba" <<EOF 
set serveroutput on;
set feedback off;
set verify off;
set heading off;
DECLARE
line varchar(100);
BEGIN 
line := '&1';
if (5 > 0)then
dbms_output.put_line(line);
end if;
END;
/
$mount
EOF

1 Answer 1

0
export mount='/u08/dbname/'
sqlplus -s "/ as sysdba" <<EOF 
set serveroutput on;
set feedback off;
set verify off;
set heading off;
DECLARE
line varchar(100);
BEGIN 
line := '$mount';
if (5 > 0) then
dbms_output.put_line(line);
end if;
END;
/
$mount
EOF

You can assign the output of a Unix/Linux command to a variable too:

export SPACE=$(df --output=avail -m /dev/sda8 | tail -1)
4
  • The mount point value is dynamically created in the linux code. We are not providing constant value here. suppose I am calculating a space available on filesystem. space=df -m dir How should I provide that value?
    – Divya
    Commented Oct 30, 2020 at 12:44
  • See edited answer. Commented Oct 31, 2020 at 19:22
  • Its working fine! Thanks much Gerard!!
    – Divya
    Commented Nov 2, 2020 at 5:55
  • Perhaps you could accept the answer? Commented Nov 2, 2020 at 6:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .