fork download
  1. #!/bin/bash
  2.  
  3. sqlplus () {
  4. echo 'This is the input which sqlplus receives'
  5. nl
  6. echo 'End of sqlplus'
  7. echo result
  8. }
  9.  
  10. echo '** Not working'
  11.  
  12. sqlplus "${DBAdminUser}/${DBAdminPassword}@(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = ${DBServerName})(PORT = ${DBServerPort}))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = ${ServiceName})))"<<EOF
  13. -- =======================================================
  14.  
  15. spool File_`date +%d_%m_%y`.csv REPLACE
  16. result=$(echo 'select SP_CREATION_TIME from shared_space where SP_CREATION_TIME like '%20-AUG-20' ');
  17. spool off
  18. EOF
  19. echo ==============================================================
  20. echo Printing the results
  21. echo ==============================================================
  22. echo "$result"
  23. echo =============================================================
  24.  
  25. echo
  26. echo '** ... ^^ notice also how "result" is printed when sql runs, not when you echo "$result"'
  27. echo
  28.  
  29. echo
  30. echo '** Working'
  31.  
  32. result=$(sqlplus "${DBAdminUser}/${DBAdminPassword}@(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = ${DBServerName})(PORT = ${DBServerPort}))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = ${ServiceName})))"<<EOF
  33. -- =======================================================
  34.  
  35. spool File_`date +%d_%m_%y`.csv REPLACE
  36. select SP_CREATION_TIME from shared_space where SP_CREATION_TIME like '%20-AUG-20;
  37. spool off
  38. EOF
  39. )
  40. echo ==============================================================
  41. echo Printing the results
  42. echo ==============================================================
  43. echo "$result"
  44. echo =============================================================
  45.  
  46.  
Success #stdin #stdout 0s 4556KB
stdin
Standard input is empty
stdout
** Not working
This is the input which sqlplus receives
     1	-- =======================================================  
       
     2	spool File_07_10_20.csv REPLACE     
     3	result=select SP_CREATION_TIME from shared_space where SP_CREATION_TIME like %20-AUG-20 ;  
     4	spool off  
End of sqlplus
result
==============================================================
Printing the results
==============================================================

=============================================================

** ... ^^ notice also how "result" is printed when sql runs, not when you echo "$result"


** Working
==============================================================
Printing the results
==============================================================
This is the input which sqlplus receives
     1	-- =======================================================  
       
     2	spool File_07_10_20.csv REPLACE     
     3	select SP_CREATION_TIME from shared_space where SP_CREATION_TIME like '%20-AUG-20;
     4	spool off  
End of sqlplus
result
=============================================================