1

Sequel from this question

define a='eee"dd'
prompt &a                       -- eee"dd OK
host powershell.exe echo '&a';  -- eeedd  not OK
host powershell.exe echo &a;    -- eeedd  not OK

As you can see, I can't print a stirng with a quotation quote in powershell from sql plus. Is there a way to do that.?


I've tried the solution of Alex Poole when the value comes from a query.But it's not working if there is more than one quotation string.

column a new_value a 
select replace('eee"d"d', '"', '""') as a from dual;

prompt &a                      -- eee""d""d  Ok as expected
host powershell.exe echo '"&a"'-- eee"dd instead of eee"d"d

2 Answers2

1

It seems to work if you escape the quote (for PowerShell's benefit) by using "" within the value, and use both types of quotes, for both PowerShell's and SQL*Plus's benefit:

SQL> define a='eee""dd'
SQL> host powershell.exe echo '"&a"'
eee"dd

If you are actually populating the a variable from a query, as in your previous questions, then you can replace() quotes with:

column a new_value a
select replace('eee"dd', '"', '""') as a from dual;
Alex Poole
  • 183,384
  • 11
  • 179
  • 318
  • thanks for your answer. I's not working if I use more than one quotation quote. I've given a exemple in my question. – Pierre-olivier Gendraud Jun 07 '22 at 09:00
  • 1
    That seems to be a PowerShell issue... from the command line, one of their sample strings `"As they say, ""live and learn."""` works, but not with anything between the 'real' closing quote and the string-ending quote, even a space, e.g. `"As they say, ""live and learn."" "`. – Alex Poole Jun 07 '22 at 09:09
  • 1
    _Without_ `cmd.exe` in the picture, the robust way to escape `"` chars. for the PowerShell CLI with the (possibly implied) `-Command` parameter is to use `\"`. _With_ `cmd.exe` in the picture, this may break _situationally_, and the workaround depends on the edition of PowerShell you use - see [this answer](https://stackoverflow.com/a/49060341/45375). – mklement0 Jun 08 '22 at 01:03
1
column a new_value a
select replace('eee"d"d', '"', '\"') as a from dual;
host powershell.exe echo '&a'

works for me