Error in SQL-Oracle Code when raising value to the nth power - Need assistance - sql

I'm running SQL code within Oracle and need help revising the below "Update" script. The below script gives me the error “missing equal sign” due to the " ^ " in the last line of the code that is meant to take the Table-B.ValueY value to the Table-A.ValueZ power. I tried changing the last line to a Power (x,y) formula, but that gives me "%s: invalid identifier" error. I also went so far as to change the code completely into a CREATE TABLE, but that just appears be caught in a loop and never finishes.
Any help is much appreciated.
Original code:
UPDATE Table-A
SET Column-X = 0
WHERE
TABLE-A.mid = TABLE-B.mid AND
TABLE-A.tdlinx = TABLE-B.tdlinx AND
TABLE-B.ValueY ^ TABLE-A.ValueZ > 0.1;

there is a POWER function
SELECT POWER(10,2) FROM DUAL;
yours should look similar to this:
POWER( TABLE-B.ValueY, TABLE-A.ValueZ ) > 0.1

Related

How to split a large query in command line?

I installed oracle db version 19c in my docker environment and set up a database filled with dummy data. However, when I try to run a very large query I get the error:
SP2-0341: line overflow during variable substitution (>3000 characters at line 1).
I tried splitting it up with linebreaks but depending on how I split it I get all kinds of errors like:
ERROR at line 2: ORA-00933: SQL command not properly ended
or
ERROR at line 2:
SP2-0341: line overflow during variable substitution (>3000 characters at line 3)
The query is formatted as
SELECT AA.n_name AS AA_n_name, AA.n_nationkey AS ...
FROM nation AS AA FULL OUTER JOIN supplier...
WHERE (AC.p_partkey = ... AND...) OR((AC.p_partkey = ...)); -- The where part is over 5000 characters long--
Is there an alternative or solution to tackling this in the command line? I tried running the query as a sql file as well and hit a 4999 limit. I am on a Ubuntu server if that would help and any assistance would be appreciated.
It depends on the environment that you're working in, but generally you are able to continue a command onto the next line by ending the line with a 'back slash' \.

Kmodes function Error in x[[jj]][iseq] <- vjj : replacement has length zero

I got this error when using a big data set, I cleaned the data and used Data<-na.omit(Data) to delete all rows with nulls, it worked and in RStudio I don't get any errors.
When I run the script in SQL as an external script I get the same error as before
Error in x[[jj]][iseq] <- vjj : replacement has length zero
even though I'm using the same Rscript and dataset is the same.
Has anyone had the same issue and how did you solve it.
thanks

Is it possible to assign a value to already declared variable in NuoDB

Is it possible to assign a value to a variable in NuoDB after the variable is created.
I've tried:
VAR $test string;
$test = 'test';
But it says:
[Code: -1, SQL State: 42000] syntax error on line 1
$test = 'test'
^ expected statement got $test
According to their examples "Example 2: Redefining variables within a stored procedure"
"A variable cannot be redefined, using the same name, within the same
scope or code block."
Wasn't able to find anything else regarding the variables in the docs. But something might have slipped out from me..
And moreover, it's incredible to have a variable without an opportunity to change it's value! Sounds like a nonsense.
Thanks in advance.
From the error message, I suspect that you simply need to change the DELIMITER.
Try:
SQL> set delimiter #
Delimiter is now [#]
SQL> var $test string;
> $test = 'abc';
> select $test from dual#
$TEST
------
abc
SQL>
Cheers!
Nik
eventually found that the problem was in the way I've been launching the script.
It was so silly of me... It was just because of the way I've been launching script. There were 3 buttons, to execute a query in a certain way, but the one I've used was just to execute a line under current position of a cursor.. Seems it has been trying to launch a separate line but not all the query. I've just tried a shortcut and it had gone well.
Thus, as a matter of fact, it was no problem with the code, but just with crooked hands =)

Bigquery Command Line Query with ">" not working

Initially took me a while to figure out that ">" causes an issue in cmd and learned from one of the answers that escaping with ^ works. So after changing my query to below format it works fine.
bq query --use_legacy_sql=false --destination_table= (SELECT * FROM `dataset_ID.table_nm` GROUP BY AAA HAVING SUM(BBB)^>0 )
But now I am trying to run the same query through a file.
bq query --use_legacy_sql=false --destination_table= --flagfile="Y:query.sql"
However above it gives me an error if I have "^>".
Error in query string: Error processing job Syntax error: Unexpected ">" at [1:227]
If I don't have "^" in front of the ">" the query doesn't return an error but the result is empty..
Hoping someone could help out with the issue above.
Thanks!

Print only nonzero results using AMPL + Neos server

I'm doing a optimization model of a relatively big model. I will use 15 timesteps in this model, but now when I'm testing it I am only using 4. However, even with 11 time steps less than desired the model still prints 22 000 rows of variables, where perhaps merely a hundred differs from 0.
Does anyone see a way past this? I.e. a way using NEOS server to only print the variable name and corresponding value if it is higher than 0.
What I've tested is:
solve;
option omit_zero_rows 0; (also tried 1;)
display _varname, _var;
Using both omit_zero_rows 0; or omit_zero_rows 1; still prints every result, and not those higher than 0.
I've also tried:
solve;
if _var > 0 then {
display _varname, _var;
}
but it gave me syntax error. Both (or really, the three) variants were tested in the .run file I use for NEOS server.
I'm posting a solution to this issue, as I believe that this is an issue more people will stumble upon. Basically, in order to print only non-zero values using NEOS Server write your command file (.run file) as:
solve;
display {j in 1.._nvars: _var[j] > 0} (_varname[j], _var[j]);