Strange characters in my Oracle Database 11G - oracle

I used Oracle 11G database, i have a LOG table
when i write in this table with this function:
Pk_Util.LOG_ERROR('Pk_Slt.IMPORT_LIAISON', 'LIAISON', NULL, liaison_code, NULL, SUBSTR(SQLERRM, 1, 200), SQLCODE);
I have this in my LOG table:
30/04/13,'Pk_Slt.IMPORT_LIAISON','LIAISON',null,'
$ยจ%r?',null,'ORA-06502: PL/SQL','-6502','5484973'
My LOG_ERROR procedure:
PROCEDURE LOG_ERROR(
nom_procedure IN VARCHAR2,
type_entite IN VARCHAR2,
id_entite IN INTEGER,
code_entite IN VARCHAR2,
date_entite IN DATE,
error_message IN VARCHAR2,
sql_code IN INTEGER
) IS
BEGIN
INSERT INTO LOG(LOG_ID,LOG_DATE, LOG_PROCEDURE, LOG_TYPE_ENTITE, LOG_ID_ENTITE, LOG_CODE_ENTITE, LOG_DATE_ENTITE, LOG_SQLERRM, LOG_SQLCODE)
VALUES (SEQ_LOG.NEXTVAL,SYSDATE, nom_procedure, type_entite, id_entite, code_entite, date_entite, error_message, sql_code);
END;
PS:
I am passing liaison_code when calling the method this datatype:
LURE 3B.RE61
THANN3AMARI2
C.SAU3ZCRIM1
PYMON6VOUGL1
ARGIE3ARSOT1
NEUVY 3
ZNEUV 3 1
....
Thanks

Related

PLSQL Procedure to insert employee: ORA-00984

I am trying to insert employee data into employee table from hr database using procedure. I'm getting these errors:
19/5 PL/SQL: SQL Statement ignored
20/72 PL/SQL: ORA-00984: column not allowed here
when I execute this code:
CREATE OR REPLACE PROCEDURE proc_add_new_emp(p_employee_id IN NUMBER,
p_employee_first_name IN VARCHAR2,
p_employee_last_name IN VARCHAR2,
p_employee_email IN VARCHAR2,
p_employee_phone_number IN VARCHAR2,
p_employee_hire_date IN DATE,
p_employee_job_id IN VARCHAR2,
p_employee_salary IN NUMBER,
p_employee_commission_pct IN NUMBER,
p_employee_manager_id IN VARCHAR2,
p_employee_department_id IN VARCHAR2) IS
BEGIN
INSERT INTO employees (employee_id, employee_first_name, employee_last_name, emp_email, employee_phone_number, employee_hire_date, employee_salary, employee_commission_pct, employee_manager_id, employee_department_id)
VALUES(p_employee_id, p_employee_first_name, p_employee_last_name, p_emp_email, p_employee_phone_number, p_employee_hire_date, p_employee_salary, p_employee_commission_pct, p_employee_manager_id, p_employee_department_id);
END;
/
This is the cause of the error:
CREATE OR REPLACE PROCEDURE proc_add_new_emp(
p_employee_id IN NUMBER,
p_employee_first_name IN VARCHAR2,
p_employee_last_name IN VARCHAR2,
p_employee_email IN VARCHAR2, --> this
INSERT INTO employees
(employee_id,
employee_first_name,
employee_last_name,
emp_email,
...)
VALUES
(p_employee_id,
p_employee_first_name,
p_employee_last_name,
p_emp_email, --> and this
If parameter's name is P_EMPLOYEE_EMAIL, then you have to use it in INSERT statement, not P_EMP_MAIL.

Inserting procedure - value in an interval

I need help with the following:
I have the following table:
CREATE TABLE LOG_PUSH_READOUTS_HEADERS
(
ID NUMBER NOT NULL,
PUSH_DATE DATE NOT NULL,
SOURCE_SERIAL VARCHAR2(100) NOT NULL,
SOURCE_START_DATE DATE NOT NULL,
SOURCE_END_DATE DATE NOT NULL,
SOURCE_RUS_TYPE_ID NUMBER,
OUTPUT_SERIAL VARCHAR2(100) NOT NULL,
FILTERS_RUS VARCHAR2(100),
FILTERS_INDICATORS VARCHAR2(100),
CONSTRAINT id_pk PRIMARY KEY (ID)
);
I need to implement the following procedure:
Input parameters for inserting in a table are all columns except ID for which we need to create a sequencer. Output parameters are ID and RESULT_CODE. ID is a value of primary key that is inserted. RESULT_CODE is zero if procedure is successful, or some value in an interval 9000-9999. Use RESULT_CODE for errors, for example, RESULT_CODE 9123 is 'FILTER_RUS cannot be null.'
Here is my attempt:
CREATE OR REPLACE PROCEDURE INSERT_HEADER
(PUSH_DATE IN DATE, SOURCE_SERIAL IN VARCHAR2, SOURCE_START_DATE IN DATE, SOURCE_END_DATE IN DATE, SOURCE_RUS_TYPE_ID IN NUMBER,
OUTPUT_SERIAL IN VARCHAR2, FILTERS_RUS IN VARCHAR2, FILTERS_INDICATORS IN VARCHAR2, ID OUT NUMBER, RESULT_CODE OUT NUMBER)
IS
hd_seq NUMBER;
BEGIN
SELECT AMM_MDM.Header_Seq.NEXTVAL INTO hd_seq FROM DUAL;
ID:=hd_seq;
INSERT INTO AMM_MDM.LOG_PUSH_READOUTS_HEADERS (PUSH_DATE IN DATE, SOURCE_SERIAL IN VARCHAR2, SOURCE_START_DATE IN DATE,
SOURCE_END_DATE IN DATE, SOURCE_RUS_TYPE_ID IN NUMBER,
OUTPUT_SERIAL IN VARCHAR2, FILTERS_RUS IN VARCHAR2, FILTERS_INDICATORS IN VARCHAR2)
VALUES (PUSH_DATE, SOURCE_SERIAL, SOURCE_START_DATE,
SOURCE_END_DATE, SOURCE_RUS_TYPE_ID,
OUTPUT_SERIAL, FILTERS_RUS, FILTERS_INDICATORS)
END;
How to set RESULT_CODE in an interval 9000-9999? How to manage errors?
The way I understood the question, it would be like the following example. I shortened column list (didn't feel like tying that much), but you should be able to get the general idea.
create or replace procedure p_insert_header
(p_push_date in date,
p_source_serial in varchar2,
p_filter_rus in varchar2,
--
p_id out number,
p_result_code out number
)
is
l_id number;
begin
-- check for errors
if p_push_date is null then
p_result_code := 1234;
elsif p_source_serial not in ('A', 'B', 'C') then
p_result_code := 5532;
elsif p_filter_rus is null then
p_result_code := 9123;
end if;
-- if there are no errors, do insert
if p_result_code is null then
-- fetch sequence number
p_id := header_seq.nextval;
insert into log_push_readouts_headers
(id, push_date, source_serial, filter_rus)
values
(p_id, p_push_date, p_source_serial, p_filter_rus);
end if;
end;
At the end, once the procedure finishes, it'll return - as OUT parameters:
ID:
some sequence number, if everything was OK
NULL, if it was not
RESULT_CODE:
NULL, if everything was OK
error number, if it was not
For user defined errors, Oracle permits negative integers in the range -20000 .. -20999. You need to remove data type declarations for the column list of the insert statement
CREATE OR REPLACE PROCEDURE INSERT_HEADER(PUSH_DATE IN DATE,
SOURCE_SERIAL IN VARCHAR2,
SOURCE_START_DATE IN DATE,
SOURCE_END_DATE IN DATE,
SOURCE_RUS_TYPE_ID IN NUMBER,
OUTPUT_SERIAL IN VARCHAR2,
FILTERS_RUS IN VARCHAR2,
FILTERS_INDICATORS IN VARCHAR2,
ID OUT NUMBER,
RESULT_CODE OUT NUMBER)
IS
BEGIN
INSERT INTO LOG_PUSH_READOUTS_HEADERS
(ID,
PUSH_DATE,
SOURCE_SERIAL,
SOURCE_START_DATE,
SOURCE_END_DATE,
SOURCE_RUS_TYPE_ID,
OUTPUT_SERIAL,
FILTERS_RUS,
FILTERS_INDICATORS)
VALUES
(Header_Seq.NEXTVAL,
PUSH_DATE,
SOURCE_SERIAL,
SOURCE_START_DATE,
SOURCE_END_DATE,
SOURCE_RUS_TYPE_ID,
OUTPUT_SERIAL,
FILTERS_RUS,
FILTERS_INDICATORS);
--Suppose some opertions performed and gave the RESULT_CODE value below
RESULT_CODE := 20123;
IF RESULT_CODE = 20123 THEN raise_application_error(-RESULT_CODE, 'FILTER_RUS cannot be null');
--ELSIF RESULT_CODE = 20124 THEN raise_application_error(-RESULT_CODE, 'Some other message 1');
--ELSIF RESULT_CODE = 20125 THEN raise_application_error(-RESULT_CODE, 'Some other message 2');
END IF;
END;
In this case it hurls with the message : FILTER_RUS cannot be null

Oracle Passing Custom Table Type To Stored Procedure

FYI: Oracle 12c
I have created a custom type called Payeezy_Error:
create or replace TYPE PAYEEZY_ERROR
AS
OBJECT (
CODE VARCHAR(30),
DESCRIPTION VARCHAR(200)
);
And then in turn created a Table type of Payeezy_Errors:
create or replace TYPE PAYEEZY_ERRORS AS TABLE OF PAYEEZY_ERROR;
I then have a Procedure that takes Payeezy_Errors as an IN parameter:
create or replace PROCEDURE SAVE_USER_PAYMENT_TRANSACTION
(
in_AccountID IN VARCHAR2,
in_SequenceID IN VARCHAR2,
in_CorrelationID IN VARCHAR2,
in_TransactionID IN VARCHAR2,
in_TransactionTag IN VARCHAR2,
in_Currency IN VARCHAR2,
in_TransactionType IN VARCHAR2,
in_BankResponse IN VARCHAR2,
in_GatewayResponse IN VARCHAR2,
in_ValidationStatus IN VARCHAR2,
in_TransactionStatus IN VARCHAR2,
in_Errors IN PAYEEZY_ERRORS
)
AS
var_uptID NUMBER;
var_ErrorCount NUMBER := 0;
EX_AUTHENTICATION EXCEPTION;
BEGIN
-- Insert the Payeezy Response values tied to the user
INSERT INTO
USER_PAYMENT_TRANSACTION (
ACCOUNT_ID, UP_PAYMENT_SEQ_ID, CORRELATION_ID, TRANSACTION_ID,
TRANSACTION_TAG, CURRENCY, TRANSACTION_TYPE, BANK_RESPONSE,
GATEWAY_RESPONSE, VALIDATION_STATUS, TRANSACTION_STATUS
) VALUES (
in_AccountID, in_SequenceID, in_CorrelationID, in_TransactionID,
in_TransactionTag, in_Currency, in_TransactionType, in_BankResponse,
in_GatewayResponse, in_ValidationStatus, in_TransactionStatus
)
RETURNING
ID
INTO
var_uptID;
-- Insert any errors that may be associated with a failure/unsuccessful transaction
SELECT
COUNT(*)
INTO
var_ErrorCount
FROM
in_Errors;
IF (var_ErrorCount > 0) THEN
INSERT INTO
USER_PAYMENT_TRANSACTION_ERROR (
UPT_ID, CODE, DESCRIPTION
)
SELECT
var_uptID, e.CODE, e.DESCRIPTION
FROM
in_Errors;
END IF;
-- Exception Handling
EXCEPTION
WHEN EX_AUTHENTICATION THEN
raise_application_error(-20001, 'Authentication Failed.');
END SAVE_USER_PAYMENT_TRANSACTION;
When I compile the procedure it yells at me at the SELECT COUNT(*) statement that:
ORA-00942: table or view does not exist.
And red-dashes are under SELECT and in_Errors.
Further down the procedure I get the same error and the second INSERT INTO and in_Errors lines are red-dashes too.
I have exited and reloaded Oracle SQL Developer just to see if it was a caching thing. I have searched around the web but have not found my particular case.
If you want to use the table in a query, you'd need to use the table operator
SELECT
COUNT(*)
INTO
var_ErrorCount
FROM
table( in_Errors );
That works. But it means that you're taking all of the data that you have in the PL/SQL collection, moving it to the SQL VM, doing the aggregation, and then returning the result to PL/SQL. It would likely be more efficient (and less code) in this case to just do
var_ErrorCount := in_Errors.count;

Dynamic SQL accept table column as input in a procedure

Hey I am trying to write a procedure in which the user can insert which columns he would like to get as parameter input. As of right now when I run a test script I get this error:
error -1 message error in ct_cu_act_medrecon_pg.spm_search_patientmedrecs =>ORA-00933: SQL command not properly ended
The error is refering to the order by part in the select statement, and when I remove that I get an error saying:
error -1 message error in ct_cu_act_medrecon_pg.spm_search_patientmedrecs =>ORA-00904: "D"."P_INSERTDT_IN": invalid identifier
Here is the spec:
procedure spm_search_patientmedrecs (
p_columnsort_in in varchar2, --which is sort column
p_medmed_in in varchar2, --first column
p_planid_in in varchar2, --second column
p_detmed_in in varchar2, --third column
p_insertdt_in in varchar2, --fourth column
p_ascdesc_in in varchar2, --asc or desc in order by
p_return_cur_out out sys_refcursor,
p_err_code_out out number,
p_err_mesg_out out varchar2
);
Here is the procedure body:
procedure spm_search_patientmedrecs (
p_columnsort_in in varchar2,
p_medmed_in in varchar2,
p_planid_in in varchar2,
p_detmed_in in varchar2,
p_insertdt_in in varchar2,
p_ascdesc_in in varchar2,
p_return_cur_out out sys_refcursor,
p_err_code_out out number,
p_err_mesg_out out varchar2)
is
lv_sql varchar2(32767);
begin
lv_sql := '';
lv_sql := 'select h.p_medmed_in,
h.p_planid_in,
d.p_detmed_in,
d.p_insertdt_in
from membermedicalreconcilationhdr h,
membermedicalreconcilationdet d
where h.membermedreconciliationhdrskey =
d.membermedreconciliationhdrskey
order by h.p_columnsort_in p_ascdesc_in';
p_err_code_out := 0;
OPEN p_return_cur_out FOR lv_sql;
exception
when others then
p_err_code_out := -1;
p_err_mesg_out := 'error in ct_cu_act_medrecon_pg.spm_search_patientmedrecs =>'||sqlerrm;
end spm_search_patientmedrecs;
Here is my test script:
set serveroutput on
declare
type tempcursor is ref cursor;
v_cur_result tempcursor;
errcode number;
errmesg varchar2(1000);
begin
ct_cu_act_medrecon_pg.spm_search_patientmedrecs
('primarymemberplanid',
'membermedreconciliationhdrskey',
'primarymemberplanid',
'membermedreconciliationdetskey',
'inserteddt',
'ASC',
v_cur_result,
errcode,
errmesg
);
-- dbms_output.put_line(v_cur_result);
dbms_output.put_line('error '||errcode||' message '||errmesg);
end;
First off, I know how I'm handeling the error isnt the best way to do it but thats how the person asking me to do this wanted it.
Now I dont know if this is a possible thing to do in Oracle PL/SQL, but if it is I would greatly appreciate some help in pointing me in the right direction. If you guys need any more information feel free to ask and I will assist as best I can (Ive only been working with SQL and PL/SQL for 2 months). Thanks in advance.
Dynamic SQL means assembling strings which are executed as SQL statements. Your string hardcodes the parameter names, whereas what you actually need is the contents of the parameters.
Something like this:
lv_sql := 'select h.'||p_medmed_in||',
h.'||p_planid_in||',
d.'||p_detmed_in||',
d.'||p_insertdt_in||'
from membermedicalreconcilationhdr h,
membermedicalreconcilationdet d
where h.membermedreconciliationhdrskey =
d.membermedreconciliationhdrskey
order by h.'||p_columnsort_in||' '|| p_ascdesc_in;

create/declare a sequence in a stored procedure in oracle

I have a table non_employee with emp_no as the primary key and a package with a procedure to insert in to this table.
I need to be able to autoincrement the emp_no when the procedure is run. I tried creating a sequence within the procedure like this, but getting errors. please see below and advice.
CREATE OR REPLACE PACKAGE BODY WFDDEV."ERD" IS
create SEQUENCE #seq_emp_nmbr;
PROCEDURE INS_NON_EMPLOYEES
(
in_DATE_ADDED DATE,
in_EMPLOYEE_NAME VARCHAR2,
in_DEPT_ID VARCHAR2,
in_SUB_DEPARTMENT VARCHAR2,
in_LOCATION VARCHAR2,
in_WORK_TEL_NO VARCHAR2,
in_TOUR VARCHAR2,
in_REST_DAYS VARCHAR2,
in_HOME_ADDRESS VARCHAR2,
in_CITY VARCHAR2,
in_STATE VARCHAR2,
in_ZIP VARCHAR2,
in_HOME_TEL_NO VARCHAR2,
in_GENDER VARCHAR2,
in_RACE VARCHAR2,
in_DATE_OF_BIRTH DATE,
in_AGE VARCHAR2,
in_HIRE_DATE DATE,
in_UNION_AFFILIATION VARCHAR2,
in_TITLE VARCHAR2,
in_NON_EE_INDICATOR VARCHAR2
) IS
BEGIN
INSERT INTO WFDDEV.NON_EMPLOYEES
(
EMP_NO,
DATE_ADDED,
EMPLOYEE_NAME,
DEPT_ID,
SUB_DEPARTMENT,
LOCATION,
WORK_TEL_NO,
TOUR,
REST_DAYS,
HOME_ADDRESS,
CITY,
STATE,
ZIP,
HOME_TEL_NO,
GENDER,
RACE,
DATE_OF_BIRTH,
AGE,
HIRE_DATE,
UNION_AFFILIATION,
TITLE,
NON_EE_INDICATOR
)
VALUES
(
emp_no.NEXTVAL,
in_DATE_ADDED,
in_EMPLOYEE_NAME,
in_DEPT_ID,
in_SUB_DEPARTMENT,
in_LOCATION,
in_WORK_TEL_NO,
in_TOUR,
in_REST_DAYS,
in_HOME_ADDRESS,
in_CITY,
in_STATE,
in_ZIP,
in_HOME_TEL_NO,
in_GENDER,
in_RACE,
in_DATE_OF_BIRTH,
in_AGE,
in_HIRE_DATE,
in_UNION_AFFILIATION,
in_TITLE,
in_NON_EE_INDICATOR
);
END;
Im getting PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
begin end function pragma procedure subtype type
error with this...
You need to create the sequence just once outside of the package as a separate database object. Then, in the insert statement in your package body you can reference the sequence to get the next value.
Try-
EXECUTE IMMEDIATE 'CREATE SEQUENCE SEQ_NAME START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE 1000000 NOCYCLE NOCACHE ORDER';
This should be inside a Procedure or Function body and not in the Declaration section i.e. this should be treated as a executable statement.
Creating a sequence using Dynamic SQL is a bad idea and I am not sure why you would want to do that. However, if you are creating a sequence dynamically then remember to drop it as well after finishing up, using
EXECUTE IMMEDIATE 'DROP SEQUENCE SEQ_NAME';
This way you would atleast not run into errors (like ORA-00955) while calling the package procedure.

Resources