Functions in the inner query
Hello!I challenged the following problem. Here's the simple query:
SELECT id, id, id from
(select 1, sys_guid () as double id)
as you can see there is a sys_guid() function in the inner query. So, why do we use these
constructions? Right - to calculate the value of a function once and use it again so much
time, that we need. So I guess to get three identical fields. But, as it turns out, it is not
always too! I mean, on one version of Oracle database this query return the same three
fields, but on another - three different! Based on what the sys_guid() function is a kind of
random function, I can assume that the function is run three times in the second case
instead of one (as it should)! So why is it? Is - this bug from version, or an option in
control file that influence the optimizer?
PS: I found a workaround on this basis, where this query produces abnormal results, we can use
Internal ORDER BY clause in the query:
SELECT id, id, id from
(select 1, sys_guid () as command id double by 1)
The oracle optimizer is the fusion view inline with the outer select block. He replaced effectively by:
select sys_guid(), sys_guid(), sys_guid()
from dual
You can avoid this as follows:
select /*+ no_merge(x) */
id,id,id from
(select 1,sys_guid() as id from dual) x
Published by: Toon Koppelaars on July 9, 2009 09:22
Tags: Database
Similar Questions
-
With functions in the SQL query tuning
Hello
I'm trying to settle a query with functions in the select section. You wonder how to see the results of the plan to explain these features included. Will there be a qs to include when you run the explain plan command
Thank you
Hilton
Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
PL/SQL Release 11.2.0.3.0 - Production
"CORE 11.2.0.3.0 Production."
AMT for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
Thank you. The function is not in the where clause but in the query using some of the returned columns. I realized that using the trace gave me the plan explanation of each of the functions.
-
make a function using the update query - error PLS-00103
I get the following error message in my pl/sql developer every time, I try to create this function in my package
PLS3-00103 encountered the symbol ";" when expecting one of the following return
Please note, I'm trying to do is to get a user entered to perform an update for a specific row in a table called accountingtable that is located in the CDC schema. I don't want to make a comeback but in my update function.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The package Specfication
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FUNCTION update_price (needed_newprice in ccl.accountingtable.price%rowtype,
partforupdate in ccl.accountingtable.part_id%rowtype,
colourpart to ccl.accountingtable.colour_id%rowtype);
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package body
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FUNCTION update_price (needed_newprice in ccl.accountingtable.price%rowtype
partforupdate in ccl.accountingtable.part_id%rowtype,
colourpart to ccl.accountingtable.colour_id%rowtype);
BEGIN
Update accountingtable
fixed price = (needed_newprice)
where part_id = (partforupdate)
and colour_id = (colourpart);
END update_price;
Thanks in advance for any help.Procedure update_price (needed_newprice in ccl.accountingtable.price%rowtype,
partforupdate in ccl.accountingtable.part_id%rowtype,
colourpart to ccl.accountingtable.colour_id%rowtype);No % rowtype. Use type %
Procedure update_price (needed_newprice in ccl.accountingtable.price%type,
partforupdate in ccl.accountingtable.part_id%type,
colourpart to ccl.accountingtable.colour_id%type);is not respected in the body
create or replace pacakage body test_board is
procedure update_price (needed_newprice in ccl.accountingtable.price%rowtype---ici
partforupdate in ccl.accountingtable.part_id%rowtype,
colourpart to ccl.accountingtable.colour_id%rowtype) isPublished by: user2679851 on June 2, 2010 14:01
-
To generate the sequence in the select clause of the inner query
Hi all
Have the table and the data as below,
I want to generate a sequence number for all the distinct combinations of emp_id and emp_name running
DROP TABLE emp1.
CREATE TABLE emp1 (emp_id NUMBER, emp_name VARCHAR2 (100));
INSERT INTO emp1 VALUES (1, 'Name1');
INSERT INTO emp1 VALUES (2, 'Name2');
INSERT INTO emp1 VALUES (1, 'Name3');
INSERT INTO emp1 VALUES (2, 'Conjoint4');
COMMIT;
Output must be same as below:
EMP_ID EMP_NAME Reference ID 1 Name1 1000 1 Name1 1000 1 Name3 1001 2 Name4 1002 2 Name2 1003 "You cannot invoke CURRVAL and NEXTVAL in the subquery to CREATE."
"MATERIALIZED VIEW, or a SELECT, UPDATE, or DELETE statement;
Steve O'Hearn, Guide to preparing Oracle 1Z0-047
------
-
Subselect query returns "invalid identifier", but the nested query return lines
I don't think it's a general SQL question.
Select * from persons where person_id in)
Select person_id with people whose name = 'Obama' - subquery
) and age > 18;
When I run the subquery, I get:
ORA-00904: "PERSON_ID": invalid identifier
00904, 00000 - '% s: invalid identifier '.
* Cause:
* Action:
Error on line: column 5: 8
This is because the table people do not have the person_id field.
But when I run the nested together query it returns all the lines in people with the AGE greater than 18.
How is he succeeds when the subquery is obviously wrong?
363f652b-263D-4418-933F-74a1d0a41b4c wrote:
I don't think it's a general SQL question.
Select * from persons where person_id in)
Select person_id with people whose name = 'Obama' - subquery
) and age > 18;
When I run the subquery, I get:
ORA-00904: "PERSON_ID": invalid identifier
00904, 00000 - '% s: invalid identifier '.
* Cause:
* Action:
Error on line: column 5: 8
This is because the table people do not have the person_id field.
But when I run the nested together query it returns all the lines in people with the AGE greater than 18.
How is he succeeds when the subquery is obviously wrong?
Yes - this is a general SQL question and ask often enough.
Correlated subqueries depend on the inner query, be able to see and access to the columns of the outer query. Normally see you referenced in the WHERE clause of the subquery and not in the SELECT clause, but the reference is valid in both places. This works because the columns of the tables in the main query are accessible in the subquery. "Person_id" is probably a column in the table 'people '.
Which can be a cause of problems 'odd' when the column (in your case "person_id") is more of a table.
Use an alias in the subquery in the subquery and you will find that it will not succeed.
See these two articles AskTom where he addresses this specific issue
http://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:3317493900346468494
http://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:155200640564
-
Hey guys,.
I'm using version 4.2.6 apex. The theme is 26.
IM also using Listener Oracle APEX.
I can print my classic report in PDF or CSV format.
But I need to export it as a .xls extension.
Report type: SQL (body of function from PL/SQL returning the SQL) query
I need is like this cause my 'where' clause type is dynamic.
Look at using this method: Tom's Blog: a non-standard export excel 2010 (.xlsx)
I do something similar for downloads to excel in my projects...
Thank you
Tony Miller
Software LuvMuffin
Ruckersville, WILL -
Function returning the query takes longer to run in Apex4.0
Hi all
I've created a report using the function returns the query. The function returns the query based on parameters that returns the dynamic columns. When I run the query in sql developer the query generates and returns the result in 3mins. But in the apex, it takes 35 minutes maximum to return.
The query returns about 10000 lines.
What a performance problem in the query or Apex? can someone help plz
Concerning
REDANo it's just the first tranche of 500. You can run it in good old SQL * more and the total time of the time (be patient however)
-
function count() throws the error in the EQL query for metric
Hello
I try to use count function in query EQL for metric bar to display the number of occurrences of a record.
When the record type does not exist, I hope that the function returns the number 0. Instead the lift function a runtime exception and the whole Bar Metric portlet fails, error no. results available. Even if the other components of the metric bar have valid results.
2013-02-21 13:03:51, 216 WARN [MetricsBarQueryProcessor] EQL the query returns no results.
2013-02-21 13:03:51, 216 ERROR [MetricsBarQueryProcessor] EQL the query returns no results.
2013-02-21 13:03:51, 216 WARN [MetricsBarResultsProcessor] no declaration is the result of process.
The EQL query I use is
BACK NUMBER_OCCURS AS SELECT COUNT (EMP_ID) AS NUMBER_OCCURS where EMP_NAME IS NOT NULL group;
I tried to use COALESCE, but it does not help.
Can someone please suggest a work around?Varkashy,
It should work...
DEFINE foo AS SELECT COUNT (1) AS NUMBER_OCCURS where EMP_NAME IS NOT NULL group;
RETURN NUMBER_OCCURS AS SELECT
COALESCE (foo []. NUMBER_OCCURS, 0) AS NUMBER_OCCURS
GROUPPatrick Rafferty
http://branchbird.comEdited by: Branchbird - Pat on February 21, 2013 05:20
-
PL/SQL Query return function, adding the column links
Hi all
I'm working on a SQL report with the area type = function from PL/SQL Query to return
All columns are generated dynamically based on my mapping table and a column of ID.
So whenever the page is loaded, according to the ID mapping table returns a set of columns in a particular order.
So not only the columns are dynamic, but the order of the columns varies also.
But the first 1 column is standard (it doesn't come from the mapping table) and is coded in my pl/sql block hard.
I'm fighting with the addition of a link to this column. The link must be a Javascript function which takes the parameters in the form of 2 columns in the mapping table.
My pl/sql block is something like that...
Now, I'm not able to transmit the values of this #map_id # and #comments # correctly. I tried so many different combinations of channels, but could not make it work.v_select := 'SELECT <g href=javascript:f_report1(#map_id#,#comments#)><img src=""></a> as report1, '; // g=a v_cols := 'contains all columns from the mapping table based on a ID(hidden item)'; v_from := 'FROM table'; v_where := 'where condition is put in here'; v_query := v_select||v_from||v_where; return v_query;
I'm not sure that the order of this map_id and commentscolumn and therefore cannot connect through the report attributes.
How can I go to a column value to the function?
Thank you
DippyThis should work if all goes well:
v_select := q'[ SELECT '' as chart, ]';
Published by: Dimitri Gielis on May 20, 2010 20:10
-
What are the inner workings of the grid in forms?
Hi, I have some doubts, I want to know what are the inner workings of the grid in forms.
1. how forms followed the value change in the grid?
2. when we run the query that we will get the selected lines, then we changed some values in certain fields in the grid, how it follows the change in value? .how he knows the process is update or insert?
It is this that my concept, when we realized the request forms will be store values in the tables with rowid.i thought a lot more, but I can't any idea on it.any help me?
You just want to understand the functioning of the forms or you encounter some difficult techniques in certain areas? If you have a hearing problem, please describe, and we can try to help. If you try just to know how it all works, I would recommed referring to Forms Builder online help.
In help, search for information on GET_RECORD_PROPERTY. This part of the documentation provides a pretty good explanation as to what is happening and how to determine the current state of a folder.
In short, when you make a change to a field that represents a recording of the db, a SELECT for UPDATE is issued. This causes the recording to be blocked. Actually change value, we monitor internally. I won't go into the details on how we do here.
-
Bills of the AP - query gives output in the editor, but no data found when run from a workflow
Hello
I am working on a custom workflow related to invoices from the AP and I came across this very odd situation where the below query works perfectly well by operating in any PL/SQL as Toad/SQL Developer editor but when run in an Oracle Workflow custom, the query raises an exception NO_DATA_FOUND.
I set debugging instructions to capture the values of the parameters (lv_invoice_id and lv_hold_id being retrieved workflow attributes) before and after the SELECT statement and noticed that the values of the parameters are set correctly.
SELECT type
IN lv_match_type
DE ap_invoices_all aia , ap_invoice_lines_all Arnaud , ap_holds_all aha
OÙ ail . invoice_id = lv_invoice_id
ET line_type_lookup_code = "ITEM"
ET AIA . invoice_id = garlic . invoice_id
ET AHA . invoice_id = AIA . invoice_id
ET AHA . hold_id = lv_hold_id
ET ROWNUM = 1 ;
Can anyone suggest what could be wrong with that? Having spent 2 days trying to debug this but without success.
Any help would be greatly appreciated.
I added a function of the WorkflowTimeout JOB just before function which becomes the flag Match, and it worked. It appears like the workflow engine is somehow unable to assign values to the query. Putting a WAIT, he probably gave the workflow a second to assign variables with values. Seems very strange, but seems to have solved the problem. Do thorough tests to confirm that it does not break something else. Mike - appreciate all your help with this post until now. You were very prompt in answering my questions. Appreciate it.
-
Invalidation of the index based on a function because the recompilation
Hello
one of our customers has two indices according to the functions that fall under the State "off" in some situations. After looking more closely at the situation, there are some things that my opinion are different from what I expected of a function-based index. Because I am unable to find anything about either on metalink (or I'm not asking the right question) I would appreciate a second opinion of you.
To keep things simple, I gave an example to illustrate the behavior. I use Oracle 12.1.0.2, although it can also be reproduced on versions 10.2 and 11.2.
It's my environment and three parameters that I find relevant to the discussion:
SQL> select banner from v$version; BANNER ---------------------------------------------------------------------------- Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production PL/SQL Release 12.1.0.2.0 - Production CORE 12.1.0.2.0 Production TNS for Linux: Version 12.1.0.2.0 - Production NLSRTL Version 12.1.0.2.0 - Production SQL> show parameter remote_dependencies NAME TYPE VALUE ------------------------------------ ----------- ---------- remote_dependencies_mode string TIMESTAMP SQL> show parameter query_rewrite NAME TYPE VALUE ------------------------------------ ----------- ------------- query_rewrite_enabled string TRUE query_rewrite_integrity string enforced
Test case:
SQL> CREATE OR REPLACE FUNCTION f1 (p_string IN VARCHAR2) 2 RETURN VARCHAR2 3 DETERMINISTIC 4 IS 5 BEGIN 6 RETURN lower(p_string); 7 END f1; 8 / Function created. SQL> CREATE TABLE tmp_t1 (a_string VARCHAR2(10)); Table created. SQL> INSERT INTO tmp_t1 VALUES ('a'); 1 row created. SQL> COMMIT; Commit complete. SQL> CREATE INDEX x1_tmp_t1 ON tmp_t1(f1(a_string)); Index created. SQL> set linesize 80; SQL> column index_name format a10; SQL> SELECT index_name, index_type, status, funcidx_status 2 FROM user_indexes; INDEX_NAME INDEX_TYPE STATUS FUNCIDX_ ---------- --------------------------- -------- -------- X1_TMP_T1 FUNCTION-BASED NORMAL VALID ENABLED
We have our table and our based on an index function which basically converts the values to lowercase. From here on things, download a little weird. What happens with the index based on a function if the underlying function is recompiled? I always thought (and which is also stated in the Concepts and the use of function index (Doc ID 66277.1)) that the index would change its status to "disabled". Here is an excerpt of the said Doc ID:
The index depends on the State of the PL/SQL function. The index can be
struck down or rendered useless by changes to the function. The index is marked
People with DISABILITIES, if he is brought to the function or function is re-created.
The timestamp of the function is used to validate the index.
To allow the index after it is created, the function if the signature of the
the function is identical to the front:
ALTER INDEX ENABLE;
If the signature of functions is changed, to make the changes effective
in the index, the index must be renewed to make it valid.
ALTER INDEX REBUILD.
It seems that this is not the case, as the index remains valid and activate.
SQL> alter function f1 compile; Function altered. SQL> SELECT index_name, index_type, status, funcidx_status 2 FROM user_indexes; INDEX_NAME INDEX_TYPE STATUS FUNCIDX_ ---------- --------------------------- -------- -------- X1_TMP_T1 FUNCTION-BASED NORMAL VALID ENABLED
OK, explicitly recompiling function F1 single timestamp changed. What if we replace the function completely and we change the output of the function - for example we will switch from a LOWER function to SUPERIOR function in the body of the F1. Again, it is change that I thought would be not only to disable the index based on a function, but also force its reconstruction. At least that is my understanding of the explanation in Doc ID).
SQL> CREATE OR REPLACE FUNCTION f1 (p_string IN VARCHAR2) 2 RETURN VARCHAR2 3 DETERMINISTIC 4 IS 5 BEGIN 6 RETURN UPPER(p_string); 7 END f1; 8 / Function created. SQL> SELECT index_name, index_type, status, funcidx_status 2 FROM user_indexes; INDEX_NAME INDEX_TYPE STATUS FUNCIDX_ ---------- --------------------------- -------- -------- X1_TMP_T1 FUNCTION-BASED NORMAL VALID ENABLED
Should not be. Because of the function "create or replace" F1 never go through a "invalid" phase which may be necessary for index becomes unusable? What about queries on the TMP_T1 table? Does optimizer always uses access index or not? What about the results?
SQL> EXPLAIN PLAN SET statement_id='s1' FOR 2 SELECT a_string, f1(a_string) as f1_a_string, f1('a') as f1_literal 3 FROM tmp_t1 4 WHERE f1(a_string) = 'a'; Explained. SQL> SELECT * from table(dbms_xplan.display(statement_id=>'s1')); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------ Plan hash value: 3133804460 ------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 2024 | 2 (0)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID BATCHED| TMP_T1 | 1 | 2024 | 2 (0)| 00:00:01 | |* 2 | INDEX RANGE SCAN | X1_TMP_T1 | 1 | | 1 (0)| 00:00:01 | -------------------------------------------------------------------------------------------------
The index is used by the optimizer, see the results.
SQL> column f1_a_string format a15; SQL> column f1_literal format a15; SQL> SELECT a_string, f1(a_string) as f1_a_string, f1('a') as f1_literal 2 FROM tmp_t1 3 WHERE f1(a_string) = 'a'; A_STRING F1_A_STRING F1_LITERAL ---------- --------------- --------------- a a A
A_STRING = value in the table
F1_A_STRING = value of f1 (a_string) but the value is not evaluated because it comes from an index, so tiny value (remember, at the time index created the function returned small values)
F1_LITERAL = value of the function f1 newly evaluated, using literal instead of the value in the table.
Predicate f1 (a_string) = 'a' should return no rows because no character uppercase is equivalent to "a". Query with f1 (a_string) = 'A' should return a line, but it doesn't.
SQL> SELECT a_string, f1(a_string) as f1_a_string, f1('a') as f1_literal 2 FROM tmp_t1 3 WHERE f1(a_string) = 'A'; no rows selected
Anyone know if this is an expected behavior? And, is it possible to disable the index based on a function whenever the underlying function signature is changed? The parameter query_rewrite_integrity = applied from
DOC-ID 66277.1 does not seem to do the trick:
(c) session variables
~~~~~~~~~~~~~~~~~~~~
QUERY_REWRITE_ENABLED (true, false),
QUERY_REWRITE_INTEGRITY (confidence, forced, stale_tolerated)
determines the optimizer to use index based on a function with
expressions using SQL, user defined functions functions.
TRUST: Oracle allows rewrites using relationships that have
was declared.
APPLIED: Oracle ensures and guarantees consistency and integrity.
STALE_TOLERATED: Oracle allows rewrites using vessels of the relationship not applied.
Used in the case of materialized views.
Set session variable cost function optimizer to choose the
a function-based index
Kind regards
SAMO
From the Manual 11.2 ( https://docs.oracle.com/cd/E11882_01/appdev.112/e41502/adfns_indexes.htm#ADFNS254 )
"If you change the semantics of a
DETERMINISTIC
run and recompile, then you must manually rebuild all addicts depending on index and materialized views." Otherwise, they report results for the previous version of the function. »This note is not that I made my initial comment well - which was based on an incorrect memory the relationship between function-oriented and autonomous pl/sql functions, so I won't try to explain it. In fact, I went back to Oracle 8i practice to see if something had changed between yesterday and today and found that I had described exactly the behavior that the OP has been seeing. It's the way it is supposed to be.
Concerning
Jonathan Lewis
-
Correct use of the function in the pipeline?
Hello
I have a function in the pipeline, I am using 11 g. the idea is I can pass in the name of a table, and it returns a set of rowcounts for this table
I obviously have something wrong, but what?
-Package
create or replace PACKAGE IS GetMigSamples
-set types for a record and an array of records like this
TYPE sample_record IS RECORD)
PERSON_ID NUMBER,
CF_ID VARCHAR2 (10),
number_of_records NUMBER);
TYPE sample_table IS the TABLE OF THE sample_record;
FUNCTION SP_MIG_SAMPLES (P_TABLE IN VARCHAR)
RETURN sample_table
IN PIPELINE;
END;
-Package body
create or replace PACKAGE GetMigSamples BODY IS
FUNCTION SP_MIG_SAMPLES (P_TABLE IN VARCHAR) sample_table RETURN PIPELINED IS
v_cur sys_refcursor;
v_rec sample_record;
v_migtable VARCHAR (64);
v_stmt_str VARCHAR2 (400);
v_col VARCHAR (64);
BEGIN
v_migtable: = P_TABLE;
-some tables have a different name for the foreign key column
v_col: = box
When v_migtable = "MYTABLE" then "MAIN_ID".
another end 'PERSON_ID ';
-build a sql query for this table and the foreign key column
v_stmt_str: = ' SELECT
MX.' | v_col |' like PERSON_ID,.
COALESCE (MX. Reference, "?") as CF_ID,.
Count (*) as number_of_records
OF ' | P_TABLE |' mx
GROUP BY mx.' | v_col;
-Open the query and loop through it, each line of pipes
Open the v_cur for v_stmt_str;
LOOP
EXTRACTION v_cur
IN v_rec;
EXIT WHEN v_cur % NOTFOUND;
PIPE ROW (v_rec);
END LOOP;
CLOSE V_cur;
RETURN;
End;
END GetMigSamples;
When I use it
Select getmigsamples.sp_mig_samples ('M_MY_TABLE') of double
I get
FW. SYS_PLSQL_228255_29_1()
Which I guess means that I have a reference to an object, rather than the actual values in the lines. I tried to corrrect it for centuries and have now arrived at the point of the tear-my-hair-out. Can anyone help please?
Thank you
When I use it
Select getmigsamples.sp_mig_samples ('M_MY_TABLE') of double
I get
FW. SYS_PLSQL_228255_29_1()
Which I guess means that I have a reference to an object, rather than the actual values in the lines. I tried to corrrect it for centuries and have now arrived at the point of the tear-my-hair-out.
No - this 'thing' you got is a hidden type of SQL Oracle automatically created to match the type of PL/SQL, that you used. SQL can only work with the SQL types defined at the schema level. But for functions PIPELINED Oracle allows you to specify the types of PL/SQL and it will create SQL HIDDEN types to make it work.
A pipeline function should be treated as a table. You must use the SCOREBOARD operator
Select * from table (myFunction);
Try this simple example
-type to match record emp
create or replace type emp_scalar_type as an object
(EMPNO NUMBER 4,
ENAME VARCHAR2 (10),
USE VARCHAR2 (9).
MGR NUMBER 4,
HIREDATE DATE,
NUMBER OF SAL (7, 2)
NUMBER OF COMM (7, 2)
DEPTNO NUMBER (2)
)
/
-records of the emp table
create or replace type emp_table_type to table of emp_scalar_type
/
-function of pipelined
create or replace function get_emp (p_deptno number)
return emp_table_type
PIPELINED
as
TYPE EmpCurTyp IS REF CURSOR RETURN emp % ROWTYPE;
emp_cv EmpCurTyp;
l_rec emp % rowtype;
Start
Open emp_cv SELECT * from emp where deptno = p_deptno;
loop
extract the emp_cv in l_rec;
When the output (emp_cv % notfound);
line of conduct (emp_scalar_type (l_rec.empno, LOWER (l_rec.ename),
l_rec.job, l_rec.mgr, l_rec.hiredate, l_rec.sal, l_rec.comm, l_rec.deptno));
end loop;
return;
end;
/
Select * from table (get_emp (20))
See use of the SCOREBOARD operator?
-
Collection of the dynamic query
Hi All-
I'm trying to get the value of the collection through the dynamic query but I am facing some problem please let me know that I hurt.
Created a function like below to run the dynamic query to select statement
create or replace FUNCTION rfunGetColumnValue ( ColumnName VARCHAR2, TableName VARCHAR2, DefaultValue OUT VARCHAR2, Criteria VARCHAR2) RETURN VARCHAR2 IS ReturnValue VARCHAR2 (32767 byte) ; Stmt VARCHAR2 (32767 byte) ; BEGIN stmt := 'begin select '|| ColumnName || ' into :1 from table(:2) ' ||NVL ( Criteria, ' ') || ' Fetch First Row only ; EXCEPTION WHEN OTHERS THEN :2 := SQLERRM; end;' ; dbms_output.put_line (stmt) ; EXECUTE IMMEDIATE stmt USING OUT ReturnValue, OUT DefaultValue; --select Valueinto into Returnvalue from dual; RETURN ReturnValue; END;
Now, I created a folder in the Package
create or replace PACKAGE Collection_PKG is type Bank_rec is RECORD ( SNO NUMBER(10), BANKID NUMBER(5), BANKNAME VARCHAR2(50), BANKSC VARCHAR2(50), ADDEDIT varchar2(1), COMPID number(5), ISBULK number(1), ROWNO number(10), ERROR VARCHAR2(500) ); TYPE Bank_tbl IS TABLE OF Bank_rec; --type Bank_cur is ref cursor return Bank_rec; end Collection_PKG; end Collection_PKG; end Collec tion_PKG;
Now, when I'm Trying the code below
DECLARE V_EXECQUERYPARAM XMLTYPE:= XMLTYPE('<QueryParam> <BankXML> <Bank> <BankID>0</BankID> <BankSC><![CDATA[RCB]]></BankSC> <BankName><![CDATA[Royal challenger Bank]]></BankName> <IsBulk>0</IsBulk> <AddEdit>A</AddEdit> </Bank> </BankXML> </QueryParam>'); BEGIN Rspbanksave( v_SPParamList => V_EXECQUERYPARAM ); END;
create or replace PROCEDURE rspBankSave ( v_SPParamList XMLTYPE DEFAULT NULL) IS V_Addedit VARCHAR2 (1 CHAR) ; Bank_tbl Collection_PKG.BANK_TBL := Collection_PKG.BANK_TBL () ; BEGIN SELECT Row_number () OVER (ORDER BY 1), XT.BankID, XT.BankName, XT.BankSC, XT.AddEdit, v_CompID, XT.IsBulk, CAST (0 AS NUMBER (5)), CASE WHEN MBank.BankID IS NOT NULL THEN CASE WHEN XT.BankSC = MBank.BankSC AND XT.BankName = MBank.BankName THEN 'R104|Entry Already Exist,R114|Short Code Already Exist' WHEN XT.BankSC = MBank.BankSC THEN 'R114|Short Code Already Exist' WHEN XT.BankName = MBank.BankName THEN 'R104|Entry Already Exist' END ELSE NULL END Bulk collect INTO Bank_tbl FROM XMLTABLE ('//QueryParam/BankXML/Bank' PASSING v_SPParamList COLUMNS BankID NUMBER (5) PATH 'BankID', BankName VARCHAR2 ( 50) PATH 'BankName', BankSC VARCHAR2 ( 50) PATH 'BankSC', AddEdit VARCHAR2 ( 1) PATH 'AddEdit', IsBulk NUMBER (1) PATH 'IsBulk') XT LEFT JOIN MBank ON XT.BankID != MBank.BankID AND v_CompID = MBank.CompID AND (XT.BankSC = MBank.BankSC OR XT.BankName = MBank.BankName) ; v_TotalRowCount := SQL%ROWCOUNT; IF (v_TotalRowCount > 0) THEN BEGIN V_Addedit:=rfunGetColumnValue (ColumnName=> 'Upper(AddEdit)',TableName=>'table(Bank_tbl)',DefaultValue=>'',Criteria =>''); END; --SQL Code here END IF; END rspBankSave;
As I've suggested before:
To get the name of the table the column
and as others have:
Type global temporary Tables vs. table
If you give more context, more information about the bigger picture, more information about what you're trying to do and why you're going down the road you go down, you can return more useful information. But you seem reluctant to do.
For the moment, your recent posts seem to just raise the same type of question - why are you doing this?
The normal way to return data to a client is a refcursor.
It is the most effective way.
Not through collections that you seem to be put on the must-do approach.
-
Clarification of the SQL query in 2 day + Guide APEX
I worked through the Oracle Database Express Edition 2 day + Application Express Developer's Guide, and try to decipher the SQL query in Chapter 4 (building your app).
The code is:
SELECT d.DEPARTMENT_ID,
d.DEPARTMENT_NAME,
(select count (*) from oehr_employees where department_id = d.department_id)
"Number of employees", he said.
substr (e.first_name, 1, 1) |'. ' || Select 'Name Manager',
c.COUNTRY_NAME 'place '.
OEHR_DEPARTMENTS d,
E OEHR_EMPLOYEES
OEHR_LOCATIONS l,
C OEHR_COUNTRIES
WHERE d.LOCATION_ID = l.LOCATION_ID
AND l.COUNTRY_ID = c.COUNTRY_ID
AND e.department_id = d.DEPARTMENT_ID
AND d.manager_id = e.employee_id
AND instr (superior (d.department_name), superior (nvl (:P2_REPORT_SEARCH,d.department_name))) > 0)
I don't know exactly what is happening in the last line. I think I understand what the different functions but I'm not clear on the use of the: P2_REPORT_SEARCH string.
What does this string? This code simply checking that d.department_name isn't NA?
I have SQL experience but am not very familiar with the Oracle PL/SQL implementation. Can someone please give me a brief breakdown that check is doing in the context of the overall query? The application seems to work even if the conditional statement is not included.
Thank you.
2899145 wrote:
Thanks for the reply. I apologize if the information I added was incomplete. The code came from the day 2 + Application Express (version 4.2) Developer Guide.
In the section 'your own Application of 4 Buuilding' https://docs.oracle.com/cd/E37097_01/doc.42/e35122/build_app.htm#TDPAX04000 , they describe the creation of a report
page that includes the "manager_id" and 'location_id '. The SQL query, I pasted above extracted from the data in other tables to substitute the real 'name of the Manager' and 'rent '.
for the corresponding ID values. It makes sense, and the part of the SQL query that explicitly doing this makes sense.
However, given that the document is a guide for the development of the APEX, I guess the command:
AND instr (upper (d.department_name), upper (nvl (:P2_REPORT_SEARCH,d.department_name))) > 0
done something valuable, and I do not recognize what is exactly the value.
From a practical point of view why would I need to include this conditional statement? Which only added to the application?
Looking at the guide in question, it is clear that the
AND instr(upper(d.department_name),upper(nvl(:P2_REPORT_SEARCH,d.department_name)))>0
the line is completely unnecessary in the context of this tutorial, and it can be removed. The search in the tutorial app page is implemented by using a report filter interactive rather than a P2_REPORT_SEARCH element, which does not seem to exist at all. (It's a quirk of the APEX that bind variable references to non-existent items are replaced with NULL silently rather than exceptions). I thought that perhaps it would be legacy code a version of the tutorial prior to the introduction of interactive reports at the APEX 3.1, but I can't find explicit instructions to create such an element of filter in the 3.0 tutorial. I guess it must have been automatically generated by the application wizard when you create a standard report page.
If you do not want to see the effect he would have (as described in the post above), leave it in the source report, add a text element of P2_REPORT_SEARCH, and a button "submit" on page 2 and experimenting to find different values of the element and clicking on the submit button...
Maybe you are looking for
-
Satellite A200-AH7 - will not power on, only power LED blinks
Hello I have this laptop where all of a sudden it turned off and does not turn upward. All that happens is this flashing electric blue. I tried to remove the battery and just go out of the adapter. I tested the cards that I have two and both seem fin
-
Cannot connect my Satellite L500-1WG to Wi - Fi router Netgear
Hello I hope someone can help as Im pulling my hair out. Just replace an old Wireless ADSL router/modem to a "n" wireless Netgear DGND 3300 range Max Dual Band router ADSL. Everything is connected by ethernet to my Office PC Ok. Just bought a laptop
-
Hello My dear friends, please be careful when you buy an HP laptop, read the terms and conditions of warranty before purchasing their products. My screen went without any problem of mine. I had informed the Hp of the same thing, they mentioned that t
-
BlackBerry Smartphones Whatsapp display image not shown
My picture in my Whatsapp account does not appear in my contacts. In some people, it's show a different image than what I currently use. Please what do I do?
-
product lost crasis actv #.
Hi a problem to upgrade hp win7 for win 7 pro asking old adv # comp crased reload but can, t very well in # actv e-mail help please