rowtype

How to call a procedure with a rowtype literal as parameter in PL/SQL?

落爺英雄遲暮 提交于 2021-01-27 16:29:23
问题 Lets say I have a table and a procedure that accepts one argument of the tables rowtype: CREATE TABLE t (a NUMBER, b NUMBER); CREATE PROCEDURE p (x t%ROWTYPE) IS BEGIN NULL; END; Can I call that procedure using a rowtype literal, that is without explicitly creating a rowtype variable (or at least not explicitly listing and assigning every field of it)? The two following approaches both generate the below error: p(1, 2); p((1, 2)); PLS-00306: wrong number or types of arguments in call to 'P'

plpgsql function that returns multiple columns gets called multiple times

女生的网名这么多〃 提交于 2019-12-14 02:35:13
问题 I'm running PostgreSQL 9.2.1 and have a plpgsql function that returns 3 columns. It's called like this (simplified): SELECT (my_function(b.input)).*, a.other, b.columns FROM table_a a JOIN table_b b ON a.id = b.id WHERE ... The function prints out a WARNING message and I was surprised to find it printed 3 times. It looks like the function gets called 3 times - presumably once for each column. This can't be good for performance! How can I make sure it's called only once? It's already marked

Postgres: invalid type name “query%ROWTYPE”

烂漫一生 提交于 2019-12-13 03:55:47
问题 I want to create a variable based on the table "query" ( l_query query%ROWTYPE ), but I got this message: invalid type name "query%ROWTYPE" I also tried to use the fully qualified table name l_query dbname.public.query%ROWTYPE , but it didn't help me ether. CREATE OR REPLACE FUNCTION somefunc() RETURNS int AS $$ DECLARE l_res dbname.public.query%ROWTYPE; BEGIN return 1; END; $$ LANGUAGE plpgsql; PS:I do have the table query. I checked it a couple of times. I have this error only on the

How to pass an entire row (in SQL, not PL/SQL) to a stored function?

杀马特。学长 韩版系。学妹 提交于 2019-12-12 13:38:19
问题 I am having the following (pretty simple) problem. I would like to write an (Oracle) SQL query, roughly like the following: SELECT count(*), MyFunc(MyTable.*) FROM MyTable GROUP BY MyFunc(MyTable.*) Within PL/SQL, one can use a RECORD type (and/or %ROWTYPE), but to my knowledge, these tools are not available within SQL. The function expects the complete row, however. What can I do to pass the entire row to the stored function? Thanks! 回答1: Don't think you can. Either create the function with

How to use %ROWTYPE when inserting into Oracle table with identity column?

我是研究僧i 提交于 2019-12-06 01:45:21
问题 I have an Oracle 12c database with a table containing an identity column: CREATE TABLE foo ( id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, bar NUMBER ) Now I want to insert into the table using PL/SQL. Since in practice the table has many columns, I use %ROWTYPE : DECLARE x foo%ROWTYPE; BEGIN x.bar := 3; INSERT INTO foo VALUES x; END; However, it give me this error: ORA-32795: cannot insert into a generated always identity column ORA-06512: at line 5 Since it is very good for code

how to pass a table name as parameter to stored procedure?

别来无恙 提交于 2019-12-04 05:03:09
问题 Is it possible to create a rowtype for a table name which is passed as a parameter to a Stored-Procedure and also how do i know the columns to address them in the DBMS_OUUTPUT.PUT_LINE() statement. The end user can give any user name(schema) and table name I want to do something as below but it does not work. CREATE OR REPLACE PROCEDURE SP_PASS(USER_NAME VARCHAR2,TAB_NAME IN VARCHAR2) AS TYPE REF_CUR IS REF CURSOR; V_ARR REF_CUR; V_SQL VARCHAR(200); V_ROWTYPE USER_NAME.TAB_NAME%ROWTYPE; BEGIN

%ROWTYPE variable from table name

心不动则不痛 提交于 2019-12-04 02:49:01
问题 I've got an Oracle procedure, that I want to be somehow generic. I would like to: pass a table name as a varchar parameter use EXECUTE IMMEDIATE to dynamically select data store the result in the %ROWTYPE variable of passed type The third point seems to be a problem. I'm not sure if i can create a type dynamically inside the procedure body. It would be great to have something like this: procedure CHANGE_GENERIC(tableName in VARCHAR2, someOldVal in integer, someNewVal in integer) is v_sql

how to pass a table name as parameter to stored procedure?

我的未来我决定 提交于 2019-12-02 04:28:34
Is it possible to create a rowtype for a table name which is passed as a parameter to a Stored-Procedure and also how do i know the columns to address them in the DBMS_OUUTPUT.PUT_LINE() statement. The end user can give any user name(schema) and table name I want to do something as below but it does not work. CREATE OR REPLACE PROCEDURE SP_PASS(USER_NAME VARCHAR2,TAB_NAME IN VARCHAR2) AS TYPE REF_CUR IS REF CURSOR; V_ARR REF_CUR; V_SQL VARCHAR(200); V_ROWTYPE USER_NAME.TAB_NAME%ROWTYPE; BEGIN V_SQL := 'SELECT * FROM '||USER_NAME||'.'||TAB_NAME; OPEN V_ARR FOR V_SQL; LOOP FETCH V_ARR INTO V

Oracle: Insert rowtype data into another table

淺唱寂寞╮ 提交于 2019-11-28 11:20:25
I have one table called event , and created another global temp table tmp_event with the same columns and definition with event. Is it possible to insert records in event to tmp_event using this ? DECLARE v_record event%rowtype; BEGIN Insert into tmp_event values v_record; END; There are too many columns in event table, I want to try this because I don't want to list all the columns. Forget to mention: I will use this in the trigger, can this v_record be the object :new after insert on EVENT table ? To insert one row- DECLARE v_record event%rowtype; BEGIN SELECT * INTO v_record from event

how to declare %ROWTYPE of a variable that is a weakly typed SYS_REFCURSOR?

和自甴很熟 提交于 2019-11-27 16:06:45
W.r.t code below I can not declare the type of fetch-into-variable as the underlying table's %ROWTYPE because the SYS_REFCURSOR is on a select that joins two tables and also selects a few functions called on the attributes of the underlying two tables; i.e I can't declare as L_RECORD T%ROWTYPE --- DECLARE P_RS SYS_REFCURSOR; L_RECORD P_RS%ROWTYPE; BEGIN CAPITALEXTRACT( P_RS => P_RS ); OPEN P_RS; LOOP BEGIN FETCH P_RS INTO L_RECORD; EXIT WHEN P_RS%NOTFOUND; ... EXCEPTION WHEN OTHERS THEN ... END; END LOOP; CLOSE P_RS; END; -------- CREATE or REPLACE PROCEDURE CAPITALEXTRACT ( p_rs OUT SYS