Getting value from apex_item.text - oracle

I have a classic report with the following example query:
select apex_item.text(1,book.title,30,30,' readonly="readonly" ','P4083_BOOKTITLE') as "booktitle"
from book;
I would like to retrieve the value of this page item in a plsql proces:
declare
pl_booktitle varchar2(255);
begin
pl_booktitle := v('P4083_BOOKTITLE');
apex_debug.message('Book Title:'|| pl_booktitle);
end;
However when debugging it only shows: 'Book Title:' ... and not the value of the page item.
In Session -> Page Items, I cannot find P4083_BOOKTITLE.
Should I set the items before I can retrieve the value? And how do I do this?
Thanks!

try this
enter code here
declare
pl_booktitle varchar2(255);
begin
pl_booktitle :=:P4083_BOOKTITLE
apex_debug.message('Book Title:'|| pl_booktitle);
end;

Related

interactive report with dynamic sql statement

I'm trying to generate an Interactive-Report in Apex with a SQL-Statement which lies in a page item (:P10_SQL), for example: select 1 from dual.
declare
l_sql VARCHAR2(4000 CHAR);
Begin
select V('P10_SQL') into l_sql from dual;
return l_sql;
End;
The Report has the type PL/SQL Function Body returning SQL Query.
Apex shows an error
ORA-20999: WWV_FLOW_EXEC.NULL_QUERY_RETURNED_BY_FUNCTION
Somebody gets an idea?
Apex acts kind of crazy as it doesn't always want to accept code I write (which is perfectly valid), saying that function doesn't return anything. Oh well.
Therefore, my function that returns SQL query was written in stages. The following bullets represents attempts I made; all of them are OK. The final version - the one that runs right now is as simple as return :P77_SQL; (I'm on page 77)
return 'select dummy from dual'
declare
l_str varchar2(4000);
begin
l_str := case when :P77_SQL is null then 'select dummy from dual'
else :P77_SQL
end;
return l_str;
end;
return :P77_SQL;
However: you can't use interactive report, has to be a classic report because not all tables you'll have as a source will have the same column names (unless you use aliases and match number and datatypes, which is rather complicated).
But, if you use a classic report, then turn "Use generic column names" on and set desired number of generic columns (I set it to 10; you'll know what to do in your case).
My P77_SQL text item submits the page when I press ENTER, which causes the report to refresh.
A few examples:

How to Get datablock default where that oracle forms generate with Enter-query action

I am working with oracle forms 6i.
Simply I am using database block with these items :
Employees: employee_id , job_id , department_id , manager_id
note: employees is the data-block name .
For example: when end user click enter-query button and write 50 in department_id item and then click execute-query button; data block will return all employees who are in department 50.
My question is : How can I get the WHERE CLAUSE that oracle forms generate when returned desired data?...
I used this code in pre-query trigger
:parameters.whr:=get_block_property('employees',default_where);
But it returned no results
You're close, but not close enough. It is the GET_BLOCK_PROPERTY you need, but use its LAST_QUERY parameter. It will return SQL statement of the last query in the specified block.
Alternatively, use system variable :SYSTEM.LAST_QUERY (returns the same result).
Here's an example( the following code might be put in KEY-EXEQRY trigger of employees block ):
declare
l_lastq varchar2(4000);
l_where_position number;
l_where_clause varchar2(4000);
begin
execute_query;
l_lastq := :system.last_query;
l_where_position := instr(lower(l_lastq), 'where');
if l_where_position > 0 then
l_where_clause := substr(l_lastq, l_where_position, length(l_lastq));
message('WHERE clause: ' || l_where_clause);
end if;
end;

PL/SQL Dynamic action [Set Value] not recognizing apex item value

I have a problem setting the value of an apex item (P13_3) using a pl/sql defined dynamic action. At the moment the dynamic action is triggered using a button. For example if "530000000019" is entered into the item (P13_3), after the clicking the button it should return a value (Product Code) and set the item with that value.
This is the pl/sql code that runs when the button is clicked:
DECLARE
p_code products.prod_code%TYPE;
p_id products.prod_id%TYPE;
BEGIN
p_id := :P13_2;
SELECT prod_code INTO p_code FROM products WHERE prod_id = p_id;
RETURN p_code;
END;
This is the error that appears:
Ajax call returned server error ORA-01403: no data found for Set Value.
This means that no data was returned when the SELECT INTO clause ran. I then altered the code and ran this code to see if there were any faults in the code:
DECLARE
p_code products.prod_code%TYPE;
p_id products.prod_id%TYPE;
BEGIN
p_id := 530000000019;
SELECT prod_code INTO p_code FROM products WHERE prod_id = p_id;
RETURN p_code;
END;
This code returned a value and the set value dynamic action was successful. This therefore means, that in apex was not picking up the value in the P13_3 item.
I have a apex process that has similar syntax that calls the P13_3 apex item and it runs successfully. Here is the code of the apex process:
DECLARE
b_code products.prod_id%TYPE := :P13_3;
p_quant products.prod_qnty%TYPE := :P13_2;
BEGIN
UPDATE products
SET prod_qnty = prod_qnty - p_quant
WHERE prod_id = b_code;
END;
If I am not mistaken, I would say that this proves that the problem lies with dynamic action and not the pl/sql code. I am currently using apex 5.1 (The 16 Dec release). Please Help. Thank you in advance :)
I have tried similar work ,I have created two text boxes one for input & another for output & I am getting expected result .Please check following screen shots of result & dynamic action settings
And dynamic action settings is as follows :
Edit view of True action is as follows :
Hope this will help you.

Unable to execute oracle procedure in PLSQL Developer

I am having sample Procedure as Below
CREATE OR REPLACE PROCEDURE proc_Table1
BEGIN
SELECT 'Sample UserName' AS UserName
FROM Dual;
END;
Now I want to run this Proc in PLSQL developer.I tried the below but its generating error
begin
proc_Table1;
end;
Its Displaying
Thanks for the Help.
Any Idea why this Happens.
When you created the procedure, you should have been alerted to the fact that you had syntax errors. If you're going to run a SELECT statement, you need to do something with the results-- either populate a local variable or open a cursor or something else. The code you've posted is also missing the IS/AS keyword
CREATE OR REPLACE PROCEDURE proc_Table1
AS
l_username VARCHAR2(30);
BEGIN
SELECT 'Sample UserName' AS UserName
INTO l_username
FROM Dual;
END;
will be syntactically valid. It doesn't appear, however, to be particularly useful-- you procedure isn't modifying the database and has no way to communicate with the caller so it isn't doing anything meaningful. As a general principal, you would also generally want to use a simple PL/SQL assignment operator to populate a local variable rather than selecting from dual, i.e.
l_username := 'Sample UserName';
Try this, it should work:
CREATE OR REPLACE PROCEDURE proc_Table1(UserName OUT VARCHAR2)
AS
BEGIN
SELECT 'Sample UserName' INTO UserName
FROM Dual;
dbms_output.put_line(UserName);
END PROC_TABLE1;
-------------------------------
How to Execute
-------------------------------
declare
name varchar2(50);
result varchar2(100);
begin
proc_table1(name);
end;

Oracle SQL Developer: how to view results from a ref cursor?

If I have a function which returns a reference cursor for a query, how can I view the result set of this in SQL Developer? Toad has a special tab for viewing the results of a reference cursor, this is the functionality I would like to find.
SET SERVEROUTPUT ON;
VARIABLE X REFCURSOR;
EXEC PROCEDURE_WITH_OUTPUT_SYS_REFCURSOR(:X);
PRINT X;
Double click the cursor fields in your result record. On the right side there is a "..." icon. Click this and you'll see the contents
Hi I know this was asked a while ago but I've just figured this out and it might help someone else. Not sure if this is exactly what you're looking for but this is how I call a stored proc and view the output in SQL Developer.
In SQL Developer when viewing the proc, right click and choose 'Run' or select Ctrl+F11 to bring up the Run PL/SQL window. This creates a template with the input and output params which you need to modify. To return the results of a sys_refcursor you then need to declare a row type that is exactly equivalent to the select stmt / sys_refcursor being returned by the proc. Below I declare "type t_row" which matches my output fields, then loop through the returned sys_refcursor. If t_row matches my sys_refcursor then it gets populated with each row of the sys_refcursor:
DECLARE
P_CAE_SEC_ID_N NUMBER;
P_FM_SEC_CODE_C VARCHAR2(200);
P_PAGE_INDEX NUMBER;
P_PAGE_SIZE NUMBER;
v_Return sys_refcursor;
type t_row is record (CAE_SEC_ID NUMBER,FM_SEC_CODE VARCHAR2(7),rownum number, v_total_count number);
v_rec t_row;
BEGIN
P_CAE_SEC_ID_N := NULL;
P_FM_SEC_CODE_C := NULL;
P_PAGE_INDEX := 0;
P_PAGE_SIZE := 25;
CAE_FOF_SECURITY_PKG.GET_LIST_FOF_SECURITY(
P_CAE_SEC_ID_N => P_CAE_SEC_ID_N,
P_FM_SEC_CODE_C => P_FM_SEC_CODE_C,
P_PAGE_INDEX => P_PAGE_INDEX,
P_PAGE_SIZE => P_PAGE_SIZE,
P_FOF_SEC_REFCUR => v_Return
);
-- Modify the code to output the variable
-- DBMS_OUTPUT.PUT_LINE('P_FOF_SEC_REFCUR = ');
loop
fetch v_Return into v_rec;
exit when v_Return%notfound;
DBMS_OUTPUT.PUT_LINE('sec_id = ' || v_rec.CAE_SEC_ID || 'sec code = ' ||v_rec.FM_SEC_CODE);
end loop;
END;
there are no way to display a refcursor in datagrid in sqldeveloper.
we can define a refcursor,call SP,then print refcursor,then data will be printed in Script output window in a plane text mode,but not in Query Result window.

Resources