Ajax call returned server error ORA-01403: no data found for APEX Interactive Grid - oracle-apex

I am trying to save data into my table using an interactive grid with the help of custom plsql. I am running into an "ORA-01403-no data found" error while inserting data and I can't figure out why.
This is my plsql custom process which I run. Appreciate your help.
DECLARE
em_id NUMBER;
BEGIN
CASE :apex$row_status
WHEN 'C'
THEN
SELECT NVL (MAX (emergency_id), 0) + 1
INTO em_id
FROM emp_emergency_contact;
INSERT INTO emp_emergency_contact
(emergency_id, emp_id, emergency_name, emergency_relation
)
VALUES (em_id, :emp_id, :emergency_name, :emergency_relation
);
WHEN 'U'
THEN
UPDATE emp_emergency_contact
SET emergency_name = :emergency_name,
emergency_relation = :emergency_relation
WHERE emergency_id = :emergency_id;
WHEN 'D'
THEN
DELETE emp_emergency_contact
WHERE emergency_id = :emergency_id;
END CASE;
END;

So far I have not come across any documented way on how to use custom PL/SQL logic for processing submitted rows of APEX 5.1 Interactive Grid via AJAX call.
You are getting no data found error because the return is expected to be in certain json format.
The example you have provided is not too complex and can be with done using standard "Interactive Grid - Automatic Row Processing (DML)" process, which is an AJAX approach. If AJAX call is not important then you can create your own PL/SQL process with custom logic. Example of which is demonstrated in "Sample Interactive Grids" package application, check out Advanced > Custom Server Processing page in this application for more information.
I agree with Scott, you should be using a sequence or identity column for ids.

Not entirely sure. A 'select into' can raise a no_data_found exception, but yours shouldn't.
That being said, you shouldn't have max(id)+1 anywhere in your code. This is a bug. Use a sequence or identity column instead.

I have gotten this many times so the first thing I do is go look at any columns in my grid sql that are not part of the "Save", they are from a join for data only.
I just got it again and it was a heading sort column that I had as a column type of "Number". I changed it to display only and the "Save" now works.
Although, I had already set the "Source" of the column to "Query Only" which is also needed.
It is a bummer the Ajax error message doesn't at least give the column name that caused the error.
Hope this helps someone..
BillC

Add a RETURNING INTO clause after the insert. IG expects a primary key to be returned to query the inserted row.

Related

File browse Item uploading to BLOB column

One of the tables in my DB has a BLOB column that stores images. So now I am setting up the page for this table. I have a bunch of IGs and such to process most of the data, but I set up a modal page to process the image.
The modal page gets the ID (which is the PK) into an item, and then it reads the image currently in the table into a 'Display Image' item. And I have a 'File browse...' item to upload new images.
Except I cannot get it to save.
I initially started with the display image item just having Setting Based on : BLOB column returned by SQL statement, as I couldn't get the source to work with the SQL query(Error Expected CHAR, source is BLOB), I managed to resolve this by putting automatic row processing on the page and then having the source be a column.
So now it displays well, with no errors.
But the save does nothing. I have tried saving by having the File browse reference the column and using automatic row processing, and there is just nothing. No errors pop up, but it just does nothing.
I have tried saving to APEX_APPLICATION_TEMP_FILES and then having a PLSQL DA or a PLSQL process to
SELECT blob_content
FROM APEX_APPLICATION_TEMP_FILES
WHERE name = :FILE_BROWSER_ITEM
And insert this into the table, but it just pops up a 'No data found' error.
I have gone through every bit of intel my google-fu has found, but I have failed to find a solution.
So I would appreciate any insight any of you might have.
Since noone answered, I stepped away from it for a bit and tried again at a later date. And now I made it work finaly.
I set up automatic row fetch and automatic row processing but disabled both of them, for some reason automatic row processing must be there so that you can have the source for the display image and file browse be the column.
Then I set the browse file to load into apex_application_temp_files.
and set up a process to be executed at page submit(but after the automatic row processing even though its disabled and shouldnt matter). The process executing the following code:
BEGIN
UPDATE MY_TABLE
SET MY_IMAGE = (SELECT blob_content
FROM apex_application_temp_files
WHERE name = :FILE_BROWSER_ITEM)
WHERE id = :ID;
END;
And I execute the page submit through a button with the action page submit and Database action being SQL UPDATE action.
I am guessing a fair bit of the things I did and have set up dont even matter, but I dont dare remove them for fear of breaking shit. What I have described here finaly works for me, and if you stumble upon this then you can try and I hope it works for you too, and you can try removing some of the disabled stuff and see if it still works.

Refreshing IG after save if validations pass

I have an interactive grid with some data, when users add a new row it didnt show up(found that this is because I have written a custom procedure to save and I dont return the PK).
So I set up a dynamic action, on Save[Interactive Grid] with a server side condition Type: Inline Validation Errors NOT displayed, with a true action of Refresh region.
But the condition doesent appear to work.
When adding row which passes the validations, it refreshes just fine, but when adding a row that fails validations, the validation error shows up and a popup comes up asking if I am sure I want to procede as changes were made(tries to refresh).
I have tried changing the condition to Inline Validation Errors displayed, but that doesent work. I have tried changing Event scope to Dynamic(which I dont even know what it does), but that didnt help.
I also changed the IG primary key to ROWID from the default PK from my table if that might help with the custom save procedure.
I would prefer to fix this w/o editing the save procedure as if I have to I will need to fix up a LOT of save procedures. But if I cant I am willing to fix them. But I am not sure how.
My save procedure is formated as follows:
PROCEDURE save_table (s_variable1 IN table.variable1%TYPE
, s_variable2 IN table.variable2%TYPE
, row_status IN VARCHAR2)IS
BEGIN
CASE row_status
WHEN 'C' THEN
INSERT INTO table(variable1, variable2)
VALUES (variable1_seq.nextval, s_variable2);
WHEN 'U' THEN
UPDATE table
SET variable2= s_variable2
WHERE variable1= s_variable1;
WHEN 'D' THEN
DELETE FROM table
WHERE variable1= s_variable1;
END CASE;
END save_table;
If someone could tell me the easiest way to fix this to return the PK(variable1) or ROWID so that the IG updates that one row so I dont even need the Dynamic Action.
EDIT:
Found the easiest way to do this is to change the procedure and found out how:
PROCEDURE save_table (s_variable1 IN OUT table.variable1%TYPE
, s_variable2 IN table.variable2%TYPE
, row_status IN VARCHAR2)IS
a_variable1 table.variable1%TYPE;
BEGIN
CASE row_status
WHEN 'C' THEN
a_variable1 := variable1_seq.nextval;
INSERT INTO table(variable1, variable2)
VALUES (a_variable1, s_variable2)
RETURNING a_variable1 INTO s_variable1;
Only posted the section I changed.
RETURNING INTO clause allows us to return column values for rows affected by DML statements. You can use this in your procedure to return the column value as shown below.
DECLARE
l_id t1.id%TYPE;
BEGIN
INSERT INTO t1 VALUES (t1_seq.nextval, 'FOUR')
RETURNING id INTO l_id;
COMMIT;
DBMS_OUTPUT.put_line('ID=' || l_id);
END;
For more details on Returning into see this link

Oracle APEX - Reusable Pages?

We have some tables in our database that all have the same attributes but the table is named differently for each. I'm not sure of the Architect's original intent in creating them in this way, but this is what I have to work with.
My question for all the expert Oracle APEX developers: is there away to create a reusable page that I can pass the table name to and that table name would be used in the reporting region and DML processing of that page?
I've read up on templates and plugins and don't see a path forward with those options. Of course, I'm new to webdevelopment, so forgive my ignorance.
We are using version 18.2.
Thanks,
Brian
For reporting purposes, you could use a source which is a function that returns a query (i.e. a SELECT statement). Doing so, you'd dynamically decide which table to select from.
However, DML isn't that simple. Instead of default row processing, you should write your own process(es) so that you'd insert/update/delete rows in the right table. I've never done that, but I'd say that it is possible. Basically, you'd keep all logic in the database (for example, a package) and call those procedures from your Apex application.
You could have multiple regions on one page; one region per table. Then use dynamic actions to show/hide the regions and run the select query based on a table name selected by the user.
Select table name from a dropdown or list
Show the region that matches the table name (dynamic action)
Hide the any other regions that are visible (dynamic action)
Refresh the selected region so the data loads (dynamic action)
If that idea works let me know and I can provide a bit more guidance.
I never tried it with reports, but would it work to put all three reports in a single page, and set them via an Item to have Server-Side Conditions that decide what gets shown in the page? You'd likely need separate items with a determined value for the page to recognize and display.
I know I did that to set buttons such as Delete, Save and Create dynamically, rather than creating two or more separate pages for handling editing of certain information. In this case it regarded which buttons to shown based on a reports' primary key being sent to said "Edit" page. If the value was empty, it meant you wanted to create a new record (also because the create button/link sent no PK). If said PK was sent (via a edit button/link), then you'd have the page recognize it and hide the create button and rather show the edit button.

Copy Records in Oracle Apex

I need to copy selected row values and store as a new record.
I am using Oracle Apex 4.2 and Tabular Form.
I need to use checkbox to select the rows and button copy. When i select multiple rows followed by click copy button to copy all the selected row values as new rows and save.
Can anyone Help
Copying Records Through an APEX Tabular Form Input
The idea of cloning existing records from a single table through an Oracle APEX Tabular Form works without much interference with the default design that you can set up through the APEX wizard for page region content.
Build a table with an independent primary key.
Suggested to include two auxiliary columns: COPY_REQUEST and COPIED_FROM for running copy operations. Specific form elements will map to these columns on the tabular form that will be set up.
Build an Oracle stored procedure that can read which records need to be copied. This procedure will be invoked each time the SUBMIT button is pressed.
(optional) Consider including a suppression of step (3) in the event that there is nothing to process (i.e., no records marked for copying).
The Working Table for Receiving Input: COPY_ME
TIP: You will have an easier time if you use the standard TABLE creation wizard. Designate CUSTOMER_ID as the PRIMARY_KEY and have APEX create its standard auto-incrementing functionality on top. (sequence plus trigger set up.)
Here's the sample data I used... though it doesn't matter. You can put in your own values and be able to verify what happened easily.
The Heavy Lifting: The Stored Procedure for Cloning Records in COPY_ME
This procedure works with 1 or more records at a time with a special identifier in the COPY_REQUEST table. After the task is done, the procedure cleans up and resets the request value again.
create or replace procedure proc_copy_me_request is
c_request_code CONSTANT char(1):= 'Y';
cursor copy_cursor is
SELECT cme.CUSTOMER_ID, cme.CUSTOMER_NAME, cme.CITY, cme.COUNTRY,
cme.COPY_REQUEST
FROM copy_me cme
WHERE cme.COPY_REQUEST = c_request_code
FOR UPDATE OF cme.COPY_REQUEST;
BEGIN
FOR i in copy_cursor LOOP
INSERT INTO copy_me (customer_name, city, country, copied_from)
VALUES (i.customer_name, i.city, i.country, i.customer_id);
UPDATE copy_me
SET copy_request = null
WHERE CURRENT OF copy_cursor;
END LOOP;
COMMIT;
END proc_copy_me_request;
There is also a column that can be hidden. It tracks where the record was originally copied from.
Note that the cursor is using the FOR UPDATE OF and WHERE CURRENT OF notation. This is important because the procedure is changing the records that are referenced by it.
APEX Page Setup Instructions
Set up a standard FORM type page and choose the TABULAR FORM style. Follow the set up instructions, taking care to map the correct primary key, and also to the PK sequence object created with the table in the previous steps above.
This is what your page set up will look like after these steps are completed:
EDIT The COPY_REQUEST Form Value:
Under the column attributes section, change the Display As option to "simple checkbox"
Under the list of values section, put a single value under the LOV Definition: Y (case sensitive in either way... just be consistent)
EDIT The COPIED_FROM Form Value:
Under the column attributes section, change the Display As option to "Display as Text(Saves State)". This is just to prevent users from stepping on this read-only field. You could also suppress it if it isn't important to know.
CREATE a New Process: Execute Copy Procedure
This is the bottom of the same configuration page, there are very few things to change or add:
Demonstration: Screenshot of COPY_ME Tabular Form Page in Action
The first screenshot below is before the page is tidied up and the checkbox control is put into place.
Plug in some test data and give it at try. The Page Process created in the step above conditionally invokes the stored procedure that processes all copy requests made at the same time when the SUBMIT form button is selected.
COMMENTS: If you spend enough time tinkering around with the built-in wizards in Oracle APEX, there are opportunities to learn new design patterns and process flows compatible within the tool. Adapting your approach can reduce the amount of additional work and frustration.

APEX ORACLE How to use one form to insert data into multiple tables

I was wondering if you can help me out with my current problem which is to insert data into multiple tables in my relational database using a single form. I am fairly new to APEX but do have a little bit of background on mysql and php programming. In the past, I normally achieve such task by creating a view of all the columns from different table that I want to populate and using a simple insert commands but doing the same thing in apex gives me and error stating that "ORA-01779: cannot modify a column which maps to a non key-preserved table".
In Oracle you can not just update a view which has eg a JOIN clause. Oracle will not map all columns back to the source tables: one table might while the others won't. This isn't an apex problem: if you were to run an update against your view in the db you would get this error just as well.
If you want to have your apex screen remain as transparent as possible, then you may want to consider user an instead-of trigger on the view. You will have to write the correct dml statements in this trigger though in order to ensure your data is pushed through correctly to all tables.
Another option is to use the view only to fetch, and use different processes to push the data to the correct tables. Using data-layer packages might alleviate the use of code stored in apex (eg having a lot of plsql code in apex itself is usually not favored and is rather stored in packages).
Create items and get all the items values and use PL/SQL on submit button.
Eg: p1_party_Name, p2_Service_Name
BEGIN;
INSERT INTO par VALUES(par_party_uid_seq.nextval,:p1_Party_name);
INSERT INTO par VALUES(ser_service_uid_seq.nextval,:p2_Service_name);
END;