Creating stored procedure in toad failed to execute - oracle

I'm creating Update Stored Procedure in Toad. When I'm executing the query it returns me an error like this.
1/51 PLS-00103: Encountered the symbol "(" when expecting one of the following:
:= . ) , # % default character
Heres my Code:
I've tried to change the AS to IN but still same error
Create Or Replace Procedure SP_EMPLOYEE_UPDATE(P_EMPLOYEEID VARCHAR2(20 CHAR),
P_EMPLOYEENAME VARCHAR2(100 CHAR),
P_STATUS VARCHAR2(50 CHAR),
P_SUPERIORID VARCHAR2(20 CHAR),
P_MANAGERSUPERIORID VARCHAR2(20 CHAR),
P_BFG VARCHAR2(10 CHAR),
P_DATEHIRED Date,
P_DESIGNATION VARCHAR2(100 CHAR),
P_JOBGRADE NUmber,
P_EMAILADDRESS VARCHAR2(100 CHAR),
P_PRODUCTLINE VARCHAR2(80 BYTE),
P_STATION VARCHAR2(80 BYTE),
P_MACHINE VARCHAR2(80 BYTE),
P_OPERATIONGROUP VARCHAR2(80 BYTE),
P_ISACTIVE VARCHAR2(1 BYTE))
AS
Begin
Update REFEMPLOYEES set REFEMPLOYEES.EMPLOYEENAME = P_EMPLOYEENAME , REFEMPLOYEES.STATUS= P_STATUS,REFEMPLOYEES.SUPERIORID = P_SUPERIORID,REFEMPLOYEES.MANAGERSUPERIORID= P_MANAGERSUPERIORID,REFEMPLOYEES.BFG = P_BFG,
REFEMPLOYEES.DATEHIRED = P_DATEHIRED,REFEMPLOYEES.DESIGNATION = P_DESIGNATION,REFEMPLOYEES.JOBGRADE = P_JOBGRADE,REFEMPLOYEES.EMAILADDRESS = P_EMAILADDRESS,REFEMPLOYEES.PRODUCTLINE = P_PRODUCTLINE,REFEMPLOYEES.STATION = P_STATION,
REFEMPLOYEES.MACHINE = P_MACHINE,REFEMPLOYEES.OPERATIONGROUP = P_OPERATIONGROUP,REFEMPLOYEES.ISACTIVE = P_ISACTIVE
Where REFEMPLOYEES.EMPLOYEEID = P_EMPLOYEEID;
End

Your code should look like following ideally:
CREATE OR REPLACE PROCEDURE SP_EMPLOYEE_UPDATE (
P_EMPLOYEEID VARCHAR2,
P_EMPLOYEENAME VARCHAR2,
P_STATUS VARCHAR2,
P_SUPERIORID VARCHAR2,
P_MANAGERSUPERIORID VARCHAR2,
P_BFG VARCHAR2,
P_DATEHIRED DATE,
P_DESIGNATION VARCHAR2,
P_JOBGRADE NUMBER,
P_EMAILADDRESS VARCHAR2,
P_PRODUCTLINE VARCHAR2,
P_STATION VARCHAR2,
P_MACHINE VARCHAR2,
P_OPERATIONGROUP VARCHAR2,
P_ISACTIVE VARCHAR2
) AS
BEGIN
UPDATE REFEMPLOYEES
SET
REFEMPLOYEES.EMPLOYEENAME = P_EMPLOYEENAME,
REFEMPLOYEES.STATUS = P_STATUS,
REFEMPLOYEES.SUPERIORID = P_SUPERIORID,
REFEMPLOYEES.MANAGERSUPERIORID = P_MANAGERSUPERIORID,
REFEMPLOYEES.BFG = P_BFG,
REFEMPLOYEES.DATEHIRED = P_DATEHIRED,
REFEMPLOYEES.DESIGNATION = P_DESIGNATION,
REFEMPLOYEES.JOBGRADE = P_JOBGRADE,
REFEMPLOYEES.EMAILADDRESS = P_EMAILADDRESS,
REFEMPLOYEES.PRODUCTLINE = P_PRODUCTLINE,
REFEMPLOYEES.STATION = P_STATION,
REFEMPLOYEES.MACHINE = P_MACHINE,
REFEMPLOYEES.OPERATIONGROUP = P_OPERATIONGROUP,
REFEMPLOYEES.ISACTIVE = P_ISACTIVE
WHERE
REFEMPLOYEES.EMPLOYEEID = P_EMPLOYEEID;
END SP_EMPLOYEE_UPDATE;
/
Cheers!!

Related

How to exec stored procedure execution using objects as output

I have this header of a stored procedure
PROCEDURE CONSULTAR_PR(
piinRegion IN NUMBER,
pistIdTramite IN VARCHAR2,
pistFolio IN NUMBER,
pistFzaVta IN VARCHAR2,
pistTipoTramite IN VARCHAR2,
pistCurp IN VARCHAR2,
potyTramite OUT PRE_TRAMITE_TYP,
potyCanal OUT NOCOPY PRE_CANAL_TYP,
potyCliente OUT NOCOPY PRE_CLIENTE_TYP,
potyContrato OUT NOCOPY PRE_CONTRATO_TYP,
potyDomicilios OUT NOCOPY SYS_REFCURSOR,
potyEquipo OUT NOCOPY PRE_EQUIPO_TYP,
potyFinanciamiento OUT NOCOPY PRE_FINAN_TYP,
potyCreditcheck OUT NOCOPY SYS_REFCURSOR,
potyFacturacion OUT NOCOPY PRE_FACTURACION_TYP,
potySuplementarios OUT NOCOPY SYS_REFCURSOR,
potyReferencias OUT NOCOPY SYS_REFCURSOR,
potyResumen OUT NOCOPY PRE_RESUMEN_TYP,
potyMigracion OUT NOCOPY PRE_MIGRACION_TYP) IS
...
and I'm trying to test with this script
set autoprint on;
VAR cursortemp1 PRE_TRAMITE_TYP;
VAR cursortemp2 PRE_CANAL_TYP;
VAR cursortemp3 PRE_CLIENTE_TYP;
VAR cursortemp4 PRE_CONTRATO_TYP;
VAR cursortemp5 REFCURSOR;
VAR cursortemp6 PRE_EQUIPO_TYP;
VAR cursortemp7 PRE_FINAN_TYP;
VAR cursortemp8 REFCURSOR;
VAR cursortemp9 PRE_FACTURACION_TYP;
VAR cursortemp10 REFCURSOR;
VAR cursortemp11 REFCURSOR;
VAR cursortemp12 PRE_RESUMEN_TYP;
VAR cursortemp13 PRE_MIGRACION_TYP;
EXEC PKG.CONSULTAR_PR(123, null, null, 'qwer', 'asdf', 'xxxxx',:cursortemp1,:cursortemp2 ,:cursortemp3,:cursortemp4,:cursortemp5,:cursortemp6,:cursortemp7,:cursortemp8,:cursortemp9,:cursortemp10,:cursortemp11,:cursortemp12,:cursortemp13);
However, some outputs are objects like the following
create TYPE PRE_RESUMEN_TYP AS OBJECT
(
COL1 VARCHAR2(50 Byte),
COL2 NUMBER,
COL3 NUMBER,
COL4 NUMBER,
COL5 NUMBER,
COL6 VARCHAR2(50 Byte),
COL7 NUMBER,
COL8 NUMBER,
COL9 NUMBER,
COL10 NUMBER,
COL11 NUMBER,
COL12 NUMBER,
COL13 NUMBER,
COL14 VARCHAR2(40 Byte)
);
I'm not an expert in SQL but I would like to know if it's possible to use objects as output, I have tested script where outputs are varchar, number or refcursor but this one I can't get it
You need an anonymous block to catch the output variables,eg
declare
l_potyTramite PRE_TRAMITE_TYP;
l_potyCanal PRE_CANAL_TYP;
l_potyCliente PRE_CLIENTE_TYP;
l_potyContrato PRE_CONTRATO_TYP;
l_potyDomicilios SYS_REFCURSOR;
l_potyEquipo PRE_EQUIPO_TYP;
l_potyFinanciamiento PRE_FINAN_TYP;
l_potyCreditcheck SYS_REFCURSOR;
l_potyFacturacion PRE_FACTURACION_TYP;
l_potySuplementarios SYS_REFCURSOR;
l_potyReferencias SYS_REFCURSOR;
l_potyResumen PRE_RESUMEN_TYP;
l_potyMigracion PRE_MIGRACION_TYP;
begin
CONSULTAR_PR(
piinRegion =>123
pistIdTramite =>'x'
pistFolio =>123
pistFzaVta =>'x'
pistTipoTramite =>'x'
pistCurp =>'x'
potyTramite => l_PRE_TRAMITE_TYP;
potyCanal => l_PRE_CANAL_TYP;
potyCliente => l_PRE_CLIENTE_TYP;
potyContrato => l_PRE_CONTRATO_TYP;
potyDomicilios => l_SYS_REFCURSOR;
potyEquipo => l_PRE_EQUIPO_TYP;
potyFinanciamiento => l_PRE_FINAN_TYP;
potyCreditcheck => l_SYS_REFCURSOR;
potyFacturacion => l_PRE_FACTURACION_TYP;
potySuplementarios => l_SYS_REFCURSOR;
potyReferencias => l_SYS_REFCURSOR;
potyResumen => l_PRE_RESUMEN_TYP;
potyMigracion => l_PRE_MIGRACION_TYP;
dbms_output.put_line(...);
end;
/
and then output them in a way the matches the object attributes

Oracle ORDS expose packaged procedure with parameters

I'm trying to expose oracle packaged procedure via Oracle ORDS but getting 404 error.
My package
create or replace PACKAGE MY_PACKAGE AS -- define the package spec
TYPE userChanges IS RECORD
(
id number(32,0),
partner_id varchar2(256 byte),
application_user varchar2(256 byte),
application_name varchar2(256 byte),
transaction_start timestamp(6) with local time zone,
transaction_end timestamp(6) with local time zone ,
service_id varchar2(256 byte),
exec_time number(32,0),
error_code varchar2(256 byte),
operation varchar2(256 byte),
type varchar2(512 byte),
name varchar2(256 byte),
value varchar2(4000 byte)
);
TYPE userTable IS TABLE OF userChanges
INDEX BY BINARY_INTEGER;
PROCEDURE GetUserSnapShot(P_START_TIME in timestamp,
P_END_TIME in timestamp,
P_MAX_ROWS in int,
myTable in out userTable);
END MY_PACKAGE;
Package body
create or replace PACKAGE BODY MY_PACKAGE AS -- define the package body
PROCEDURE getusersnapshot(P_START_TIME in timestamp,
P_END_TIME in timestamp,
P_MAX_ROWS in int,
myTable in out userTable)
AS
rec userChanges;
BEGIN
rec.id := 1;
rec.partner_id := 'test';
rec.application_user := 'ABCDEF';
rec.application_name := 'ddd';
rec.transaction_start := SYSDATE;
rec.transaction_end := SYSDATE;
rec.service_id := 'ddd';
rec.exec_time := 2;
rec.error_code := 'dddd';
rec.operation := 'ddd';
rec.type := 'ddd';
rec.name := 'ddd';
rec.value := 'ddd';
myTable(1) := rec;
END;
END MY_PACKAGE;
This package enabled rest service via SQL developer which execute following sql.
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
ORDS.ENABLE_OBJECT(p_enabled => TRUE,
p_schema => 'TESTUSER',
p_object => 'MY_PACKAGE',
p_object_type => 'PACKAGE',
p_object_alias => 'my_package',
p_auto_rest_auth => FALSE);
commit;
END;
This execute successfully.
My URL for POST is http://localhost:8083/ords/testuser/my_package/getusersnapshot with body {} as i testing.
This gives error 404.
But when i execute package with procedure without parameters it works fine. What is the problem i have here ?

PLS-00225: subprogram or cursor 'CHR' reference is out of scope

i make a procedure in plsql it return this error anyone know about it i post my code and error snap shot here
CREATE OR REPLACE PROCEDURE CHR.ATT_INSERT_TEST
IS
CURSOR ATT
IS
SELECT emp.EMPLOYEE_ID EMPLOYEE_ID,
io.CHECKTYPE CHECKTYPE,
io.MACHINE_NUM MACHINE_NUM,
io.ATT_ID ATT_ID,
io.SWIPE_DATE SWIPE_DATE,
io.SWIPE_TIME SWIPE_TIME
FROM INOUT_LIVE_MACHINE_TEST io, CHR_EMGT_EMPLOYEE emp
WHERE emp.EMPLOYEE_CODE = io.EMPLOYEE_CODE
AND io.ATT_ID NOT IN (SELECT ATT_ID_REF
FROM CHR_TA_EMP_SWIPE_IN_OUT
WHERE io.ATT_ID = ATT_ID_REF);
BEGIN
FOR I IN ATT
LOOP
INSERT INTO CHR_TA_EMP_SWIPE_IN_OUT (EMPLOYEE_ID,
SWIPE_DATE,
SWIPE_TIME,
SWIPE_ID,
SWIPE_TYPE,
CREATED_BY,
CREATION_DATE,
CLIENT_IP)
VALUES (I.EMPLOYEE_ID,
TO_DATE (i.SWIPE_DATE, 'MM/DD/YYYY'),
I.SWIPE_TIME,
CHR_TA_SWIPE_IN_OUT_SEQ.NEXTVAL,
I.CHECKTYPE,
I.EMPLOYEE_ID,
TO_DATE (i.SWIPE_DATE, 'MM/DD/YYYY'),
'192.168.0.71'
);
END LOOP;
COMMIT;
END;
/
this is my procedure i make subquery mostly time but this time it return me this kind of error.
i think this error show some issue is regarding alias but i already define alias for each column
i read this artical but my code is still stuck
PLS-00402: alias required in SELECT list of cursor to avoid duplicate column names
this is my table structure
CREATE TABLE CHR.CHR_TA_EMP_SWIPE_IN_OUT
(
EMPLOYEE_ID NUMBER(10) NOT NULL,
SWIPE_DATE DATE NOT NULL,
SWIPE_TIME DATE NOT NULL,
SWIPE_ID NUMBER(10) NOT NULL,
SWIPE_TYPE VARCHAR2(1 BYTE),
CREATED_BY NUMBER(10),
CREATION_DATE DATE,
LAST_UPDATED_BY NUMBER(10),
LAST_UPDATE_DATE DATE,
IS_MANUAL VARCHAR2(1 BYTE),
REASON_LKP NUMBER(10),
CLIENT_IP VARCHAR2(50 BYTE),
IS_REQUESTED VARCHAR2(1 CHAR),
TERMINAL_ID VARCHAR2(50 BYTE),
ATT_ID_REF NUMBER
)
CREATE TABLE CHR.CHR_EMGT_EMPLOYEE
(
EMPLOYEE_ID NUMBER(10) NOT NULL,
EMPLOYEE_CODE VARCHAR2(30 BYTE) NOT NULL
)
CREATE TABLE CHR.INOUT_LIVE_MACHINE_TEST
(
ATT_ID NUMBER,
USERID NUMBER,
EMPLOYEE_CODE NUMBER,
SENSORID NUMBER,
MACHINE_NUM VARCHAR2(20 BYTE),
CHECKTIME VARCHAR2(20 BYTE),
CHECKTYPE VARCHAR2(20 BYTE)
)
Your procedure has no mistakes. Only problem is in your table "INOUT_LIVE_MACHINE_TEST". it has missing SWIPE_DATE & SWIPE_TIME columns. See below the working demo.
Created table with both the columns:
CREATE TABLE INOUT_LIVE_MACHINE_TEST
(
ATT_ID NUMBER,
USERID NUMBER,
EMPLOYEE_CODE NUMBER,
SENSORID NUMBER,
SWIPE_DATE DATE NOT NULL,
SWIPE_TIME DATE NOT NULL,
MACHINE_NUM VARCHAR2(20 BYTE),
CHECKTIME VARCHAR2(20 BYTE),
CHECKTYPE VARCHAR2(20 BYTE)
)
Procedure compiled :
CREATE OR REPLACE PROCEDURE ATT_INSERT_TEST
IS
CURSOR ATT
IS
SELECT emp.EMPLOYEE_ID EMPLOYEE_ID,
io.CHECKTYPE CHECKTYPE,
io.MACHINE_NUM MACHINE_NUM,
io.ATT_ID ATT_ID,
io.SWIPE_DATE SWIPE_DATE,
io.SWIPE_TIME SWIPE_TIME
FROM INOUT_LIVE_MACHINE_TEST io, CHR_EMGT_EMPLOYEE emp
WHERE emp.EMPLOYEE_CODE = io.EMPLOYEE_CODE
AND io.ATT_ID NOT IN (SELECT ATT_ID_REF
FROM CHR_TA_EMP_SWIPE_IN_OUT
WHERE io.ATT_ID = ATT_ID_REF);
BEGIN
FOR I IN ATT
LOOP
INSERT INTO CHR_TA_EMP_SWIPE_IN_OUT (EMPLOYEE_ID,
SWIPE_DATE,
SWIPE_TIME,
SWIPE_ID,
SWIPE_TYPE,
CREATED_BY,
CREATION_DATE,
CLIENT_IP)
VALUES (I.EMPLOYEE_ID,
TO_DATE (i.SWIPE_DATE, 'MM/DD/YYYY'),
I.SWIPE_TIME,
CHR_TA_SWIPE_IN_OUT_SEQ.NEXTVAL,
I.CHECKTYPE,
I.EMPLOYEE_ID,
TO_DATE (i.SWIPE_DATE, 'MM/DD/YYYY'),
'192.168.0.71'
);
END LOOP;
COMMIT;
END;
/

Am getting compilation error whenever I execute

CREATE or REPLACE PROCEDURE SP_INSERT_OVERSEAS_COMPANY
(
COMPANY_CODE IN NUMBER,
COMPANY_NAME IN VARCHAR2,
STREET_ADDR IN VARCHAR2,
COMPANY_STATE IN VARCHAR2,
ZIP_CODE IN VARCHAR2,
COUNTRY IN VARCHAR2,
CONTACT_PERSON IN VARCHAR2,
CONTACT_NUMBER IN VARCHAR2
)
AS
BEGIN
IF sysdate between trunc(sysdate,'DD')+interval '9' hour and trunc(sysdate,'DD')+interval '17' hour
THEN
INSERT INTO Overseas_Company
VALUES
(COMPANY_NAME,COMPANY_NAME,STREET_ADDR,COMPANY_STATE,ZIP_CODE,COUNTRY,CONTACT_PERSON,CONTACT_NUMBER);
ELSE
dbms_output.put_line ('Process is outside of normally working hours');
END IF;
END SP_INSERT_OVERSEAS_COMPANY;
/
Should COMPANY_NAME,COMPANY_NAME,... be COMPANY_CODE,COMPANY_NAME,...? The parameter COMPANY_CODE is not used in the procedure. Are you getting numeric conversion errors?

Oracle input parameter not able to get results

I have oracle stored procedure where I pass an input parameter and get a cursor as an output parameter:
CREATE OR REPLACE PROCEDURE OS_DIVISIONDDL(
p_dept_name IN VARCHAR2,
p_cursor_division OUT SYS_REFCURSOR
) IS
tmpVar NUMBER;
BEGIN
tmpVar := 0;
OPEN p_cursor_division FOR
select Division_code,
Division_name
from DIVISION_TBL
where dept_code=p_dept_name;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END OS_DIVISIONDDL;
/
The input parameter I am able to see using dbms print, but where condition is not executed by server Am i going wrong anywhere
DIVISION_CODE CHAR (10 Char)
DIVISION_NAME VARCHAR2 (30 Char)
DEPT_CODE CHAR (10 Char)
COMPANY_CODE CHAR (3 Char)
LOCATION_CODE CHAR (3 Char)
CREATED_DATE TIMESTAMP(6)
CREATED_BY VARCHAR2 (50 Char)
MODIFIED_DATE TIMESTAMP(6)
MODIFIED_BY VARCHAR2 (50 Char)
Perhaps you have a problem of implicit convertions:
declare
a char(10) := '123';
b varchar2(100) := '123';
dummy integer;
begin
select null
into dummy
from dual
where a = b;
end;
this code raises "no data found" but looks totally the same.
The problem here is that char(10) is not equal "123" but equal to "123<7 spaces here>". And varchar2(100) remains "123".
Check for char and varchar2 differences e.g. in Oracle docs

Resources