stored-functions

Is there any way to keep a track of rows inserted by a oracle function in database

自古美人都是妖i 提交于 2019-12-12 04:32:03
问题 I have a procedure to update the balance from start date to end date and also I want to keep a track of number of records being inserted . I am using dbms_output.put_line to get the number of records inserted but it does not give any output , when the execution completes then the output of the count is being displayed. The code of procedure is as follows : create or replace function updatebal(start_date IN DATE, end_date IN DATE) RETURN NUMBER IS difference number; curr_r number; BEGIN

Error: ORA - 47410: Realm violation for GRANT on SOME ROLE

隐身守侯 提交于 2019-12-11 15:14:18
问题 I have created a function (CREATINGUSER) in a schema (OWNER) with the scope, among others, of creating users and also granting specific rights (for example CONNECT, etc.). I have another schema (SLAVE) which has execute right to OWNER.CREATINGUSER. If I call OWNER.CREATINGUSER from SLAVE, I'm getting some error for role granting ORA -47410: Realm violation for GRANT on ROLENAME . Moreover if I call OWNER.CREATINGUSER from OWNER everything runs smoothly. Please help me with some advice on how

sql server 2005 convert time to minutes [duplicate]

时光怂恿深爱的人放手 提交于 2019-12-11 06:34:07
问题 This question already has answers here : datetime to totalminute in sql (3 answers) Closed 4 years ago . I have a few date time functions within my database, but I need to add one that takes the time portion of a datetime field and then converts the time into minutes I have a function that get the minutes between two times, but not just the minutes of a single time. ALTER FUNCTION [dbo].[fn_MinutesBetween] ( @fStart datetime, @fEnd datetime ) RETURNS int AS BEGIN RETURN DateDiff(minute,

How to get the dimension of a DECLAREd variable in SPs?

…衆ロ難τιáo~ 提交于 2019-12-11 06:31:30
问题 Suppose I declared some variables in SPs. DECLARE _R1 VARCHAR(25); DECLARE _R2 DECIMAL(4,0); DECLARE _R3 DECIMAL(3,0); DECLARE _R4 DECIMAL(2,0); How do I get their dimensions like 25, 4, 3, 2? 回答1: One option is to create a really long value. Than put in the variable, and run the length() function on it. As it will keep only as much value as the definition says it returns the correct length. Now remains to find out how to do this without affecting the current value. SET _R1=LPAD('',1000,1);

SELECT…INTO returns null in Stored Procedure

三世轮回 提交于 2019-12-11 02:15:15
问题 This function: CREATE FUNCTION `GetCardID`(numId INT) RETURNS int(11) DETERMINISTIC BEGIN DECLARE retcard INT(11); SELECT id INTO retcard FROM cards WHERE `number` = numId AND enabled = 1 LIMIT 1; RETURN retcard; END Always returns null even when the query: SELECT id FROM cards WHERE `number`=<Insert Value Here> AND ENABLED = 1 LIMIT 1; returns a valid value for the same value used in and the function parameter. For instance: SELECT id FROM cards WHERE number=12345 AND ENABLED = 1 LIMIT 1; --

Postgresql: dblink in Stored Functions

為{幸葍}努か 提交于 2019-12-11 00:03:46
问题 I want to insert top 20 ROWS from a table tbl_A in db_A to tbl_B in db_B. The schema for tbl_A and tbl_B is: CREATE TABLE <tbl_name> ( id serial PRIMARY KEY, int a, int b ); I have some questions related to following queries psql db_A SELECT dblink_connect("dbname=db_B"); SELECT dblink_open('curse', 'SELECT id, a, b FROM tbl_B'); INSERT INTO tbl_A (SELECT id, a, b FROM dblink_fetch('curse', 20) AS (s_is int, s_a int, s_b int)) RETURNING a; Can I put the following statements in stored

Temporary Table in Stored Functions?

隐身守侯 提交于 2019-12-10 15:48:01
问题 I'm writing a function that I need to use either a TABLE variable for (I hear they don't exist in MySQL) or a temporary table. However, it seems that temporary tables only seem to work in stored procedures, not functions. I keep getting this error: Explicit or implicit commit is not allowed in stored function or trigger. What I'm trying to build is a solution to an earlier question of mine. It's a function that receives a start date, an end date, and a comma-deliminated string. It first finds

INSERT ON DUPLICATE KEY UPDATE with last_insert_id()

♀尐吖头ヾ 提交于 2019-12-08 01:20:15
问题 im trying to create a function CREATE FUNCTION `func`(param1 INT, param2 INT, param3 TEXT) RETURNS int(11) BEGIN INSERT INTO `table1` (`column1`, `column2`, `column3` ) VALUES (param1, param2, param3) ON DUPLICATE KEY UPDATE `time_stamp` = UNIX_TIMESTAMP(); RETURN last_insert_id(); END this would insert into a table a row if it doesn't exist but otherwise update it. Notice that i returned last_insert_id() which would be correct if the function would insert otherwise would be unpredictable if

How to create a MySQL stored aggregate function?

对着背影说爱祢 提交于 2019-12-07 18:35:20
问题 I need to write a stored function that does an aggregate operation on a column. Let's say a median (but actually, there are many different summary functions I want to implement). Ideally, I would like to have something like medBy( col1 col2 col3 ) which then for each row returns a median of the col1 values of all the rows that have the same col2 and col3 value as this one. That way, I wouldn't have to do GROUP BY on the whole query, just have a repeating value in that one column. This

Mysql stored functions and groupwise min [closed]

与世无争的帅哥 提交于 2019-12-06 07:06:59
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . Schema Database schema is simplified Events table This table stores events. CREATE TABLE `Events` ( `event_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `isPublic` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`event_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; Places table