Insert new line after semicolon in SQL* Plus - sqlplus

I want to run an insert script in SQL Plus on a table in which the value has a new line after semicolon. I'm able to insert new lines using command
SET SQLBLANKLINES ON
But when I try to insert a string which has a new line after a semicolon, it gives error
ORA-01756: quoted string not properly terminated
and
unknown command beginning "Bye;',..." - rest of line ignored.
when I try to insert like this
INSERT INTO M_TABLE VALUES('Hi!
My Name is Tom;
Bye', 0)

SQL*Plus is interpreting the semicolon as a statement terminator.
You can change that to another character, or temporarily stop it being recognised via the client settings:
set sqlterminator off
INSERT INTO M_TABLE VALUES('Hi!
My Name is Tom;
Bye', 0)
/
set sqlterminator on
The overall insert statement now has to be ended and submitted with a slash on a new line, since just sticking a semicolon on the end now won't be recognised.

Related

code blocks don't work in Spyder (Anaconda3)

I am a beginner in Python using Spyder to code from Anaconda3.
I tried to enter such codes in Spyder (Python 3.7). I pressed "Enter" when trying to split the codes and the indents appear auto. But it always returns with "SyntaxError: invalid syntax" and "SyntaxError: 'return' outside function".
E.g. 1
data = {'state':['Ohio','Ohio','Ohio','Nevada','Nevada','Nevada'],
'year':[2000,2001,2002,2001,2002,2003],
'pop':[1.5,1.7,3.6,2.4,2.9,3.2]}
When I press F9 in either line, it returns "SyntaxError: invalid syntax".
E.g. 2
def f(x):
return pd.Series([x.min(),x.max()],index=['min','max'])
Press F9 to run the line, it returns "SyntaxError: unexpected EOF while parsing". If in the second line, it returns "SyntaxError: 'return' outside function".
In addition, I also tried to put "\"s at the end of each line. It doesn't work either. And find from webpages that if the lines end with : or , then you don't need \ to split.
But!!! if I deleted the 'Enters' and put everything in a single line without splits, it works well totally.
Why my python cannot work with code blocks? How can I fix it with Anaconda3?
Thank you so much~~~~
The problem is that you need to select the entire function before pressing F9, if you select only a part of it it will raise an error
You can use \ at the end of each line to tell Python that the line continues below:
data = {\
'state':['Ohio','Ohio','Ohio','Nevada','Nevada','Nevada'],\
'year':[2000,2001,2002,2001,2002,2003],\
'pop':[1.5,1.7,3.6,2.4,2.9,3.2]\
}
Having the dictionary split across multiple lines may look pretty, but it is not proper syntax. I've also been tripped up by tutorials that show their dictionaries like that :|
This may not work in interpreters other than IDLE.

How do I execute a SQL script using a bind variable

I'm running Oracle 18.c on a Windows 10 platform.
I have a large DOS script which calls SQL Plus to run the first SQL script, passing a parameter to it.
The parameter is successfully passed to the first SQL script. In that SQL script I'm trying to append some text to the passed parameter so that it can call a second script using the "#" feature.
DOS Script test1.bat
#echo off
SET value1=2020_01_19_17_00_01
sqlplus my_username/my_password#my_TNS as sysdba #C:\Backups\test1.sql %value1%
SQL Script test1.sql
SET SERVEROUTPUT ON
variable param1 varchar2(512);
variable full_file_name varchar2(512);
BEGIN
:param1 := '&&1';
dbms_output.put_line('The value of the passed parameter is: ' || :param1);
:full_file_name := :param1 || '_f104.sql';
dbms_output.put_line('The new filename would be: ' || :full_file_name);
#:full_file_name;
END;
/
I'm having problems getting the value in :full_file_name to execute from the test1.sql script. If a variable were not involved I would simply use the line #2020_01_19_17_00_01_f104.sql
How do I go about getting the script file whose name is stored in :full_file_name to execute?
I found a way to do this. My sql script now looks like:
Define ffn104 = '&&1._f104.sql'
#&ffn104
exit
Note that in the Define statement I had to put a period after the passed variable &&1 to end its definition. Then I appended _f104.sql.
That solved the problem.

Got the error when use LUA script to query a list

when I use Lua script to query a list, I got the correctly result if the list is not empty. But got error if the list is empty.
Blow is my script:
const char * sLuaQueryServers = "local key_list = redis.call('KEYS',
KEYS[1]); return(redis.call('MGET', unpack(key_list)))";
I passed the "serverlist:*" as the key, it's successfully returned the server in list.
But if there no server in redis, I got below error:
ERR Error running script (call to
f_88620231033e13635dc3181f2947a740f91012dc): #user_script:1: #user_script:
1: Wrong number of args calling Redis command From Lua script
"
Please help.
To your question, add a check that the list isn't empty before calling MGET, e.g.:
local key_list = redis.call('KEYS', KEYS[1])
if #key_list > 0 then
return(redis.call('MGET', unpack(key_list)))
else
return nil
end
Note #1: no need for semicolons in Lua
Note #2: Using KEYS isn't recommended for anything, except debugging
Note #3: You're using the KEYS table to pass an argument, but since your script is running KEYS (the command) that's really a moot point

Error while creating a simple DB2 sql procedure

I am trying to create a db2 procedure on DB2 z/OS 10.1.5. The code I am using is :
CREATE PROCEDURE WSDIWW16.CALCULATE_SALARY()
LANGUAGE SQL
BEGIN ATOMIC
update wsdiww16.emptable
set dailywage = dailywage * 30;
END;
I am getting sqlcode - 104
SQL0104N An unexpected token "<END-OF-STATEMENT>" was found following "".
Expected tokens may include: "DECLARE".
I haven't created an sql procedure earlier. Can somebody please help ?
You've got two semicolons in that CREATE statement. The first one needs to be a different character that's recognized as a statement terminator.
What development environment are you using? In Rational Developer for z, you can right-click the editor and select the Set Statement Terminator option:
1
Similar options should be available in Data Studio, etc.
You should use end line terminator such as '/' and execute your query using below command -
db2 +c -td/ -vf SQL_file_name
HTH
The answer with the graphical menu worked for me. From inside my SQL script I did a right click anywhere in the white space. The menu above then appeared. I then left clicked on "Set Statement Terminator" (as requested). I then changed my terminator character to "#" (no quote marks). After that the semicolon character ";" started working again.
I hope this helps.
I believe you need to end your procedures with a '/'.

Rhino: Retrieving the Line No and Column No

I am running my own proxy objects which extend org.mozilla.javascript.ScriptableObject.
I also have my own functions which extend org.mozilla.javascript.Function.
My desire is to have any exceptions thrown here return the line no and if possible the column number where they occurred in the evaluated script. Is this possible? I only have access to the context and the scope.
Whenever an exception is thrown from a script, Rhino throws RhinoException which already has line and column number (and more). However when you execute the script you need to provide the line number that will be used by Rhino as the starting line number. The actual line number of where the exception/error occurred will be relative to this number. So something line this:
//-- Define a simple test script to test if things are working or not.
String testScript = "function simpleJavascriptFunction() {" +
" this line has syntax error." +
"}" +
"simpleJavascriptFunction();";
//-- Compile the test script.
Script compiledScript = Context.getCurrentContext().compileString(testScript, "My Test Script", 2, null);
//-- Execute the test script.
compiledScript.exec(Context.getCurrentContext(), anyJavascriptScope);
In the above code, the starting line number is set to 2 (third parameter of the call to compileString()). When this is executed, Rhino will throw a RhinoException that will have the lineNumber property set to the value '3' (the first line is treated as the second line b/c we passed 2).
Hope this helps.

Resources