VB procedure cursor treatment.
Hello.
I develop VB form that get cursor from PL/SQL procedure. Could anybody offer library or any another way for tretment the cursor by VB.
Thanks in advance.
Andrey.
By declaring the cursor in between "IS" and "BEGIN" solves the problem as
the following sample. I didn't know thisThen perhaps it is time for you to familarise yourself with the documentation. Here is the relevant bit on declaring variables and here is the section on procedures and functions.
Cheers, APC
blog: http://radiofreetooting.blogspot.com
Similar Messages
-
Package Procedure cursor declaration
Hi am facing this issues , I am too close the problem to figure. Pl help
procedure addRox(p_reg_type_id in number, p_offender_id in number,p_sentence_end_date in date,
p_registration_date in date,p_end_registration_date in date,
p_aggravated in varchar2,p_habitual in varchar2, p_comments in varchar2, p_status in varchar2 DEFAULT null , p_OFFENSE_CODE in number) is
cursor tierNum is
select max(c.tier) from sor_offense o, sor_offense_code c
where o.offender_id = p_offender_id
and o.offense_code = c.CODE_ID
and o.state = 30658
and upper(o.status) = 'ACTIVE';
tier number;
vEndRegDate registration_offender_xref.END_REGISTRATION_DATE%type default null;
begin
open tierNum;
Fetch tierNum into tier;
if tierNum%NotFound then
tier := Null;
end if;
Close tierNum;
if tier is not null then
if(p_sentence_end_date is null) then -- sentenceEndDate is null
if tier = 1 then
vEndRegDate := add_months(p_registration_date - 1,180);
end if;
if tier = 2 then
vEndRegDate := add_months(p_registration_date - 1,300);
end if;
if tier = 3 then
vEndRegDate := Null;
end if;
else -- sentence_end_date is not null
if tier = 1 then
vEndRegDate := add_months(p_sentence_end_date - 1,180);
end if;
if tier = 2 then
vEndRegDate := add_months(p_sentence_end_date - 1,300);
end if;
if tier = 3 then
vEndRegDate := Null;
end if;
end if;
end if;
insert into registration_offender_xref (reg_type_id, offender_id, status,sentence_end_date,
registration_date,end_registration_date,aggravated,habitual,status_date, comments)
values (p_reg_type_id, p_offender_id, 'Active',p_sentence_end_date,
p_registration_date,vEndRegDate,p_aggravated,p_habitual,sysdate, p_comments);
-- commit;
exception
when others then
DBMS_OUTPUT.PUT_LINE('ERR in '||sqlerrm);
end addRox;\
error:Error(4,12): PLS-00323: subprogram or cursor 'ADD_ABC' is declared in a package specification and must be defined in the package body>
Hi am facing this issues , I am too close the problem to figure. Pl help
error:Error(4,12): PLS-00323: subprogram or cursor 'ADD_ABC' is declared in a package specification and must be defined in the package body
>
You aren't getting that exception from the code you posted. There is nothing with 'ABC' in any of that code.
If you want help you need to post the code that you need help with. -
Calling Stored Procedure - Cursor SP 16
I upgraded XI to SP16 so that I can use Cursor. I am calling the stored procedure. No errors. I do not see any data in the Cursor.
I am thinking the stored procedure is returning data but for some reason I am not able to see the result set. Can someone give me a hint as to how JDBC Adapter reads the cursor that is returned or what how I can retrieve data from the cursor?
I tested the stored procedure from a java program and everthing works fine.
Any suggestions welcome.Hi Michael,
Please check the SAP Note <a href="https://websmp103.sap-ag.de/~form/handler?_APP=01100107900000000342&_EVENT=REDIR&_NNUM=941317&_NLANG=E">941317</a>
This is a fragment:
<i>
Oracle Database 10g 10.1.x JDBC Driver
"Invoking Oracle stored procedures from within a JDBC sender channel is not supported as Oracle does not return a ResultSet in response to the query."
Oracle Database 10g 10.2.x JDBC Driver
Invoking Oracle stored procedures from within a JDBC sender channel is only possible for Oracle DBMS versions >= 10.2.x using so-called table functions</i>
Regards,
Luis Diego. -
Hi all,
I am running into some wired errors ...
I can easily do a select statement, e.g., select * from schema.table ...
But when I do a cursor in a stored procedure, e.g.,
CURSOR cursor_x
IS
select * from schema.table;
I will hit error ORA-01031: insufficient privileges
definitely, I should be able to read from that table ...
What is going on here ...
Any help ???842787 wrote:
Hi all,
I am running into some wired errors ...
I can easily do a select statement, e.g., select * from schema.table ...
But when I do a cursor in a stored procedure, e.g.,
CURSOR cursor_x
IS
select * from schema.table;
I will hit error ORA-01031: insufficient privileges
definitely, I should be able to read from that table ...
What is going on here ...
Any help ???As sybrand says, this is a basic documentation question and easily answered by searching the web.
To repeat what millions have already answered before....
The problem is that when you issue a direct select statement, you are using role based permissions to access the database objects (table in your case).
When you write PL/SQL code (your CURSOR...) this does not use role based permissions, but must have explicit permission granted on that object to that user.
In other words, you need to grant read permissions on that table to your user directly (not via the role of the user). -
Toplink storedProcedure/funtion + PL/SQL Procedure with cursor
Hi,
I am working on Toplink storedProcedure but, I am not getting any output. I go through the Oracle Tutorial but, still I am not getting any alternative.
please, anyone help out....
Thanking You,
regards,
sufianHello Sufian,
You seem to have a few threads trying to get a Stored proc working. In How to work with Toplink + PL/SQL Procedure + Cursor
you mention you get an error when executing, have you gotten past this exception? You may want to turn on TopLink logging to see the statement TopLink is creating and sending to the driver. Please see
http://www.oracle.com/technology/products/ias/toplink/doc/1013/main/_html/sescfg004.htm
If you are not familar with how to turn on logging.
Also, are you able to get results from a stored procedure that returns data instead of a cursor?
Best Regards,
Chris -
How to declare cursor in procedure based on if condition?
Hi Experts,
In sql server I have eprocedure in which I declare cursor like this:
IF (@int_cntCondition = 1 )
BEGIN
DECLARE Date_Cursor CURSOR FOR select HolidayCcy,HolidayDate from Definition..HolidayCalendar WITH (NOLOCK) where
HolidayCcy in (@Deposit_Currency,@Alternate_Currency)
AND CONVERT(SMALLDATETIME,CONVERT(VARCHAR(25),HolidayDate,106)) >=
CONVERT(SMALLDATETIME,CONVERT(VARCHAR (25),@T_Date,106))
END
ELSE
BEGIN
DECLARE Date_Cursor CURSOR FOR select HolidayCcy,HolidayDate from Definition..HolidayCalendar WITH (NOLOCK) where
HolidayCcy in (@Deposit_Currency,@Alternate_Currency,@Bank_Base_Currency)
AND CONVERT(SMALLDATETIME,CONVERT(VARCHAR(25),HolidayDate,106)) >=
CONVERT(SMALLDATETIME,CONVERT(VARCHAR(25),@T_Date,106))
END
I have to declare same cursor in oracle based on 'if' condition.
But in oracle stored procedur cursor has to declare outside of Begin statment of procedure, so how can I declare This cursor in Orracle?
if anyone know about it, Plese help or send any link to refer.
Thanks.Digambar wrote:
I have to declare same cursor in oracle based on 'if' condition.The simple answer is to use a reference cursor data type. E.g.
SQL> create or replace procedure GetObjects( cur in out sys_refcursor, objType varchar2 ) is
2 begin
3 case
4 when upper(objType) = 'EMP' then
5 open cur for select * from emp;
6
7 when upper(objType) = 'DEPT' then
8 open cur for select * from dept;
9
10 end case;
11 end;
12 /
Procedure created.
SQL>
SQL>
SQL> --// define a host refcursor variable in client
SQL> --// (e.g. VB, .Net, Java, etc)
SQL> var c refcursor
SQL>
SQL> --// make the stored proc call
SQL> begin GetObjects( :c, 'EMP' ); end;
2 /
PL/SQL procedure successfully completed.
SQL>
SQL> --// process cur reference in client
SQL> print c
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 1980/12/17 00:00:00 800 20
7499 ALLEN SALESMAN 7698 1981/02/20 00:00:00 1600 300 30
7521 WARD SALESMAN 7698 1981/02/22 00:00:00 1250 500 30
7566 JONES MANAGER 7839 1981/04/02 00:00:00 2975 20
7654 MARTIN SALESMAN 7698 1981/09/28 00:00:00 1250 1400 30
7698 BLAKE MANAGER 7839 1981/05/01 00:00:00 2850 30
7782 CLARK MANAGER 7839 1981/06/09 00:00:00 2450 10
7788 SCOTT ANALYST 7566 1987/04/19 00:00:00 3000 20
7839 KING PRESIDENT 1981/11/17 00:00:00 5000 10
7844 TURNER SALESMAN 7698 1981/09/08 00:00:00 1500 0 30
7876 ADAMS CLERK 7788 1987/05/23 00:00:00 1100 20
7900 JAMES CLERK 7698 1981/12/03 00:00:00 950 30
7902 FORD ANALYST 7566 1981/12/03 00:00:00 3000 20
7934 MILLER CLERK 7782 1982/01/23 00:00:00 1300 10
14 rows selected.
SQL>
SQL>
SQL> --// make the stored proc call
SQL> begin GetObjects( :c, 'DEPT' ); end;
2 /
PL/SQL procedure successfully completed.
SQL>
SQL> --// process cur reference in client
SQL> print c
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> -
Returning result set from procedure out parameter, display with anon block
I'm trying to do something pretty simple (I think it should be simple at least). I want to use a pl/sql procedure to return a result set in an OUT parameter. If I run this code by itself (in the given anonymous block at the end, without trying to display any results), toad says that the PL/SQL procedure successfully completed.
How can I display the results from this procedure? I am assuming that the result set should be stored in the O_RETURN_REDEEM_DTL, but how can I get anything out of it?
I have this package with the following procedure:
/* FUNCTION - REDEEM_DTL_READ */
PROCEDURE REDEEM_DTL_READ(
ZL_DIVN_NBR_IN IN REDEEM_DTL.ZL_DIVN_NBR%TYPE,
GREG_DATE_IN IN REDEEM_DTL.GREG_DATE%TYPE,
ZL_STORE_NBR_IN IN REDEEM_DTL.ZL_STORE_NBR%TYPE,
REGISTER_NBR_IN IN REDEEM_DTL.REGISTER_NBR%TYPE,
TRANS_NBR_IN IN REDEEM_DTL.TRANS_NBR%TYPE,
O_RETURN_REDEEM_DTL OUT REDEEM_DTL_TYPE,
o_rtrn_cd OUT NUMBER,
o_err_cd OUT NUMBER,
o_err_msg OUT VARCHAR2
IS
BEGIN
o_rtrn_cd := 0;
o_err_msg := ' ';
o_err_cd := 0;
--OPEN REDEEM_DTL_READ_CUR(ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN, REGISTER_NBR_IN, TRANS_NBR_IN);
OPEN O_RETURN_REDEEM_DTL FOR SELECT * FROM REDEEM_DTL;
-- LOOP
-- FETCH REDEEM_DTL_READ_CUR INTO O_RETURN_REDEEM_DTL;
-- EXIT WHEN REDEEM_DTL_READ_CUR%NOTFOUND;
-- END LOOP;
-- CLOSE REDEEM_DTL_READ_CUR;
EXCEPTION
WHEN OTHERS
THEN
o_rtrn_cd := 7;
o_err_msg := SUBSTR (SQLERRM, 1, 100);
o_err_cd := SQLCODE;
END REDEEM_DTL_READ;and call it in an anonymous block with:
DECLARE
ZL_DIVN_NBR_IN NUMBER;
GREG_DATE_IN DATE;
ZL_STORE_NBR_IN NUMBER;
REGISTER_NBR_IN NUMBER;
TRANS_NBR_IN NUMBER;
O_RETURN_REDEEM_DTL PSAPP.CY_SALESPOSTING.REDEEM_DTL_TYPE;
O_RETURN_REDEEM_DTL_OUT PSAPP.CY_SALESPOSTING.REDEEM_DTL_READ_CUR%rowtype;
O_RTRN_CD NUMBER;
O_ERR_CD NUMBER;
O_ERR_MSG VARCHAR2(200);
BEGIN
ZL_DIVN_NBR_IN := 71;
GREG_DATE_IN := TO_DATE('07/21/2008', 'MM/DD/YYYY');
ZL_STORE_NBR_IN := 39;
REGISTER_NBR_IN := 1;
TRANS_NBR_IN := 129;
-- O_RETURN_REDEEM_DTL := NULL; Modify the code to initialize this parameter
O_RTRN_CD := NULL;
O_ERR_CD := NULL;
O_ERR_MSG := NULL;
PSAPP.CY_SALESPOSTING.REDEEM_DTL_READ ( ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN,
REGISTER_NBR_IN, TRANS_NBR_IN, O_RETURN_REDEEM_DTL, O_RTRN_CD, O_ERR_CD, O_ERR_MSG );
FOR item IN O_RETURN_REDEEM_DTL
LOOP
DBMS_OUTPUT.PUT_LINE('ZL_DIVN_NBR = ' || item.ZL_DIVN_NBR);
END LOOP;
END; And end up with an error:
ORA-06550: line 25, column 15:
PLS-00221: 'O_RETURN_REDEEM_DTL' is not a procedure or is undefined
ORA-06550: line 25, column 3:
PL/SQL: Statement ignoredMessage was edited by:
user607908Aha, I knew I forgot something!
I actually had it defined as a REF CURSOR in PSAPP.CY_SALESPOSTING package spec:
TYPE REDEEM_DTL_TYPE IS REF CURSOR;since I wasn't sure what to make it.
Cursor used in procedure:
CURSOR REDEEM_DTL_READ_CUR (
zl_divn_nbr_in IN NUMBER,
greg_date_in IN DATE,
zl_store_nbr_in IN NUMBER,
register_nbr_in IN NUMBER,
trans_nbr_in IN NUMBER)
IS
SELECT ZL_DIVN_NBR, GREG_DATE, ZL_STORE_NBR, REGISTER_NBR, TRANS_NBR, PAYMENT_TYP_NBR
FROM REDEEM_DTL
WHERE ZL_DIVN_NBR = zl_divn_nbr_in AND GREG_DATE = greg_date_in AND
ZL_STORE_NBR = zl_store_nbr_in AND REGISTER_NBR = register_nbr_in AND
TRANS_NBR = trans_nbr_in;Updated code:
/* PROCEDURE - REDEEM_DTL_READ */
PROCEDURE REDEEM_DTL_READ(
ZL_DIVN_NBR_IN IN REDEEM_DTL.ZL_DIVN_NBR%TYPE,
GREG_DATE_IN IN REDEEM_DTL.GREG_DATE%TYPE,
ZL_STORE_NBR_IN IN REDEEM_DTL.ZL_STORE_NBR%TYPE,
REGISTER_NBR_IN IN REDEEM_DTL.REGISTER_NBR%TYPE,
TRANS_NBR_IN IN REDEEM_DTL.TRANS_NBR%TYPE,
O_RETURN_REDEEM_DTL OUT REDEEM_DTL_TYPE,
o_rtrn_cd OUT NUMBER,
o_err_cd OUT NUMBER,
o_err_msg OUT VARCHAR2
IS
BEGIN
o_rtrn_cd := 0;
o_err_msg := ' ';
o_err_cd := 0;
OPEN REDEEM_DTL_READ_CUR(ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN,
REGISTER_NBR_IN, TRANS_NBR_IN);
--OPEN O_RETURN_REDEEM_DTL FOR SELECT * FROM REDEEM_DTL;
LOOP
FETCH REDEEM_DTL_READ_CUR INTO O_RETURN_REDEEM_DTL;
EXIT WHEN REDEEM_DTL_READ_CUR%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('ZL_DIVN_NBR = ' || O_RETURN_REDEEM_DTL.ZL_DIVN_NBR);
END LOOP;
CLOSE REDEEM_DTL_READ_CUR;
-- LOOP
-- FETCH REDEEM_DTL_READ_CUR INTO O_RETURN_REDEEM_DTL;
-- EXIT WHEN REDEEM_DTL_READ_CUR%NOTFOUND;
-- END LOOP;
-- CLOSE REDEEM_DTL_READ_CUR;
EXCEPTION
WHEN OTHERS
THEN
o_rtrn_cd := 7;
o_err_msg := SUBSTR (SQLERRM, 1, 100);
o_err_cd := SQLCODE;
END REDEEM_DTL_READ;the updated anon block:
DECLARE
ZL_DIVN_NBR_IN NUMBER;
GREG_DATE_IN DATE;
ZL_STORE_NBR_IN NUMBER;
REGISTER_NBR_IN NUMBER;
TRANS_NBR_IN NUMBER;
O_RETURN_REDEEM_DTL PSAPP.CY_SALESPOSTING.REDEEM_DTL_TYPE;
O_RTRN_CD NUMBER;
O_ERR_CD NUMBER;
O_ERR_MSG VARCHAR2(200);
BEGIN
ZL_DIVN_NBR_IN := 71;
GREG_DATE_IN := TO_DATE('07/21/2008', 'MM/DD/YYYY');
ZL_STORE_NBR_IN := 39;
REGISTER_NBR_IN := 1;
TRANS_NBR_IN := 129;
-- O_RETURN_REDEEM_DTL := NULL; Modify the code to initialize this parameter
O_RTRN_CD := NULL;
O_ERR_CD := NULL;
O_ERR_MSG := NULL;
PSAPP.CY_SALESPOSTING.REDEEM_DTL_READ ( ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN,
REGISTER_NBR_IN, TRANS_NBR_IN, O_RETURN_REDEEM_DTL, O_RTRN_CD, O_ERR_CD, O_ERR_MSG );
FOR item IN 1..O_RETURN_REDEEM_DTL.COUNT
LOOP
DBMS_OUTPUT.PUT_LINE('ZL_DIVN_NBR = ' || O_RETURN_REDEEM_DTL(item).ZL_DIVN_NBR);
END LOOP;
END;and the new error:
ORA-06550: line 25, column 38:
PLS-00487: Invalid reference to variable 'O_RETURN_REDEEM_DTL'
ORA-06550: line 25, column 3:
PL/SQL: Statement ignoredAlso, it would be nice if the forums would put a box around code so that it would be easy to
distinguish between what is supposed to be code and what should be regular text...
Message was edited by:
user607908 -
How to find Unused variables in procedure,function or package
Hi all,
I want find out unused variables in procedure, function and package.
I have written below script for doing this ,but i am not getting the expected result.
Kindly help me to improve the below code ,so that it works as expected.
{code}
version details
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
"CORE 11.2.0.3.0 Production"
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
{code}
{code}
What i Have tried is This.
DECLARE
V_OBJECT_NAME VARCHAR2(30) :='PR_PRINT';
V_OBJECT_TYPE VARCHAR2(30) :='PROCEDURE';
CURSOR C1(CP_OBJECT_NAME VARCHAR2,CP_OBJECT_TYPE VARCHAR2)
IS
SELECT US.NAME,
US.TYPE,
US.LINE,
REGEXP_SUBSTR(US.TEXT,'.* ') AS var_name
FROM user_source US
WHERE name=CP_OBJECT_NAME
AND type =CP_OBJECT_TYPE
AND REGEXP_LIKE (TEXT,'(v_|g_|c_)','i')
AND REGEXP_LIKE (TEXT,'^[^ ]')
AND REGEXP_LIKE (TEXT,'^[^--]') ;
v_count NUMBER ;
BEGIN
FOR i IN C1(V_OBJECT_NAME,V_OBJECT_TYPE)
LOOP
SELECT COUNT( *)
INTO V_COUNT
FROM USER_SOURCE US
WHERE US.NAME=I.NAME
AND REGEXP_LIKE(US.TEXT,i.var_name,'i' )
AND US.LINE<>I.LINE;
IF V_COUNT =0 THEN
DBMS_OUTPUT.PUT_LINE('variable '||I.VAR_NAME||'Is declared at line#'||I.LINE||' But no where used');
END IF ;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('p_err_code := '||SQLCODE||dbms_utility.format_Error_backtrace());
DBMS_OUTPUT.PUT_LINE('p_err_msg := '||sqlerrm);
END ;
{code}
Thanks,
P PrakashHello,
as suggested by padders you can use PL/Scope, an example:
ALTER SESSION SET PLSCOPE_SETTINGS='IDENTIFIERS:ALL';
CREATE OR REPLACE PACKAGE ui_test1 AS
global_number NUMBER := 9;
FUNCTION get_number
RETURN NUMBER;
END ui_test1;
CREATE OR REPLACE PACKAGE BODY ui_test1 AS
PROCEDURE setNull
p_varchar IN OUT VARCHAR2
IS
BEGIN
p_varchar := NVL(p_varchar,'NULL');
END setNull;
FUNCTION get_number
RETURN NUMBER
IS
FUNCTION setZero
p_number IN NUMBER
RETURN NUMBER
IS
BEGIN
RETURN NVL(p_number,0);
END setZero;
BEGIN
RETURN global_number;
END get_number;
END ui_test1;
SELECT DISTINCT
object_name
,object_type
,name
,type
,line
,col
FROM all_identifiers obj
WHERE obj.owner = USER
AND obj.usage = 'DECLARATION'
AND obj.object_name = 'UI_TEST1'
AND NOT EXISTS (
SELECT 1
FROM all_identifiers with_rh
WHERE obj.signature = with_rh.signature
AND with_rh.usage IN ('REFERENCE','CALL','ASSIGNMENT')
ORDER BY TYPE
,object_name
,object_type
,name;
OBJECT_NAME OBJECT_TYPE NAME TYPE LINE COL
UI_TEST1 PACKAGE GET_NUMBER FUNCTION 11 10
UI_TEST1 PACKAGE BODY SETZERO FUNCTION 35 14
UI_TEST1 PACKAGE UI_TEST1 PACKAGE 1 9
UI_TEST1 PACKAGE BODY SETNULL PROCEDURE 12 11
Regards
Marcus -
How to generate csv ouput by using a procedure
Hi All,
How do I generate a csv (comma separate value) output by using procedure. I have 2 SQL statements in my procedure, I need to generate a csv file with the result set of 2 SQL's. For Example;
I have the following 2 SQL's in my procedure
Cursor emp_det Is Select * From emp where sal < 4000;
Cursor sal_det Is Select e.* from emp e,dept d where d.dname = 'SALES'
My requirement is to generate a csv ouput with the result set of cursors emp_det & sal_det. How can I generate a csv ouput by using PL/SQL. I could generate the same by using tools like TOAD & PL/SQL Developer. But I need to generate csv output by using PL/SQL only...Your help would be more appreciated.use tom kyte's dump_csv.
create or replace function dump_csv( p_query in varchar2,
p_separator in varchar2
default ',',
p_dir in varchar2 ,
p_filename in varchar2 )
return number
AUTHID CURRENT_USER
is
l_output utl_file.file_type;
l_theCursor integer default dbms_sql.open_cursor;
l_columnValue varchar2(2000);
l_status integer;
l_colCnt number default 0;
l_separator varchar2(10) default '';
l_cnt number default 0;
l_colDesc dbms_sql.DESC_TAB;
begin
l_output := utl_file.fopen( p_dir, p_filename, 'w' );
dbms_sql.parse( l_theCursor, p_query, dbms_sql.native );
for i in 1 .. 255 loop
begin
dbms_sql.define_column( l_theCursor, i,
l_columnValue, 2000 );
l_colCnt := i;
exception
when others then
if ( sqlcode = -1007 ) then exit;
else
raise;
end if;
end;
end loop;
dbms_sql.define_column( l_theCursor, 1, l_columnValue, 2000 );
l_status := dbms_sql.execute(l_theCursor);
dbms_sql.describe_columns(l_theCursor,l_colCnt, l_colDesc);
l_separator := '';
for lColCnt in 1..l_colCnt
loop
utl_file.put( l_output, l_separator || '"' || Upper(l_colDesc(lColCnt).col_name) || '"');
l_separator := p_separator;
end loop;
utl_file.new_line( l_output );
loop
exit when ( dbms_sql.fetch_rows(l_theCursor) <= 0 );
l_separator := '';
for i in 1 .. l_colCnt loop
dbms_sql.column_value( l_theCursor, i,
l_columnValue );
utl_file.put( l_output, l_separator || '"' ||
l_columnValue || '"');
l_separator := p_separator;
end loop;
utl_file.new_line( l_output );
l_cnt := l_cnt+1;
end loop;
dbms_sql.close_cursor(l_theCursor);
utl_file.fclose( l_output );
return l_cnt;
end dump_csv;Thanks,
Karthick. -
How to pass dynamically table name in my cursor declaration
Hi:
I am new. could you please let me know how to pass a table name dynamically in my cursor declaration? for instance I am declaring the following cursor in my pl/sql procedure:
CURSOR crs_validate IS
select * FROM <ACT_JUN_2006_LOB>;
this ACT_JUN_2006_LOB table name, I should able to pass it when I open the cursor ... any help appreciated. thanks.
sriniThanks all for the response. REFCURSOR does work: here is an example ... which I found on-line
procedure emp_test(
month varchar2,
year varchar2)
is
type cur_typ is ref cursor;
c cur_typ;
query_str varchar2(200);
emp_number number := 7900;
salary number;
name varchar2(30);
Begin
query_str := 'Select empno, ename, sal from emp_' || month ||'_'||year
|| ' where empno = :id';
open c for query_str using emp_number;
loop
fetch c into emp_number, name, salary;
exit when c%notfound;
dbms_output.put_line(emp_number);
end loop;
close c;
end; -
I have the following cursor defined in a oracle procedure:
Cursor counts_cursor_comb is
Select period, sum(count) as count, sum(group_cnt_total) as group_cnt_total, sum(total_income) as total_income,
sum(group_income_total) as group_income_total, sum(total_itd) as total_itd, sum(group_itd_amt) as group_itd_amt
From rpt_recency_counts_report
Where trim(country) = 'US'
Group by trim(period);
The SQL runs fine in SQL Worksheet
but when I run it in my procedure I get the following error:
ERROR at line 1:
ORA-00937: not a single-group group function
ORA-06512: at "DEMO.P_RECENCY_COUNTS_REPORT", line 63
ORA-06512: at "DEMO.P_RECENCY_COUNTS_REPORT", line 635
ORA-06512: at line 1
line 63 is where the cursor is defined and line 635 is where I open it.
Any help would be appreciated.
Thanks,
RaviTry removing the trim() from the GROUP BY, or add it to the select
-
Using cursor to update column, is this inefficient or illegal?
I have declared a cursor as follows in a PL/SQL procedure:
cursor C is SELECT a FROM t
FOR UPDATE;
Later on in the procedure, I've written the following:
update t
set b = 'text'
where current of C;
My question is, am I allowed to do this when the column I am updating is not the one which I have selected in the cursor? If this is indeed legal, are there any performance issues involved?
Thanks,
PeterPeter,
As it is confirmed by our folks that it is LEGAL to update columns that are not
fetched in the CURSOR, I am just going to talk about other things.
CURSOR is a read only resultset in PL/SQL which just gives you a handle to each of the rows that you are fetching from one or more table(s), based on the columns that you select in CURSOR. It is advised that you select the ID columns of the table(s) like PK if available from those tables so that you would not run into updating rows more than what is actually required. If we are not fetching the rows based on UNIQUE value and we use these values in UPDATE statements inside, we may get into trouble. Alternative and proves very good with performance is ROWID. I have used ROWID in CURSOR fetches and it works great.DECLARE
CURSOR empCur IS
SELECT ROWID unique_col, ename, job, sal FROM EMP
WHERE sal > 1000;
BEGIN
FOR empRec IN empCUR
LOOP
UPDATE emp SET job = 'Tech Lead'
WHERE ROWID = empRec.unique_col;
END LOOP;
END;Andrew,
Just curious, could you educate me on MVP status from Brainbech?
Thx,
SriDHAR -
Different query behaviour (index or no index use) between sql and pl/sql
Hi All,
I have a query inside a cursor in a procedure, let's say:
cursor c_emp (b_dept_no in number)
is
select *
from emp
where dept_no = b_dep_no;
There is an non unique index on dept_no.
In this procedure i first loop through another cursor which gets the dept_no and with this dept_no i go into a for loop for the c_emp cursor.
When i run this procedure i see that the explain plan of above query gives me a Full table Scan on EMP, eventhough there is a index on dept_no and there are 1.3 million records in the em table. When i take the above query and explain it seperately, it uses the index on dept_no.
I have rebuild/analyzed the tables and indexes, nothing seems to work. Even hints in the procedure cursor are not helping at all.
I'm using Oracle Database 10.2.0.1.0 and have never seen such behaviour before.
Anyone an idea what is going on here?
Kind regards,
DaveHoi Rob,
it's like i have three tables. The first i have to get data from for my output, then for every record of table one there are one or more records in table 2 and table 3.
I had to create a xml file and it looks like this:
<Table1 Record 1>
<Name>...</Name>
etc...
<Table2 Record 1>
</Table2 Record 1>
<Table2 Record 2>
</Table2 Record 2>
<Table3 Record 1>
</Table3 Record 1>
<Table3 Record 2>
</Table3 Record 2>
<Table1 Record 2>
etc.etc.etc.
So that's why i programmed:
for r_1 in c_table1 loop
for r_2 in c_table2(r_1.dept_no) loop
end loop;
for r_3 in c_table3(r_1.dept_no) loop
end loop;
end loop;
And when i look at the first record,
it has 2 records in table2 en 16 records in table3. So nothing huge.
For now i'm unable to trace the session. I will try to post the tkprof later.
Kind regards,
Dave -
How to check a XMLTYPE table for corrupted (not invalid!) XML records ??
Hello,
I'd like to get help on the following issue, please. I need to check the XML data in a number of tables with XMLTYPE data type. Some of the data is corrupted but in terms not that the XML format is wrong but there is no XML at all in the fields but just only, for example, control characters (no tags, no anything, just corrupted data).
So, I have made a PL/SQL procedure cursor to get all the tables from a list, and then another cursor inside to browse each table for corrupted records. But can you help me how to check this? Any of the XML functions like for example: XMLIsValid, isFragment(), getrootelement(), etc. return to me an Oracle error "ORA-31011 XML parsing failed" and the procedure gets stuck on the first found bad record. But I need to continue and check all of them. Is it possible to get the ORA-31011 error with EXCEPTION, write to a logging table the corrupted record ID, and then continue?
Here is my simple procedure:
CREATE OR REPLACE PROCEDURE CHECKXML (v_schema in VARCHAR2)
IS
v_Message VARCHAR2(254);
sql_stmt1 VARCHAR2(1000);
sql_stmt2 VARCHAR2(1000);
c1 SYS_REFCURSOR;
c2 SYS_REFCURSOR;
cur_tab varchar2(100);
cur_appl varchar2(100);
cur_rec varchar2(200);
valid_flag number;
criteria VARCHAR2(20);
tab1 VARCHAR2(20);
tab2 VARCHAR2(20);
BEGIN
criteria := 'XMLTYPE';
sql_stmt1 := 'select id, path from ' || v_schema || '.stubfiles where type=:bcriteria';
open c1 for sql_stmt1 using criteria;
loop
begin
fetch c1 into cur_tab, cur_appl;
exit when c1%notfound;
insert into system.log_table values (sysdate, v_schema, 'next table', 'id ' || cur_tab, 'appl ' || cur_appl, '');
sql_stmt2 := 'select t.recid, t.xmlrecord.isFragment() from ' || v_schema || '.' || cur_tab || ' t';
open c2 for sql_stmt2;
loop
begin
fetch c2 into cur_rec, valid_flag;
exit when c2%notfound;
insert into system.log_table values (sysdate, v_Schema, 'next record', 'id ' || cur_tab, 'recid ' || cur_rec, 'valid ' || valid_flag);
commit;
EXCEPTION
WHEN OTHERS THEN v_Message := sqlerrm;
dbms_output.put_line('Error for ' || cur_tab);
dbms_output.put_line('-' || v_Message);
insert into system.log_table values (sysdate, cur_tab, 'id err' || c_Row.ID,'appl err' || c_Row.path, v_Message,'');
end;
end loop;
close c2;
commit;
end;
end loop;
close c1;
commit;
END CHECKXML;
Thanks in advance
EvgeniHi
Why do you use a GTT? Just keep your xml in memory...
HTH
Chris -
My itunes wont open! but my quicktime player works fine! help please
my itunes wont opena dn ive been told that if my quick time does not open then people have solutions but what should i do if my quicktime opens fine its just my itunes that wont work??
pleas help me i appreciate ithi ho!
well i did what u suggested and the itunes only stayed there for about 10 seconds...
hmmm. i don't really like the sound of that. it's consistent with the malware problem (it seems to be a Qoologic variant) that has been causing "error-less" itunes launch failures for a lot of people since late October.
however, there are at least two other fairly common causes of error-less launch failures (and some rarer ones), so the diagnosis can be a bit tricky. look through the diagnostic procedures and treatment suggestions given in this post here:
http://discussions.apple.com/click.jspa?searchID=349706&messageID=1211446
if you do get itunes launching using the MSCONFIG technique, let us know the names of the start-up items you you have to disable. (letter-for-letter-capitalisation-for-capitalisation. include the filename extensions of the start-up items.)
love, b
Maybe you are looking for
-
Help needed in getting real time system performance monitor
Hi, I need a real time system performance monitor for my solaris. i am able to graph system usage graph on a daily/weely basis using the ksar grapher. In the same way i need to capture the system utilisation real time to be viewed on a webpage. Pleas
-
MarginPreference in InDesign CS5 js
Hi, I need to set margins to a different value, and my line doesn't work: myDoc.marginPreferences(MarginPreference.bottom =".125 in"); Thank you very much. Yulia
-
Can i backup photos and music to the icloud
Can I backup photos and music to the icloud
-
i recently got a contract sim with talk talk on my iphone 3gs but i cannot send mms using the settings from their websidt and going through them over the phone with talktalk they said the only people to contact is apple any suggestions please
-
Solaris does not see second cpu
I have put together the following system: Asus A7M266-D mobo 2 - Athlon MP 1.6+ cpus 2 - 512 MB DDR PC2100 Maxtor 60 gb hd Matrox G450 agp video mpstat shows only cpu 0. Any thoughts on how to get both cpus running? Allen