Use dblink in cursor
Hi All:
In procedure create a parameterize cursor to find the records from another databse through db link.
this db link can change at run time, its depand on the region.
lets exp there is two db link for R1 and R2.
how can i create a cursor with dynamic db link.
Please help!!!
Thanks alot.
Ragards,
Abhishek
PROCEDURE xyz (p_dblink VARCHAR2) AS
sql_stmt VARCHAR2(2000) := 'SELECT <column_list> FROM <table>@'||p_dblink;
BEGIN
OPEN <l_cursor> FOR sql_stmt;
Do the rest of the processing
END;
Regards
JJ
Similar Messages
-
Can we pass Reference cursor using dblink
Can we pass reference cursor from one DB to another DB using DBlink?
I feel like it is not possible because the memory structure of same will be available in other DB.
Could you please let me know whether we can give a work around which will solve the issue.
Regards,
BaluBalu, cursor is a memory area which contains parsed SQL statement and everything needed for
the execution of the SQL command. That, of course, is instance specific and carrying it over to another DB using db-link would make no sense whatsoever. -
Using DBLINK in PL/SQL SQL Query
Hi
is it possible to use dblink in plsql cursor query.
are there any do's or dont's in this regard or any special things to take care of?
Basically what I need to do is access data from remote tables and put them in local tables after some proessing on data.
Any help !!well, since all pl/sql does is to pass the SQL statement to the database to be run, it's not a pl/sql issue. it's a SQL question. so it's the same as running the query in sqlplus (or toad or frog or whatever you use). the fact that it's embedded in pl/sql doesn't change anything, so: yes, it's possible, and no there aren't any do/don'ts (other than what would already apply to native SQL.
-
How to Execute Remote procedures that use DBLinks?
Using Oracle 10g (RAC Linux) to remote connect Windows 10g to dblink to AS/400 <
<I have created a procedure that I execute remotely by issuing the following:
CALL GLOBAL.REFRESH_STAGING@KRONOSLINK();
The procedure errors as
Error at line 2
ORA-20001: ERROR OCCURED
ORA-06512: at "GLOBAL.REFRESH_STAGING", line 47
ORA-06512: at line 1
The procedure runs without error from the host database. The problem is when the procedure makes a call to the dblink.
I unsuccessfully attempted to capture the error message.
Question: Is it possible to execute remote procedures that use dblinks? If so, How is that accomplished.
Question: What is the proper way to handle exceptions in this case?
Bonus: What can be done to improve this procedure? (Suggestions, like adding return on the procedure).
CREATE OR REPLACE PROCEDURE GLOBAL.REFRESH_STAGING IS
NOOBJECT EXCEPTION;
OBJECTEXIST EXCEPTION;
PRAGMA EXCEPTION_INIT(NOOBJECT, -00942); -- Exception handling for ORA-00942 - table or view does not exist
PRAGMA EXCEPTION_INIT(OBJECTEXIST, -00955); -- Exception handling for ORA-009555 - name is already used by an existing object
sT LONG := '';
sS LONG := '';
sST LONG := '';
cursor csrO is
SELECT
SCHEMANAME,
TABLENAME
FROM GLOBAL.STAGING_TABLES;
csrR csrO%ROWTYPE;
BEGIN
FOR csrR IN csrO
LOOP
sT := csrR.TABLENAME;
sS := csrR.SCHEMANAME;
sST := sS || '.' || sT;
BEGIN
EXECUTE IMMEDIATE 'drop table global.' || sT || ' purge';
EXCEPTION
WHEN NOOBJECT THEN
NULL;
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.FORMAT_CALL_STACK);
DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.FORMAT_ERROR_STACK);
RAISE_APPLICATION_ERROR (-20001, 'ERROR OCCURED');
END;
BEGIN
EXECUTE IMMEDIATE 'create table global.' || sT || ' nologging as select * from ' || sST || '@thebosslink';
COMMIT;
EXCEPTION
WHEN OBJECTEXIST THEN
NULL;
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.FORMAT_CALL_STACK);
DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.FORMAT_ERROR_STACK);
DBMS_OUTPUT.PUT_LINE(SQLCODE || ' - ' || SQLERRM);
RAISE_APPLICATION_ERROR (-20001, 'ERROR OCCURED');
END;
END LOOP;
END REFRESH_STAGING;
Thanks,
blevelsSET LINESIZE 500;
COLUMN DB_LINK FORMAT a20
COLUMN HOST FORMAT a20
COLUMN USERNAME FORMAT a20
COLUMN OWNER FORMAT a10
COLUMN TABLE_NAME FORMAT a20
select db_link,username, host from all_db_links where db_link = 'KRONOSLINK';
select privilege from dba_sys_privs where grantee = 'SYSTEM';
select owner, table_name from dba_tab_privs where grantee='SYSTEM';
DBLINK_ USERNAME HOST
KRONOSLINK SYSTEM ORCL
1 row selected.
PRIVILEGE
GLOBAL QUERY REWRITE
CREATE MATERIALIZED VIEW
CREATE TABLE
UNLIMITED TABLESPACE
SELECT ANY TABLE
5 rows selected.
OWNER TABLENAME_
SYS INCEXP
SYS INCEXP
SYS INCEXP
SYS INCEXP
SYS INCEXP
SYS INCEXP
SYS INCEXP
SYS INCEXP
SYS INCEXP
SYS INCEXP
SYS INCEXP
SYS INCVID
SYS INCVID
SYS INCVID
SYS INCVID
SYS INCVID
SYS INCVID
SYS INCVID
SYS INCVID
SYS INCVID
SYS INCVID
SYS INCVID
SYS INCFIL
SYS INCFIL
SYS INCFIL
SYS INCFIL
SYS INCFIL
SYS INCFIL
SYS INCFIL
SYS INCFIL
SYS INCFIL
SYS INCFIL
SYS INCFIL
SYS DBMS_ALERT
SYS DBMS_SYS_ERROR
SYS DBMS_RULE_EXIMP
SYS DBMS_AQ
SYS DBMS_AQADM
SYS DBMS_AQ_IMPORT_INTER
NAL
SYS DBMS_AQELM
SYS DBMS_TRANSFORM_EXIMP
SYS SYS_GROUP
SYS DBMS_DEFER_IMPORT_IN
TERNAL
SYS DBMS_REPCAT
WMSYS WM$UDTRIG_INFO
SYS SET_TABLESPACE
SYS CHECK_UPGRADE
SYS AVINASH
SYS AVINASH
SYS AVINASH1
SYS AVINASH1
SYS DB_PMP
SYS DB_PMP
SYS DIR_TESTCASE
SYS DIR_TESTCASE
SYS EXPORT_FULL_DIR
SYS EXPORT_FULL_DIR
SYS PUMP
SYS PUMP
SYS LOGS
SYS LOGS
SYS DPUMP_DIR2
SYS DPUMP_DIR2
SYS AVIS
SYS AVIS
SYS DPDIR_LCLLGS
SYS DPDIR_LCLLGS
67 rows selected.
Edited by: user10860953 on Jan 28, 2010 10:43 AM -
How can I access a database remote without using dblink, synonyms,aliases?
My store procedure access a remote tables using dblink, synonyms, alias, but by business company requirenments I nedd to use another data base access method. My PL/SQL statement looks like
select c.cus_id, c.cus_name, p.bankaccno
into v_cus_id, v_cus_name, v_bankaccno
from customer c, payment@finantial p
where c.cus_id = p.cus_id
Are any method else to connect to several remote databases concurrently?
If Yes, plase say me how is it, or tell me where do I obtain some examples, or any documentation.
Edited by: user518321 on Apr 21, 2009 1:58 PM
Ok, But I must not use any of these data base access method, metioned: dbliks, aliases, synonyms.
Edited by: user518321 on Apr 21, 2009 2:05 PM
Ok, It is enough for now, I am surprised for the response time and for their arguments, thanks a lot.
Edited by: user518321 on Apr 21, 2009 2:50 PMIf you want to access a table in a remote database using SQL, you will need a database link. It would be exceptionally odd for the business to require that you access a remote database and to prohibit the use of database links. What is the business reason for that combination?
If you want to look into rather more esoteric solutions, you could load a JDBC driver for the remote database, write a Java stored procedure that queries the remote table using that JDBC driver, and then cobble together some PL/SQL that joins the two result sets. You won't be able to reference the remote table in SQL and the solution won't scale well as data volumes increase and you'll be writing a whole lot of code to manually join tables together, but it does avoid database links. Of course, whatever concerns lead to the ban on database links would probably apply to loading a JDBC driver into the database and writing Java stored procedures to access the remote database, but since you haven't explained the reasoning behind the restrictions, we're just guessing.
Justin -
Oracle VPD on Remote database using DBLINk
Hi All,
How can i apply row level security on a table that is available in another database using DBlink
we have two databases PDSSM and EVTA, and i would like to apply row level security on a table in EVTA from a schema in PDSSM using dblink. MXODSADM IS A SCHEMA IN EVTA AND MXEMBARGO IS A SCHEMA IN PDSSM. there is a dblink(EVTA.GMM.COM) between mxembargo and mxodsadm.
begin
dbms_rls.add_policy (
object_schema => 'MXODSADM',
object_name => 'vehicle_retail_sale',
policy_name => ' MXEMBARGO_EVTA_POLICY',
function_schema =>'MXEMBARGO',
policy_type => dbms_rls.SHARED_CONTEXT_SENSITIVE,
--policy_type => dbms_rls.STATIC,
policy_function => ' MXEMBARGO_EVTA_POLICY.MXEMBARGO_EVTA_PREDICATE',
statement_types => 'select, insert,update,delete',
update_check => TRUE,
enable => TRUE,
static_policy => TRUE
end;
I am a complete Database person and i need to do this in my application, can anyone provide me how can i do this using dblink.wojpik wrote:
hello
I have one short question to you.
Is that possible to create view at remote database using dblink? Following syntax returns error
create view ViewName@DbLinkDame (ColumnName) as
(select 1 from dual )
"ORA-00905:missing keyword"
Is that possible at all?
And particulary - is that possible when remote database is MSSQL and I am using heterogeneous services?
I really appreciate your help
best regards
Wojtek
Edited by: wojpik on Oct 21, 2009 3:59 AMI doubt you would be able to fire any ddl through database link. You have to connect to remote database to run any ddl even if it is Oracle or some other database.
Regards
Anurag -
How can i use the same cursor in a loop fro multipletimes.
I am using two cursors.One to fetch sites and the other to fetch participants under each site.I am performing some job with that participants data.Now the problem is i am using the 2nd cursor in a loop.So it fetches the data of participants falling under one state.But when it comes to the second state,as the second cursor is already open it is unable to fetch the records.Please help me .How can i use the same cursor in a loop fro multipletimes.
I am sending the code which i have written in When-Button-Pressed-Trigger...
declare
sid number;
pid number;
cursor csid is select distinct(site_id) from cyber_ppt;
cursor cpid is select pc_id,st_dt,ed_dt from cyber_ppt where site_id = sid;
stdt varchar2(10);
eddt varchar2(10);
nom number;
stmonth varchar2(10);
edmonth varchar2(10);
cjan number:=0;
cfeb number:=0;
cmar number:=0;
capr number:=0;
cmay number:=0;
cjun number:=0;
cjul number:=0;
caug number:=0;
csep number:=0;
coct number:=0;
cnov number:=0;
cdec number:=0;
i number:=1;
begin
open csid ;
loop
fetch csid into sid;
exit when csid %notfound;
message(sid);
open cpid;
loop
fetch cpid into pid,stdt,eddt ;
exit when cpid %notfound;
message(sid||'-'||pid);
stmonth:=substr(stdt,4,3);
edmonth:=substr(eddt,4,3);
nom:= months_between(eddt,stdt);
while i <= round(nom)
loop
stmonth:=substr(stdt,4,3);
if stmonth='JAN' then
cjan:=cjan+1;
elsif stmonth='FEB' then
cfeb:=cfeb+1;
elsif stmonth='MAR' then
cmar:=cmar+1;
elsif stmonth='APR' then
capr:=capr+1;
elsif stmonth='MAY' then
cmay:=cmay+1;
elsif stmonth='JUN' then
cjun:=cjun+1;
elsif stmonth ='JUL' then
cjul:=cjul+1;
elsif stmonth ='AUG' then
caug:=caug+1;
elsif stmonth ='SEP' then
csep:=csep+1;
elsif stmonth ='OCT' then
coct:=coct+1;
elsif stmonth ='NOV' then
cnov:=cnov+1;
elsif stmonth ='DEC' then
cdec:=cdec+1;
end if;
stdt:=add_months(stdt,1);
i:=i+1;
end loop;
end loop;
end loop;
end;
try this /* untested */
DECLARE
sid NUMBER;
pid NUMBER;
CURSOR csid IS SELECT DISTINCT(site_id) FROM cyber_ppt;
CURSOR cpid(nSid NUMBER) is SELECT pc_id,st_dt,ed_dt FROM cyber_ppt WHERE site_id = nSid;
stdt VARCHAR2(10);
eddt VARCHAR2(10);
nom NUMBER;
stmonth VARCHAR2(10);
edmonth VARCHAR2(10);
cjan NUMBER:=0;
cfeb NUMBER:=0;
cmar NUMBER:=0;
capr NUMBER:=0;
cmay NUMBER:=0;
cjun NUMBER:=0;
cjul NUMBER:=0;
caug NUMBER:=0;
csep NUMBER:=0;
coct NUMBER:=0;
cnov NUMBER:=0;
cdec NUMBER:=0;
i NUMBER:=1;
BEGIN
FOR rec IN csid
LOOP
sid := rec.csid;
FOR cRec IN cpid(sid)
LOOP
pid := cRec.pc_id;
stdt := cRec.st_dt;
eddt := cRec.ed_dt;
stmonth:= SUBSTR(stdt,4,3);
edmonth:= SUBSTR(eddt,4,3);
nom:= months_between(eddt,stdt);
WHILE i <= round(nom)
LOOP
stmonth := SUBSTR(stdt,4,3);
IF stmonth='JAN'
THEN
cjan:=cjan+1;
ELSIF stmonth='FEB' THEN
cfeb:=cfeb+1;
ELSIF stmonth='MAR' THEN
cmar:=cmar+1;
ELSIF stmonth='APR' THEN
capr:=capr+1;
ELSIF stmonth='MAY' THEN
cmay:=cmay+1;
ELSIF stmonth='JUN' THEN
cjun:=cjun+1;
ELSIF stmonth ='JUL' THEN
cjul:=cjul+1;
ELSIF stmonth ='AUG' THEN
caug:=caug+1;
ELSIF stmonth ='SEP' THEN
csep:=csep+1;
ELSIF stmonth ='OCT' THEN
coct:=coct+1;
ELSIF stmonth ='NOV' THEN
cnov:=cnov+1;
ELSIF stmonth ='DEC' THEN
cdec:=cdec+1;
END IF;
stdt:=add_months(stdt,1);
i:=i+1;
END LOOP;
END LOOP;
END LOOP;
END; -
For example on Find-A-Grave when filling in the form to add a memorial there are several blocks that you fill in including location. For some blocks you type in the information and others are pick one of the preset selections. I generally hit the tab key on my keyboard and goes to the next block except when it comes to the preset selection blocks. If I use the tab key to go to the next selection it skips right past the next selection to the selection below that. For example, after I fill in the year I hit the tab key and type u for the United States under the country selection. But in order to get the next block to appear I have to hit tab again (but only when using your browser). Your browser then skips past the state selection to the county selection. Then when I pick the state using the cursor it does it again and drops down to the Bio past the county selection.
When I use Internet Explorer I don't have this problem. I merely hit the tab button on my keyboard and it goes to the next selection rather than as your browser does that is skips to the block below.
Is there some reason you have it set up this way because it is quite annoying to have to go back up each time using the mouse cursor rather than continuing to use the keyboard to fill in everything (typing, tab key or using the arrow keys). To say the least it slows the whole process down a lot. No, it is not my computer. I've had the exact same problem using another computer. No, it is not the find-a-grave website. I just used it as an example. Using your browser forces me to stop using the keyboard to fill in a form and use the mouse and then the keyboard and then the mouse and then the keyboard and then the mouse, etc when it shouldn't be necessary when filling out a form on a website.Are you having the problem with just the one site? Others?
Please post some public linkss.
Start '''[https://support.mozilla.org/en-US/kb/troubleshoot-firefox-issues-using-safe-mode Firefox in Safe Mode]''' {web Link} by holding down the '''<Shift><br> ''(Mac Options)'' ''' key, and then starting Firefox. Is the problem still there? -
Executing A Procedure In a Package Using DBLink
I need to execute a procedure which is residing in a package using dblink.
The package got a execute PUBLIC grant.
When I execute the following statement, I am getting error ORA: 00904, Invalid Identifier
select PKG_NAME.PROCEDURE_NAME@dblink(null,null,null,null,null,null,null,null,null,null,null) from dual
How can I execute the above statement.
Thanks in advanceI have a database INLABNEW in that i have done this
SQL> create table temp(no number)
2 /
Table created.
SQL> create or replace package pkg
2 as
3 procedure p;
4 end;
5 /
Package created.
SQL> create or replace package body pkg
2 as
3 procedure p
4 is
5 begin
6 insert into temp values(1);
7 end;
8 end;
9 /
Package body created.
SQL> select * from temp
2 /
no rows selectedNow i executed the procedure pkg.p from another database
SQL> exec pkg.p@to_inlabnew
PL/SQL procedure successfully completed.
SQL> commit
2 /And i query the table tmp in INLABNEW
SQL> select * from temp
2 /
NO
1Now question is have you given your procedure name properly.
as your procedure is in a package it should be Your_package_name.Your_procedure_name@Your_db_link -
We can't create form using dblink and synonim
We have created a dblink pointing to a table in the remote database.
When we create a form based on table or view using this dblink, we get the error "page not found".
We read from
Re: I can't create form using dblink
that we must create a synonim, and this was done creating one in the same schema of the db-link using the "Database Objects" of oracle portal 10g (external db is an oracle 9.0.2).
The new synonim work (tested with reports and pl/sql page)
but if we click on "Grant Access" (of the synonim) we get the following error :
Error: The underlying object of the synonym does not exist, is a remote object or is not of type function, procedure, package, sequence, synonym, table or view. (WWV-17076)
Does form work only with table and view of the portal database (not external one)? or have we loose something in the creation of the synonim?
Have someone succesfully created a form based on a db-link towards an external database?
Thanks to all.Hei guys, has nobody created succesfully a data-driven forms based on a dblink towards an external database?
I can't believe this!!!! -
Can't use DBLINK in Forms 4.5!!!
Hi All,
Can i use dblink in forms 4.5..b'coz it is giving me an error..
like PL/SQL Check#20108 Pls. inofrm your Oracle represnative
Thanx in advance!!!Solutions previously posted to this sort of question include creating a synonym for the link or wrapping it in a view. If that fails then move all the code to the database.
This is an issue in later versions too, certainly in 6i and IIRC in 10g. -
Hello.
I would like to program a Drag-and-Drop like, and I need to use my own cursor during the drag.
I use the createCustomCursor function, but the program never run correctly and exit with a Divide by zero Exception !
Here is my code (in a Canvas) :
Toolkit tlk;
Image img;
Cursor cur;
tlk = getToolkit(); // I've also tried : tlk = Toolkit.getDefaultToolkit();
img = "dndred.gif"; // the file exists, it is displayed on the Canvas
cur = tlk.createCustomCursor( img, new Point( 1, 1 ), "DragAndDrop" ); // Exception when running
setCursor( cur );
Here the printStackStrace :
Exception in thread "main" java.lang.ArithmeticException: / by zero
at sun.awt.motif.X11CustomCursor.createNativeCursor(X11CustomCursor.java:114)
at sun.awt.CustomCursor.<init>(CustomCursor.java:80)
at sun.awt.motif.X11CustomCursor.<init>(X11CustomCursor.java:26)
at sun.awt.motif.MToolkit.createCustomCursor(MToolkit.java:503)
at DragNDrop.<init>(DragNDrop.java:27)
at princ.main(princ.java:6)
Is my code wrong ?
I'm under Linux Debian. dndred.gif is a GIF image, exists, and is 20x20 (I've also tried a 50x50 image).
The function getBestCursorSize( 50, 50 ) returns 32x32.I just seen an error in the code above, I've forget 1 line.
But the problem remain the same.
Toolkit tlk;
Image img;
Cursor cur;
tlk = getToolkit(); // I've also tried : tlk = Toolkit.getDefaultToolkit();
img = tlk.getImage( "dndred.gif" ); // the file exists, it is displayed on the Canvas
cur = tlk.createCustomCursor( img, new Point( 1, 1 ), "DragAndDrop" ); // Exception when running
setCursor( cur );
Please help me. -
Hi,
Can some one help.
I am getting string more than 32767 char so I want to use CLOB but I am unable to use in ref Cursor.
CREATE OR REPLACE PROCEDURE PM.PROC_CURSOR_BTDCS (P_QUERY IN varchar2, P_batchid out Number) AS
P VARCHAR2(32767);
P_CURSOR_QUERY SYS_REFCURSOR;
X_JOBID varchar2(30);
X_BATCHID VARCHAR2(1000);
X_CREF VARCHAR2(10000);
X_CLIENTREF VARCHAR2(10000);
X_CLIENTID NUMBER;
X_USERID NUMBER;
X_RDATE varchar2(40);
X_DDATE varchar2(40);
X_STAGE NUMBER;
X_DIFF NUMBER;
X_CLIENTDUEDATE varchar2(40);
X_ASSETID NUMBER;
X_MODEID NUMBER;
p_o_error VARCHAR2(100);
p_o_status NUMBER;
BEGIN
P := 'SELECT DISTINCT JOBID,CLID,USERID,STAGE,
GET_CSV_DATA(CURSOR (SELECT CREF FROM ('|| P_QUERY ||') WHERE jobid =A.JOBID AND CLID=A.CLID AND USERID=A.USERID AND RDATE=A.RDATE AND DDATE=A.DDATE AND STAGE=A.STAGE AND ASSETID=A.ASSETID AND CLDATE=A.CLDATE AND DIFF=A.DIFF)) C_CREF,
GET_CSV_DATA(CURSOR (SELECT BATCHID FROM ('|| P_QUERY ||') WHERE jobid =A.JOBID AND CLID=A.CLID AND USERID=A.USERID AND RDATE=A.RDATE AND DDATE=A.DDATE AND STAGE=A.STAGE AND ASSETID=A.ASSETID AND CLDATE=A.CLDATE AND DIFF=A.DIFF)) C_BATCH,
GET_CSV_DATA(CURSOR (SELECT Crefname FROM ('|| P_QUERY ||') WHERE jobid =A.JOBID AND CLID=A.CLID AND USERID=A.USERID AND RDATE=A.RDATE AND DDATE=A.DDATE AND STAGE=A.STAGE AND ASSETID=A.ASSETID AND CLDATE=A.CLDATE AND DIFF=A.DIFF)) C_CLIENTREF
,DIFF,cldate,ASSETID
,RDATE,DDATE,MODEID
FROM('||P_QUERY||') A';
--INSERT INTO FROG VALUES(P,sysdate);
OPEN P_CURSOR_QUERY FOR P;
LOOP
FETCH P_CURSOR_QUERY INTO X_JOBID
,X_CLIENTID,X_USERID,X_STAGE,
X_CREF,X_BATCHID,X_CLIENTREF,X_DIFF,
X_CLIENTDUEDATE,
X_assetid,X_RDATE,X_DDATE,X_MODEID;
EXIT WHEN P_CURSOR_QUERY%NOTFOUND;
-- INSERT INTO FROG VALUES (X_CREF);
Proc_batchchangestage_upd (X_JOBID,X_BATCHID,X_CREF,X_CLIENTREF,X_userid,X_clientid,X_RDATE,
X_DDATE,
X_stage,
X_CLIENTDUEDATE,
X_diff,
X_assetid,X_MODEID,p_batchid,
p_o_error,
p_o_status);
END LOOP;
CLOSE P_CURSOR_QUERY;
COMMIT;
END;It would be helpful to indicate the error you're getting and the line where you're getting the error.
I will assume that your goal is to construct a SQL query > 32k, store that query in p, and open a cursor using p. In order to do that, you'd have to use the DBMS_SQL package, which is going to complicate your life rather significantly.
That said, it's far from obvious to my why the SQL statement needs to exceed 32k. At a minimum, concatentaing P_QUERY three times would seem unnecessary. If the text of P_QUERY exceeds 10,000 characters, I would really tend to suspect that you've done something wrong there and would benefit from simplifying the query or at least using a couple views.
Justin -
I have a function that I created and am trying to use it to output data using a ref cursor. My function call is
declare
ret_cursor crsiweb.types.cursorType;
type output_rec_type is record(
location varchar2(100),
client varchar2(100),
number_in long,
number_out long,
total_cost varchar2(100),
total_charge varchar2(100),
net varchar2(100),
average varchar2(100)
output output_rec_type;
begin
ret_cursor := all_db.net_profit.net_profit(to_date(:P1_Date_Chart,'DD-Mon-RR'));
fetch ret_cursor into output;
dbms_output.put_line('Location' || ',' || 'Company'|| ',' || 'In' ||
','|| 'Out'|| ',' || 'Cost'|| ',' || 'Charge'
|| ',' || 'Net' || ',' || '30 Day Average');
while ret_cursor%FOUND loop
dbms_output.put_line(output.location || ',' || output.client || ',' || output.number_in ||
','|| output.number_out || ',' || output.total_cost || ',' || output.total_charge
|| ',' || output.net || ',' || output.average);
fetch ret_cursor into output;
end loop;
close ret_cursor;
end;
i have it as a PL/SQL Procedure (anonymous block) in a region. When executed I get the following error:
"ORA-06550: line 15, column 25: PLS-00904: insufficient privilege to access object ALL_DB.NET_PROFIT ORA-06550: line 15, column 4: PL/SQL: Statement ignored"
The function is as follows: ( I created the function in OEM)
create or replace procedure all_db.net_profit.net_profit
as
function net_profit(sdate IN date) return crsiweb.types.cursortype as
ret_cursor crsiweb.types.cursortype;
begin
open ret_cursor for select 'a_chase' "Location",a."Client" "Client", sum(nvl(b."In",0)) "In", sum(nvl(a."Out",0)) "Out", to_char(sum(nvl(a."Cost",0)
+ nvl(b."Cost",0)),'FM$9999999990.00PR') "Cost",
to_char(sum(nvl(a."Charge",0) + nvl(b."Charge",0)),'FM$9999999990.00PR') "Charge", to_char(sum(nvl(a."Net",0)
+ nvl(b."Net",0)),'FM$9999999990.00PR') "Net",
to_char(sum(nvl("Average",0)),'FM$9999999990.00PR') "30 Day Average"
-- Get Out, Cost, Net by date_out
from (select client_name "Client", count(date_sent) "Out",
round(sum(nvl(product_cost,0) + nvl(acost1,0) + nvl(acost2,0) + nvl(acost3,0) +
nvl(acost4,0) + nvl(acost5,0) + nvl(acost6,0) + nvl(acost7,0)
+ nvl(acost8,0) + nvl(acost9,0) + nvl(acost10,0)),2)"Cost",
round(sum(nvl(product_fee,0) + nvl(copy_fee,0) + nvl(afee1,0) + nvl(afee2,0)+ nvl(afee3,0)
+ nvl(afee4,0)+ nvl(afee5,0)+ nvl(afee6,0)+ nvl(afee7,0)+ nvl(afee1,8)+ nvl(afee1,9)
+ nvl(afee1,10)),2) "Charge",
round(sum((nvl(product_fee,0) + nvl(copy_fee,0) + nvl(afee1,0) + nvl(afee2,0)+ nvl(afee3,0)
+ nvl(afee4,0)+ nvl(afee5,0)+ nvl(afee6,0)+ nvl(afee7,0)+ nvl(afee1,8)+ nvl(afee1,9)
+ nvl(afee1,10)) - (nvl(product_cost,0) + nvl(acost1,0) + nvl(acost2,0) + nvl(acost3,0) +
nvl(acost4,0) + nvl(acost5,0) + nvl(acost6,0) + nvl(acost7,0)
+ nvl(acost8,0) + nvl(acost9,0) + nvl(acost10,0))),2) "Net"
from a_chase.jim a
inner join a_chase.clients b
on a.clientid = b.clientid
where trunc(date_sent) = trunc(sdate)
group by client_name) a
--Get In, Cost, Net by date_In
left outer join (select client_name "Client", count(date_in) "In",
round(sum(nvl(product_cost,0) + nvl(acost1,0) + nvl(acost2,0) + nvl(acost3,0) +
nvl(acost4,0) + nvl(acost5,0) + nvl(acost6,0) + nvl(acost7,0)
+ nvl(acost8,0) + nvl(acost9,0) + nvl(acost10,0)),2)"Cost",
round(sum(nvl(product_fee,0) + nvl(copy_fee,0) + nvl(afee1,0) + nvl(afee2,0)+ nvl(afee3,0)
+ nvl(afee4,0)+ nvl(afee5,0)+ nvl(afee6,0)+ nvl(afee7,0)+ nvl(afee1,8)+ nvl(afee1,9)
+ nvl(afee1,10)),2) "Charge",
round(sum((nvl(product_fee,0) + nvl(copy_fee,0) + nvl(afee1,0) + nvl(afee2,0)+ nvl(afee3,0)
+ nvl(afee4,0)+ nvl(afee5,0)+ nvl(afee6,0)+ nvl(afee7,0)+ nvl(afee1,8)+ nvl(afee1,9)
+ nvl(afee1,10)) - (nvl(product_cost,0) + nvl(acost1,0) + nvl(acost2,0) + nvl(acost3,0) +
nvl(acost4,0) + nvl(acost5,0) + nvl(acost6,0) + nvl(acost7,0)
+ nvl(acost8,0) + nvl(acost9,0) + nvl(acost10,0))),2) "Net"
from a_chase.jim a
inner join a_chase.clients b
on a.clientid = b.clientid
where trunc(date_in) = trunc(sdate)
group by client_name) b
on a."Client" = b."Client"
-- Get 30 Day Average
inner join (select client_name, round(avg("Net"),2) "Average" from
(select trunc(date_in) "In", client_name, round(sum((nvl(product_fee,0) + nvl(copy_fee,0) + nvl(afee1,0) + nvl(afee2,0)+ nvl(afee3,0)
+ nvl(afee4,0)+ nvl(afee5,0)+ nvl(afee6,0)+ nvl(afee7,0)+ nvl(afee1,8)+ nvl(afee1,9)
+ nvl(afee1,10)) - (nvl(product_cost,0) + nvl(acost1,0) + nvl(acost2,0) + nvl(acost3,0) +
nvl(acost4,0) + nvl(acost5,0) + nvl(acost6,0) + nvl(acost7,0)
+ nvl(acost8,0) + nvl(acost9,0) + nvl(acost10,0))),2) "Net"
from a_chase.jim a
inner join a_chase.clients b
on a.clientid = b.clientid
where trunc(date_in) between (trunc(sdate) - 30) and trunc(sdate)
group by trunc(date_in), client_name)
group by client_name) c
on a."Client" = c.client_name
group by a."Client"
union --BU_TS
select 'bu_ts' "Location",a."Client" "Client", sum(nvl(b."In",0)) "In", sum(nvl(a."Out",0)) "Out", to_char(sum(nvl(a."Cost",0)
+ nvl(b."Cost",0)),'FM$9999999990.00PR') "Cost",
to_char(sum(nvl(a."Charge",0) + nvl(b."Charge",0)),'FM$9999999990.00PR') "Charge", to_char(sum(nvl(a."Net",0)
+ nvl(b."Net",0)),'FM$9999999990.00PR') "Net",
to_char(sum(nvl("Average",0)),'FM$9999999990.00PR') "30 Day Average"
-- Get Out, Cost, Net by date_out
from (select client_name "Client", count(date_sent) "Out",
round(sum(nvl(product_cost,0) + nvl(acost1,0) + nvl(acost2,0) + nvl(acost3,0) +
nvl(acost4,0) + nvl(acost5,0) + nvl(acost6,0) + nvl(acost7,0)
+ nvl(acost8,0) + nvl(acost9,0) + nvl(acost10,0)),2)"Cost",
round(sum(nvl(product_fee,0) + nvl(copy_fee,0) + nvl(afee1,0) + nvl(afee2,0)+ nvl(afee3,0)
+ nvl(afee4,0)+ nvl(afee5,0)+ nvl(afee6,0)+ nvl(afee7,0)+ nvl(afee1,8)+ nvl(afee1,9)
+ nvl(afee1,10)),2) "Charge",
round(sum((nvl(product_fee,0) + nvl(copy_fee,0) + nvl(afee1,0) + nvl(afee2,0)+ nvl(afee3,0)
+ nvl(afee4,0)+ nvl(afee5,0)+ nvl(afee6,0)+ nvl(afee7,0)+ nvl(afee1,8)+ nvl(afee1,9)
+ nvl(afee1,10)) - (nvl(product_cost,0) + nvl(acost1,0) + nvl(acost2,0) + nvl(acost3,0) +
nvl(acost4,0) + nvl(acost5,0) + nvl(acost6,0) + nvl(acost7,0)
+ nvl(acost8,0) + nvl(acost9,0) + nvl(acost10,0))),2) "Net"
from bu_ts.jim a
inner join bu_ts.clients b
on a.clientid = b.clientid
where trunc(date_sent) = trunc(sdate)
group by client_name) a
--Get In, Cost, Net by date_In
left outer join (select client_name "Client", count(date_in) "In",
round(sum(nvl(product_cost,0) + nvl(acost1,0) + nvl(acost2,0) + nvl(acost3,0) +
nvl(acost4,0) + nvl(acost5,0) + nvl(acost6,0) + nvl(acost7,0)
+ nvl(acost8,0) + nvl(acost9,0) + nvl(acost10,0)),2)"Cost",
round(sum(nvl(product_fee,0) + nvl(copy_fee,0) + nvl(afee1,0) + nvl(afee2,0)+ nvl(afee3,0)
+ nvl(afee4,0)+ nvl(afee5,0)+ nvl(afee6,0)+ nvl(afee7,0)+ nvl(afee1,8)+ nvl(afee1,9)
+ nvl(afee1,10)),2) "Charge",
round(sum((nvl(product_fee,0) + nvl(copy_fee,0) + nvl(afee1,0) + nvl(afee2,0)+ nvl(afee3,0)
+ nvl(afee4,0)+ nvl(afee5,0)+ nvl(afee6,0)+ nvl(afee7,0)+ nvl(afee1,8)+ nvl(afee1,9)
+ nvl(afee1,10)) - (nvl(product_cost,0) + nvl(acost1,0) + nvl(acost2,0) + nvl(acost3,0) +
nvl(acost4,0) + nvl(acost5,0) + nvl(acost6,0) + nvl(acost7,0)
+ nvl(acost8,0) + nvl(acost9,0) + nvl(acost10,0))),2) "Net"
from bu_ts.jim a
inner join bu_ts.clients b
on a.clientid = b.clientid
where trunc(date_in) = trunc(sdate)
group by client_name) b
on a."Client" = b."Client"
-- Get 30 Day Average
inner join (select client_name, round(avg("Net"),2) "Average" from
(select trunc(date_in) "In", client_name, round(sum((nvl(product_fee,0) + nvl(copy_fee,0) + nvl(afee1,0) + nvl(afee2,0)+ nvl(afee3,0)
+ nvl(afee4,0)+ nvl(afee5,0)+ nvl(afee6,0)+ nvl(afee7,0)+ nvl(afee1,8)+ nvl(afee1,9)
+ nvl(afee1,10)) - (nvl(product_cost,0) + nvl(acost1,0) + nvl(acost2,0) + nvl(acost3,0) +
nvl(acost4,0) + nvl(acost5,0) + nvl(acost6,0) + nvl(acost7,0)
+ nvl(acost8,0) + nvl(acost9,0) + nvl(acost10,0))),2) "Net"
from bu_ts.jim a
inner join bu_ts.clients b
on a.clientid = b.clientid
where trunc(date_in) between (trunc(sdate) - 30) and trunc(sdate)
group by trunc(date_in), client_name)
group by client_name) c
on a."Client" = c.client_name
group by a."Client"
union --BU
select 'BU' "Location", a."Company" "Client", sum(nvl(b."In",0)) "In", sum(nvl(a."Out",0)) "Out", to_char(sum(nvl(a."Cost",0)
+ nvl(b."Cost",0)),'FM$9999999990.00PR') "Cost",
to_char(sum(nvl(a."Charge", 0) + nvl(b."Charge",0)),'FM$9999999990.00PR') "Charge", to_char(sum(nvl(a."Net",0)
+ nvl(b."Net",0)),'FM$9999999990.00PR') "Net",
to_char(sum(nvl("Average",0)),'FM$9999999990.00PR') "30 Day Average"
from
(--Out Query
select b.clcompanyname "Company", count(*) "Out",
round(sum(nvl(cost1,0) + nvl(cost2,0) + nvl(cost3,0) + nvl(cost4,0) + nvl(cost5,0) + nvl(costx1,0)
+ nvl(costx2,0)+ nvl(costx3,0)+ nvl(costx4,0)+ nvl(costx5,0)+ nvl(costy1,0)+ nvl(costy2,0)+ nvl(costy3,0)
+ nvl(costy4,0)+ nvl(costy5,0)),2) "Cost",
round(sum(nvl(fee1,0) + nvl(fee2,0) + nvl(fee3,0) + nvl(fee4,0) + nvl(fee5,0) + nvl(feex1,0)
+ nvl(feex2,0)+ nvl(feex3,0)+ nvl(feex4,0)+ nvl(feex5,0)+ nvl(feey1,0)+ nvl(feey2,0)+ nvl(feey3,0)
+ nvl(feey4,0)+ nvl(feey5,0)),2) "Charge",
round( sum(nvl(fee1,0) + nvl(fee2,0) + nvl(fee3,0) + nvl(fee4,0) + nvl(fee5,0) + nvl(feex1,0)
+ nvl(feex2,0)+ nvl(feex3,0)+ nvl(feex4,0)+ nvl(feex5,0)+ nvl(feey1,0)+ nvl(feey2,0)+ nvl(feey3,0)
+ nvl(feey4,0)+ nvl(feey5,0) - nvl(cost1,0) - nvl(cost2,0) - nvl(cost3,0) - nvl(cost4,0) - nvl(cost5,0) - nvl(costx1,0)
- nvl(costx2,0)- nvl(costx3,0)- nvl(costx4,0)- nvl(costx5,0)- nvl(costy1,0)- nvl(costy2,0)- nvl(costy3,0)
- nvl(costy4,0)- nvl(costy5,0)),2) "Net"
from [email protected] a
inner join [email protected] b
on a.clientid = b.clientid
where trunc(compdate1) = trunc(sdate)
or trunc(compdate2) = trunc(sdate)
or trunc(compdate3) = trunc(sdate)
or trunc(compdate4) = trunc(sdate)
or trunc(compdate5) = trunc(sdate)
group by b.clcompanyname) a
--in Query
left outer join (select b.clcompanyname "Company", count(a.loandatein) "In",
round(sum(nvl(cost1,0) + nvl(cost2,0) + nvl(cost3,0) + nvl(cost4,0) + nvl(cost5,0) + nvl(costx1,0)
+ nvl(costx2,0)+ nvl(costx3,0)+ nvl(costx4,0)+ nvl(costx5,0)+ nvl(costy1,0)+ nvl(costy2,0)+ nvl(costy3,0)
+ nvl(costy4,0)+ nvl(costy5,0)),2) "Cost",
round(sum(nvl(fee1,0) + nvl(fee2,0) + nvl(fee3,0) + nvl(fee4,0) + nvl(fee5,0) + nvl(feex1,0)
+ nvl(feex2,0)+ nvl(feex3,0)+ nvl(feex4,0)+ nvl(feex5,0)+ nvl(feey1,0)+ nvl(feey2,0)+ nvl(feey3,0)
+ nvl(feey4,0)+ nvl(feey5,0)),2) "Charge",
round( sum(nvl(fee1,0) + nvl(fee2,0) + nvl(fee3,0) + nvl(fee4,0) + nvl(fee5,0) + nvl(feex1,0)
+ nvl(feex2,0)+ nvl(feex3,0)+ nvl(feex4,0)+ nvl(feex5,0)+ nvl(feey1,0)+ nvl(feey2,0)+ nvl(feey3,0)
+ nvl(feey4,0)+ nvl(feey5,0) - nvl(cost1,0) - nvl(cost2,0) - nvl(cost3,0) - nvl(cost4,0) - nvl(cost5,0) - nvl(costx1,0)
- nvl(costx2,0)- nvl(costx3,0)- nvl(costx4,0)- nvl(costx5,0)- nvl(costy1,0)- nvl(costy2,0)- nvl(costy3,0)
- nvl(costy4,0)- nvl(costy5,0)),2) "Net"
from [email protected] a
inner join [email protected] b
on a.clientid = b.clientid
where trunc(a.loandatein) = trunc(sdate)
group by b.clcompanyname) b
on a."Company" = b."Company"
--Avg Query
inner join (select "Company", round(avg("Net"),2) "Average" from
(select trunc(loandatein) "In", b.clcompanyname "Company",
round( sum(nvl(fee1,0) + nvl(fee2,0) + nvl(fee3,0) + nvl(fee4,0) + nvl(fee5,0) + nvl(feex1,0)
+ nvl(feex2,0)+ nvl(feex3,0)+ nvl(feex4,0)+ nvl(feex5,0)+ nvl(feey1,0)+ nvl(feey2,0)+ nvl(feey3,0)
+ nvl(feey4,0)+ nvl(feey5,0) - nvl(cost1,0) - nvl(cost2,0) - nvl(cost3,0) - nvl(cost4,0) - nvl(cost5,0) - nvl(costx1,0)
- nvl(costx2,0)- nvl(costx3,0)- nvl(costx4,0)- nvl(costx5,0)- nvl(costy1,0)- nvl(costy2,0)- nvl(costy3,0)
- nvl(costy4,0)- nvl(costy5,0)),2) "Net"
from [email protected] a
inner join [email protected] b
on a.clientid = b.clientid
where trunc(loandatein) between (trunc(sdate) - 30) and trunc(sdate)
group by trunc(loandatein), b.clcompanyname)
group by "Company") c
on a."Company" = c."Company"
group by a."Company";
return(ret_cursor);
end;
end;
I also have given htmldb_public_user grant/execute privileges on this function. Any help would be greatly appreciated.
Thanks,
Scottthanks, lalit. that's almost correct. htmldb_public_user is the username through which the mod_plsql DAD connects to the database. he has just the privs he needs to serve that function. the htmldb engine compiles into a FLOWS_010500 schema in the production release. having said that, lalit's suggestion is correct. you need to make sure your htmldb application schema (identified by the application-level attribute "Default Parsing Schema") has been directly granted privileges (directly as opposed to coming through a role rant) to run the objects it's calling.
hope this helps,
raj -
Problem declaring and using a REF CURSOR
I'm having a real problem using a REF CURSOR type
Here's the DECLARE and the start of the BEGIN I've so far developed.
DECLARE
TYPE r1 IS RECORD (
szvcapc_pidm szvcapc.szvcapc_pidm%TYPE,
szvcapc_term_code szvcapc.szvcapc_term_code%TYPE,
szvcapc_request_no szvcapc.szvcapc_request_no%TYPE);
szvcapc_rec r1;
TYPE cursor_1 IS REF CURSOR RETURN r1;
szvcapc_cv cursor_1;
TYPE r2 IS RECORD (
stvests_code stvests.stvests_code%TYPE
stvests_rec r2;
TYPE cursor_2 IS REF CURSOR RETURN stvests_rec;
stvests_cv cursor_2;
BEGIN
OPEN szvcapc_cv FOR
SELECT szvcapc_pidm, szvcapc_term_code, szvcapc_request_no
FROM szvcapc
WHERE szvcapc_passed_ind = 'Y'
AND szvcapc_award_credits = 'N';
LOOP
FETCH szvcapc_cv INTO szvcapc_rec;
EXIT WHEN szvcapc_cv%NOTFOUND;
END LOOP;
OPEN stvests_cv FOR
SELECT stvests_code
FROM stvests
WHERE stvests_eff_headcount = 'Y';
LOOP
FETCH stvests_cv INTO stvests_rec;
EXIT WHEN stvests_cv%NOTFOUND;
END LOOP;
SELECT *
FROM (
<snip>
INNER JOIN stvests_rec
ON SFBETRM.SFBETRM_ESTS_CODE = stvests_rec.STVESTS_CODE
<snip>
I later try to use the stvests_rec and szvcapc_rec in the main SELECT statement it doesn't recognise stvests_rec and szvcapc_rec as a "Table or View".
I have to use a REF CURSOR as this code is ultimately for use in Oracle Reports.
What am I doing wrong?> The reason I'm trying to use a REF CURSOR is that I was told that you
couldn't use CURSORs in Oracle Reports.
That does not change anything ito what happens on the Oracle server side. A cursor is a cursor is a cursor.
Every single SQL winds up as a cursor. Each cursor has a reference handle to access and use. HOW this handle is used in the language differs. But that is a language issue and not an Oracle RDBMS issue.
For example. An EXECUTE IMMEDIATE in PL/SQL creates a cursor handle and destroys it after use - automatically. An implicit cursor works the same. An explicit cursor you have the handle fetch from it and close from it when done.
A ref cursor is simply a handle that can be returned to an external client - allowing that application to use the handle to fetch the rows.
Do not think that a ref cursor is any different from the RDBMS side than any other cursor. The RDBMS does not know the difference. Does not care and nor should it.
> I'm trying to reduce the hits on the database from nested selects by
removing the dataset from the main SELECT statement and performing it only
once outside and then referencing this previously collected dataset inside the
main SELECT statement.
Good stuff that you are considering SQL performance. But you need to make sure that you
a) identify the performance inhibitor issue correctly
b) address this issue correctly
And you need to do that within SQL. Not PL/SQL. PL/SQL will always be slower at crunching data than SQL. For example, wanting to cache the data somehow to reduce the read overhead - that is exactly what the DB buffer cache does. It caches data. That is also exactly what the CBO will attempt - reduce the amount of data that needs to be read and processed.
Not saying that the RDBMS can do it all. It needs help from you - in the form of a SQL that instructs it to process only the minimum amount of data required to get the required results. In the form of a sound physical design that provides optimal usage of data storage and access (like indexing, partitioning, clustering, etc).
Bottom line - you cannot use a REF CURSOR to make a SQL go faster. A REF CURSOR is simply a cursor in the SQL Engine. A cursor is nothing but the "compiled-and-executable" code of a SQL "source program".
Maybe you are looking for
-
Downloading Photos from PC to iPad2
How do I download photographs from my PC hard disk to the iPad2? My pictures all went on to the iPod touch just fine, but only a few pictures came through when I set up my new iPad2, and no albums at all. I tried to drag and drop the file folder co
-
Hi, there, When I open my helpset from my Java applet (which is put on a server), the toolbar buttons (back, forward, print,..) are displayed without the original icons. They still function correctly, but the images are not shown. The buttons are in
-
Can we connect 2 ECC to a single PI system.
hi , can we connect 2 ECC to a single PI system. here we would be using proxies in the 2 ECC. Is it possible to enable the SProxy for both systems. EG: ECC1< -> PI (A)<-.>APO ECC2<-->PI (A)<-.>APO Regards, Praveen K Edited by: praveen kalwa on
-
How do I open separate playlist windows in itunes?
I need to open a playlist on my computer and a playlist on my ipod at the same time.
-
I purchased a iphone5 and a pair of beat headphones on finance from apple in July, with recent events im in need of reporting theft to the police over these products stolen!! im not too sure if they were insured, or either covered for theft, the prod