Problem running plsql using printf command on bash shell

I am running plsql using printf on a shell, but i am getting some strange error, can someone point what exactly am i missing,

$ echo $SHELL
/bin/bash  
$ printf "
> SET serveroutput ON trimspool on feed off echo off
> declare
> p_val number;
> d_val varchar2(10);
> begin
> SELECT ROUND((1- (free_mb / total_mb))*100) into p_val from v\$asm_diskgroup where name in (select substr(value,2,8) from v\$parameter where name = 'standby_archive_dest');
> select trim(value) into d_val from v\$parameter where name = 'db_create_file_dest';
> if p_val >= 95 then
> execute immediate 'alter system set standby_archive_dest = ''||d_val||'' scope=both';
> execute immediate 'alter system set log_archive_dest_2 = ''location = ''||d_val||'' valid_for=(''STANDBY_LOGFILE'',''ALL_ROLES'')'' scope=both';
> DBMS_OUTPUT.PUT_LINE('DISKGROUP_MODIFIED');
> else
> DBMS_OUTPUT.PUT_LINE('NO_ACTION');
> end if;
> end;
> /
> " | sqlplus -s / as sysdba
  declare
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 5

I am getting correct values for p_val & d_val as well. Thanks !

Regards
Kannan

Hi,

The first parameter of printf is a format parameter where certain characters have special meanings. Therefore it is best to not use data as the first parameter. So instead of

printf " ....
"

Use

printf '%s\n' " ...
"

Note that the double quotes still allow things like variable expansion (for example $var).

If you do not want that then use single quotes..

Use 
printf '%s\n' ' ...
'

That said a better option would be to use a so-called "here document"

sqlplus -s / as sysdba << EOF
SET serveroutput ON trimspool on feed off echo off
declare
...
EOF

Where EOF is an arbitrary word where the second occurrence needs to be on a line containing only that word.

If you want to avoid variable expansion, use quotes (single or double) around the first occurrence of the arbitrary word :

sqlplus -s / as sysdba << "EOF"
SET serveroutput ON trimspool on feed off echo off
declare
...
EOF