No more data to read from socket (Oracle SQL Developer) - oracle

I have created one trigger that calls one procedure, using oracle sql developer. Here is the code for trigger:
CREATE OR REPLACE TRIGGER noteTrigger
BEFORE
INSERT OR
UPDATE OF valoare OR
DELETE
ON note
BEGIN
CASE
WHEN INSERTING THEN
DBMS_OUTPUT.PUT_LINE('Inserting');
updateBursa();
WHEN UPDATING('valoare') THEN
DBMS_OUTPUT.PUT_LINE('Updating valoare');
updateBursa();
WHEN DELETING THEN
DBMS_OUTPUT.PUT_LINE('Deleting');
updateBursa();
END CASE;
END;
/
Now, the procedure is written here:
CREATE OR REPLACE PROCEDURE updateBursa IS
v_countBursieri NUMBER := 0;
BEGIN
UPDATE STUDENTI SET bursa = null;
FOR v_i IN (SELECT nr_matricol from studenti natural join note group by nr_matricol having avg(valoare) =
(select max(avg(valoare)) from studenti natural join note group by nr_matricol)) LOOP
v_countBursieri := v_countBursieri + 1;
END LOOP;
FOR v_i IN (SELECT nr_matricol from studenti natural join note group by nr_matricol having avg(valoare) =
(select max(avg(valoare)) from studenti natural join note group by nr_matricol)) LOOP
UPDATE STUDENTI SET bursa = 1000/v_countBursieri where nr_matricol = v_i.nr_matricol;
END LOOP;
END;
/
And when I try to modify note table by this:
INSERT INTO note VALUES ('111', '25', 5, TO_DATE('20/06/2015', 'dd/mm/yyyy'));
I get error:
Error report -
ORA-00603: ORACLE server session terminated by fatal error
ORA-00600: internal error code, arguments: [kqlidchg0], [], [], [], [], [], [], [], [], [], [], []
ORA-00604: error occurred at recursive SQL level 1
ORA-00001: unique constraint (SYS.I_PLSCOPE_SIG_IDENTIFIER$) violated
00603. 00000 - "ORACLE server session terminated by fatal error"
*Cause: An Oracle server session was in an unrecoverable state.
*Action: Log in to Oracle again so a new server session will be created
automatically. Examine the session trace file for more
information.
Error report -
SQL Error: No more data to read from socket

This is Ora-600 you should deeply explore reasons why is raised in your case, maybe you should open SR.
also, in the code you are referencing the table "note" on which you are creating a trigger, which could lead to mutating table, so consider the option of changing your code logic.
In my understanding, you need statement level trigger, not row level trigger?

ORACLE server session terminated by fatal error
Try this, had the same problem on the same "topic" let's say :) And setting things as shown previously just solved my problem. Good luck!

Related

SQL Trigger error (ORA-00942: table or view does not exist)

I create this sql trigger:
CREATE OR REPLACE TRIGGER create_event_from_task BEFORE INSERT ON llx_projet_task
BEGIN
INSERT INTO llx_actioncomm (priority, fulldayevent, location, label, fk_element, elementtype, fk_project, datep, datef, percentage, note)
SELECT 0, 0, '', 'prova', id, 'project_task', fk_project, date_start, date_end, progress, description
FROM inserted;
END;
/
But when I execute says this errors:
Errors: TRIGGER CREATE_EVENT_FROM_TASK
Line/Col: 2/2 PL/SQL: SQL Statement ignored
Line/Col: 4/7 PL/SQL: ORA-00942: table or view does not exist
Can anyone help me?
I think it got this error because of the select query inside the trigger. Check if the user which called the trigger has the grant to execute select from the "inserted" table.
https://www.tekstream.com/resource-center/ora-00942-table-or-view-does-not-exist/
Ora-00942 means you are attempting to execute an SQL statement that references a table or view which does not exist. There are several possible causes for the “table or view does not exist” error, including:
1) Referencing a table or view that does not exist
2) Using an unauthorized synonym
3) Using an expression of view where a table is required
4) Attempting to use a table without proper permission or privilege
inserted is part of SQL Server. I think you want:
BEGIN
INSERT INTO llx_actioncomm (priority, fulldayevent, location, label, fk_element, elementtype, fk_project, datep, datef, percentage, note)
SELECT 0, 0, '', 'prova', :new.id, 'project_task',
:new.fk_project, :new.date_start, :new.date_end,
:new.progress, :new.description
FROM dual;
END;

How can use array type in where clause of update statement

I want a procedure get a list of disabling privilege, and update their record in table. For doing this scenario, I defined an array as database object with below code:
CREATE OR REPLACE TYPE T_DISABLE_LIST IS TABLE OF NUMBER(32)
Then I defined an input parameter in procedure signature, and got passed value.
PROCEDURE PRC_ROLE_PRIVILAGE_MANAGEMENT(P_REQ_USER_ID IN VARCHAR2,
P_DISABLE_LIST IN T_DISABLE_LIST,
P_RES_DESC OUT VARCHAR2)
BEGIN
UPDATE T_ PRIVILAGE p
SET P.ENABLE_STATUS = 0, P.GRANT_USERID = P_REQ_USER_ID
WHERE P.ID IN (SELECT * FROM TABLE(P_DISABLE_LIST));
COMMIT;
EXCEPTION
WHEN OTHERS THEN
RES_DESC := SUBSTR(SQLERRM,1, 400);
END;
This procedure will be compile successfully. But when I test it, I got this error:
ORA-22905: cannot access rows from a non-nested table item
Any body can help me? And say why this code don't work correctly?
And finally, how can i resolve this problem?
P.S: My orcale version is 9.2!!!
This assumes you are using Oracle 10g or later (and was written before the OP clarified what version they are using)
Use the MEMBER OF operator:
UPDATE T_PRIVILAGE
SET ENABLE_STATUS = 0,
GRANT_USERID = P_REQ_USER_ID
WHERE ID MEMBER OF P_DISABLE_LIST;
You can also use the COLUMN_VALUE pseudo-column:
UPDATE T_PRIVILAGE
SET ENABLE_STATUS = 0,
GRANT_USERID = P_REQ_USER_ID
WHERE ID IN ( SELECT COLUMN_VALUE FROM TABLE( P_DISABLE_LIST ) );
why this code does not work correctly?
SELECT * FROM TABLE( P_DISABLE_LIST )
Is selecting the row from the table. However, the table is generated by a table collection expression and there is no underlying database table to reference a row of so Oracle generates an ORA-22905 exception.(there would be an underlying table if the collection was stored in a nested table; which is why that situation is specifically mentioned in the exception).
Update: PL/SQL solution:
FOR i IN 1 .. P_DISABLE_LIST.COUNT LOOP
UPDATE T_PRIVILAGE
SET ENABLE_STATUS = 0,
GRANT_USERID = P_REQ_USER_ID
WHERE ID = P_DISABLE_LIST(i);
END LOOP;

PL/SQL Block returns ORA-06553: PLS-114: identifier 'MyMSAccessFieldIsOver30CharsLong' too long when using a Remote NON-Oracle Database

I have a database link to a MS Access database in an Oracle database using Oracle's Heterogeneous Services. Some of the Access table column names are longer than the Oracle allowed 30 characters. As a result, my PL/SQL code is returning an error:
declare
my_record myaccesstable#MSAccessODBC64%rowtype;
begin
null;
--dbms_output.put_line(my_record."flight_pattern_combination_string");
end;
/
declare
*
ERROR at line 1:
ORA-04052: error occurred when looking up remote object BASE.MSNS_MISSIONS#AMGBASETABLES64
ORA-00600: internal error code, arguments: [kglhfr-bad-free], [], [], [], [], [], [], [], [], [], [], []
ORA-06553: PLS-114: identifier 'flight_pattern_combination_str' too long
Is there a way to trim or truncate the column names when using the %rowtype syntax? I'm not allowed to modify the Access database. I can use a record data type declaration, but this would involve copying all of the column data types into a pl/sql block or package. I tried to use the following:
create table test as select * from myaccesstable#MSAccessODBC64
*
ERROR at line 1:
ORA-00997: illegal use of LONG datatype
Is there a way to trim or truncate the column names when using the %rowtype syntax in a PL/SQL Block?
I am not sure what exactly your requirement is, but Did you try creating a View based on the table
create or replace view vw (col1) as select flight_pattern_combination_str from myaccesstable#MSAccessODBC64
and then use that view in your procedure.

How can I solve the mutating table error here?

set serveroutput on;
CREATE OR REPLACE TRIGGER hw3
BEFORE DELETE on ENROLLS
for EACH ROW
ENABLE
DECLARE
v_sid number;
v_term varchar2(20);
v_sectno number;
v_COMPNAME varchar2(20);
v_points number;
BEGIN
select :old.SID,:old.TERM,:old.SECTNO into v_sid,v_term,v_sectno from enrolls;
select COMPNAME,points into v_compname,v_points from scores
where scores.sid=v_sid and scores.term=v_term and scores.sectno=v_sectno;
INSERT into DELETED_SCORES (SID,TERM,SECTNO,compname,points)
values (v_sid,v_term,v_sectno,v_compname,v_points);
DELETE FROM SCORES
WHERE SID=V_SID AND TERM=V_TERM AND SECTNO=V_SECTNO;
END;
/
There are two table, which is enrolls and scores. And SCORES table has a combined foreign keys including SID,TERM,AND SECTNO referring to table ENROLLS.
The trigger is now successfully compiled, but there is a problem shown as below:
Error starting at line : 24 in command -
DELETE FROM enrolls
WHERE SID=1111 and term='F12' and sectno=1031
Error report -
SQL Error: ORA-04091: table C16_HE_JIEL.ENROLLS is mutating, trigger/function may not see it
ORA-06512: at "C16_HE_JIEL.HW3", line 8
ORA-04088: error during execution of trigger 'C16_HE_JIEL.HW3'
04091. 00000 - "table %s.%s is mutating, trigger/function may not see it"
*Cause: A trigger (or a user defined plsql function that is referenced in
this statement) attempted to look at (or modify) a table that was
in the middle of being modified by the statement which fired it.
*Action: Rewrite the trigger (or function) so it does not read that table.
never use before trigger for DML. In some situations before trigger can be fired more than once for the same row. It might happen in situations when your session is blocked by other session updating/deleting the same row.
Use compound trigger and apply DML changes in after trigger session.
Then you can be sure, that data you see are really correct.
The mutating table error means that Oracle can not quarantee that what you're doing is deterministic.
This select:
select :old.SID,:old.TERM,:old.SECTNO into v_sid,v_term,v_sectno from enrolls;
Is invalid for two reasons:
you can't select from the table where the trigger fired on
you are selecting all rows from that table, not just one.
The select isn't needed anyway, you can simply use the values in the OLD record directly (and remove the invalid select ... from enrolls)
select COMPNAME,points
into v_compname,v_points
from scores
where scores.sid = :old.SID
and scores.term = :old.TERM
and scores.sectno = :old.SECTNO;
The above statement requires that the combination of (sid, term, secno) is unique in the table scores. If that is not the case and you need to insert multiple rows with into deleted_scores you need to use an INSERT based on a select.
Which then removes the need for variables completely. So the whole trigger can be simplified to:
CREATE OR REPLACE TRIGGER hw3
BEFORE DELETE on ENROLLS
for EACH ROW
BEGIN
INSERT into DELETED_SCORES (SID,TERM,SECTNO,compname,points)
select sid, term, sectno, compname, points
from scores
where scores.sid = :old.SID
and scores.term = :old.TERM
and scores.sectno = :old.SECTNO;
DELETE FROM SCORES
WHERE SID = :OLD.sid
AND TERM = :OLD.term
AND SECTNO = :OLD.sectno;
END;
/
More details about the "table is mutating" restriction can be found in the manual:
http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/triggers.htm#LNPLS759

DB2 for IBM iSeries: IF EXISTS statement syntax

I am familiar with Sybase which allows queries with format: IF EXISTS () THEN ... ELSE ... END IF (or very close). This a powerful statement that allows: "if exists, then update, else insert".
I am writing queries for DB2 on IBM iSeries box. I have seen the CASE keyword, but I cannot make it work. I always receive the error: "Keyword CASE not expected."
Sample:
IF EXISTS ( SELECT * FROM MYTABLE WHERE KEY = xxx )
THEN UPDATE MYTABLE SET VALUE = zzz WHERE KEY = xxx
ELSE INSERT INTO MYTABLE (KEY, VALUE) VALUES (xxx, zzz)
END IF
Is there a way to do this against DB2 on IBM iSeries? Currently, I run two queries. First a select, then my Java code decides to update/insert. I would rather write a single query as my server is located far away (across the Pacific).
+UPDATE+
DB2 for i, as of version 7.1, now has a MERGE statement which does what you are looking for.
>>-MERGE INTO--+-table-name-+--+--------------------+----------->
'-view-name--' '-correlation-clause-'
>--USING--table-reference--ON--search-condition----------------->
.------------------------------------------------------------------------.
V |
>----WHEN--+-----+--MATCHED--+----------------+--THEN--+-update-operation-+-+----->
'-NOT-' '-AND--condition-' +-delete-operation-+
+-insert-operation-+
'-signal-statement-'
See IBM i 7.1 InfoCenter DB2 MERGE statement reference page
DB/2 on the AS/400 does not have a conditional INSERT / UPDATE statement.
You could drop the SELECT statement by executing an INSERT directly and if it fails execute the UPDATE statement. Flip the order of the statements if your data is more likely to UPDATE than INSERT.
A faster option would be to create a temporary table in QTEMP, INSERT all of the records into the temporary table and then execute a bulk UPDATE ... WHERE EXISTS and INSERT ... WHERE NOT EXISTS at the end to merge all of the records into the final table. The advantage of this method is that you can wrap all of the statements in a batch to minimize round trip communication.
You can perform control-flow logic (IF...THEN...ELSE) in an SQL stored procedure. Here's sample SQL source code:
-- Warning! Untested code ahead.
CREATE PROCEDURE libname.UPSERT_MYTABLE (
IN THEKEY DECIMAL(9,0),
IN NEWVALUE CHAR(10) )
LANGUAGE SQL
MODIFIES SQL DATA
BEGIN
DECLARE FOUND CHAR(1);
-- Set FOUND to 'Y' if the key is found, 'N' if not.
-- (Perhaps there's a more direct way to do it.)
SET FOUND = 'N';
SELECT 'Y' INTO FOUND
FROM SYSIBM.SYSDUMMY1
WHERE EXISTS
(SELECT * FROM MYTABLE WHERE KEY = THEKEY);
IF FOUND = 'Y' THEN
UPDATE MYTABLE
SET VALUE = NEWVALUE
WHERE KEY = THEKEY;
ELSE
INSERT INTO MYTABLE
(KEY, VALUE)
VALUES
(THEKEY, NEWVALUE);
END IF;
END;
Once you create the stored procedure, you call it like you would any other stored procedure on this platform:
CALL UPSERT_MYTABLE( xxx, zzz );
This slightly over complex piece of SQL procedure will solve your problem:
IBM Technote
If you want to do a mass update from another table then have a look at the MERGE statement which is an incredibly powerful statement which lets you insert, update or delete depending on the values from another table.
IBM DB2 Syntax

Resources