Creating stored procedure giving error - plsql

I have created a stored procedure
create or replace
PROCEDURE "USP_USER_ADD" (
USERNAME IN VARCHAR2 ,
P_PASSWORD IN VARCHAR2 ,
SALT IN BLOB ,
EMAIL IN VARCHAR2 ,
FIRST_NAME IN VARCHAR2 ,
LAST_NAME IN VARCHAR2 ,
ip_address IN VARCHAR2 ,
EMAIL_VERIFIED IN NUMBER ,
ACTIVE IN NUMBER ,
CREATEDBY IN VARCHAR2 ,
CREATED IN DATE ,
MODIFIED IN DATE ,
MODIFIEDBY IN VARCHAR2 ,
USER_GROUP_ID IN NUMBER ,
LAST_PASSWORD_CHANGE_DATE IN DATE ,
P_failed_login_attempts IN NUMBER )
AS
BEGIN
declare
user_id_tmp number(20);
INSERT INTO users( "username" ,
"password" ,
"salt" ,
"email" ,
"first_name" ,
"last_name" ,
"email_verified" ,
"active" ,
"ip_address" ,
"created" ,
"createdby" ,
"modified" ,
"modifiedby" ,
"user_group_id" ,
"last_password_change_date" ,
"FAILED_LOGIN_ATTEMPTS"
)
VALUES
(
username ,
p_password ,
salt ,
email ,
first_name ,
last_name ,
email_verified ,
active ,
ip_address ,
created ,
createdby ,
modified ,
modifiedby ,
user_group_id ,
last_password_change_date ,
p_failed_login_attempts
);
SELECT MAX(id) INTO user_id_tmp FROM users ;
INSERT INTO user_passwords
(
"user_id" ,
"password" ,
"created"
)
VALUES
(
user_id_tmp,
p_password,
created
);
END USP_USER_ADD;
It's giving me two errors
1: Error(26,5): PLS-00103: Encountered the symbol "INSERT" when expecting one of the following: begin function package pragma procedure subtype type use form current cursor The symbol "begin" was substituted for "INSERT" to continue.
2: Error(78,19): PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: begin case declare end exception exit for goto if loop mod null pragma raise return select update while with << close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe
These are my tables
--------------------------------------------------------
-- DDL for Table USER_PASSWORDS
--------------------------------------------------------
CREATE TABLE "NEWS1.0"."USER_PASSWORDS"
( "ID" NUMBER(11,0),
"USER_ID" NUMBER(11,0),
"PASSWORD" VARCHAR2(255 BYTE),
"SALT" VARCHAR2(255 BYTE),
"IP" VARCHAR2(15 BYTE),
"CREATEDBY" VARCHAR2(255 BYTE),
"CREATED" DATE,
"MODIFIED" DATE,
"MODIFIEDBY" VARCHAR2(255 BYTE)
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;
--------------------------------------------------------
-- DDL for Index USERS_PK
--------------------------------------------------------
CREATE UNIQUE INDEX "NEWS1.0"."USERS_PK" ON "NEWS1.0"."USER_PASSWORDS"
("ID")
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;
--------------------------------------------------------
-- Constraints for Table USER_PASSWORDS
--------------------------------------------------------
ALTER TABLE "NEWS1.0"."USER_PASSWORDS" MODIFY ("ID" NOT NULL ENABLE);
ALTER TABLE "NEWS1.0"."USER_PASSWORDS" MODIFY ("USER_ID" NOT NULL ENABLE);
ALTER TABLE "NEWS1.0"."USER_PASSWORDS" MODIFY ("PASSWORD" NOT NULL ENABLE);
ALTER TABLE "NEWS1.0"."USER_PASSWORDS" ADD CONSTRAINT "USERS_PK" PRIMARY
KEY ("ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ENABLE;
--------------------------------------------------------
-- DDL for Trigger BI_USER_PASSWORDS_ID
--------------------------------------------------------
CREATE OR REPLACE TRIGGER "NEWS1.0"."BI_USER_PASSWORDS_ID"
before insert on "USER_PASSWORDS"
for each row
begin
if inserting then
if :NEW."ID" is null then
select USER_PASSWORDS_SEQ.nextval into :NEW."ID" from dual;
end if;
end if;
end;
/
ALTER TRIGGER "NEWS1.0"."BI_USER_PASSWORDS_ID" ENABLE;
--------------------------------------------------------
-- DDL for Table USERS
--------------------------------------------------------
CREATE TABLE "NEWS1.0"."USERS"
( "ID" NUMBER(*,0),
"USERNAME" VARCHAR2(100 BYTE),
"PASSWORD" VARCHAR2(255 BYTE),
"SALT" BLOB,
"EMAIL" VARCHAR2(100 BYTE),
"FIRST_NAME" VARCHAR2(100 BYTE),
"LAST_NAME" VARCHAR2(100 BYTE),
"EMAIL_VERIFIED" NUMBER(*,0) DEFAULT 1,
"ACTIVE" NUMBER(*,0) DEFAULT 1,
"IP_ADDRESS" VARCHAR2(50 BYTE),
"USER_GROUP_ID" NUMBER(*,0),
"LAST_PASSWORD_CHANGE_DATE" DATE,
"FAILED_LOGIN_ATTEMPTS" NUMBER(*,0),
"CREATED" DATE,
"CREATEDBY" VARCHAR2(255 BYTE),
"MODIFIED" DATE,
"MODIFIEDBY" VARCHAR2(255 BYTE)
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS"
LOB ("SALT") STORE AS (
TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 10
NOCACHE LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)) ;
--------------------------------------------------------
-- DDL for Index USERS_UK2
--------------------------------------------------------
CREATE UNIQUE INDEX "NEWS1.0"."USERS_UK2" ON "NEWS1.0"."USERS" ("EMAIL")
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;
--------------------------------------------------------
-- DDL for Index USERS_UK1
--------------------------------------------------------
CREATE UNIQUE INDEX "NEWS1.0"."USERS_UK1" ON "NEWS1.0"."USERS" ("USERNAME")
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;
--------------------------------------------------------
-- Constraints for Table USERS
--------------------------------------------------------
ALTER TABLE "NEWS1.0"."USERS" MODIFY ("ID" NOT NULL ENABLE);
ALTER TABLE "NEWS1.0"."USERS" MODIFY ("USERNAME" NOT NULL ENABLE);
ALTER TABLE "NEWS1.0"."USERS" MODIFY ("PASSWORD" NOT NULL ENABLE);
ALTER TABLE "NEWS1.0"."USERS" ADD CONSTRAINT "USERS_UK1" UNIQUE
("USERNAME")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ENABLE;
ALTER TABLE "NEWS1.0"."USERS" ADD CONSTRAINT "USERS_UK2" UNIQUE ("EMAIL")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ENABLE;

The problem is in this section of code:
P_failed_login_attempts IN NUMBER )
AS
BEGIN
declare
user_id_tmp number(20);
INSERT INTO users( "username" ,
-- rest omitted
Remove the declare and move the declaration of user_id between the AS and the BEGIN:
P_failed_login_attempts IN NUMBER )
AS
user_id_tmp number(20);
BEGIN
INSERT INTO users( "username" ,
-- rest omitted
In Oracle PL/SQL, a block has the form
DECLARE
-- some variable declarations
BEGIN
-- some code
EXCEPTION
-- some exception-handling
END;
The variable declarations and exception-handling sections are optional. If there are no variable declarations, you can remove the keyword DECLARE (it's not an error if you leave it there). However, if the block has no exception handling, the EXCEPTION keyword must be removed.
When declaring a procedure or function, the CREATE OR REPLACE PROCEDURE ... AS part takes the place of a DECLARE.
The -- some code section of a PL/SQL block can contain further blocks inside it. In fact, this is what the PL/SQL compiler thought you wanted when it saw your declare keyword. It thought you were doing something like the following:
CREATE OR REPLACE PROCEDURE USP_USER_ADD (
-- parameters omitted
)
AS
BEGIN
DECLARE
-- some variable declarations
BEGIN
-- some code
END;
END USP_USER_ADD;
However, you had an INSERT after the declare. The compiler wasn't expecting that, and that's why you got an error. You also got an error about end-of-file, and that was because the PL/SQL compiler was expecting two ENDs but got to the end of your stored procedure before it found the second one.

I think that you should remove DECLARE.
Oracle 11g Create Procedure Documentation

Previous answers have cleared up the compile errors, so I won't address those. But you have a potential bug in place; the id inserted into "user_password" table may not be the same as in "user" table In a multi-user environment it is possible another user could insert and commit into after you insert into set but before you do the select max. That would hopefully raise dup-val-on-index, but would be extremely difficult to find.
You can remove this possibility, and have slightly less/cleaner(?) code by getting the id assigned by a trigger?) by using the return option on the insert itself:
insert into user ( ... ) values (...) returning id into user_id_tmp ;
and delete the select max(id) ... statement.

Related

MariaDB limit value of column

I want to limit the value of the column limited_column, where 0 >= limited_column <= 100 SQL side, on MariaDB
I've tried creating a trigger on INSERT ad UPDATE as such:
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`username` varchar(25) NOT NULL,
`user_id` int(100) NOT NULL,
`limited_column` bigint(20) unsigned NOT NULL DEFAULT '0',
[...]
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DELIMITER $$
CREATE TRIGGER `limited_column_check_on_insert_trigger` BEFORE INSERT ON `users` FOR EACH ROW
BEGIN
DECLARE dummy,baddataflag INT;
SET baddataflag = 0;
IF NEW.limited_column > 100 THEN
SET baddataflag = 1;
END IF;
IF NEW.limited_column < 0 THEN
SET baddataflag = 1;
END IF;
IF baddataflag = 1 THEN
SELECT CONCAT('Cannot INSERT new value because limited_column is > 100, value was ',NEW.limited_column)
INTO dummy FROM information_schema.tables;
END IF;
END; $$
CREATE TRIGGER `limited_column_check_on_update_trigger` BEFORE UPDATE ON `users` FOR EACH ROW
BEGIN
DECLARE dummy,baddataflag INT;
SET baddataflag = 0;
IF NEW.limited_column > 100 THEN
SET baddataflag = 1;
END IF;
IF NEW.limited_column < 0 THEN
SET baddataflag = 1;
END IF;
IF baddataflag = 1 THEN
SELECT CONCAT('Cannot UPDATE new value because limited_column is > 100, value was ',NEW.limited_column)
INTO dummy FROM information_schema.tables;
END IF;
END; $$
DELIMITER ;
This is what I get if I try inserting a new user when limited_column > 100 (limited_column > 100 works):
MariaDB [NameOfADatabase]> INSERT INTO users (username,user_id,limited_column,[...]) VALUES ('testestes',1,1000,[...]);
ERROR 1172 (42000): Result consisted of more than one row
MariaDB [NameOfADatabase]> INSERT INTO users (username,user_id,limited_column,[...]) VALUES ('testestes',2,100,[...]);
Query OK, 1 row affected (0.02 sec)
Any ideas on what I can do to make this more graceful?
This is running on 10.1.38-MariaDB-0ubuntu0.18.04.2 Ubuntu 18.04
Upgrading to 10.3.15 was the best solution for this, as I can use the CHECK option. Thanks to #RickJames for the info about the update.
Here's the Schema I'm using that works:
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`username` varchar(25) NOT NULL,
`user_id` int(100) NOT NULL,
`limited_column` bigint(20) unsigned NOT NULL DEFAULT '0',
[...]
PRIMARY KEY (`user_id`),
CHECK (limited_column<=100)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Here's the output I get:
MariaDB [NameOfADatabase]> INSERT INTO users (username,user_id,limited_column,[...]) VALUES ('test1',1,100,[...]);
Query OK, 1 row affected (0.016 sec)
MariaDB [NameOfADatabase]> INSERT INTO users (username,user_id,limited_column,[...]) VALUES ('test2',2,101,[...]);
ERROR 4025 (23000): CONSTRAINT `CONSTRAINT_1` failed for `NameOfADatabase`.`users`

Errors in triggers

This is my trigger:
CREATE OR REPLACE TRIGGER trg_CheckStaffID
BEFORE INSERT ON ASSIGN
FOR EACH ROW
BEGIN
DECLARE id integer := 0;
SET id := (select count(*) from (select staffid from staff where staffid ='T2');
IF (id=0) THEN
RAISE_APPLICATION_ERROR(-20000,'Please Enter A Valid Staff ID');
END IF;
END;
/
And this is the error message I get:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( - + case mod new not null
continue avg count current exists max min prior sql stddev
sum variance execute forall merge time timestamp interval
date
pipe
PLS-00103: Encountered the symbol "IF"
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
end not pragma final instantiable order overriding static
member constructor map
Invalid syntax on different places; DECLARE section should be before BEGIN. There's no SET command in PL/SQL.
Here's code that compiles; whether it does what you meant, can't tell. (I'm creating dummy tables, just to make sure that trigger creation wouldn't fail).
SQL> create table assign (id number);
Table created.
SQL> create table staff (staffid varchar2(2));
Table created.
SQL> create or replace trigger trg_checkstaffid
2 before insert on assign
3 for each row
4 declare
5 id integer := 0;
6 begin
7 select count(*)
8 into id
9 from (select staffid
10 from staff
11 where staffid ='T2');
12
13 if id = 0 then
14 raise_application_error(-20000, 'Please Enter A Valid Staff ID');
15 end if;
16 end;
17 /
Trigger created.
SQL>

Getting error while creating PL SQL function

Question is :
Create a Function named 'credit_limit' which takes shipment entity id(i.e, entity_id) as input and returns the limit_status of type varchar.
Function name : credit_limit
Input Parameter : entity_id in int
Output variable : limit_status variable of type varchar
Design rules:
1. If the credit_limit of the given entity id is greater then 50000,then display the limit_status as 'Credit limit is greater than 50000'
2. If the credit_limit of the given entity id is less then 50000,then display the limit_status as 'Credit limit is less than 50000'
Note: DO NOT CHANGE the given status message in your solution.
create or replace function credit_limit (entity_id in integer)
return varchar
is
c_credit_limit NUMBER(*,2);
limit_status varchar(255);
begin
select credit_limit into c_credit_limit from shipment_entity
where id = entity_id;
return(c_credit_limit);
if c_credit_limit > 50000 then
limit_status := 'Credit limit is greater than 50000';
else
if c_credit_limit < 50000 then
limit_status := 'Credit limit is less than 50000';
end if;
return (limit_status);
end;
/
I entered the code received an error
Warning: Function created with compilation errors.
please help me out.
You get issue because of 2 reasons:
1) You can return only once from a Function. You used it multiple times.
2) END IF is missing in one of the IF-ENDIF block.
Modifed code is:
CREATE OR REPLACE FUNCTION credit_limit (entity_id IN INTEGER)
RETURN VARCHAR2
IS
c_credit_limit NUMBER (5, 2);
limit_status VARCHAR (255);
BEGIN
SELECT credit_limit
INTO c_credit_limit
FROM shipment_entity
WHERE id = entity_id;
IF c_credit_limit > 50000
THEN
limit_status := 'Credit limit is greater than 50000';
ELSE
IF c_credit_limit < 50000
THEN
limit_status := 'Credit limit is less than 50000';
END IF;
END IF;
RETURN (c_credit_limit);
END;
/

Oracle Sql Developer can't export clob data?

I have a table, which contain a clob field having some data. When I export, i couldn't get the data of clob field.
CREATE TABLE "ADMIN"."TABLE"
( "ID" NUMBER(10,0),
"DATAS" CLOB
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSTEM"
LOB ("DATAS") STORE AS BASICFILE (
TABLESPACE "SYSTEM" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION
NOCACHE LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) ;
REM INSERTING into ADMIN.TABLE
SET DEFINE OFF;
Insert into ADMIN.TABLE (ID) values (1);
This is the exported sql query. Here you can find the last line in 'Insert into ADMIN.TABLE (ID) values (1);' No 'DATAS' field here. Its a clob field.
You'll have to do this.
SELECT /*insert*/* FROM ADMIN.TABLE;
Click run script, not run statement. This will produce the insert statements you are looking for.

Not able to store values to a nested table in oracle

I am trying to write a function to show values for monthly data according to the selection made by the user in monthly report. Code snippet below is just trying to fetch values in a nested table and once data is loaded successfully in a nested table, I will call the function to display the table. I have tried a few things; but am running into issues while loading data. Below are 2 different SQLs to create this function but both of them are getting same error regarding incorrect values; I have tried a few things but to no avail:
Snippet 1:
/* Formatted on 10/16/2012 8:40:45 AM (QP5 v5.215.12089.38647) */
CREATE OR REPLACE TYPE tempObject AS OBJECT
(
kpiid number,
kpigroup VARCHAR2 (300)
);
CREATE OR REPLACE TYPE tempTable AS TABLE OF tempObject;
CREATE OR REPLACE FUNCTION KPI_HORIZON.Monthly_All_Data (
mainarea IN VARCHAR2)
RETURN tempTable
IS
MonthlyData temptable := temptable ();
n INTEGER := 0;
BEGIN
IF (mainarea = 'ALL')
THEN
FOR r IN (SELECT DISTINCT kpiid, kpigroup
FROM kpi_summary_reporting
WHERE kpifrequency = 'Monthly' AND active_ind = 'Y')
LOOP
monthlydata.EXTEND;
n := n + 1;
monthlydata (n) := tempobject (r.kpiid, r.kpigroup);
END LOOP;
END IF;
RETURN MonthlyData;
END;
Error: [Error] PLS-00306 (26: 29): PLS-00306: wrong number or types of arguments in call to 'TEMPOBJECT'
Snippet2:
/* Formatted on 10/16/2012 8:27:22 AM (QP5 v5.215.12089.38647) */
CREATE OR REPLACE TYPE tempObject AS OBJECT
(
kpiid NUMBER,
kpigroup VARCHAR2 (300)
);
CREATE OR REPLACE TYPE tempTable AS TABLE OF tempObject;
CREATE OR REPLACE FUNCTION KPI_HORIZON.Monthly_All_Data (
mainarea IN VARCHAR2)
RETURN tempTable
AS
MonthlyData temptable := temptable ();
BEGIN
IF (mainarea = 'ALL')
THEN
SELECT DISTINCT ksr.kpiid, ksr.kpigroup
INTO MonthlyData
FROM kpi_summary_reporting ksr
WHERE kpifrequency = 'Monthly' AND active_ind = 'Y';
ELSE
SELECT DISTINCT kpiid, kpigroup
INTO MonthlyData
FROM kpi_summary_reporting;
END IF;
RETURN MonthlyData;
END;
Error: [Error] ORA-00947 (24: 9): PL/SQL: ORA-00947: not enough values
I would do something like this assuming that the data is small enough that it really makes sense to load it entirely into a nested table in the server's PGA. If the data volume is larger, you probably want to use a pipelined table function instead.
Since your nested table is a table of object types, you need to use the object type constructor.
CREATE OR REPLACE FUNCTION KPI_HORIZON.Monthly_All_Data (
mainarea IN VARCHAR2)
RETURN tempTable
IS
MonthlyData temptable;
BEGIN
IF (mainarea = 'ALL')
THEN
SELECT tempObject( kpiid, kpigroup )
BULK COLLECT INTO monthlydata
FROM kpi_summary_reporting
WHERE kpifrequency = 'Monthly'
AND active_ind = 'Y';
END IF;
RETURN MonthlyData;
END;
I'm always dubious when I see a DISTINCT in a query. Do you really expect to get duplicate rows that you need to remove? If not, you'll be much better served removing the DISTINCT as I did above. If you really need the DISTINCT, then your object type would need a MAP or an ORDER method which would complicate the example a bit.
A demonstration of this working
SQL> CREATE OR REPLACE TYPE tempObject AS OBJECT
2 (
3 kpiid NUMBER,
4 kpigroup VARCHAR2 (300)
5 );
6 /
Type created.
SQL> CREATE OR REPLACE TYPE tempTable AS TABLE OF tempObject;
2 /
Type created.
SQL> create table kpi_summary_reporting (
2 kpiid integer,
3 kpigroup varchar2(300),
4 kpifrequency varchar2(30),
5 active_ind varchar2(1)
6 );
Table created.
SQL> insert into kpi_summary_reporting values( 1, 'Foo', 'Monthly', 'Y' );
1 row created.
SQL> ed
Wrote file afiedt.buf
1 CREATE OR REPLACE FUNCTION Monthly_All_Data (
2 mainarea IN VARCHAR2)
3 RETURN tempTable
4 IS
5 MonthlyData temptable;
6 BEGIN
7 IF (mainarea = 'ALL')
8 THEN
9 SELECT tempObject( kpiid, kpigroup )
10 BULK COLLECT INTO monthlydata
11 FROM kpi_summary_reporting
12 WHERE kpifrequency = 'Monthly'
13 AND active_ind = 'Y';
14 END IF;
15 RETURN MonthlyData;
16* END;
17 /
Function created.
SQL> select monthly_all_data( 'ALL' ) from dual;
MONTHLY_ALL_DATA('ALL')(KPIID, KPIGROUP)
--------------------------------------------------------------------------------
TEMPTABLE(TEMPOBJECT(1, 'Foo'))

Resources