Creating a procedure that inserts into 2 tables with a relationship - oracle

I understand that there is a lot of questions like this one but as it is for my school project it needs to follow the same techniques that they have taught us and the other answers aren't quite what i'm looking for.
My code:
CREATE or REPLACE PROCEDURE add_hire1 (hire_no_in IN NUMBER, date_hired_in IN DATE, drop_off_in IN DATE, fk1_customer_id_in IN NUMBER, fk2_charge_no_in IN NUMBER,
charge_no_in, final_cost_in)
AS
BEGIN
INSERT INTO hire(hire_no, date_hired, drop_off, fk1_customer_id, fk2_charge_no)
VALUES (hire_no_in, date_hired_in, drop_off_in, fk1_customer_id_in, fk2_charge_no_in);
INSERT INTO charge(charge_no, final_cost)
VALUES(charge_no_in, final_cost_in);
END add_hire1;
This is the error returned:
ORA-24344: success with compilation error
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_190100", line 590
ORA-06512: at "SYS.DBMS_SYS_SQL", line 1658
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_190100", line 576
ORA-06512: at "APEX_190100.WWV_FLOW_DYNAMIC_EXEC", line 2033
As we have just been taught how to do it with one table I have just added the second table in the same format as the original code so I'm not sure if it's correct or if there's just a few small errors.
Any help appreciated,
Thanks.

ORA-24344 signifies compilation errors. If you are using a tool like SQL Developer it should show you the compilation errors. But you can always find them for yourself like this:
select * from user_errors
where name = 'ADD_HIRE1'
If we had a package which compiled then we changed it and now it doesn't compile we know we need to focus on the changes we made. In this case we can see that the two parameters you've just added …
,
charge_no_in, final_cost_in)
AS
… are not declared in the same way as the other parameters:
, fk1_customer_id_in IN NUMBER, fk2_charge_no_in IN NUMBER
That difference is a big clue as to how you need to fix your code.

Related

PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ; - Not sure what is wrong in code

I am trying to create trigger as below but getting error specified below. Can any one please help me to figure out what is wrong with the code. Thank you in advance
Code:
CREATE OR REPLACE EDITIONABLE TRIGGER TEST_DATA.IVR_SEQ
BEFORE INSERT ON TEST_DATA.TRANSACTION
FOR EACH ROW
BEGIN
SELECT TEST_DATA.IVR_SEQ.NEXTVAL
INTO :new.IVRID
FROM dual;
END;
/
Error:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ;
Tool: Oracle SQL Developer
Strange, as there's nothing wrong with it, but I get the same error as you do when executing it literally.
SQL> create or replace -- EDITIONABLE
2 trigger scott.trg_ivr_seq
3 before insert on scott.transaction
4 for each row
5 begin
6 select scott.ivr_seq.nextval
7 into :new.ivrid
8 from dual;
Warning: Trigger created with compilation errors.
SQL> show err trigger trg_ivr_Seq
Errors for TRIGGER TRG_IVR_SEQ:
LINE/COL ERROR
-------- -----------------------------------------------------------------
4/11 PLS-00103: Encountered the symbol "end-of-file" when expecting
one of the following:
;
(editionable is not an option in my 11gXE so I removed it).
As you can see, error points to line #4, column #11 which is
4 for each row
Rewritten from scratch (and "improved" a little bit):
SQL> create or replace trigger scott.ivr_seq
2 before insert on scott.transaction
3 for each row
4 begin
5 :new.ivrid := scott.ivr_seq.nextval;
6 end;
7 /
Trigger created.
SQL>
It works with select as well (just that you wouldn't think that it is wrong):
SQL> create or replace trigger scott.ivr_seq
2 before insert on scott.transaction
3 for each row
4 begin
5 select scott.ivr_seq.nextval
6 into :new.ivrid
7 from dual;
8 end;
9 /
Trigger created.
SQL>
So ... rewrite it. I don't see any garbage characters (in Notepad++), I have no idea what's wrong with it.
[EDIT]
Luke Woodward's comment made me do another test. Yes, Luke is right!
Comment in the 1st line, before actually stating what I'm creating causes an error:
SQL> create or replace -- comment
2 trigger trg_test
3 before insert on dept
4 for each row
5 begin
6 null;
Warning: Trigger created with compilation errors.
But, comment in the 1st line AFTER stating what's being created doesn't cause any errors:
SQL> create or replace trigger -- comment here
2 trg_test
3 before insert on dept
4 for each row
5 begin
6 null;
7 end;
8 /
Trigger created.
Thank you, Luke!
There are several ways you can get this error:
Your SQL is malformed, you are missing a ; somewhere
Not present in the provided snippet.
Your SQL is malformed, the parser is being tripped up and believes things to be things they are not, finally failing when it get to the end of the file.
Not obviously present in the provided snippet. However i can't test the EDITIONABLE clause as it is not present in my db version, so it may be introducing some addition required syntax.
Your interface is mangling the SQL before it sends it to the database to be compiled.
Unlikely as SQL developer is way better at not doing this than SQL*Plus was, but if you have any custom configuration there are all kinds of things that could be happening, check what is actually getting to the database by looking at trigger in the database and see if it matches what you expect to be there.
Invalid characters in your code
Not a common issue but can be eliminated by either retyping the trigger manually, not using copy paste, or by pasting from a know clean source. (copy/paste from the web can include lots of weird character replacements used to get the layout right in the browser (no-break spaces, etc.), and apps like word can mangle things like quotes (e.g.Word replaces ' ' with ‘ ’)
Code in the same file before the trigger definition that has errors.
I am assuming you have run this separately from any other code, but if not put this trigger create statement in its own file and run it there.
Scenario 2 is being triggered by a non obvious misparse of the code.
This could be caused by other objects in this or a different schema with identical names, keyword use, etc. and can depend on which schema is running the DDL statement.
Try quoting TEST_DATA.TRANSACTION as TEST_DATA."TRANSACTION", TRANSACTION is a keyword in oracle, and while some keywords can be used in some contexts, possibly your version of oracle is treating it as a keyword and messing up the rest of the parsing. This compiles fine on my DB without the quotes so i would lean more toward the next possibility, but I have this issue with a schema named "SEARCH" on my database, in some contexts you need to quote the name to prevent compile errors.
Check for name reuse on schemas, tables, views, etc. In your example your trigger and your sequence have the same name TEST_DATA.IVR_SEQ. On its own this is not an issue, but can cause seemingly random compile errors depending on where the duplication is.
I could not reproduce your specific compile error, but I was able to create a few different compile errors by creating different name collisions (example creating a table in the TEST_DATA schema named TEST_DATA, creating a function named TEST_DATA, creating a package, sequence named TEST_DATA, a function named IVR_SEQ in a package named TEST_DATA, etc.). It is possible on your version of Oracle this or a similar collision is creating the EOF error.

error when collecting tokens from a full text database

I want to test Oracle's CTX_DOC.TOKENS procedure in order to count the number of occurrence of a string into a document.
For this, I have:
create table documents (id number primary key, text bfile);
insert into documents values (1, bfilename('MY_DIR','12things_about_122.pdf'));
create index documents_idx on documents (text) indextype is ctxsys.context;
declare
the_tokens ctx_doc.token_tab;
begin
ctx_doc.set_key_type ('PRIMARY_KEY');
ctx_doc.tokens('documents_idx','1',the_tokens);
dbms_output.put_line('Number of tokens: '|| the_tokens.count);
end;
When I test this, the PLSQL part fails with:
Error report:
ORA-20000: Oracle Text error:
DRG-10001: can not access result table the_tokens
ORA-06512: at "CTXSYS.DRUE", line 160
ORA-06512: at "CTXSYS.CTX_DOC", line 862 ORA-06512: at line 5
00000 - "%s"
*Cause: The stored procedure 'raise_application_error'
was called which causes this error to be generated.
*Action: Correct the problem as described in the error message or contact
the application administrator or DBA for more information.
Can you help me to understand what is needed much more in order to work correctly, please?
Thank you,
it seems that the answer was too easy to be seen from the 1st time:
It was necessary to referenciate the ctx_doc.token_tab; with schema name, too.
Instead of the_tokens ctx_doc.token_tab, I had to do the_tokens ctxsys.ctx_doc.token_tab;

Stored Proc hitting ORA-06502: PL/SQL: numeric or value error

I'm having a problem calling a stored procedure from OSB 11g thru JCA Adapter.
The error I'm getting is:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 1
The error is as short as it is without any appends behind the error description. It only happens in production environment and there are no problems when I point the database to the UAT one.
More surprisingly, it will work in production envrionement if one of the variables I pass in is less than 128 characters. (or else I will hit the error above).
The stored procedure type and length are defined correctly. having the table column able to cope for 4000 characters.
Both Oracle 9i DB sharing the same major minor build revision. The stored proc is located in a package. I extracted out and compared the stored proc from both DB environments using winmerge and it shows they mirror each other.
Executing the stored procedure manually in production environment works, provides that I declare a big enough varchar size. I manage to simulate the ORA-06502 error by declaring a variable size lesser than the data length I'm passing in.
I even went as far as capturing the network dump from both executions and found there are slightly differences. (Note: I'm reusing the same datasource and only change the ip and username in WLS and did a restart before each executions)
When I point to production environment(the 1 having trouble), the tcpdump looks something like below:
BEGIN packagename.stored_proc_name(V_value1=>:1 , v_value2=>:2, v_value3=>:3); END .... {variable1}... {variable2}... {variable3})
When I point to UAT environment(the successful 1), the dump looks shorter and without the BEGIN; END tag
.... {variable1}... {variable2}... {variable3})
What else could have gone wrong? Appreciate for any helps!
"The stored proc is located in a package. I extracted out and compared the stored proc from both DB environments using winmerge and it shows
they mirror each other."
It is not about the code, the issue is data specific. In UAT you might not have production like data and thus you aren't able to replicate the issue.
Your error message just says error at line 1, which is not quite helpful. Are you executing the code without formatting it? If you format the code and execute it, and remove all exception handling, you will correctly know the line number. For example :
SQL> declare
2 num number;
3 begin
4 num := 'a';
5 end;
6 /
declare
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at line 4
See, it clearly tells that error is at line 4.
By any chance if you have an EXCEPTION block, then make sure you use dbms_utility.format_error_stack and dbms_utility.format_error_backtrace to log the error details. Else, the error line number will be never correct.

How to find out line number, procedure name in PL/SQL in case of an error

I am using a D2k 6i form and getting the error on form from stored database(oracle9i) procedure ORA-00001:Unique constraint(.) violated but i m not able to trace out from which procedure it is coming.
can anybody help me regarding this
For posterity, here is the solution the OP found:
ok in D2k forms there is an ON-ERROR trigger where you can use the function DBMS_ERROR_TEXT to get the procedure,package name line number of the statement from where the error is coming
I've come across this pattern after much research, head banging and gnashing of teeth:
CREATE OR REPLACE PACKAGE BODY my_schema.package_name
IS
PROCEDURE foo
IS
BEGIN
-- Call stored procedures/functions that throw unhandled exceptions
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('ERROR! - '
|| DBMS_UTILITY.FORMAT_ERROR_STACK
|| DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
END foo;
END;
The DBMS_UTILITY.FORMAT_ERROR_STACK function seems to give the error code and message, and DBMS_UTILITY.FORMAT_ERROR_BACKTRACE seems to give an honest to goodness stack trace, complete with line numbers and stored procedure names in Oracle 10g at least.
I'm not sure if those functions are available in Oracle 9i. I couldn't find much information about this sort of thing even for Oracle 10g, so I thought I would at least post this answer since 9i is quite old (and so it 10g for that matter).
Posting your exception with your question would give us a better idea of what you are confronted with.
Usually an exception will tell you the package and the line number within the error message. From that, you can query the USER_SOURCE table:
SELECT text
FROM user_source
WHERE type = 'PACKAGE BODY'
AND name = 'myProcName'
AND line = [the line number];
It might be useful to know more about the context within which the error was triggered. For that you can use the `BETWEEN' operator:
SELECT text
FROM user_source
WHERE type = 'PACKAGE BODY'
AND name = 'myProcName'
AND line BETWEEN [the line number - 5] AND [the line number +5];

How to make Oracle error messages more verbose?

The message that drives me crazy is ORA-01008 - Not all variables bound.
Is there a way to know which one of the 42 possible variable names I have misspelled without staring at the monitor till my eyes pop out?
Update: I use ADO.NET to access the database. Perhaps it does lose some information in Oracle exceptions, as #Justin Cave has suggested. But I'm positive that the parameter name never appears even in SQL Plus.
In general, Oracle provides the line and column number of any errors, but it is up to the particular API you are using (unless you happen to be writing an OCI application, which is probably unlikely) as to whether and how those APIs are called. Since the answer is likely to end up being API-specific, what API are are you using and what does your code look like when the error occurs (i.e. JDBC, ODBC, OLE DB, etc)?
As an example, if I write a PL/SQL block with a misspelled variable name, SQL*Plus will report the line and column number of the error in addition to the error message. Many APIs, on the other hand, will just report the PLS-00201 error by default.
SQL> declare
2 i integer;
3 begin
4 j := 1;
5 end;
6 /
j := 1;
*
ERROR at line 4:
ORA-06550: line 4, column 3:
PLS-00201: identifier 'J' must be declared
ORA-06550: line 4, column 3:
PL/SQL: Statement ignored
Similarly, if you execute a SQL statement with an invalid variable name, SQL*Plus will get the column and line position and put a * under the offending character, i.e.
SQL> create table a( col1 number );
Table created.
SQL> insert into a( colN ) values ( 1 );
insert into a( colN ) values ( 1 )
*
ERROR at line 1:
ORA-00904: "COLN": invalid identifier
Most PL/SQL IDE's (TOAD, SQL Developer, etc.) will do something similar by interrogating the appropriate OCI APIs under the covers. Precisely how this is done, however, will depend on the API.
I don't know of any way to get Oracle to make the error more specific. Maybe some future version will improve this error message.
Instead of just staring at it, though, there are other things you can try. For example, convert each variable in the SQL statement to a literal one at a time, until the error goes away. If possible, generate the list of variable names instead of typing them manually.

Resources