A function defined in a relational database system. Most RDBS's include numerous built-in functions and also allow for the creation of additional custom functions.
Questions tagged [sql-function]
908 questions
2
votes
2 answers
Using Input of Snowflake Function as the From clause
I have a function that takes a list of inputs to draft a query, it is dynamic SQL but not complex in any way the inputs directly pass through to the from and select clauses. In Snowflake, I cannot get it to allow me to use the name of the input as…

Holt
- 41
- 1
- 4
2
votes
1 answer
ORACLE SQL How to use custom function iside insert cte
I am trying to use function inside insert SQL, but I am getting error ORA-32034. Looks like that I couldn't access this function in the cte.
Maybe someone can help?
insert into table1 (
Field1,
Field2,
Field3
)
with…

Erlica
- 55
- 4
2
votes
1 answer
Create function that returns a "SELECT" statement result
I was told to create a mysql function that, given the artwork title, return the name of the creator. I know it sounds silly, i could use just a select.
I followed some tutorials, but none of them helped me. When I try to create the function, mysql…

joaomrossetto
- 21
- 2
2
votes
2 answers
How to parse JSON string recursively with openjson
I have the following JSON data :
set @json = N'{
"Book":{
"IssueDate":"02-15-2019"
, "Detail":{
"Type":"Any Type"
, "Author":{
"Name":"Annie"
, "Sex":"Female"
}
…

Annie
- 139
- 14
2
votes
3 answers
How convert string to array on SQL
In a column I have "1;2;3;6-9"
I need make this string in a array like this (1,2,3,6,7,8,9)
select range from my_table
return
| range |
|-----------|
| 1;2;3;6-9 |
I need run
select id from my_another_table where id in("1;2;3;6-9")
| id…

thiaguerd
- 807
- 1
- 7
- 16
2
votes
1 answer
Function to insert data into different tables
I have three tables in PostgreSQL:
CREATE TABLE organization (id int, name text, parent_id int);
CREATE TABLE staff (id int, name text, family text, organization_id int);
CREATE TABLE clock(id int, staff_id int, Date date, Time time);
I need a…

Reza
- 113
- 2
- 11
2
votes
3 answers
Use Output of Oracle SQL Function in WHERE condition of SQL query
I wrote a Oracle SQL Function that will return EMP IDs in the following format.
Query: select CUSFNC_GETEMPID('HIGH-RATED') from dual;
Output: ('1436','1444','1234')
I want to use this Output in SQL Query as follows:
SELECT ID, NAME, SAL
FROM…

Upendhar Singirikonda
- 179
- 14
2
votes
1 answer
How can I return an additional column of a table without having to repeat all column names and types in the return definition?
I have table with a lot of columns. I want to create a function which returns all these column, with an additional column. Is there a way to do this type-safe (that is, without returning a record) without having to repeat all column names and…

Katrin
- 125
- 4
2
votes
2 answers
Create function in postgresql to update column values from a table with preferred values and aliases
I want to create a function that will update a column of type varchar to a preferred string that is referenced in the column of another table to help me clean this column more iteratively.
CREATE TABLE big_table (
mn_uid NUMERIC PRIMARY KEY,
…

nmsindt
- 21
- 1
- 2
2
votes
0 answers
How to find 50th percentile in postgres for date and time field?
How to find the 50th percentile date and time filed for example from below set in PostgreSQL
file_time
8/14/18 2:57:38
8/14/18 2:56:59
8/14/18 2:54:43
8/14/18 2:54:27
8/14/18 2:54:16
8/14/18 2:53:42
8/14/18 2:53:26
8/14/18 2:53:20
8/14/18…

Madhu
- 367
- 2
- 7
- 20
2
votes
1 answer
set date from one year of getdate ()?
I got a DECLARE statement like this
DECLARE ,@ACTIVATE DATETIME,
@DEACTIVATE DATETIME
I want to set the Activate date as today's date, which is
SET @ACTIVATE = GETDATE()
I want to set the @DEACTIVATE date to one year from the Activate…

Karamzov
- 343
- 1
- 4
- 12
2
votes
0 answers
Oracle: Extract WITH clause Subqueries into Chained Functions Pipelined; Efficiency Comparison
Have legacy complex SQL script in form of
WITH
A AS (......),
B AS (......),
C AS (......),
...
SELECT ... FROM
A
LEFT JOIN B
LEFT JOIN C
LEFT JOIN ...
ON ....
Trying to extract the SUB_QA, SUB_QB ... into functions,…

Stochastika
- 305
- 1
- 2
- 14
2
votes
1 answer
Error in MySQL function with parameters
I have MySQL function with 2 parameters namely user_id and post_id
Here's my function:
CREATE FUNCTION isliked(pid INT, uid INT)
RETURN TABLE
AS
RETURN (EXISTS (SELECT 1 FROM likedata ld WHERE post_id = pid AND user_id = uid
)) as…

Purge Project
- 39
- 5
2
votes
1 answer
sql function parameter in function return value
sql view in how can I return the return value from the function into the function
select
dbo.fn_CalculatePrice
(
p.Price,
p.CargoPrice,
p.Factor,
p.PointRatio,
null,
p.OperactivePromoCode,
SELECT IncludingCargoPrice FROM…

seleyemene
- 23
- 5
2
votes
3 answers
Is there a function equivalent to Hive's 'explode' function in Apache Impala?
Hive's function explode is documented here
It is essentially a very practical function that generates many rows from a single one. Its basic version takes a column whose value is an array of values and produces a copy of the same row for each of…

Mateo
- 1,494
- 1
- 18
- 27