I'm new to oracle pl/sql. I want to write code to get table space info and database lock status and i want to output them as varchar2. My code gives me error
** Errors for PACKAGE BODY FINAL_PACKAGE: i run this as **SYS AS SYSDBA
LINE/COL ERROR
11/13 PLS-00103: Encountered the symbol "SELECT" when expecting one of
the following:
( ; is return
line 11 is
11 CURSOR tbsp select a.TABLESPACE_NAME as
code is,
CREATE OR REPLACE PACKAGE final_package as
PROCEDURE final_procedure(var1 in varchar2, dbinfo out varchar2);
END final_package;
/
CREATE OR REPLACE PACKAGE BODY final_package IS
PROCEDURE final_procedure(var1 in varchar2, dbinfo out varchar2) IS
BEGIN
IF var1 = 'a'
------ /* get tablespaces name, percentage */ ----
THEN
DECLARE
tsinfo varchar(500); ---- /* i want to put tablespaces result to this tsinfo */----
CURSOR tbsp select a.TABLESPACE_NAME as
Tablespace,round((1-((a.BYTES-nvl(b.BYTES,0))/a.BYTES))*100,2)
AS Percentages from (select TABLESPACE_NAME, sum(BYTES) BYTES from
sys.dba_data_files group by TABLESPACE_NAME) a,
(select TABLESPACE_NAME, sum(BYTES) BYTES from sys.dba_free_space
group by TABLESPACE_NAME) b
where a.TABLESPACE_NAME = b.TABLESPACE_NAME (+)
order by ((a.BYTES-b.BYTES)/a.BYTES) desc;
BEGIN
FOR each_data in tbsp
LOOP
FETCH tbsp INTO tsinfo; --- /* i want to put tablespaces result to this tsinfo */ ---
END LOOP;
CLOSE tbsp;
---- /* get database lock status */ ----
ELSIF var1 = 'b' THEN
DECLARE lockinfo varchar(1500);
CURSOR lock_info SELECT vh.sid locking_sid,
vw.sid waiter_sid,
vs.status status,
vs.program program_holding,
vsw.program program_waiting
FROM v$lock vh, v$lock vw,
v$session vs, v$session vsw
WHERE(vh.id1, vh.id2) IN
(SELECT id1, id2
FROM v$lock
WHERE request = 0
INTERSECT
SELECT id1, id2
FROM v$lock
WHERE lmode = 0)
AND vh.id1 = vw.id1
AND vh.id2 = vw.id2
AND vh.request = 0
AND vw.lmode = 0
AND vh.sid = vs.sid
AND vw.sid = vsw.sid;
BEGIN
FOR each_data in lockinfo
LOOP
FETCH lock_info INTO lockinfo; -- i want to put database lock result to this tsinfo
END LOOP;
CLOSE lock_info;
END IF;
END;
END;
/