Home > Net >  sqlplus - No characters are allowed after a here-string header but before the end of the line
sqlplus - No characters are allowed after a here-string header but before the end of the line

Time:01-11

I'm trying to use sqlplus to do an Oracle query for the first time in a PowerShell script. I get this error message:

At line:1 char:73
  ... user/[email protected]:1521/RRRPRDC @"C:\Users\ ...
                                                                  ~
No characters are allowed after a here-string header but before the end of the line.

It seems to be pointing to the C: after @". Any ideas? I seem to be doing what is at this example. I get the same error when I try to do echoargs of the connection info.

This is my powershell code I am testing at the command line since it hangs forever running the program:

sqlplus user/[email protected]:1521/RRRPRDC @"C:\Users\me\Documents\2021\temp endToEnd\short.sql"

This is using powershell 5.1. Any ideas? I see here string header, but since I am following the example that was accepted in the link for sqlplus above, it's unclear to me what's wrong with it.

CodePudding user response:

Replace

@"C:\Users\me\Documents\2021\temp endToEnd\short.sql"

with any of the following:

  • `@"C:\Users\me\Documents\2021\temp endToEnd\short.sql"
  • "@C:\Users\me\Documents\2021\temp endToEnd\short.sql"
  • '@C:\Users\me\Documents\2021\temp endToEnd\short.sql'

Note: Using a verbatim (single-quoted) string ('...') is arguably the best choice here, given that the path contains no variable references; if it did, a expandable (double-quoted) string ("...") would be equired.

All variations end up passing the following string verbatim to sqlplus, which I presume is your intent:

@C:\Users\me\Documents\2021\temp endToEnd\short.sql


Presumably, you're trying to pass @ as a verbatim part of an argument to sqlplus - a common convention among CLIs is to use @<file-path> to request that argument data be taken from a file rather than using the argument value itself.

However, unlike in other shells, @ is a metacharacter in PowerShell that serves a variety of purposes.

Thus, a @ that should be a verbatim character at the start of an argument must either be escaped (with `) or part of a quoted string, as shown above. See the conceptual about_Special_Characters help topic.

If an unescaped argument-initial @ is followed by " or ', PowerShell thinks you're trying to create a here-string, which has special, multi-line syntax requirements; the error message indicates that they're not met.

  •  Tags:  
  • Related