Function in pipeline with immediate execution
Hello Experts,I created a tube lined function to run immediately, cause of sub condition;
(1) columns where clause dynamically.
(2) I want to know the data stored in above the dynamic columns.
(3) I want to use in the report, so I don't want to insert it into a table.
I have created a TYPE, then thanks to run immediately, I got the query and the result of this query will be stored in the TYPE.
But when you call the function I get
ORA-00932: inconsistent data types: expected - was -.
Below is my function and type, let me know I am wrong and it is my correct logic.
CREATE OR REPLACE TYPE OBJ_FPD AS OBJECT
(LOW_PLAN_NO VARCHAR2 (40),
FPD VARCHAR2 (5),
SERIAL_NO NUMBER,
CEDIA_CODE VARCHAR2 (2),
DT DATE);
----
CREATE OR REPLACE TYPE FPD_TBL_TYPE AS TABLE OF OBJ_FPD;
----
CREATE OR REPLACE FUNCTION FUNC_GET_FPD_DATE (P_LOW_PLAN_NO VARCHAR2,
P_CEDIA_CODE VARCHAR2,
P_SERIAL_NO NUMBER)
RETURN FPD_TBL_TYPE
PIPELINED
AS
CURSOR C1
IS
SELECT 'FPD' || LEVEL TBL_COL
FROM DUAL
CONNECT BY LEVEL <= 31;
V_STR VARCHAR2 (5000);
V_TBL_TYPE FPD_TBL_TYPE;
BEGIN
FOR X IN C1
LOOP
V_STR :=
'SELECT A.low_PLAN_NO,
A.FPD,
A.SERIAL_NO,
A.cedia_code,
TO_DATE (
SUBSTR (FPD, 4, 5)
|| ''/''
|| TO_CHAR (C.low_PLAN_PERIOD_FROM, ''MM'')
|| ''/''
|| TO_CHAR (C.low_PLAN_PERIOD_FROM, ''RRRR''),
''DD/MM/RRRR'')
DT FROM ( SELECT low_PLAN_NO, '
|| ''''
|| X.TBL_COL
|| ''''
|| ' FPD, '
|| X.TBL_COL
|| ' SPTS, SERIAL_NO, cedia_code FROM M_low_PLAN_DETAILS WHERE NVL('
|| X.TBL_COL
|| ',0) > 0 AND SERIAL_NO = '
|| P_SERIAL_NO
|| ' AND cedia_code = '
|| ''''
|| P_CEDIA_CODE
|| ''''
|| ' AND low_PLAN_NO = '
|| ''''
|| P_LOW_PLAN_NO
|| ''''
|| ') A,
M_low_PLAN_DETAILS B,
M_low_PLAN_MSTR C
WHERE A.low_PLAN_NO = B.low_PLAN_NO
AND A.cedia_code = B.cedia_code
AND A.SERIAL_NO = B.SERIAL_NO
AND B.low_PLAN_NO = C.low_PLAN_NO
AND B.CLIENT_CODE = C.CLIENT_CODE
AND B.VARIANT_CODE = C.VARIANT_CODE
CONNECT BY LEVEL <= SPTS';
EXECUTE IMMEDIATE V_STR INTO V_TBL_TYPE;
FOR I IN 1 .. V_TBL_TYPE.COUNT
LOOP
PIPE ROW (OBJ_FPD (V_TBL_TYPE (I).LOW_PLAN_NO,
V_TBL_TYPE (I).FPD,
V_TBL_TYPE (I).SERIAL_NO,
V_TBL_TYPE (I).CEDIA_CODE,
V_TBL_TYPE (I).DT));
END LOOP;
END LOOP;
RETURN;
EXCEPTION
WHEN OTHERS
THEN
RAISE_APPLICATION_ERROR (-20000, SQLCODE || ' ' || SQLERRM);
RAISE;
END;
Waiting for your point of view.Kind regards
ORA Ash wrote:
This result is coming as FPD4 has 2 as a value, then there will be two records to the result with column date (DT).
Your query is perfect only thing is that I have to go to connect the name of the column immediately above as below;AND FPD = 'FPD14' CONNECT BY LEVEL <= SPTS;
So, if possible, please let me know is there a better way to spend the column name, to get the correct data.
Well, we don't have any example for working with information and the expected results of these data in the example, then it is very difficult for us to understand exactly what is affected by the query.
What happens if you delete the connection by clause? Why must you connect him by clause in your query? It is not clear what you include that for (like I said).
Tags: Database
Similar Questions
-
Changing table via the package with immediate execution (problem)
Hello
I have a unusual problem. I have a package that contains the procedure that via execute immediate statement, creates a table on which he performs different actions for example:
-alter table some_owner.dummy_table noparallel
-create index some_owner.idx_name on some_owner.dummy_table (column)...
But I only managed to run move and create synonym table/public via execute immediate statement. Actions as alter table and create index fails with error ORA-01031: insufficient privileges.
Note If call these commands outside the package (a simple script) this all done OK.
I found a way, where I set the AUTHID CURRENT_USER command create package statement. In this way all the actions executed OK.
I wonder why I can't change the table via the package with immediate execution on a table that is in the tablespace "SOME_TABLESPACE" and the title of owner "SOME_OWNER", without putting the AUTHID command on the package.
There must be a problem why a package cannot change the table which is owned by the user 'SOME_OWNER '.
All useful responses would be appreciated.
I have a unusual problem.
No - you don't have. This question has been answered SEVERAL times on this forum and others.
But I only managed to run move and create synonym table/public via execute immediate statement. Actions as alter table and create index fails with error ORA-01031: insufficient privileges.
OK - your username doesn't have privileges to do these operations or only received privileges through roles.
Roles are DISABLED in named PL/SQL blocks that use of the AUTHOR's rights.
Note If call these commands outside the package (a simple script) this all done OK.
I found a way, where I set the AUTHID CURRENT_USER command create package statement. In this way all the actions executed OK.
Of course - the roles are NOT disabled in named PL/SQL blocks that use the rights of the APPELLANT or in anonymous blocks.
I wonder why I can't change the table via the package with immediate execution on a table that is in the tablespace "SOME_TABLESPACE" and the title of owner "SOME_OWNER", without putting the AUTHID command on the package.
Well now you know!
-
Procedure failed with ORA-01403, associated with immediate execution, captured
This procedure compiles without error. Its purpose is to copy the sequence of one schema to another object. After it failed with ORA-01403, I added exception code of capture (see the comments in the code).
A few notes:
1. I started the proceedings with exec copy_sequence ('ADDRESS_SEQ', 'SST', 'TEST1');
2. the first sql string is built correctly since I can see in the console output:
Select last_number in the all_sequences where sequence_owner = upper('TSS') and upper('ADDRESS_SEQ') = sequence_name
I can run this SQL command, and returns a real value;
Here is the procedure
SET SERVEROUTPUT ON;
create or replace procedure copy_sequence (seq VARCHAR2, prod_schema VARCHAR2, VARCHAR2 test_schema)
as
Val number (21);
s_sql varchar2 (200);
Start
s_sql: = ' select last_number in the all_sequences where sequence_owner = upper('''|| prod_schema ||'') ') and sequence_name = upper('''||) Seq | " ')';
-immediate' select last_number in the Vale of all_sequences where sequence_owner = upper('''|| prod_schema ||'') ') and sequence_name = upper('''||) Seq | " ')';
Dbms_output.put_line ('sql 1 ' | s_sql);
execute immediate s_sql in val; ---!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! The code does not work here!
Dbms_output.put_line ('val' |) Val);
s_sql: = 'delete the sequence'. test_schema |'. ' || FF.;
Dbms_output.put_line ('sql 2 ' | s_sql);
-execution immediate s_sql;
s_sql: = 'create the sequence'. test_schema |'. ' || Seq |' minvalue maxvalue 1 999999999999999999999 begin by ' | Val | 'increment of 1';
Dbms_output.put_line ('sql 3 ' | s_sql);
-execution immediate s_sql;
-Add the following after procedure thown ORA-01403: no data found
exception when TOO_MANY_ROWS then DBMS_OUTPUT.put_line ('TOO_MANY_ROWS error');
When NO_DATA_FOUND then DBMS_OUTPUT.put_line ('error NO_DATA_FOUND');
While some other then raise_application_error (-20011, "Unknown Exception in this procedure");
end;
/
Hoek wrote:
The user (no SYSTEM, SYS, and SYSTEM are special, you should not use them unless you have TO) execution of the procedure must have the necessary privileges granted directly, bypassing a role...
??? There is nothing special about SYS or SYSTEM in what concerns them stored procedures. SYS by default is granted directly SELECT ANY SEQUENCE, so it does not work for the owner of MS by SYS. SYSTEM is therefore not:
Scott@pdborcl12 > create sequence s;
Order of creation.
Scott@pdborcl12 > create or replace
2 procedure system.p1
3 is
number of v_last_value 4;
5. start
6. Select last_number
7 in v_last_value
8 of all_sequences
9 where sequence_owner = 'SCOTT '.
10 and s = sequence_name ';
11 end;
12.Created procedure.
Scott@pdborcl12 > system.p1 exec.
BEGIN system.p1; END;*
ERROR on line 1:
ORA-01403: no data found
ORA-06512: at "SYSTEM. "P1", line 5
ORA-06512: at line 1Scott@pdborcl12 > grant select on s to the system;
Grant succeeded.
Scott@pdborcl12 > system.p1 exec.
PL/SQL procedure successfully completed.
SY.
-
Error ORA-14450 function parallel pipeline with PRAGMA AUTONOMOUS_T
Hello
I have a problem with a function.
I define this types:
CREATE or REPLACE TYPE utrOutRrsc () AS OBJECT
Id_ressource NUMBER
, Resource_tp varchar2 (50)
, Resource_nm varchar2 (256)
, Message_tp VARCHAR2 (50)
, Message_tx VARCHAR2 (4000)
);
CREATE or REPLACE TYPE uttResources AS TABLE OF THE utrOutRrsc;
I defined a package with this code:
TYPE utrResource () IS RENDERING
Id_ressource rdbmx.resources_vt.resource_id%TYPE
Resource_tp rdbmx.resources_vt.resource_tp%TYPE
Resource_nm rdbmx.resources_vt.resource_nm%TYPE);
TYPE rc_Resources IS REF CURSOR RETURN cons_ref_pkg.utrResource;
FUNCTION CONS_Process_Pool)
cur_Pools IN Conshope_pkg.rc_Resources
, icadena_tp IN VARCHAR2: = '-1212121212'. "
)
RETURN uttResources
PIPELINED PARALLEL_ENABLE (PARTITION cur_Pools IN ALL)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
LTypecons_fl NUMBER: = itypecons_fl;
r_pools rdbmx_site. Conshope_pkg.utrResource;
r_Out utrOutRrsc;
blnInit BOOLEAN: = TRUE;
numPos NUMBER;
I have SEVERAL;
LMessage_tp VARCHAR2 (50): = "OK";
LMessage_tx VARCHAR2 (4000): = NULL;
BEGIN
LOOP
SEEK cur_Pools INTO r_pools;
EXIT WHEN cur_Pools % NOTFOUND;
Start
insert into mytable values (r_pools.resource_id, r_pools.resource_tp, "other information");
COMMIT;
exception
L_Message_tp: = "ERROR";
LMessage_tx: = sqlerrm;
end;
r_out. Id_ressource: = r_pools. Id_ressource;
r_out. Resource_tp: = r_pools. Resource_tp;
r_out. Resource_nm: = r_pools. Resource_nm;
r_out. Message_tp: = LMessage_tp;
r_out. Message_tx: = LMessage_tx;
COURSE OF ACTION (r_out);
END of LOOP / * cur_Pools * /.
MSG_LOG ('Salida CONS_Process_Pool (Gestor: ' | r_pools.)) Resource_nm | () ', LTypeCons_fl, 'CONNECT');
RETURN;
END CONS_Process_Pool;
The error is worth trying.
I need to help you, pleaseIn addition, as damorgan noted, "There are so many things wrong here", keep in mind:
>
Restrictions on independent operations}You cannot execute a statement LINE of conduct in your own routine
your autonomous transaction is open. You must close the autonomous transaction
before you run the statement LINE of conduct. This is usually accomplished by
validation or restoring the transaction independent before running the PIPE
Return LINE. >SY.
-
Function in pipeline with dynamic query
Hi all
ORCL worm: 11g R2.
I'm operator function table in pipeline of the Oracle.
It works very well for static SQL.
create or replace package test13_pkg as
type r_disc_req is (number of disc_line_id,
number of req_id);
type t_disc_req is table of the r_disc_req;
function F_GetDiscReq return t_disc_req in pipeline;
procedure P_ProcessDiscReq;
end;
CREATE or REPLACE PACKAGE test13_pkg BODY
AS
FUNCTION F_GetDiscReq
RETURN t_disc_req
PIPELINED
IS
lo_disc_req r_disc_req;
BEGIN
FOR r_row IN (SELECT disc_line_id, req_id
Of edms_disc_lines_stg
WHERE ROWNUM < 10)
LOOP
lo_disc_req.disc_line_id: = r_row.disc_line_id;
lo_disc_req.req_id: = r_row.req_id;
COURSE OF ACTION (lo_disc_req);
END LOOP;
END F_GetDiscReq;
PROCEDURE P_ProcessDiscReq
AS
ln_totalRecords NUMBER;
BEGIN
SELECT COUNT (*)
IN ln_totalRecords
Of t1, TABLE edms_disc_lines_stg (F_GetDiscReq ()) t2
WHERE t1.disc_line_id = t2.disc_line_id AND t1.req_id = t2.req_id;
Dbms_output.put_line (ln_totalRecords);
END;
END;
Start
test13_pkg. P_ProcessDiscReq();
end;
---------------------------------------------------------------------------------------------
How he put for dynamic sql.
FUNCTION F_GetDiscReq (p_filter1 in NUMBER, p_filter2 number, p_filter3 number)
RETURN t_disc_req
PIPELINED
IS
lo_disc_req r_disc_req;
l_sql varchar2 (4000): = ' SELECT disc_line_id, req_id
To edms_disc_lines_stg ';
l_where_clause varchar2 (4000): = 'WHERE 1 = 1';
BEGIN
IF p_filter1 IS NOT NULL THEN
l_where_clause: = l_where_clause | "AND filter1 = ' | p_filter1;
END IF;
IF p_filter2 IS NOT NULL THEN
l_where_clause: = l_where_clause | "AND filter1 = ' | p_filter2;
END IF;
IF p_filter3 IS NOT NULL THEN
l_where_clause: = l_where_clause | "AND filter1 = ' | p_filter3;
END IF;
l_sql: = l_sql | l_where_clause;
-I'm stuck here.
FOR r_row IN (l_sql)
LOOP
lo_disc_req.disc_line_id: = r_row.disc_line_id;
lo_disc_req.req_id: = r_row.req_id;
COURSE OF ACTION (lo_disc_req);
END LOOP;
END F_GetDiscReq;
Could you please guide me here?
THX
Rod.
Hello
It is very doubtful, if you need or want dynamic SQL for this task.
If you do so, however, here's a way to do it:
FUNCTION F_GetDiscReq
(p_filter1 IN edms_disc_lines_stg.filter1%TYPE
p_filter2 IN edms_disc_lines_stg.filter1%TYPE
p_filter3 IN edms_disc_lines_stg.filter1%TYPE
)
RETURN t_disc_req
PIPELINED
IS
lo_disc_req r_disc_req;
l_sql varchar2 (4000): = ' SELECT disc_line_id, req_id
To edms_disc_lines_stg ';
l_where_clause varchar2 (4000): = 'WHERE 1 = 1';c SYS_REFCURSOR;
BEGIN
IF p_filter1 IS NOT NULL THEN
l_where_clause: = l_where_clause | "AND filter1 ="' | p_filter1 | '''';
END IF;
IF p_filter2 IS NOT NULL THEN
l_where_clause: = l_where_clause | "AND filter2 ="' | p_filter2 | '''';
END IF;
IF p_filter3 IS NOT NULL THEN
l_where_clause: = l_where_clause | "AND filter3 ="' | p_filter3 | '''';
END IF;
l_sql: = l_sql | l_where_clause;-dbms_output.put_line (l_sql |) "= l_sql"); -For debugging
C OPEN FOR l_sql;
LOOP
Fetch c lo_disc_req;
EXIT WHEN c % NOTFOUND;COURSE OF ACTION (lo_disc_req);
END LOOP;
END F_GetDiscReq;Static SQL, in general, will be more effective than dynamic SQL.
Because you need dynamic SQL statements, there are ways that the above function could be made more effective. If this is a problem, make sure that you understand what it is doing before you try to improve it.
-
Help with IMMEDIATE EXECUTION and drop
Hi all
We strive to create a procedure to do the following:
* We have in the database of the tables named as C$ _XXXXXXXXX
* We want to drop some of these tables with a common prefix (Fe C$ _1203101)
DECLARE
v_sql VARCHAR2 (300);
BEGIN
SELECT 'DROP TABLE ODISTAG.' | TABLE_NAME | « ; » IN v_sql FROM USER_TABLES WHERE TABLE_NAME LIKE ' C$ _1203101% ';
EXECUTE IMMEDIATE v_sql;
END;
But we are getting this error:
Error report:
ORA-00911: invalid character
ORA-06512: at line 5
00911 00000 - "invalid character".
* Cause: identifiers may not start with any character other than ASCII
letters and numbers. $# _ are allowed after the first
character. May contain identifiers surrounded by doublequotes
any character other than a quotation mark. Other quotes
(q' #... #') cannot use spaces, tabs or as carriage returns
delimiters. For all other settings, consult the SQL language
Reference manual.
* Action:
Any help on this please?
Thank you!You don't need the semicolon.
-
Hello people can help you Execute Immediate below set out? I'm a little confused on how to use it.
#!/bin/sh sqlplus -s ${DB_USER} << EOF SELECT 'ALTER TABLE PANDORA.'||table_name||' DROP PARTITION '||partition_name||';' FROM user_tab_partitions WHERE TABLE_NAME IN ('SIU', 'NGME') AND partition_name = (SELECT MIN(partition_name) FROM user_tab_partitions WHERE TABLE_NAME IN ('NGME') AND partition_name <> 'DUMMY' ); SELECT 'ALTER TABLE PANDORA.'||table_name||' ADD PARTITION WEEK'||TO_CHAR(TO_NUMBER(REPLACE(partition_name,'WEEK'))+1)||';' FROM user_tab_partitions WHERE TABLE_NAME IN ('SIU', 'NGME') AND partition_name = (SELECT MAX(partition_name) FROM user_tab_partitions WHERE TABLE_NAME IN ('NGME') AND partition_name <> 'DUMMY' ); SELECT 'ALTER INDEX PANDORA.IDX_SERVED_IMSI MODIFY PARTITION '||partition_name||' UNUSABLE;' FROM user_tab_partitions WHERE TABLE_NAME = 'SIU' AND partition_name = (SELECT MAX(partition_name) FROM user_tab_partitions WHERE TABLE_NAME IN ('NGME') AND partition_name <> 'DUMMY' ); EXIT EOF
Thank you in advance.
Something like
BEGIN
I'm IN)
SELECT table_name, nom_partition
Of user_tab_partitions
WHERE TABLE_NAME IN ("SIU", "NGME")
AND nom_partition = (SELECT MIN (partition_name)
Of user_tab_partitions
WHERE TABLE_NAME IN ("NGME")
AND nom_partition <> 'DUMMY '.
)
) LOOP
RUN IMMEDIATELY "ALTER TABLE PANDORA." | i.table_name |' DROP PARTITION '. i.PARTITION_NAME;
END OF LOOP:
END;
NOT TESTED.
-
Error with immediate execution in Oracle 10 g of form
Hi all
I use Oracle Forms 10 g. I have a remote database and I've created a database link to the db. Now, I need to update some data in this database from my system using forms. To do this, I wrote a statement such as:
run immediately "SELECT GLH_CODE_SEQ. NEXTVAL@WB IN '. GLHCODE | ' THE DOUBLE '. (glh_code_seq is a sequence in remote db)
but his error showing as error 591: this feature is not supported in programs on the client side.
then I changed the statement
forms_ddl ("SELECT GLH_CODE_SEQ. NEXTVAL@WB IN '. GLHCODE | (' DOUBLE ');
Now that the error is not burst but the variable is not under any value.
The same statement (forms_ddl) works fine on sql * more.
Someone please help me if I do something wrong or suggest if anything to do about it.
Thank you
Sandeep
write your code in the database accordingly. call function of database forms.
-
problem with immediate execution
Hi all
I use 10g db.
I wrote a database procedure. When I call front end (forms 6i) I get the error message
and here is my procedureORA-00911: invalid character ORA-06512:at schema.update_tables line 10
What could be gone bad?create or replace procedure update_tables is BEGIN declare lstring varchar(100) := 'update '; lvalue varchar2(10) := 'LVM'; begin for i in (select table_name,column_name from user_tab_columns where column_name like '%_COMPANY') loop lstring := lstring||i.table_name || ' set '||i.column_name || '= ' || chr(39) || lvalue || chr(39) || ' ; ' ; execute immediate lstring; end loop; end; END; /
Thank you...
Published by: GD on May 19, 2012 21:36Is chr (39) a quote on your system?
Did you try my example or something else?
(I've tried before, I posted it).Here is a complete example.
I changed it to my previous post to use a variable binding to remove the tank (39).
It will also help if lvalue contains a quote.create table hutest (my_company varchar2(30)); Table created. insert into hutest values('djhg'); 1 row created. create or replace procedure update_tables is BEGIN declare lstring varchar(100) := 'update '; lvalue varchar2(10) := 'LVM'; begin for i in (select table_name,column_name from user_tab_columns where column_name like '%_COMPANY') loop lstring := lstring||i.table_name || ' set '||i.column_name || '= :val'; dbms_output.put_line(lstring); execute immediate lstring using lvalue; end loop; end; END; / Procedure created. set serveroutput on size 20000 exec update_tables update HUTEST set MY_COMPANY= :val <------ From dbms_output PL/SQL procedure successfully completed. select * from hutest; MY_COMPANY ------------------------------ LVM 1 row selected.
Published by: HU 2012-05-20 08:59
-
ERROR WITH IMMEDIATE EXECUTION (ORA-00936)
Hello
I am trying to implement this statement but I get this error message (ORA-00936)
RUN IMMEDIATELY 'REMOVE'. V_TABLE_DETAIL_NAME | ' WHERE ' | V_COLUMN_DETAIL_NAME |' = ' | TO_CHAR (P_DEL_VAL);
Kind regardsHello
I assume you are using below in the database. Try this...
EXECUTE IMMEDIATE 'DELETE FROM '||V_TABLE_DETAIL_NAME||' WHERE '||V_COLUMN_DETAIL_NAME ||' = '''||TO_CHAR(P_DEL_VAL)||'''';
-Clément
-
Update not available with immediate execution?
Hello;
When I run this code, I get no error (s) (and I see the dbms_output [UPDATE]) but the update is not effective:
What is the problem? Thanks for your help, regards.WHENEVER OSERROR EXIT OSCODE set head off set scan on set verify off set flush off set feedback off set linesize 410 set pagesize 0 set serveroutput on size 1000000 DECLARE ... BEGIN collection := get_tables_with_column('REF_PLAN'); ... IF ... THEN dbms_output.put_line('[UPDATE]'); EXECUTE IMMEDIATE 'UPDATE ' || collection(i) ||' SET REF_PLAN=:quatre_champ WHERE FAM_SIM=:prem_champ AND PRISE_V1P=:deux_champ AND BROCHE_V1P=:trois_champ' USING quatre_champ,prem_champ,deux_champ,trois_champ; COMMIT; ...
Well, add:
dbms_output.put_line(SQL%ROWCOUNT);
after EXECUTE IMMEDIATE. Most likely update targets 0 lines. If so, print and check the prem_champ, the deux_champ, the values of trois_champ.
SY.
-
Appeal procedure set up by IMMEDIATE EXECUTION
Package: my_packageSQL> Create table bipul_test (a number(3), b number(2), c number(5), d varchar2(10), status varchar2(10)); Table Created. SQL> desc bipul_test Name Null? Type ----------------------------------------- -------- ---------------------------- A NUMBER(3) B NUMBER(2) C NUMBER(5) D VARCHAR2(10) STATUS VARCHAR2(10) SQL> insert into bipul_test values(1,1,1,'a', null); SQL> insert into bipul_test values(1,1,1,'b', null); SQL> insert into bipul_test values(2,1,2,'c', null); SQL> insert into bipul_test values(2,2,2,'d', null); SQL> insert into bipul_test values(null, null, null, 'x',null); SQL> commit; SQL> select * from bipul_test; A B C D STATUS ---------- ---------- ---------- ---------- ---------- 1 1 1 a 1 1 1 b 2 1 2 c 2 2 2 d x
Procedure: proc2, proc3
The Code of the appellant:CREATE OR REPLACE PACKAGE SRGUPTA.my_package AS -- PROCEDURE proc2; PROCEDURE proc2 (status OUT varchar2); PROCEDURE proc3 (Proc_name IN VARCHAR2, status IN OUT varchar2); END my_package; / CREATE OR REPLACE PACKAGE BODY SRGUPTA.my_package IS -- PROCEDURE proc2 PROCEDURE proc2(status OUT varchar2) AS n number(2); BEGIN update bipul_test set status ='SUCCESS' where A=1; commit; status:='FAILURE'; end proc2; PROCEDURE proc3 (proc_name varchar2, status IN OUT varchar2) AS x varchar2(100):=null; BEGIN --EXECUTE IMMEDIATE 'BEGIN '||proc_name||'; END;'; EXECUTE IMMEDIATE 'BEGIN '||proc_name||'(status); END;'; if status='FAILURE' then update bipul_test set status ='FAILURE' where A=2; commit; end if; end proc3; END my_package; /
Without THE normal execution mode param works very well. Above code is an effort through which I tried to capture the value of OUT to the appellant PROC3 param.set feedback on set serveroutput on DECLARE status VARCHAR2(100):=''; begin my_package.proc3('my_package.proc2', status); end; / EXIT;
PROC3 call PROC2 with immediate execution. Now if PROC2 have a parameter OUT and I want to capture in PROC3, is it possible?
Out of desire to my code:
Published by: handsome June 3, 2011 06:29SQL> select * from bipul_test; A B C D STATUS ---------- ---------- ---------- ---------- ---------- 1 1 1 a SUCCESS 1 1 1 b SUCCESS 2 1 2 c FAILURE 2 2 2 d FAILURE x
SQL> Create table bipul_test (a number(3), b number(2), c number(5), d varc (10)); Table created. SQL> insert into bipul_test values(1,1,1,'a', null); 1 row created. SQL> SQL> insert into bipul_test values(1,1,1,'b', null); 1 row created. SQL> insert into bipul_test values(2,1,2,'c', null); 1 row created. SQL> insert into bipul_test values(2,2,2,'d', null); 1 row created. SQL> insert into bipul_test values(null, null, null, 'x',null); 1 row created. SQL> commit; Commit complete. SQL> select * from bipul_test; A B C D STATUS ---------- ---------- ---------- ---------- ---------- 1 1 1 a 1 1 1 b 2 1 2 c 2 2 2 d x
SQL> CREATE OR REPLACE PACKAGE my_package AS 2 -- PROCEDURE proc2; 3 PROCEDURE proc2(status OUT varchar2); 4 PROCEDURE proc3(Proc_name IN VARCHAR2, status IN OUT varchar2); 5 END my_package; 6 / Package created. SQL> CREATE OR REPLACE PACKAGE BODY my_package 2 IS 3 -- PROCEDURE proc2 4 PROCEDURE proc2(status OUT varchar2) 5 AS 6 n number(2); 7 BEGIN 8 update bipul_test set status ='SUCCESS' where A=1; 9 commit; 10 status:='FAILURE'; 11 end proc2; 12 13 PROCEDURE proc3 (proc_name varchar2, status IN OUT varchar2) 14 AS 15 x varchar2(100):=null; 16 BEGIN 17 --EXECUTE IMMEDIATE 'BEGIN '||proc_name||'; END;'; 18 EXECUTE IMMEDIATE 'BEGIN '||proc_name||'(:1); END;' USING IN OUT status; 19 20 if status='FAILURE' then 21 update bipul_test set status ='FAILURE' where A=2; 22 commit; 23 end if; 24 end proc3; 25 END my_package; 26 / Package body created. SQL> set serverout on SQL> DECLARE 2 status VARCHAR2(100):=''; 3 begin 4 my_package.proc3('my_package.proc2', status); 5 dbms_output.put_line(status); 6 end; 7 / FAILURE PL/SQL procedure successfully completed. SQL>
-
Update in immediate execution with rownum
Can I put in an UPDATE by immediate execution that only maximum 10 lines will be updated?
It is:
Thanks in advanceEXECUTE IMMEDIATE 'UPDATE A_PAZIENTI_ESAMI SET '|| ' NREFERTO = :1, '|| ' DATA_REFERTO = :2, '|| ' ANNOREFERTO = :3, '|| ' DATA_EROGAZ = :4, '|| ' STATO_REFERTO = :5, '|| ' MEDICO_E = :6 '|| ' WHERE '|| WHERE_CLAUSE_ESA -- || ' and rownum <= 10' -- this is my doubt -- USING AP_REFERTOB.NREFERTO, AP_REFERTOB.DATARF, EXTRACT (YEAR FROM AP_REFERTOB.DATARF) , AP_REFERTOB.DATAEROGA, STATOREFERTO, AP_REFERTOB.K_MED; COMMIT;
Hello
your query works very well. It updates only the first 10 rows based on the place where the condition.Thank you.
-
Call function pipeline with entry as a record of cursor type parameter
Hello
I want result set of query curosr to function in pipeline and then proceed to Ref cusror for java application. I wrote the code below:
It gives me compilation error when you call the function pipeline (type_out (get_emp_rec)). Is it wrong to call pipelined function or please correct where I'm wrong.CREATE OR REPLACE PACKAGE emp_pkg IS TYPE t_emp_rec IS RECORD(empid varchar2(5),last_name varchar2(25),email varchar2(25)); type obj_t_emp_rec is table of t_emp_rec; CURSOR get_emp_data_cur(empid IN employee.employee_id%type) IS SELECT EMPLOYEE_ID,LAST_NAME,EMAIL FROM employee WHERE employee_id=empid; --Rowtype for table TYPE t_emp IS TABLE OF get_emp_data_cur%ROWTYPE INDEX BY PLS_INTEGER; --Object for the table type created get_emp_rec t_emp; PROCEDURE Populate_emp_details(empid IN employee.employee_id%type,get_emp_rec OUT t_emp, result out sys_refcursor); function type_out(get_emp_rec in t_emp) return obj_t_emp_rec pipelined; END emp_pkg; / CREATE OR REPLACE PACKAGE BODY emp_pkg AS PROCEDURE Populate_emp_details(empid IN employee.employee_id%type,get_emp_rec OUT t_emp,result out sys_refcursor) IS BEGIN SELECT EMPLOYEE_ID,LAST_NAME,EMAIL BULK COLLECT INTO get_emp_rec FROM employee WHERE employee_id=empid; open result for SELECT * FROM TABLE (type_out(get_emp_rec)); EXCEPTION when no_data_found then dbms_output.put_line('Invalid booking number entered'); END Populate_emp_details; function type_out(get_emp_rec in t_emp) return obj_t_emp_rec pipelined as currec t_emp_rec; begin for i in 1..get_emp_rec.count loop pipe row(currec); dbms_output.put_line('row count of rec -'|| get_emp_rec.count); end loop; end; END emp_pkg; /
Help, please.
Thank youEngine SQL doesn't know PL/SQL types.
Really? :
SQL> create or replace package emp_pkg is type t_emp_rec is record ( empid varchar2 (5), last_name varchar2 (25), email varchar2 (25) ); type obj_t_emp_rec is table of t_emp_rec; cursor get_emp_data_cur (empid in employees.employee_id%type) is select employee_id, last_name, email from employees where employee_id = empid; --Rowtype for table type t_emp is table of get_emp_data_cur%rowtype; get_emp_rec t_emp; procedure populate_emp_details (empid in employees.employee_id%type); function type_out (empid in employees.employee_id%type) return obj_t_emp_rec pipelined; end emp_pkg; / Package created. SQL> create or replace package body emp_pkg as function type_out (empid in employees.employee_id%type) return obj_t_emp_rec pipelined as currec t_emp_rec; begin populate_emp_details (empid); for i in 1 .. get_emp_rec.count loop currec.empid := get_emp_rec(i).employee_id; currec.last_name := get_emp_rec(i).last_name; currec.email := get_emp_rec(i).email; pipe row (currec); --dbms_output.put_line ('row count of rec -' || get_emp_rec.count); end loop; return; end type_out; procedure populate_emp_details (empid in employees.employee_id%type) is begin select employee_id, last_name, email bulk collect into get_emp_rec from employees where employee_id = empid; end populate_emp_details; end emp_pkg; / Package body created. SQL> select * from table(emp_pkg.type_out(114)) / EMPID LAST_NAME EMAIL ------- ------------------------------------- ------------------------------------- 114 Raphaely DRAPHEAL 1 row selected.
;)
-
Functions in pipeline for the csv data analysis?
Hi all
I currently have a pl/sql procedure that is used to load and parse a CSV file in a table of database within the Apex.
Downloading csv files are quite large (nearly 1 million rows or more) and there is a time of significant waiting for the course ends. I tried both Wizard 4.2 data that was very slow loading and the apex plugin excel2collection who timed out/never finished.
I heard functions in pipeline and how they can offer great time savings for insert instructions where the database lines have no interconnect/dependencies to each other.
My question is, would the data through pipes to offer me a gain with my time insert statements, and if so someone could help me to implement? The current procedure is listed below, less any code validation etc. for readability. The CSV is first uploaded to a table in a BLOB file before be analyzed by the procedure.
-- Chunk up the CSV file and split into a line at a time rawChunk := dbms_lob.substr(bloContent, numChunkLength, numPosition + numExtra); strConversion := strConversion || utl_raw.cast_to_varchar2(rawChunk); numLineEnd := instr(strConversion,chr(10),1); --This will return 0 if there is no chr(10) in the String strColumns := replace(substr(strConversion,1,numLineEnd -numTrailChar),CHR(numSpacer),','); strLine := substr(strConversion,1,numLineEnd); strLine := substr(strLine,1,length(strLine) - numTrailChar); -- Break each line into columns using the delimeter arrData := wwv_flow_utilities.string_to_table (strLine, '|'); FOR i in 1..arrData.count LOOP --Now we concatenate the Column Values with a Comma strValues := strValues || arrData(i) || ','; END LOOP; --Remove the trailing comma strValues := rtrim(strValues,','); -- Insert the values into target table, one row at a time BEGIN EXECUTE IMMEDIATE 'INSERT INTO ' || strTableName || ' (' || strColumns || ') VALUES (' || strValues || ')'; END; numRow := numRow + 1; --Keeps track of what row is being converted -- We set/reset the values for the next LOOP cycle strLine := NULL; strConversion := null; strValues := NULL; numPosition := numPosition + numLineEnd; numExtra := 0; numLineEnd := 0; END IF; END LOOP;
Apex-user wrote:
Hi Chris,
I'm trying to expand your code to use more tou both current columns, but having trouble with the format here...
- While (l_clob) dbms_lob.getlength > l_off and l_off > 0 loop
- l_off_new: = instr (l_clob, c_sep, l_off, c_numsep);
- line (csv_split_type)
- substr (l_clob, l_off, instr (l_clob, c_sep, l_off)-l_off)
- , substr (l_clob, instr (l_clob, c_sep, l_off) + 1, l_off_new - instr (l_clob, c_sep, l_off) - 1)
- ));
- l_off: = l_off_new + 2; -to switch c_sep and line (10 sep
How can I add more columns to this code? I'm mixed with all segments of substr and instr.
I've done a rewrite on it (12 sec for 50,000 lines, 4 columns ~ 7 MB, 2.2 sec for 10,000 lines)
create or replace function get_csv_split_cr (blob p_blob)
return csv_table_split_type
pipelined
as
c_sep constant varchar2 (2): = "";
c_line_end constant varchar2 (1): = Chr (10);
l_row varchar2 (32767).
number of l_len_clob;
number of l_off: = 1;
CLOB l_clob;
-below is used only for the call of dbms_lob.converttoclob
l_src_off pls_integer: = 1;
l_dst_off pls_integer: = 1;
number of l_ctx: = dbms_lob. DEFAULT_LANG_CTX;
number of l_warn: = dbms_lob. WARN_INCONVERTIBLE_CHAR;
Start
DBMS_LOB.CREATETEMPORARY (l_clob, true);
DBMS_LOB.converttoclob (l_clob, p_blob, dbms_lob.lobmaxsize, l_src_off, l_dst_off, dbms_lob. DEFAULT_CSID, l_ctx, l_warn);
-Attention: hypothesis that there is at least a 'correct' csv-line
-should perhaps find a better guard condition
-Hypothesis: last column ends with the separator
l_len_clob: = length (l_clob);
While l_len_clob > l_off and l_off > 0 loop
l_row: = substr (l_clob, l_off, instr (l_clob, c_line_end, l_off)-l_off);
line (csv_split_type)
-start of the first; occurrence - 1
substr (l_row, 1, instr (l_row, c_sep) - 1)
-first; second occurrence; accident - first; occurrence
, substr (l_row, instr (l_row, c_sep, 1, 1) + 1, instr (l_row, c_sep, 1, 2) - instr (l_row, c_sep, 1, 1) - 1)
-second; third occurrence; occurrence - second; occurrence
, substr (l_row, instr (l_row, c_sep, 1, 2) + 1, instr (l_row, c_sep, 1, 3) - instr (l_row, c_sep, 1, 2) - 1)
- and so on
, substr (l_row, instr (l_row, c_sep, 1, 3) + 1, instr (l_row, c_sep, 1, 4) - instr (l_row, c_sep, 1, 3) - 1)
));
l_off: = l_off + length (l_row) + 1; -to switch c_sep and line (10 sep
end loop;
return;
end;
You must change the csv_split_type also.
Update: I had to correct, combined version of two upward.
Maybe you are looking for
-
Need for DVI, HDMI on Satellite A300-15 b output
My toshiba laptop Satellite A300-15 b has only a VGA and S-video out;It has an Ati Radeon HD 3650 512 MB graphics card that supports hdmi and dvi, FullHD; I know that dvi and hdmi are of better quality than vga, so how can I connect my laptop to the
-
Satellite P200-1FY - sound does not come immediately
Hello world Whenever I want to listen to music (with Windows media player or web radio or music on the web), the sound does not come immediately. It takes at least a minute to come. Sometimes, I need to go to the windows "sound" Panel and click "Reco
-
Spade continues to play after having reached 500 points
Why asset stings on Microsoft Internet sometimes allows the play to continue when you reach 500 points? I have had several games which were apparently won only whether continue to play. I had a waiting game until my partner and I had almost 700 poi
-
Trying to cash game down load site. "your security settings do not allow websites to use activeX controls installed on your computer". ?????
-
I have the XP license and you want to reinstall. How can I do this without my disk? I moved and am still unpacked.