Oracle math functions - sql

I am trying to get a rounded value in Oracle (using SQL Developer) through following statement:
ROUND((1-POWER((SUM(D.PFY/100*E.OUT_8_)/SUM(E,OUT_8_)), (1/(SUM(PHOTO*E.OUT_8_)/SUM(E.OUT_8_)))))*1000000, 0) AS PFYPPM
However, I am getting an error as:
invalid number of arguments.
What is it that I am doing wrong?

Sometimes Oracle error messages are actually helpful.
invalid number of arguments
Check your function calls.
sum() takes only one argument.
SUM(E,OUT_8_)
should probably be
SUM(E.OUT_8_)

Related

Consistent Missing Right Parenthesis Error

I'm trying to right a query that checks if the value is a number and I keep getting a
ORA-00907: missing right parenthesis
error no matter what I do.
Even these queries return the error:
SELECT CAST(123456 AS NUMBER(1,0) DEFAULT -1 ON CONVERSION ERROR)
FROM ANY_TABLE_NAME
SELECT VALIDATE_CONVERSION('99' AS NUMBER)
FROM ANY_TABLE_NAME
Anything I can do to solve this?
I'm using Oracle SQL Developer version 20.2.1.175
VALIDATE_CONVERSION was not introduced until Oracle 12.2.
CAST also did not get the error handling extension until Oracle 12.2.
Therefore, if you are using Oracle 12.1 or earlier then those functions will not be valid.
For example:
They fail in Oracle 11g db<>fiddle
The work in Oracle 18g db<>fiddle
Note: this is the Oracle database version and not the version of SQL Developer, which is just a front-end user interface for accessing the database.
ORA-00907: missing right parenthesis
This error belongs to generic error messages, indicating one or more syntax errors.
How to debug ?
it means we have omitted a right bracket.
(to verify, you can use an editor which allows a "match bracket" control)
it means the compiler received an "out of context" keyword.
it means a misspelled word (i.e a missing comma, a space instead of an underscore,etc )
Your sinthax seems to be right.
You're (probably) facing an "out of context" keyword.

SQL errors only in Go-GORM Exec method

Has anyone dealt with handling database errors in GORM?
I have two cases in my code where I need to exploit a database error: constraint or UUID validation.
(e.g. SQL Error [8169] [S0002]: Conversion failed when converting from a character string to uniqueidentifier.)
When I use the GORM model-find or raw-scan methods, I get the expected results in positive run, but in negative run result.error doesn’t include a SQL error (result.Error is nil), e.g. when I try to insert against a constraint or get with nonvalid UUID. I get this error in the SQL console with the same query.
On the other hand, when I use exec (also sql.Exec), I get an adequate error on a negative run, but the result of the positive run does not contain (or I can’t find) the expected value.
Does anybody have an idea?

how to use common function in query expression?

I want to use the "split" function in a simple query on my SSRS 2008 report. However, I get an error "Query execution failed for dataset "SlsmRealNum". "Split" is not a recognized built-in function name". But it's listed as a common function (text) if I open up the Expression box on the query, so not sure why it's failing?
my simple select statement is:
select slsm_num, slsm_msid from Salesman where slsm_msid = split(User.UserID,"\").GetValue(1)
right now to get the report to work, I have one parameter (SlsmnNum) that has the Split expression in it (to get the MSID of the user) and then a 2nd parameter that uses the above query in the Dataset Salesrepum using the #SlsmnNum parameter as the MSID. I'd like to not have to have 2 parapmeters if possible and just get the actualy salesrep # in just one. Any help is greatly appreciated!
Your select statement is executed as SQL so the error you are getting is actually from SQL server. This may be where you are getting confused.
There are two components to SSRS - SQL Statements and Report Expressions. Typically, SQL statements are used to generate datasets by querying the database. Report expressions are used to organize, aggregate, and filter the dataset once obtained from the SQL database. Since the SQL statement is executed IN the SQL database, only the functions that are in the database are available. The code you posted is a SQL statement not a Report Expression.
For example, you can't take a Report Expression and expect it to work in SSMS? No, because they are two different entities with wholly different syntax and purpose. When it comes to using built-in SSRS functions inside a SQL statement it will not work, the database has no concept of what the built in User.UserId is and as such you must use a parameter to transport the value over to the SQL query. This is definition and purpose of a parameter and why they exist.
Split is a function in SSRS which is why you see it in your expression reference, however, it is not a function in SQL. The code you posted is SQL syntax, so I am betting that this is the SQL statement that you are using to obtain your dataset. Therefore the query fails since the SQL DB does not have a Split Function.
You can add this split function to your database and the code is located here: Split String in SQL. You could also use something along the following in your where clause, the following is your updated SQL statement.
SELECT slsm_num, slsm_msid from Salesman where slsm_msid = SUBSTRING(#UserId, PATINDEX('%\%', #UserId), LEN(#UserId))
You would set the #UserId parameter's value to an expression of User!UserID rather than specifying it in your select statement.
The SSRS expression examples have a function similar to what your code is trying to accomplish if you were wanting the same thing in the report side. The function you are looking for is InStr(). On your report side you could use something along the lines of:
=Parameters!User.Value.Substring(Parameters!User.Value.IndexOf("\")+1, Parameters!User.Value.Length-Parameters!User.Value.IndexOf("\")-1)
Expression examples can be found here: MSDN Expression examples.

sql data type error when dividing two figures

I have a simple query which states
convert(decimal(20,10),a.sumclk)/ nullif(convert(decimal(20,10),a.sumimp),0) as CTR1
When I run this I get a message saying 'Data Type "sumclk" does not match a Defined Type name.'
I looked around for what this means but I'm stuck
I'm using Teradata
Instead of convert(decimal(20,10),a.sumclk) (which is MSSQL), try CAST(a.sumclk as decimal(20,10)) (which I found on the Teradata forums: http://forums.teradata.com/forum/database/explicit-casting)

Returned ref cursor not supported

I'm trying to make a chart in a database dashboard reporting software(Logi Info). I've got a PL SQL package that returns a ref cursor with multiple values but it seems the Logi Info does not support this and gives me an error ORA-00904: "DASHBOARD_PACKAGE"."GETSUMMARYDATA": invalid identifier. I think its either not supported or that my querty is wrong. This is my query:
select dashboard_package.getSummaryData(1,sysdate) from dual
Is that how to call a function that returns multiple values? if so, is there a solution to this problem (return type not supported)?
This is a compilation error. Your GETSUMMARYDATA() function is referencing an invalid object name, a table, a column or whatever. If you're using dynamic SQL you won't get this compilation error until runtime.
So, you need to code through the source of your function and find the misnamed thing. The line number which goes with the error message should help you here.
If you are using SQL*Plus, you need to use a special syntax in order to access REF CURSORS.
This is well explained in the SQL*Plus manual:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch5.htm#sthref1127
So it would be something like this in your case:
VARIABLE cv REFCURSOR
EXECUTE dashboard_package.getSummaryData(1, sysdate, :cv)
print cv
Note that the position of the :cv variable depends on the definition of your procedure.
But as you did not show us the source code...
Edit
To cover all possibilies (as mentioned by APC):
If the function indeed returns a ref cursor, then the syntax is slightly different as explained in the next chapter of the manual:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch5.htm#sthref1128
VARIABLE cv REFCURSOR
execute :cv := dashboard_package.getSummaryData(1, sysdate);
print cv