ORA 00904 error in a procedure without a "SELECT" statement - oracle

I have a simple procedure that should delete all rows with "CREATEDATE" earlier than the given input parameter "p_date".
For some reason I keep getting "ORA-00904: "P_DATE": invalid identifier":
PROCEDURE DELETE_TABLE (p_date date) IS
begin
delete from db.table
where CREATEDATE<=p_date;
commit;
end ;

Related

error during execution of trigger : ORA-06502: PL/SQL numeric or value error

when I try to insert in the data table, I get this"numeric or value error: character to number conversion error"
This is my trigger :
CREATE OR REPLACE TRIGGER TRIGGER_ON_TEMP
BEFORE INSERT ON DATA
FOR EACH ROW
DECLARE
CURSOR ERR_MSG_CURSOR IS
SELECT ERROR_MSG FROM REFERENTIEL;
codeERR VARCHAR2(100);
BEGIN
OPEN ERR_MSG_CURSOR; ****
LOOP
FETCH ERR_MSG_CURSOR INTO codeERR;
if (:new.DESCRIPTION LIKE '%'+codeERR+'%') THEN
DBMS_OUTPUT.PUT_LINE('I got here:'||:new.DESCRIPTION);
END IF;
END LOOP;
CLOSE ERR_MSG_CURSOR;
END;
The error is occuring on the line with ****. I'm not quite too sure as to what is causing this error, any help?

how to compress a blob column using utl_compress.lz_compress and insert it to another table

I'm new to oracle pl sql.
There is a table(tableA) with a blob column,i want to get this column, compress it using utl_compress.lz_compress(blob_column) and then insert this column in 'tableB',using procedure.
I try some ways to do this but i get 'bad argument' error.
Thank you very much.
EDIT : I need some thing like this
procedure myProcedure as
begin
FOR myrectype IN (SELECT * FROM tableA)
LOOP
insert into tableB(id,blob_column) values(myrectype.id,utl_compress.lz_compress(myrectype.blob_column));
END LOOP
end myProcedure;
Exception :
29261. 00000 - "bad argument"
*Cause: A bad argument was passed to the PL/SQL API.
*Action: Check the arguments passed to the PL/SQL API and retry the call.
others exception with code : -29261
others exception with mssg : ORA-29261: bad argumen
I solved that.need to store utl_compress.lz_compress(myrectype.blob_column) in a variable first.I Changed procedure to :
procedure myProcedure as
v_blob_column blob;
begin
FOR myrectype IN (SELECT * FROM tableA)
LOOP
v_blob_column := utl_compress.lz_compress(myrectype.blob_column);
insert into tableB(id,blob_column) values(myrectype.id,v_blob_column);
END LOOP
end myProcedure;
Thanks

Can I use if statements in a stored procedure to insert values into a table?

I am trying to write a stored procedure that selects indiv_ids and transaction_ids and inserts these into a table on my schema. In doing so, I want to pass in variables and have the stored procedure use if statements to select the indiv_ids and transaction_ids from different tables depending on the information passed in. I've tried a few variations and can't get the procedure to work without an error. Thanks!
create or replace procedure myproc (name_type in varchar2, dept in number)
is begin
if name_type='promo' then insert into mytable(indiv_id,transaction_id)
---sql here;
commit;
elsif name_type='deal' then insert into mytable(indiv_id, transaction_id)
---sql here;
commit;
end if;
end;
errors: Error(8,10): PL/SQL: SQL Statement ignored,
Error(16,31): PL/SQL: ORA-00942: table or view does not exist
Note that name_type variable is declared as NUMBER, but in the procedure body it is compared with strings:
if name_type='promo' then
This is not the cause of ORA-00942 error, but anyway it makes your procedure not working correctly.

PL/SQL: ORA-00932: inconsistent datatypes: expected UDT got NUMBER

I'm executing PL/SQL code to display the Currency Code from the Failed Reservation table. Object type and Nested Table collections are used.
When the PL/SQL code is run, the following error is generated. The corresponding line is highlighted in the PL/SQL code section.
Error report:
ORA-06550: line 27, column 11:
PL/SQL: ORA-00932: inconsistent datatypes: expected UDT got NUMBER
ORA-06550: line 27, column 4:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
The code is pasted below:
DDL - Table creation:
CREATE TABLE FAILEDRESERVATION
(
FAILEDRESERVATIONID NUMBER(18,0),
FK_TRANSACTIONID NUMBER(18,0),
DEBITRESERVATIONID NUMBER(18,0),
RESERVATIONTIME DATE,
RESERVATIONAMOUNT NUMBER(18,5),
CURRENCYCODE CHAR(3 BYTE),
AVAILABLEAMOUNT NUMBER(18,5)
);
ALTER TABLE FAILEDRESERVATION
ADD CONSTRAINT "PK_FAILEDRESERVATION" PRIMARY KEY ("FAILEDRESERVATIONID");
Object Type:
CREATE OR REPLACE TYPE TYPE type_failedreservation AS OBJECT
(
FK_TRANSACTIONID NUMBER(18),
DEBITRESERVATIONID NUMBER(18),
RESERVATIONTIME DATE,
RESERVATIONAMOUNT NUMBER(18,5),
CURRENCYCODE CHAR(3),
AVAILABLEAMOUNT NUMBER(18,5)
);
DML:
INSERT INTO FAILEDRESERVATION (FAILEDRESERVATIONID,FK_TRANSACTIONID,DEBITRESERVATIONID,RESERVATIONTIME,RESERVATIONAMOUNT,CURRENCYCODE,AVAILABLEAMOUNT)
VALUES (289,2,1,to_date('07-MAR-16','DD-MON-RR'),20000,'USD',10000);
INSERT INTO FAILEDRESERVATION (FAILEDRESERVATIONID,FK_TRANSACTIONID,DEBITRESERVATIONID,RESERVATIONTIME,RESERVATIONAMOUNT,CURRENCYCODE,AVAILABLEAMOUNT)
VALUES (288,1,1,to_date('01-MAR-16','DD-MON-RR'),10000,'NOK',10000);
Nested Tables:
CREATE OR REPLACE TYPE type_failedreservation_coll as TABLE OF type_failedreservation;
CREATE OR REPLACE TYPE type_dbtrsid_coll AS TABLE OF NUMBER;
PL/SQL Code:
DECLARE
P_FAILEDRESERVATION APPDATA.TYPE_FAILEDRESERVATION_COLL;
vdbtid_coll type_dbtrsid_coll := type_dbtrsid_coll();
BEGIN
SELECT TYPE_FAILEDRESERVATION(fk_transactionid,debitreservationid,reservationtime,reservationamount,currencycode,availableamount)
BULK COLLECT
INTO p_failedreservation
FROM failedreservation;
-- This is line 27
SELECT frs.debitreservationid
INTO vdbtid_coll
FROM TABLE(p_failedreservation) frs;
FOR v_iterate IN vdbtid_coll.FIRST..vdbtid_coll.LAST
LOOP
dbms_output.put_line('The currency code is: '||v_iterate);
END LOOP;
END;
Why is the code generating this error ?
You've declared vdbtid_coll as a collection type, so you need to bulk collect into that too:
SELECT frs.debitreservationid
BULK COLLECT INTO vdbtid_coll
FROM TABLE(p_failedreservation) frs;
With that change:
PL/SQL procedure successfully completed.
The currency code is: 1
The currency code is: 2
That's just giving you the index number in the collection though, so I don't think it's what you really want. You may want:
FOR v_iterate IN vdbtid_coll.FIRST..vdbtid_coll.LAST
LOOP
dbms_output.put_line('The currency code is: '
|| p_failedreservation(v_iterate).currencycode);
END LOOP;
which gets:
PL/SQL procedure successfully completed.
The currency code is: USD
The currency code is: NOK
You don't really need the second select/collection at all though, you can do:
FOR v_iterate IN 1..p_failedreservation.COUNT
LOOP
dbms_output.put_line('The currency code is: '
|| p_failedreservation(v_iterate).currencycode);
END LOOP;
... for the same result. Although I'm not sure what the relevance of the debitreservationid is in that second query, as it is the same value (1) in both rows.
You are trying to select multiple rows into a collection. You need to use BULK COLLECT INTO rather than just INTO.
Change
SELECT frs.debitreservationid
INTO vdbtid_coll
FROM TABLE(p_failedreservation) frs;
To
SELECT frs.debitreservationid
BULK COLLECT INTO vdbtid_coll
FROM TABLE(p_failedreservation) frs;
and you probably want the output to be:
FOR v_iterate IN vdbtid_coll.FIRST..vdbtid_coll.LAST LOOP
dbms_output.put_line('The currency code is: '|| vdbtid_coll(v_iterate) );
END LOOP;
However, you could simplify it all to:
DECLARE
P_FAILEDRESERVATION APPDATA.TYPE_FAILEDRESERVATION_COLL;
BEGIN
SELECT TYPE_FAILEDRESERVATION(
fk_transactionid,
debitreservationid,
reservationtime,
reservationamount,
currencycode,
availableamount
)
BULK COLLECT INTO p_failedreservation
FROM failedreservation;
FOR v_iterate IN p_failedreservation.FIRST .. p_failedreservation.LAST LOOP
dbms_output.put_line(
'The currency code is: '|| p_failedreservation(v_iterate).currencycode
);
END LOOP;
END;
Try casting the type array to its type as follows
SELECT frs.debitreservationid
BULK COLLECT INTO vdbtid_coll
FROM TABLE(CAST(p_failedreservation as APPDATA.TYPE_FAILEDRESERVATION_COLL)) frs;
PL/SQL: ORA-00932: inconsistent datatypes: expected UDT got CHAR
You may get this error in case you write type table in place of type object when
using BULK COLLECT INTO, i faced this error coz i did so.
FOR EXAMPLE:
CREATE OR REPLACE TYPE OBJ_TYPE AS OBJECT (NAME VARCHAR2(20));
/
CREATE OR REPLACE TYPE TBL_TYPE IS TABLE OF OBJ_TYPE;
/
CREATE OR REPLACE FUNCTION FUNC1 RETURN TBL_TYPE AS
TBL_TEXT TBL_TYPE := TBL_TYPE();
BEGIN
SELECT ***OBJ_TYPE*** (NAME) BULK COLLECT INTO ***TBL_TEXT*** FROM <table-name> ;
RETURN ***TBL_TEXT***;
END;
/
Care should be taken when using object type and table type in the function.

How to call another Procedure in CASE WHEN in Oracle Procedure

I have created many Procedures to extract the data from remote database and stored it in my local database tables. The procedures run successfully when i run it individually. But now i want to create dynamic procedure which will call based on conditions. I have created small procedure for the same but getting an error when i run this procedure as :
ORA-06512:
01403. 00000 - "no data found"
I am calling the procedure as EXT_EXTRACTION(1000161);
I think the problem is i am not calling the Procedure in CASE WHEN properly and don't know how to call it correctly.
Here is my procedure;
PROCEDURE "EXT_EXTRACTION"(
IN_KPI_DEF_ID IN NUMBER DEFAULT 0
) AS
ENTITY_CLASS_NAME Number := 0;
IN_EVENT_ID NUMBER;
BEGIN
Select EVENT_ID
INTO IN_EVENT_ID
from RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION
WHERE KPI_DEF_ID = IN_KPI_DEF_ID;
CASE
WHEN IN_EVENT_ID = 10049
THEN EXT_10049_ACTIVATE_OPTION;
END CASE;
COMMIT;
END EXT_EXTRACTION;
Try to surround select in your procedure with exception when no_data_found and look at result. May be this proc work from another user,which have no priveleges to select, or selected object is a view? May be you should create procedure like authid current_user?

Resources