I am using oracle 10g.
While Creating Package in oracle. I am getting this error SQL Statement Ignored.
My Package Specification is :
create or replace PACKAGE PACKAGE_CHECK AS
PROCEDURE USP_PASS_EXPIRE(SP_DAYS_COUNT OUT NUMBER, SP_LOGIN_NAME IN VARCHAR2);
END PACKAGE_CHECK;
and package body is:
create or replace PACKAGE BODY PACKAGE_CHECK AS
PROCEDURE USP_PASS_EXPIRE(SP_DAYS_COUNT OUT NUMBER, SP_LOGIN_NAME IN VARCHAR2) IS
BEGIN
SELECT (SYSDATE-"LastLogin")
FROM "ApplicationUser"
WHERE "LoginName"=SP_LOGIN_NAME
AND "IsActive"='Y'
AND "IsDeleted"='N' returning (SYSDATE-"LastLogin")
into SP_DAYS_COUNT;
END USP_PASS_EXPIRE;
END PACKAGE_CHECK;
Plaese help. I don't know where am I going wrong?
The reason is that you are using returning clause with SELECT, however it can be used only with DELETE, EXECUTE IMMEDIATE, INSERT, and UPDATE statements, see
docs.oracle.com/cd/B19306_01/appdev.102/b14261/returninginto_clause.htm
Try this:
CREATE OR REPLACE PACKAGE PACKAGE_CHECK
AS
PROCEDURE USP_PASS_EXPIRE(
SP_DAYS_COUNT OUT NUMBER,
SP_LOGIN_NAME IN VARCHAR2);
END PACKAGE_CHECK;
/
CREATE OR REPLACE PACKAGE BODY PACKAGE_CHECK
AS
PROCEDURE USP_PASS_EXPIRE(
SP_DAYS_COUNT OUT NUMBER,
SP_LOGIN_NAME IN VARCHAR2)
BEGIN
SELECT (SYSDATE-"LastLogin")
INTO SP_DAYS_COUNT
FROM "ApplicationUser"
WHERE "LoginName"=SP_LOGIN_NAME
AND "IsActive" ='Y'
AND "IsDeleted" ='N';
END USP_PASS_EXPIRE;
END PACKAGE_CHECK;
Related
I'm trying create package with oracle, although I have read many examples in docs oracle and built code same this tutorial but I still error this.
The following code:
create table manage_emplyee
(
f_name varchar(20),
l_name varchar(20)
);
// Specification
create or replace package fn2
as
procedure manage_emplyee(v_fname in VARCHAR2, v_lname in VARCHAR2);
procedure manage_emplyee_delete(v_fname in VARCHAR2);
end;
/
create or replace package body fn2
as
--Procedure Implementation
procedure manage_emplyee(v_fname in VARCHAR2, v_lname in VARCHAR2)
is
begin
insert into manage_emplyee VALUES (v_lname, v_lname);
end manage_emplyee;
// body
procedure manage_emplyee_delete (v_fname in VARCHAR2)
is
begin
delete manage_emplyee where v_fname = v_fname;
end manage_emplyee_delete;
end fn2;
/
Error
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
begin end function pragma procedure
Please help me fix it, thanks so much !
There are many things incorrect, so here is a correct version.
Run the table script first -
create table manage_emplyee
(
f_name varchar(20),
l_name varchar(20)
);
Run the Spec script after that
create or replace package fn2
as
procedure manage_emplyee(v_fname VARCHAR2,
v_lname VARCHAR2);
procedure manage_emplyee_delete(v_fname VARCHAR2);
end;
/
Run the body script after that
create or replace package body fn2
as
procedure manage_emplyee(v_fname VARCHAR2, v_lname VARCHAR2)
is
begin
insert into manage_emplyee VALUES (v_lname, v_lname);
end ;
procedure manage_emplyee_delete (v_fname VARCHAR2)
is
begin
delete from manage_emplyee where f_name = v_fname;
end ;
end;
/
The syntax for delete from table_name was incorrect.
I am sure, you want to match f_name from table with v_fname from the input variable to delete the data. Earlier you were matching v_fname with v_fname in your code, which will always be true (except for when its passed NULL) and you would end up loosing all your test data
*NOTE -
Adding IN explicitly is not required, the default type is IN for parameters in PLSQL procedures
i'm kind of new to Oracle Pl\SQL. I was just trying to create a simple Package with a procedure that returns a set of object id's; the code is as follows:
--Package Spec
CREATE OR REPLACE PACKAGE TEST IS
--GET OBJECT ID'S FROM CONTROL TABLE
PROCEDURE get_object_id_control(p_obj_id OUT abc_table%ROWTYPE);
END;
--Package Body
PROCEDURE get_object_id_control(p_obj_id OUT abc_table%ROWTYPE) AS
BEGIN
SELECT object_id
INTO p_obj_id
FROM abc_table
WHERE fec_proc IS NULL;
END;
I get Error: PL/SQL: ORA-00913: too many values. Is this the correct way for returning multiple values of same data type, or is there a better approach. Thanks in advance.
You can create a custom table type and set the out parameter of the procedure to that type.
CREATE TABLE ABC_TABLE(ID varchar2(100));
create or replace type abc_tab is table of varchar2(100);
/
CREATE OR REPLACE PACKAGE TEST IS
PROCEDURE get_object_id_control(p_obj_id OUT abc_tab);
END;
/
CREATE OR REPLACE PACKAGE BODY TEST IS
PROCEDURE get_object_id_control(p_obj_id OUT abc_tab) AS
BEGIN
SELECT id
bulk collect INTO p_obj_id
FROM abc_table;
END;
END;
/
Then you can call it like so:
declare
v abc_tab;
begin
TEST.get_object_id_control(p_obj_id => v);
for i in v.first..v.last loop
dbms_output.put_line(v(i));
end loop;
end;
/
Similar to GurV's answer (since he beat me by like 30 seconds...), you can use a PL/SQL object type as well. You do not need the CREATE TYPE statement if you don't need to reference the type in SQL.
--Package Spec
CREATE OR REPLACE PACKAGE TEST AS
TYPE id_table_type IS TABLE OF NUMBER;
--GET OBJECT ID'S FROM CONTROL TABLE
PROCEDURE get_object_id_control(p_obj_id_list OUT id_table_type);
END;
--Package Body
CREATE OR REPLACE PACKAGE BODY TEST AS
PROCEDURE get_object_id_control(p_obj_id_list OUT id_table_type) AS
BEGIN
SELECT object_id
BULK COLLECT INTO p_obj_id_list
FROM abc_table
WHERE fec_proc IS NULL;
END;
END;
To use it:
DECLARE
l_id_list test.id_table_type;
BEGIN
test.get_object_id_control (p_obj_id_list => l_id_list);
FOR i IN l_id_list.FIRST .. l_id_list.LAST LOOP
DBMS_OUTPUT.put_line (l_id_list (i));
END LOOP;
END;
I have got an SQL script stored in an .sql-file containing several statements like this:
create or replace package <schema>.custom_package is
procedure getReleaseEmployees(p_Cursor in out sys_refcursor, p_Role in string);
end custom_package;
/
create or replace package <schema>.pck_account_monitoring is
procedure checkAndLockOracleAccount;
end pck_account_monitoring;
/
<...some more packages following>
Running the script in an SqlDeveloper or PL/SQLDeveloper against my database works fine.
Now, when I'm trying to migrate via Flyway using the Java API, I'll get the following error message and Flyway's migration fails:
SQL State : 42000
Error Code : 900
Message : ORA-00900: Invalid SQL Statement
Location : migrations/sql/V0_2__migration.sql
Line : 6172
Statement : end pck_account_monitoring
at org.flywaydb.core.internal.dbsupport.SqlScript.execute(SqlScript.java:117)
at org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.execute(SqlMigrationExecutor.java:71)
at org.flywaydb.core.internal.command.DbMigrate.doMigrate(DbMigrate.java:352)
If I try to put the first statement into a single line, i.e.
create or replace package quattro.custom_package is procedure getReleaseEmployees(p_Cursor in out sys_refcursor, p_Role in string); end custom_package;
/
<rest as before>
I'll get the same error message, but the parser now complains about the '/' symbol and the beginning of the next statement:
Error Code : 900
Message : ORA-00900: Invalid SQL Statement
...
Line : 6167
Statement : /
create or replace package quattro.pck_account_monitoring is ...
Now, if I remove that first '/' as well, the migration will run (with warnings, though).
My schema will then correctly have compiled all the other packages except for the first one - even though every other package declaration is formatted like the first one was in my initial attempt! The first package (custom_package) however is still missing.
My Java class basically looks like the sample class from the Flyway homepage.
Does anyone have any idea what's going wrong here with the Flyway parser or can maybe provide me with a workaround?
(This is too long for a comment, therefore, I'm posting it as an answer)
FWIW, I cannot reproduce this (using the Flyway 3.2.1 command line tool); running this example script:
-- PACKAGES
create or replace package flyway_demo.custom_package is
procedure getReleaseEmployees(p_Cursor in out sys_refcursor, p_Role in string);
end custom_package;
/
create or replace package flyway_demo.pck_account_monitoring is
procedure checkAndLockOracleAccount;
end pck_account_monitoring;
/
create or replace package flyway_demo.logger
authid definer
as
-- TYPES
type rec_param is record(
name varchar2(255),
val varchar2(4000));
type tab_param is table of rec_param index by binary_integer;
g_off constant number := 0;
function is_number(p_str in varchar2)
return boolean;
end logger;
/
create or replace package body flyway_demo.pck_account_monitoring is
procedure checkAndLockOracleAccount is
begin
null;
end;
end pck_account_monitoring;
/
create or replace package body flyway_demo.custom_package is
procedure getReleaseEmployees(p_Cursor in out sys_refcursor, p_Role in string)
is
begin
open p_Cursor for select * from dual;
end;
end custom_package;
/
create or replace package body flyway_demo.logger
as
function is_number(p_str in varchar2) return boolean is
begin
return true;
end;
end logger;
/
works perfectly fine. Can you please try it with this script and post your findings?
i have an existing package named "fusion". The package definition goes like
create or replace package "fusion' as
create procedure first_procedure(abc in number)
create procedure second_procedure(efg in number)
end fusion;
The package body definition is like
create or replace package body fusion as
procedure first_procedure(abc in number) is
begin
....
end first_procedure;
procedure second_procedure(efg in number) is
begin
....
end second_procedure;
end fusion;
In this existing package i need to include a third procedure which has a custom record type as output. So where should i declare the custom record type? i have written like
create or replace package "fusion' as
type finalrecord is record(column1 varchar2,column2 number);
type mytable is table of finalrecord;
create procedure first_procedure(abc in number)
create procedure second_procedure(efg in number)
create procedure third_procedure(mt out mytable)
end fusion;
and package body as
create or replace package body fusion as
procedure first_procedure(abc in number) is
begin
....
end first_procedure;
procedure second_procedure(efg in number) is
begin
....
end second_procedure;
procedure third_procedure(mt out mytable) is
myissueid number(2);
begin
--do something
end third_procedure;
end fusion;
This is compiling in SQLDeveloper but showing these errors
subprogram or cursor 'third_procedure' is declared in a package specification and must be defined in the package body.
mytable should be declared
Try compiling the Procedure Specification with this update code
create or replace package fusion as
type finalrecord is record(column1 varchar2(20),column2 number);
type mytable is table of finalrecord;
procedure first_procedure(abc in number);
procedure second_procedure(efg in number);
procedure third_procedure(mt out mytable);
end fusion;
/
Trying to set a local variable to parameter value that is passed to Oracle stored procedure However i am getting nottihgn..what am i doing wrong. When I test the package v_param is empty.
I am passing a long text
create or replace package MA_MAIN_SP_TESTCLOB IS
v_param clob;
procedure RUNALL( iOffice clob);
end MA_MAIN_SP_TESTCLOB;
create or replace package body MA_MAIN_SP_TESTCLOB IS
procedure RUNALL(iOffice clob) IS
BEGIN
v_param := iOffice;
--dbms_output.put_line('Parmeters are ' || v_param);
insert into ICCMSDW_CR.OfficeHolder(POFFICE)
values(v_param);
END RUNALL;
END MA_MAIN_SP_TESTCLOB;