sql-function

SQL date format convert? [dd.mm.yy to YYYY-MM-DD]

半城伤御伤魂 提交于 2019-12-28 04:08:50
问题 is there mySQL function to convert a date from format dd.mm.yy to YYYY-MM-DD? for example, 03.09.13 -> 2013-09-03 . 回答1: Since your input is a string in the form 03.09.13 , I'll assume (since today is September 3, 2013) that it's dd.mm.yy . You can convert it to a date using STR_TO_DATE: STR_TO_DATE(myVal, '%d.%m.%y') Then you can format it back to a string using DATE_FORMAT: DATE_FORMAT(STR_TO_DATE(myVal, '%d.%m.%y'), '%Y-%m-%d') Note that the year is %y (lowercase "y") in STR_TO_DATE and %Y

Calling a procedure inside a function throws MySQL ERROR 1422

风格不统一 提交于 2019-12-25 16:44:10
问题 I am building a "bank" as an assignment for a database course I am taking. I have created a stored function which takes a few IN variables, such as account ID, customer ID and a PIN number, and does checks on this to see if the submitted data is valid. If the data is valid, the procedure updates the account balance to represent a monetary transaction. It then "returns" whether or not the submitted data was valid. Here is the code for the procedure: DELIMITER // CREATE PROCEDURE retrieveMoney

Calling a procedure inside a function throws MySQL ERROR 1422

青春壹個敷衍的年華 提交于 2019-12-25 16:43:04
问题 I am building a "bank" as an assignment for a database course I am taking. I have created a stored function which takes a few IN variables, such as account ID, customer ID and a PIN number, and does checks on this to see if the submitted data is valid. If the data is valid, the procedure updates the account balance to represent a monetary transaction. It then "returns" whether or not the submitted data was valid. Here is the code for the procedure: DELIMITER // CREATE PROCEDURE retrieveMoney

Postgresql: ERROR: structure of query does not match function result type Using DbLink

时光怂恿深爱的人放手 提交于 2019-12-25 03:24:39
问题 So I wrote this method that aims at querying to another remote database with the same structure using dblink (inspired from this post Specify dblink column definition list from a local existing type and this one Refactor a PL/pgSQL function to return the output of various SELECT queries) CREATE OR REPLACE FUNCTION select_remote(_table anyelement) RETURNS SETOF anyelement AS $func$ DECLARE _dblink_schema text; _cols text; _server text := 'host=ngrok.com port=45790 user=postgres password

Improving complete sql query in stored proc

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 09:39:55
问题 I have a stored proc that is used to populate a dashboard like grid in WPF. I've refined the query over time, and to be honest, the performance could be better. I'm at the point now that I do not know any good ways to improve the query where I can gain performance with the time it takes to execute. Any help would be greatly appreciated. Below is the stored proc: ALTER PROCEDURE [dbo].[spGetDashboardMainNew] AS BEGIN SET NOCOUNT ON; SELECT JC.job_number AS SalesOrder, dbo.cust.Company AS

SQL Server: How to execute UPDATE from within recursive function?

会有一股神秘感。 提交于 2019-12-24 01:25:54
问题 I have a recursive scalar function that needs to update a record in another table based on the value it is returning, however UPDATE statements are not allowed in the function. How can I update the table from within the function? 回答1: UPDATE statements are not allowed in the function That's the rule - functions are not allowed to have any data-changing side-affects. You have to use a Stored Procedure to UPDATE . 来源: https://stackoverflow.com/questions/3805250/sql-server-how-to-execute-update

Executing Oracle Functions using Spring jdbc

柔情痞子 提交于 2019-12-23 21:46:07
问题 I am trying to execute Oracle function using Spring jdbc. But I am getting below error CallableStatementCallback; bad SQL grammar [{? = call RATELIMIT_OWN.GET_LOGS(?, ?)}]; nested exception is java.sql.SQLException: ORA-06550: line 1, column 24: PLS-00653: aggregate/table functions are not allowed in PL/SQL scope ORA-06550: line 1, column 13: PLS-00382: expression is of wrong type ORA-06550: line 1, column 7: PL/SQL: Statement ignored Sql Function CREATE OR REPLACE FUNCTION RATELIMIT_OWN.Get

Create SQL function referring to a table or column that does not exist (yet)

故事扮演 提交于 2019-12-22 18:33:39
问题 I want to load some SQL functions in a empty database through psql: psql -d my_database -f fuctions.sql --set ON_ERROR_STOP=1 I use --set ON_ERROR_STOP=1 because I want that psql fails if the script contains errors. The content of functions.sql is: CREATE or REPLACE FUNCTION test_function() RETURNS INT AS $$ SELECT id from test_table; $$ LANGUAGE sql; My problem is, that psql checks if test_table exists when loading function and fails with this error: ERROR: relation "test_table" does not

divide the value of a column by another column

坚强是说给别人听的谎言 提交于 2019-12-22 14:57:08
问题 I want to divide a value of a column by the value of another column and display the result as separate column ex: project name total-percent no.of screen ------------ -------------- ------------- pro-1 150 5 pro-2 50 3 now i want to divide total-percent by no.of screen and display the result in another column 回答1: Select total_percent / no_of_scren as 'result' From yourTableName 来源: https://stackoverflow.com/questions/8257106/divide-the-value-of-a-column-by-another-column

What is the difference between a prepared statement and a SQL or PL/pgSQL function, in terms of their purposes?

偶尔善良 提交于 2019-12-22 04:44:26
问题 In PostgreSQL, what is the difference between a prepared statement and a SQL or PL/pgSQL function, in terms of their purposes, advantages and disadvantages? When shall we use which? In this very simple example, do they work the same, correct? CREATE TABLE foo (id INT, name VARCHAR(80)); CREATE FUNCTION myfunc1(INT, VARCHAR(80)) RETURNS void AS ' INSERT INTO foo VALUES ($1, $2); ' LANGUAGE SQL; SELECT myfunc1(3, 'ben'); CREATE FUNCTION myfunc2(INT, VARCHAR(80)) RETURNS void AS ' BEGIN INSERT