How to Access All Values of Cursor in MessageBox in foxpro? - visual-foxpro

I have a cursor named MyCursor containing a field named records. The below code only shows the last record of the cursor. How do I get all the records from cursor to display?
Varible=Mycursor.records
MessageBox(Varible)

You don't say what data type the 'records' field is but this will work regardless:
lcMessage = ""
select mycursor
scan
lcMessage = lcMessage + transform(records) + chr(13)
endscan
messagebox(lcMessage)

Related

function not returning a value for no rows returned

I created a function that takes a movie id as input and returns stock information based from the ID. The function mostly works but if I want to retrieve information from a movie that is not in the database(returns no rows) nothing returns. Can't figure out why?
doesn't give me an error when i call an ID that returns no rows so exception handling wouldn't work.
create or replace function stock_info
(p_id IN NUMBER
)
return VARCHAR2
IS
cursor c1 is
select movie_id, movie_title, movie_qty
from mm_movie
where p_id = movie_id;
lv_movie_info VARCHAR2(100);
BEGIN
for i in c1 loop
if p_id = i.movie_id then
lv_movie_info := i.movie_title || ' is available: ' || i.movie_qty || ' on the shelf';
else
lv_movie_info := 'no data found';
end if;
end loop;
return lv_movie_info;
END STOCK_INFO;
/
The reason you don't get anything when there is no data is that the loop doesn't execute. Logically the For expression says "execute the following loop for every row returned in the cursor" but there are no rows in the cursor so it never executes the loop. Further the structure actually indicates you are expecting multiple for a given p_id. If that's not the case you can eliminate the cursor all together. Assuming p_id is the primary key you have either 0 or 1 row so:
create or replace function stock_info (p_id in number)
return text
is
lv_movie_info varchar2(100);
begin
select i.movie_title || ' is available: ' || i.movie_qty || ' on the shelf'
into lv_movie_info
from mm_movie i
where p_id = movie_id;
return lv_movie_info;
exceptions
when no_data_found
then return 'no data found';
end stock_info;
Of course if do expect more that 1 row the cursor is needed, but the IF is not as the were clause guarantees it's true. Still with 0 rows the loop will not be executed so the 'no data found' message needs to go after "End Loop".
Belayer
the cursor statement you used fetches data from the in parameter. i.e., in the cursor select you limiting based on the movie id passed.
on passing a movie id which is not in the data base, the cursor select statement would not fetch any records, and so the flow won't even go inside the for loop.
if you wanted to return no data found - on passing a movie id which is not in the database, two ways to resolve
1. before the loop, have select statement to set a flag to Y or N if exists according and to have your requirement.
2. in if not using for cursor, there is an option to check not found...
sample:
declare
cursor c1 is select * from table_sample; -- empty table
c_rec c1%rowtype;
begin
open c1;
fetch c1 into c_rec;
if c1%notfound then
dbms_output.put_line('not found');
end if;
close c1;
end;
-- output
not found

Multiple Records being fetched in Cursor PLSQL Procedure

Table : WSH_DEL_DETAILS_INTERFACE
Unique Column:DELIVERY_DETAIL_INTERFACE_ID
Input to procedure : DELIVERY_DETAIL_INTERFACE_ID
Column values to be fetched:SALES_ORDER_LINE_NUMBER , SALES_ORDER_NUMBER
Expected Output:
Single record
Actual Output:
All records in table are being fetched
Code:
create or replace PROCEDURE procedurevalidation(
delivery_detail_interface_id IN
WSH_DEL_DETAILS_INTERFACE.DELIVERY_DETAIL_INTERFACE_ID%TYPE,
ROW_COUNT OUT INTEGER)
IS
CURSOR wddi_cur IS SELECT * FROM WSH_DEL_DETAILS_INTERFACE WHERE
DELIVERY_DETAIL_INTERFACE_ID = delivery_detail_interface_id;
wddi_record WSH_DEL_DETAILS_INTERFACE%ROWTYPE;
BEGIN
OPEN wddi_cur;
LOOP
FETCH wddi_cur into wddi_record;
EXIT when wddi_cur%NOTFOUND;
DBMS_OUTPUT.ENABLE(100000);
DBMS_OUTPUT.PUT_LINE(delivery_detail_interface_id);
DBMS_OUTPUT.PUT_LINE('SALESORDERNUMBER111:::: ' ||
wddi_record.SALES_ORDER_NUMBER);
DBMS_OUTPUT.PUT_LINE('SALESORDERLINENUMBER1111::::: ' ||
wddi_record.SALES_ORDER_LINE_NUMBER);
DBMS_OUTPUT.PUT_LINE('COUNT' || ROW_COUNT);
END LOOP;
CLOSE wddi_cur;
end;
You need to change the names of the input variable to your procedure.
create or replace PROCEDURE procedurevalidation(
p_delivery_detail_interface_id IN
WSH_DEL_DETAILS_INTERFACE.DELIVERY_DETAIL_INTERFACE_ID%TYPE,
ROW_COUNT OUT INTEGER)
And in your cursor you need to change the variable name as well.
CURSOR wddi_cur
IS
SELECT *
FROM WSH_DEL_DETAILS_INTERFACE
WHERE DELIVERY_DETAIL_INTERFACE_ID = p_delivery_detail_interface_id;
Your cursor is returning all records in the table because you are equating the table's column itself and not matching it with the input variable in the procedure

PL SQL Record Operations

Hi I am working on an academic assignment and need some help setting up records:
Write a PL/SQL block to print information about a publisher.
Declare a PL/SQL record based on the structure of the bk_publishers table.
In the declarative section, use the %ROWTYPE attribute and declare the variable publisher_record of type bk_publisher.
In the executable section, get all the information from the bk_publishers table by using publ_id and put it in your record. Display the publ_id and publ_name from the record using a cursor for loop.
Reference Database Chart
So far I have been able to write a block that outputs the contents, but I don't know how to get the contents of the record to print.
Any insights would be very helpful!
Thanks
SET SERVEROUTPUT ON
SET VERIFY OFF
DECLARE
TYPE bk_record IS RECORD
(publ_id bk_publishers.publ_id%TYPE,
publ_name bk_publishers.publ_name%TYPE);
publisher_record bk_publishers%ROWTYPE;
CURSOR bk_cur IS
SELECT * FROM bk_publishers;
BEGIN
OPEN bk_cur;
FETCH bk_cur INTO publisher_record;
CLOSE bk_cur;
FOR publ_no in bk_cur
LOOP
DBMS_OUTPUT.PUT_LINE(publ_no.publ_id || ' ' || publ_no.publ_name);
END LOOP;
END;
/
A simple RECORD variable can hold the contents of a single row, so you have to display column values of individual rows within a loop.
DECLARE
TYPE bk_record IS RECORD ( publ_id bk_publishers.publ_id%TYPE,
publ_name bk_publishers.publ_name%TYPE );
publisher_record bk_publishers%rowtype;
CURSOR bk_cur IS SELECT *
FROM bk_publishers;
BEGIN
OPEN bk_cur;
LOOP
FETCH bk_cur INTO publisher_record;
EXIT WHEN bk_cur%notfound; --Condition to exit the loop.
dbms_output.put_line(publisher_record.publ_id
|| ' ' || publisher_record.publ_name);
END LOOP;
CLOSE bk_cur;
END;
/

Where in Oracle APEX interface I put this code?

This link explains how to show an image from a BLOB in a table, to a Display image item
http://www.apexninjas.com/blog/2011/09/uploading-and-displaying-images-in-apex/
It advises to write this code (the code converts BLOB data into HTML):
create or replace PROCEDURE image(image_id IN NUMBER)
AS
l_mime VARCHAR2 (255);
l_length NUMBER;
l_file_name VARCHAR2 (2000);
lob_loc BLOB;
BEGIN
SELECT i.MIME_TYPE, i.CONTENT, DBMS_LOB.getlength (i.CONTENT), i.FILENAME
INTO l_mime, lob_loc, l_length, l_file_name
FROM EMP_IMAGE i
WHERE i.ID = image_id;
OWA_UTIL.mime_header (NVL (l_mime, 'application/octet'), FALSE);
htp.p('Content-length: ' || l_length);
htp.p('Content-Disposition: filename="' || SUBSTR(l_file_name, INSTR(l_file_name, '/') + 1) || '"');
owa_util.http_header_close;
wpg_docload.download_file(Lob_loc);
END image;
I'm new to Oracle APEX 5, and I do not understand where in the interface should I write that code
My UI loos like this
https://i.imgur.com/7xCRO7U.png
They're telling you to create that procedure in the database; it's not an APEX component. I don't think I would recommend their approach of opening a security hole to allow direct execution of a custom local procedure. And it's not necessary anymore; APEX has changed a lot since 2011.
On the left, click your Display Image item named "IMAGE". Then on the right, under "Settings", change the "Based On" to BLOB Column returned by a SQL Statement, and just put a query in there that'll return the column you want.
You'll need a primary key to find the right row; here I'm assuming that you're using the FILE_NAME page item, but probably a better option would be to have a hidden page item to hold the primary key from your IMAGES table, maybe called "P1_ID" for an "id" column, and add RETURNING id INTO :P1_ID to the end of your INSERT statement in your page process. Then your "IMAGE" page item query will look something like:
SELECT i.CONTENT
FROM IMAGES i
WHERE i.ID = :P1_ID;

Passing table name and coloumn value as variables in dynamic sqls

Here is my code:
create or replace
procedure postGateway (flgManual in nvarchar2, segmentID in number) as
sequel string(2000);
cursor download_cursor is
select downloadid from ipcsdd_download_process where status LIKE 'W' OR status
LIKE 'E';
cursor table_cursor is
select table_name from user_tab_columns where column_name = 'DOWNLOADID' and
table_name like 'IPCSDD%' OR table_name like 'IPCSCUSTDD' group by table_name;
begin
for download in download_cursor
loop
dbms_output.put_line('DownloadID: ' || download.downloadid );
for usertable in table_cursor
loop
sequel:=' select * FROM'||usertable.table_name||'where downloadid='||download.downloadid;
execute immediate sequel;
dbms_output.put_line(' select * from'||usertable.table_name||'where downloadid='||download.downloadid);
end loop;
end loop;
end postGateway ;
What I doing here is: In first cursor I am trying to get the downloadids whose status are W or E. In the second cursor I am trying to get the tables which have downloadid coloumn and those table name should start with IPCSDD or IPCSCUSTDD.
Now I have to write a query such that In every table starting from IPCSDD that i get from cursor 2 i need to see if a data is present for the downloadid that i get from cursor 1. I tried writing dynamic sql but it gives me error saying "00923. 00000 - "FROM keyword not found where expected"" .
How can I achieve this?
Thanks
You simply neglected to add spaces after and before your keywords, with a space after FROM and a space before where:
sequel:=' select * FROM '||usertable.table_name||' where downloadid='||download.downloadid;

Resources