Using a packaged function in a query
Hi ,
I have read the following statement (correct option for the question)in 1z0-147 questions.
The question is :: WHEN USING A PACKAGED FUNCTION IN A QUERY which of the following is true ::
The packaged function cannot execute DML statements against the table that is being queriedI tried the following to understand the above statement
create or replace package test_pk is
function fn_test(i number) return number ;
end;
create or replace package body test_pk is
function fn_test (i number) return number is
j number:=1;
begin
insert into a values(200,300);
commit;
return j;
end;
end test_pk; Upon executing the above function in the select statement
select TEST_PK.FN_TEST(1) from dualI got the error saying that Can't perform DML Inside SElect
Is this example for the above statement is TRUE ????
Could you please explain me if my example is wrong
Thanks
Edited by: Smile on Nov 22, 2012 9:47 AM
No, it is not true. Any function used in SQL is not allowed to perform a DML operation other than SELECT regardless if it is against the table that is being queried or not. Select is allowed against any table. And function in your example does INSERT which is not allowed. Also, Any function used in SQL is not allowed to perform commit/rollback/savepoint.
SY.
Edit: unless function is autonomous transaction.
Edited by: Solomon Yakobson on Nov 22, 2012 10:22 AM
Similar Messages
-
How to use type, packages, functions, and procedures in another schema ?
I have two target schema in one OWB project, such as A and B. In a mapping of A, I would like to use some types, packages, functions, and procedures from B. I have tried the method of synonym as suggested, but I could not find the metadata of these when importing ... The only type of synonym I can import is the synonym for table. Is there a bug for synonym?
If I cannot use synonym for this issue, is there another way to solve the problem?Now, in some instances you will absolutely need to create the second module as Carsten describes, however it should also be noted that you can reference objects in things like Expressions even if you have not loaded up the metadata. It is only when you need strong binding that it becomes neccessary to import objects. For everything else, as long as the reference will resolve at compile-time then you are good to go.
For example, I have a function in one target schema (S1) and a private synonym to it in another(s2). A mapping in the S2 schema has an expression object that uses the synonym to the function in the expression property for a couple of the output attirbutes. The synonym has not been loaded into metadata - indeed OWB has no knowledge of its existance. But it resolves at compile time so the mapping validates and generates successfully.
Mike -
Query performance affected with use of package.function in 11g
Hi,
I have a view that helps select account details for a particular account and use that in a form. The query in the view is:
select acc.* from accounts acc where acc.account_no = pkgacc.fGetAccNo;
Here "pkgacc" is a package that has set and get methods. ACCOUNT_NO is the PK for ACCOUNTS table. This same query when run in a 10g database makes use of the PK INDEX. However in 11g it does a FULL SCAN.
RegardsHi,
1/ Volume is the same
2/ All statistics are up to date
10g Plan
Plan
SELECT STATEMENT ALL_ROWS
Cost: 18 Bytes: 462 Cardinality: 3
23 NESTED LOOPS
21 NESTED LOOPS
Cost: 18 Bytes: 462 Cardinality: 3
19 VIEW VIEW SYS.VW_NSO_1
Cost: 12 Bytes: 39 Cardinality: 3
18 HASH UNIQUE
Cost: 12 Bytes: 110 Cardinality: 3
17 UNION-ALL
2 TABLE ACCESS BY INDEX ROWID TABLE SUMMIT.OLD_ACCOUNT_LINKS
Cost: 0 Bytes: 25 Cardinality: 1
1 INDEX RANGE SCAN INDEX SUMMIT.OACCL_2
Cost: 0 Cardinality: 1
8 NESTED LOOPS
6 NESTED LOOPS
Cost: 7 Bytes: 40 Cardinality: 1
4 TABLE ACCESS BY INDEX ROWID TABLE SUMMIT.ACCOUNTS
Cost: 4 Bytes: 18 Cardinality: 1
3 INDEX RANGE SCAN INDEX (UNIQUE) SUMMIT.ACC_PRIME
Cost: 3 Cardinality: 1
5 INDEX RANGE SCAN INDEX SUMMIT.ACCL_2
Cost: 2 Cardinality: 1
7 TABLE ACCESS BY INDEX ROWID TABLE SUMMIT.ACCOUNT_LINKS
Cost: 3 Bytes: 22 Cardinality: 1
16 NESTED LOOPS
Cost: 5 Bytes: 45 Cardinality: 1
14 MERGE JOIN CARTESIAN
Cost: 5 Bytes: 30 Cardinality: 1
10 TABLE ACCESS BY INDEX ROWID TABLE CVC.ACT01
Cost: 3 Bytes: 15 Cardinality: 1
9 INDEX RANGE SCAN INDEX (UNIQUE) CVC.PK_ACT01
Cost: 2 Cardinality: 1
13 BUFFER SORT
Cost: 2 Bytes: 30 Cardinality: 2
12 TABLE ACCESS BY INDEX ROWID TABLE CVC.ACF02
Cost: 2 Bytes: 30 Cardinality: 2
11 INDEX RANGE SCAN INDEX (UNIQUE) CVC.PK_ACF02
Cost: 1 Cardinality: 2
15 INDEX UNIQUE SCAN INDEX (UNIQUE) CVC.PK_BIT41
Cost: 0 Bytes: 15 Cardinality: 1
20 INDEX UNIQUE SCAN INDEX (UNIQUE) SUMMIT.CUST_PRIME
Cost: 1 Cardinality: 1
22 TABLE ACCESS BY INDEX ROWID TABLE SUMMIT.CUSTOMERS
Cost: 2 Bytes: 141 Cardinality: 1
11g Plan
Plan
SELECT STATEMENT ALL_ROWS
Cost: 1,136,322 Bytes: 138,218,223,528 Cardinality: 897,520,932
19 HASH JOIN
Cost: 1,136,322 Bytes: 138,218,223,528 Cardinality: 897,520,932
1 TABLE ACCESS FULL TABLE SUMMIT.CUSTOMERS
Cost: 14,455 Bytes: 355,037,154 Cardinality: 2,517,994
18 VIEW VIEW SYS.VW_NSO_1
Cost: 20,742 Bytes: 11,685,473,072 Cardinality: 898,882,544
17 HASH UNIQUE
Cost: 20,742 Bytes: 35,955,720,360 Cardinality: 898,882,544
16 UNION-ALL
3 TABLE ACCESS BY INDEX ROWID TABLE SUMMIT.OLD_ACCOUNT_LINKS
Cost: 0 Bytes: 25 Cardinality: 1
2 INDEX RANGE SCAN INDEX SUMMIT.OACCL_2
Cost: 0 Cardinality: 1
8 HASH JOIN
Cost: 20,354 Bytes: 35,951,952,800 Cardinality: 898,798,820
5 TABLE ACCESS BY INDEX ROWID TABLE SUMMIT.ACCOUNTS
Cost: 5,398 Bytes: 1,400,292 Cardinality: 77,794
4 INDEX RANGE SCAN INDEX (UNIQUE) SUMMIT.ACC_PRIME
Cost: 102 Cardinality: 28,006
7 TABLE ACCESS BY INDEX ROWID TABLE SUMMIT.ACCOUNT_LINKS
Cost: 4,634 Bytes: 4,575,208 Cardinality: 207,964
6 INDEX RANGE SCAN INDEX SUMMIT.ACCL_2
Cost: 145 Cardinality: 37,433
15 HASH JOIN
Cost: 388 Bytes: 3,767,535 Cardinality: 83,723
10 TABLE ACCESS BY INDEX ROWID TABLE CVC.ACT01
Cost: 271 Bytes: 4,065 Cardinality: 271
9 INDEX RANGE SCAN INDEX (UNIQUE) CVC.PK_ACT01
Cost: 3 Cardinality: 342
14 HASH JOIN
Cost: 115 Bytes: 92,580 Cardinality: 3,086
12 TABLE ACCESS BY INDEX ROWID TABLE CVC.ACF02
Cost: 76 Bytes: 46,290 Cardinality: 3,086
11 INDEX RANGE SCAN INDEX (UNIQUE) CVC.PK_ACF02
Cost: 4 Cardinality: 555
13 INDEX FAST FULL SCAN INDEX (UNIQUE) CVC.PK_BIT41
Cost: 38 Bytes: 557,220 Cardinality: 37,148 -
Use a package function inside a select of the same package
Hi.
How can i use a function defined inside a package, with a select used inside that same package ?
Example
... package example
CREATE OR REPLACE PACKAGE BODY pkg_example
AS
FUNCTION sum_two_values(p_val1 NUMBER,p_val2 NUMBER) RETURN NUMBER
IS
BEGIN
RETURN p_val1 + p_val2;
END sum_two_values;
FUNCTION use_another_function_example RETURN VARCHAR2
IS
v_value NUMBER;
BEGIN
SELECT sum_two_values(2,2) INTO v_value FROM dual;
RETURN 'waaaazzzzupppppp'
END use_another_function_example;
END pkg_example;
This will not work
-- SELECT sum_two_values(2,2) INTO v_value FROM dual;
How can i call a function inside a select statement, a function of the same package where the query is being called.
(i have Oracle 9.2x)
Cheers.are you sure? you are not using package1, you are using pack1
SQL> CREATE OR REPLACE PACKAGE package1
2 IS
3 FUNCTION f1
4 RETURN NUMBER;
5
6 FUNCTION f2
7 RETURN NUMBER;
8 END;
9 /
Package created.
SQL> CREATE OR REPLACE PACKAGE BODY package1
2 IS
3 a NUMBER;
4
5 FUNCTION f1
6 RETURN NUMBER
7 IS
8 BEGIN
9 RETURN 1;
10 END;
11
12 FUNCTION f2
13 RETURN NUMBER
14 IS
15 BEGIN
16 SELECT package1.f1
17 INTO a
18 FROM DUAL;
19
20 RETURN a;
21 END;
22 END;
23 /
Package body created.
Why not just this
SQL> ed
Wrote file afiedt.buf
1 CREATE OR REPLACE PACKAGE BODY package1
2 IS
3 a NUMBER;
4 FUNCTION f1
5 RETURN NUMBER
6 IS
7 BEGIN
8 RETURN 1;
9 END;
10 FUNCTION f2
11 RETURN NUMBER
12 IS
13 BEGIN
14 a:= f1;
15 RETURN a;
16 END;
17* END;
SQL> /
Package body created.formatted
Message was edited by:
devmiral -
How do I use the TRIM function in my Query?
I have a field that has called AP.service_user_defined_1 that houses a Code the code is like Alpha Num ie "AA01" then it has about 30 to 40 whites spaces and then the description of what the code means. I need to have the description to show in my report I don't necessarily need the code but I do need the description I tried putting the TRIM Function in as below and it will not work what do I need to do to correct this?? I need help ASAP this is due today! Thanks for any help!
SELECT DISTINCT
A1.AUTH_NUMBER,
PM.LAST_NAME,
A1.AUTH_TYPE,
A1.PLACE_OF_SERVICE,
A1.OVERALL_STATUS,
A1.CLOSED_REASON,
A1.DENIED_REASON,
Case
when A1.DENIED_REASON in ('HS001','HS002') then 'MED NECESS'
when A1.DENIED_REASON in ('HS004','HS005','HS006','HS007','HS008','HS013','HS014','HS016','HS017','HS019','HS020') then 'Admin Denial'
when A1.DENIED_REASON is NUll and ap.advisor_decision = 'AAPPR' then 'Approved'
else 'Unknown'
end DENIED,
A1.admit_primary_date,
A1.service_admit_type AS "IP ADMIT TYPE",
A1.service_user_defined_1 AS "OP Serv Type",
Trim (leading ('AA01 ',)from dual,
ap.contact_date,
AP.decision_date,
AP.ADVISOR_DECISION,
PM.PROVIDER_ID,
A1.INSERT_DATETIME,
TO_CHAR (A1.insert_datetime,'MONTH-YY')AS "Month",
A1.admit_primary_date,
A1.ACTIVE_PHYSICIAN_ADVISOR,
MV.LINE_OF_BUSINESS
FROM Windsoradm.auth_master a1
INNER JOIN Windsoradm.auth_phys_advisor ap
ON a1.auth_number=ap.auth_number
INNER JOIN windsoradm.prov_master pm
ON ap.seq_prov_id=pm.seq_prov_id
LEFT JOIN windsoradm.note_master nm
ON nm.seq_memb_id=a1.seq_memb_id
INNER JOIN windsoradm.member_mv mv
ON mv.seq_memb_id=a1.seq_memb_id
Where mv.Line_of_Business <>'SFS'
/*AND A1.PLACE_OF_SERVICE IN ('11','21','22','24')*/
/*AND a1.active_physician_advisor = 'Y'*/
/*AND (a1.closed_reason ='A06' OR a1.closed_reason is Null)*/
AND a1.insert_datetime Between To_Date ('04/01/2012', 'MM/DD/YYYY') and To_Date ('04/30/2012','MM/DD/YYYY')
ORDER BY 1I don't know how to use this within my query I put it in as you suggest and get an error: I'm new to these functions can you show me how within my query I should code it? The field Name is A1.service_user_defined_1 There are about 50 Different Codes in a Drop down list within the application that have a different Code and Different Description it appears that the Codes are all 4 character alpha numeric then about 25 to 45 spaces and then the description. Please show me in my code how to get this I wish there was a table I could link to that housed both code and description but who ever created this did not make life easy. Thanks (I also tried the TRIM but could not get it to work ) I know it is because I do not know how to put it within my code to make it work.
SELECT DISTINCT
A1.AUTH_NUMBER,
PM.LAST_NAME,
A1.AUTH_TYPE,
A1.PLACE_OF_SERVICE,
A1.OVERALL_STATUS,
A1.CLOSED_REASON,
A1.DENIED_REASON,
Case
when A1.DENIED_REASON in ('HS001','HS002') then 'MED NECESS'
when A1.DENIED_REASON in ('HS004','HS005','HS006','HS007','HS008','HS013','HS014','HS016','HS017','HS019','HS020') then 'Admin Denial'
when A1.DENIED_REASON is NUll and ap.advisor_decision = 'AAPPR' then 'Approved'
else 'Unknown'
end DENIED,
A1.admit_primary_date,
A1.service_admit_type AS "IP ADMIT TYPE",
A1.service_user_defined_1 AS "OP Serv Type",
regexp_replace('AA01 Behavioral/Mental Health Service', '^[^ ]+ +')from dual,
ap.contact_date,
AP.decision_date,
AP.ADVISOR_DECISION,
PM.PROVIDER_ID,
A1.INSERT_DATETIME,
TO_CHAR (A1.insert_datetime,'MONTH-YY')AS "Month",
A1.admit_primary_date,
A1.ACTIVE_PHYSICIAN_ADVISOR,
MV.LINE_OF_BUSINESS
FROM Windsoradm.auth_master a1
INNER JOIN Windsoradm.auth_phys_advisor ap
ON a1.auth_number=ap.auth_number
INNER JOIN windsoradm.prov_master pm
ON ap.seq_prov_id=pm.seq_prov_id
LEFT JOIN windsoradm.note_master nm
ON nm.seq_memb_id=a1.seq_memb_id
INNER JOIN windsoradm.member_mv mv
ON mv.seq_memb_id=a1.seq_memb_id
Where mv.Line_of_Business <>'SFS'
/*AND A1.PLACE_OF_SERVICE IN ('11','21','22','24')*/
/*AND a1.active_physician_advisor = 'Y'*/
/*AND (a1.closed_reason ='A06' OR a1.closed_reason is Null)*/
AND a1.insert_datetime Between To_Date ('04/01/2012', 'MM/DD/YYYY') and To_Date ('04/30/2012','MM/DD/YYYY')
ORDER BY 1 -
How to use user defined function in select query using Toplink
Hi Friends
I am little bit of new in Toplink stuff... so please help me...
I have to database functions 1. encrypt and 2. decrypt.
I want to exceute the following sql query using toplink
select port, database, user_name, decrypt(encrypt('String which is to be encrypt ','password'),'password') from CONFIGURATION
can anyone tell me , how to write code in toplink which will give the about sql output.
thanks .....The "Specifying a Custom SQL String in a DatabaseQuery" section in the TopLink Developer's Guide may help... http://download-uk.oracle.com/docs/cd/B32110_01/web.1013/b28218/qrybas.htm#BCFHDHBG
-
Help! Howto use the join function in a query with select distinct ?
Hi!
I have 2 tables. I want to select only 1 painting of each artists.
select distinct idartist
from tbl_artworks
where blah blah blah
order by rand()
how does the "join" function work for add: name, lastname, title, image and much more... i try... but i fail...
tbl_artists
idartist
name
lastname
1
Paul
Gaugain
2
Vincent
Van Gogh
3
Pablo
Picasso
tbl_artworks
idartwork
idartist
title
image
1
1
days of gods
image1.jpg
2
2
sunflower
image2.jpg
3
3
Dora maar au chat
image3.jpg
4
2
Sky
image4.jpg
5
3
La vie
image5.jpgGetting a single random image for each probably requires a combination of sql and cf. It would take someone smarter than me to do it with sql alone. I would probably try something like this:
1. Run a database query that gets all the images from all the artists.
2. Run a Q of Q that gets a distinct list of artist ids.
3. Loop through that list and run a Q of Q to get all the images for that artist.
4. Still in that loop, use randrange (1 to the recordcount) to select a random record from your Q of Q -
How to use multiple aggregate functions in single query
hi to all
The output will be giving first_name,last_name,max(salary),min(salary) and the output will be department wise.From employees table in single query
output will be:
first_name|last_name|max(salary)|min(salary)SELECT first_name||' '||last_name as ename,
MIN(sal) KEEP (DENSE_RANK FIRST ORDER BY sal) OVER (PARTITION BY deptno) "Lowest",
MAX(sal) KEEP (DENSE_RANK LAST ORDER BY sal) OVER (PARTITION BY deptno) "Highest"
FROM emp
ORDER BY deptno, sal;Edited by: Ramio on Jan 10, 2012 10:43 PM -
Using the "V" function in dynamic queries
I have a report region using 'pl/sql function body returning query'. It uses 'return package.function;'. The function makes extensive use of the "V" function to read session state.
If I have a predicate like
if (something) then
q:=q||'
and some_column=v(''P1_ID'')
end if;
When the query is parsed, this gets translated to
and some_column=v('P1_ID')
Question: Is the v('P1_ID') treated like a bind variable similar to the sys_context() concept? So it is evaluated just once per query and the value is plugged into the query. It is NOT evaluated for every row returned by the query, right?
I am pretty sure thats the way it works, just wanted someone to confirm it.
ThanksVikas,
v() is a function, no differently than any other PL/SQL function you would employ in SQL. The way you have composed your query, it would be evaluated for every row.
A simple example to show this:
SQL> create or replace function vv (p_in varchar2) return varchar2
2 is
3 begin
4 dbms_output.put_line('vv was called');
5 return p_in;
6 end;
7 /
Function created.
SQL> set serveroutput on size 100000
SQL> select count(*) from emp where ename = vv('KING')
2 /
COUNT(*)
1
vv was called
vv was called
vv was called
vv was called
vv was called
vv was called
vv was called
vv was called
vv was called
vv was called
vv was called
vv was called
vv was called
vv was called
SQL>
SQL> select count(*) from emp where ename = (select vv('KING') from dual)
2 /
COUNT(*)
1
vv was called
SQL>
Note the last query, how you can specify this without causing it to be evaluated for every row.
Joel -
Using 'Function Returning SQL Query' with Flash charts
I have created a pl/sql function that returns a SQL query as a varchar2 of this form:
select null link
<x value> value
<Series1 y value> Series 1 Label
<Series2 y value> Series 2 Label
<Series3 y value> Series 3 Label
from tablea a
join tableb b
on a.col = b.col
order by <x value>
If I now call the function from a Flash Chart Series SQL box with the Query Source Type set to 'Function Returning SQL Query' like this:
return functionname(to_date('30-sep-2010', 'dd-mon-yyyy'))
it parses correctly and the page is saved; however, when I run the page I don't get any output - nor any error messages or other indication of a problem.
Now, if I call the function in a SQL client, capture the SQL query output using dbms_output and paste that into the Flash Chart Series SQL box - changing the Query Source Type to SQL Query - and save the page it works fine when I run it and returns a multi-series flash chart.
Can anyone suggest either;
1. What have I might have missed or done wrong?
2. Any way to usefully diagnose the problem...
I have tried using the Apex debugger - which is very nice, by the way - but it doesn't provide any info on what my problem might be. I even tried writing my own debug messages from my function using the apex_debug_message package - got nothing...
Thanks,
EricHi Eric,
Try expressing the source as this:
begin
return functionname(to_date('30-sep-2010', 'dd-mon-yyyy'));
end;That works fine for me, and if I take out the begin-end and the trailing semicolon from the return statement I get the same behavior as you.
It does mention in the help for the source (only during the wizard though) that this source type has to be expressed that way, but I agree it would be helpful if the tool would validate for this format when 'Function Returning SQL Query' is used or give some sort of indication of the trouble. Anyway, this should get you going again.
Hope this helps,
John
If you find this information useful, please remember to mark the post "helpful" or "correct" so that others may benefit as well. -
Using package functions in an update
Okay, I have a package function that returns a correct value when used in a SELECT, but when used in an UPDATE, it returns Null. Why can't I used its result in the UPDATE?
Package Spec
FUNCTION fpub_get_contract_attribute
( n_contract_id_in IN CONTRACT.CONTRACT_ID%TYPE,
s_attribute_in IN VARCHAR2 )
RETURN VARCHAR2;
PRAGMA RESTRICT_REFERENCES(fpub_get_contract_attribute,TRUST,WNDS);
Source :
clear;
rollback;
select
contract_functions.fpub_get_contract_attribute(CONTRACT_ID,'ORIGINAL_SALES_CHANNEL') "Before",
original_sales_channel
from contract
where contract_id = 52549615;
update contract
set original_sales_channel = NVL(contract_functions.fpub_get_contract_attribute(CONTRACT_ID,'ORIGINAL_SALES_CHANNEL'),'Null')
where contract_id = 52549615;
select
NVL(contract_functions.fpub_get_contract_attribute(52549615,'ORIGINAL_SALES_CHANNEL'),'Null') "After",
original_sales_channel
from contract
where contract_id = 52549615;
rollback;
Result :
Rollback complete
Before ORIGINAL_SALES_CHANNEL
RE
1 row updated
After ORIGINAL_SALES_CHANNEL
Null Null
Rollback completeAny ideas?
Thanks,
JasonPragma restrict_references has not been required since 8i, so you can get rid of that. However, certain things will still be enforced, with or without the pragma. For example, you cannot perform DML from within a packaged function when that function is used in a select statement, although you can perform DML within a packaged function when it is used in an update statement. So, if you are performing some sort of DML in your function, it would not raise an error when used in the update statement, but would cause it to return whatever is specified in the exception block when used in a select statement, causing the different results.
Please see the demonstration below in which I have created a sample function that contains an insert statement. When I use the function from a select statement, it raises an error and does not insert a row. However, when I use the function in an update statement, it does not raise an error and inserts a row. I have then added an exception clause to the function and re-tested. When I used the function in a select statement, it now returns the value in the exception block, but still does not insert a row. When I used the function in an update statement, it returns a different value, not from the exception block, and inserts a row. Then I removed the insert statement from the function and re-tested. Now it returns the same value, whether used in a select statement or an update statement.
scott@ORA92> SELECT banner FROM v$version
2 /
BANNER
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
PL/SQL Release 9.2.0.1.0 - Production
CORE 9.2.0.1.0 Production
TNS for 32-bit Windows: Version 9.2.0.1.0 - Production
NLSRTL Version 9.2.0.1.0 - Production
scott@ORA92> CREATE TABLE test
2 (col1 VARCHAR2(30))
3 /
Table created.
scott@ORA92> CREATE TABLE contract
2 (contract_id NUMBER,
3 original_sales_channel VARCHAR2(30))
4 /
Table created.
scott@ORA92> INSERT INTO contract (contract_id) VALUES (52549615)
2 /
1 row created.
scott@ORA92> COMMIT
2 /
Commit complete.
scott@ORA92> CREATE OR REPLACE PACKAGE contract_functions
2 AS
3 FUNCTION fpub_get_contract_attribute
4 (n_contract_id_in IN CONTRACT.CONTRACT_ID%TYPE,
5 s_attribute_in IN VARCHAR2 )
6 RETURN VARCHAR2;
7 END contract_functions;
8 /
Package created.
scott@ORA92> SHOW ERRORS
No errors.
scott@ORA92> -- test with insert statement and no exception handling:
scott@ORA92> CREATE OR REPLACE PACKAGE BODY contract_functions
2 AS
3 FUNCTION fpub_get_contract_attribute
4 (n_contract_id_in IN CONTRACT.CONTRACT_ID%TYPE,
5 s_attribute_in IN VARCHAR2 )
6 RETURN VARCHAR2
7 IS
8 BEGIN
9 INSERT INTO test (col1) VALUES ('inserting');
10 RETURN 'Null';
11 END fpub_get_contract_attribute;
12 END contract_functions;
13 /
Package body created.
scott@ORA92> SHOW ERRORS
No errors.
scott@ORA92> SELECT * FROM contract
2 /
CONTRACT_ID ORIGINAL_SALES_CHANNEL
52549615
scott@ORA92> COLUMN "Before" FORMAT A30
scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "Before",
2 original_sales_channel
3 from contract
4 where contract_id = 52549615
5 /
select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "Before",
ERROR at line 1:
ORA-14551: cannot perform a DML operation inside a query
ORA-06512: at "SCOTT.CONTRACT_FUNCTIONS", line 9
scott@ORA92> SELECT * FROM test
2 /
no rows selected
scott@ORA92> update contract
2 set original_sales_channel = NVL (contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL'), 'Null')
3 where contract_id = 52549615
4 /
1 row updated.
scott@ORA92> SELECT * FROM test
2 /
COL1
inserting
scott@ORA92> COLUMN "After" FORMAT A30
scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "After",
2 original_sales_channel
3 from contract
4 where contract_id = 52549615
5 /
select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "After",
ERROR at line 1:
ORA-14551: cannot perform a DML operation inside a query
ORA-06512: at "SCOTT.CONTRACT_FUNCTIONS", line 9
scott@ORA92> SELECT * FROM test
2 /
COL1
inserting
scott@ORA92> --
scott@ORA92> -- repeat test with insert statement and exception handling:
scott@ORA92> ROLLBACK
2 /
Rollback complete.
scott@ORA92> CREATE OR REPLACE PACKAGE BODY contract_functions
2 AS
3 FUNCTION fpub_get_contract_attribute
4 (n_contract_id_in IN CONTRACT.CONTRACT_ID%TYPE,
5 s_attribute_in IN VARCHAR2 )
6 RETURN VARCHAR2
7 IS
8 BEGIN
9 INSERT INTO test (col1) VALUES ('inserting');
10 RETURN 'Null';
11 EXCEPTION
12 WHEN OTHERS THEN RETURN 'RE';
13 END fpub_get_contract_attribute;
14 END contract_functions;
15 /
Package body created.
scott@ORA92> SHOW ERRORS
No errors.
scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "Before",
2 original_sales_channel
3 from contract
4 where contract_id = 52549615
5 /
Before ORIGINAL_SALES_CHANNEL
RE
scott@ORA92> SELECT * FROM test
2 /
no rows selected
scott@ORA92> update contract
2 set original_sales_channel = NVL (contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL'), 'Null')
3 where contract_id = 52549615
4 /
1 row updated.
scott@ORA92> SELECT * FROM test
2 /
COL1
inserting
scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "After",
2 original_sales_channel
3 from contract
4 where contract_id = 52549615
5 /
After ORIGINAL_SALES_CHANNEL
RE Null
scott@ORA92> SELECT * FROM test
2 /
COL1
inserting
scott@ORA92> --
scott@ORA92> -- repeat test with no insert statement and no exception handling:
scott@ORA92> ROLLBACK
2 /
Rollback complete.
scott@ORA92> CREATE OR REPLACE PACKAGE BODY contract_functions
2 AS
3 FUNCTION fpub_get_contract_attribute
4 (n_contract_id_in IN CONTRACT.CONTRACT_ID%TYPE,
5 s_attribute_in IN VARCHAR2 )
6 RETURN VARCHAR2
7 IS
8 BEGIN
9 RETURN 'Null';
10 END fpub_get_contract_attribute;
11 END contract_functions;
12 /
Package body created.
scott@ORA92> SHOW ERRORS
No errors.
scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "Before",
2 original_sales_channel
3 from contract
4 where contract_id = 52549615
5 /
Before ORIGINAL_SALES_CHANNEL
Null
scott@ORA92> SELECT * FROM test
2 /
no rows selected
scott@ORA92> update contract
2 set original_sales_channel = NVL (contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL'), 'Null')
3 where contract_id = 52549615
4 /
1 row updated.
scott@ORA92> SELECT * FROM test
2 /
no rows selected
scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "After",
2 original_sales_channel
3 from contract
4 where contract_id = 52549615
5 /
After ORIGINAL_SALES_CHANNEL
Null Null
scott@ORA92> SELECT * FROM test
2 /
no rows selected
scott@ORA92> -
How to check if column_ name is used by any procedure ,package ,function
Hello
Help Is greatly appreciated .
Kindly please let me know for the folllwoing:
How to check if column_ name is used by any procedure ,package ,function ,trigger or in any dataabse objects>
How to check if column_ name is used by any procedure ,package ,function ,trigger or in any dataabse objects
>
In general you can't. Code can always exist outside the database and it is always possible that you have dynamic code and there is no way to find references like that if used by dynamic code. That dynamic code reference could be based on a query stored in a table.
And there is no way of knowing if external code (e.g. a Java app) references that column.
Another issue is that a column could exist in multiple schemas and in multiple objects of different types in those schemas. So a global DB search for 'MY_COLUMN' might turn up references in multiple schemas and you may only care about one schema.
Unfortunately a reference to 'MY_COLUMN' in code could refer to many different objects or to an object in different schemas so how would you resolve those? Especially if you take synonyms into account which can ponit about anywhere.
Why don't you tell us what it is you are really trying to do?
Are you trying to find the references to a particular column? Why? Are you planning on removing/renaming the column? If so then the simplest way is to remove/rename the column and see what objects become invalid. Those invalid objects will have become invalid because that column is no longer available.
As suggested you can use DBA_SOURCE for references in code that use the standard names. But for tables/views you need to use all_tab_columns. And for dynamic code or client code (e.g. a Java application) there is no way. -
Problem using DECODE() function with a Query of Queries
I
posted
on my blog about an issue I was having trying to use the PL/SQL
DECODE() function with a Coldfusion Query of Queries. This function
works fine when you query a database for information. However, when
you query another query, it seems that CF doesn't recognize it. I
got errors stating that it found a left parenthesis where it
expected a FROM key word. Here is a simplified version of what I am
trying to do:
quote:
<!--- Simulated query; similar to what I was calling from
my database --->
<cfscript>
qOriginal = queryNew("Name,Email,CountryCode",
"VarChar,VarChar,VarChar");
newRow = queryAddRow(qOriginal, 5);
querySetCell(qOriginal, "Name", "Joe", 1);
querySetCell(qOriginal, "Email", "[email protected]", 1);
querySetCell(qOriginal, "CountryCode", "AMER", 1);
querySetCell(qOriginal, "Name", "Sally", 2);
querySetCell(qOriginal, "Email", "[email protected]", 2);
querySetCell(qOriginal, "CountryCode", "AMER", 2);
querySetCell(qOriginal, "Name", "Bob", 3);
querySetCell(qOriginal, "Email", "[email protected]", 3);
querySetCell(qOriginal, "CountryCode", "ASIA", 3);
querySetCell(qOriginal, "Name", "Mary", 4);
querySetCell(qOriginal, "Email", "[email protected]", 4);
querySetCell(qOriginal, "CountryCode", "EURO", 4);
querySetCell(qOriginal, "Name", "John", 5);
querySetCell(qOriginal, "Email", "[email protected]", 5);
querySetCell(qOriginal, "CountryCode", "EURO", 5);
</cfscript>
<cfquery name="qCountries" dbtype="query">
SELECT DISTINCT(CountryCode) AS CountryCode,
DECODE(states, "AMER", "North America & Canada",
"EURO", "Europe & Africa", "ASIA", "Japan &
Asia","") CountryName
FROM qOriginal
ORDER BY CountryCode
</cfquery>
<cfdump var="#qCountries#">
<!--- ========== END OF CODE ========== --->
So running this returned the following error:
Query Of Queries syntax error.
Encountered "(. Incorrect Select Statement, Expecting a
'FROM', but encountered '(' instead, A select statement should have
a 'FROM' construct.
Does anybody know why this doesn't work? Is it just not
supported? Please note that I have also tried to use the CASE()
function instead of DECODE() and that resulted in basically the
same error. For now I an looping over my distinct query with a
switch statement and manually loading a new query with the data how
I want it. But it would be a lot cleaner and less code to have the
DECODE() to work. Thx!DECODE() is an Oracle function, not generic SQL. Q-of-Q is a
very limited subset of SQL and lacks many functions and clauses
available in standard SQL, especially what you may be used to using
in your particular RDBMS.
See
Query
of Queries user guide
Phil -
How to use the Table Function defined in package in OWB?
Hi,
I defined a table function in a package. I am trying to use that in owb using Table function operator. But I came to know that, owb R1 supports only standalone table functions.
Is there any other way to use the table function defined in a package. As like we create synonyms for functions, is there any other way to do this.
I tryed to create synonyms, it is created. But it is showing compilation error. Finally I found that, we can't create synonyms for functions which are defined in packages.
Any one can explain it, how to resolve this problem.
Thank you,
Regards
Gowtham Sen.Hi Marcos,
Thank you for reply.
OWB R1 supports stand alone table functions. Here what I mean is, the table fucntion which is not inculded in any package is a stand alone table function.
for example say sample_tbl_fn is a table function. It is defined as a function.It is a stand alone function. We call this fucntion as "samp_tbl_fn()";
For exampe say sample_pkg is a package. say a function is defined in a package.
then we call that function as sample_pkg.functionname(); This is not a stand alone function.
I hope you understand it.
owb supports stand alone functions.
Here I would like to know, is there any other way to use the functions which are defined in package. While I am trying to use those functions (which are defined in package -- giving the name as packagename.functionname) it is throwing an error "Invalid object name."
Here I would like know, is there any other way to use the table functions which are defined in a package.
Thank you,
Regards,
Gowtham Sen. -
Dataset query issues twice if the dataset is connected to matrix and used in multilookup function
hello everybody.
could not find any information if this is an intended behavior:
dataset query issues twice if the dataset is connected to matrix and used in multilookup function
parameters in both queries are the same
ssrs: 2008 r2, sharepoint 2010 integrated
sharepoint 2010: september 2014 cu
thanks in advance
Sergey VdovinHello, Wendy.
I prepared a very empty sample report for you to demonstrate the problem - with this report, i hope, there is no place to discuss the shrinking of time data retrieval.
There is one dataset, one parameter and one lookup function. The query is executed twice.
<?xml version="1.0" encoding="utf-8"?>
<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:cl="http://schemas.microsoft.com/sqlserver/reporting/2010/01/componentdefinition" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition">
<AutoRefresh>0</AutoRefresh>
<DataSources>
<DataSource Name="DataSource1">
<DataSourceReference>http://t005/ProjectBICenter/DocLib/IntegrationDBVdovin.rsds</DataSourceReference>
<rd:SecurityType>None</rd:SecurityType>
<rd:DataSourceID>7e554344-d6c2-48a5-a7f4-1d24608cb4b5</rd:DataSourceID>
</DataSource>
</DataSources>
<DataSets>
<DataSet Name="DataSet1">
<Query>
<DataSourceName>DataSource1</DataSourceName>
<CommandText>select 1 as temp, '$' as tempname</CommandText>
<rd:UseGenericDesigner>true</rd:UseGenericDesigner>
</Query>
<Fields>
<Field Name="temp">
<DataField>temp</DataField>
<rd:TypeName>System.Int32</rd:TypeName>
</Field>
<Field Name="tempname">
<DataField>tempname</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
</Fields>
</DataSet>
</DataSets>
<ReportSections>
<ReportSection>
<Body>
<ReportItems>
<Textbox Name="ReportTitle">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Lookup(1,Fields!temp.Value,Fields!tempname.Value,"DataSet1")</Value>
<Style>
<FontFamily>Verdana</FontFamily>
<FontSize>20pt</FontSize>
</Style>
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:WatermarkTextbox>Title</rd:WatermarkTextbox>
<rd:DefaultName>ReportTitle</rd:DefaultName>
<Top>0mm</Top>
<Height>10.16mm</Height>
<Width>139.7mm</Width>
<Style>
<Border>
<Style>None</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</ReportItems>
<Height>57.15mm</Height>
<Style>
<Border>
<Style>None</Style>
</Border>
</Style>
</Body>
<Width>152.4mm</Width>
<Page>
<PageFooter>
<Height>11.43mm</Height>
<PrintOnFirstPage>true</PrintOnFirstPage>
<PrintOnLastPage>true</PrintOnLastPage>
<Style>
<Border>
<Style>None</Style>
</Border>
</Style>
</PageFooter>
<PageHeight>29.7cm</PageHeight>
<PageWidth>21cm</PageWidth>
<LeftMargin>2cm</LeftMargin>
<RightMargin>2cm</RightMargin>
<TopMargin>2cm</TopMargin>
<BottomMargin>2cm</BottomMargin>
<ColumnSpacing>0.13cm</ColumnSpacing>
<Style />
</Page>
</ReportSection>
</ReportSections>
<ReportParameters>
<ReportParameter Name="ReportParameter1">
<DataType>String</DataType>
<DefaultValue>
<Values>
<Value>1</Value>
</Values>
</DefaultValue>
<Prompt>ReportParameter1</Prompt>
<ValidValues>
<DataSetReference>
<DataSetName>DataSet1</DataSetName>
<ValueField>temp</ValueField>
<LabelField>tempname</LabelField>
</DataSetReference>
</ValidValues>
</ReportParameter>
</ReportParameters>
<rd:ReportUnitType>Mm</rd:ReportUnitType>
<rd:ReportServerUrl>http://t005/ProjectBICenter</rd:ReportServerUrl>
<rd:ReportID>cd1262ef-eca7-4739-a2ce-d3ca832d5cd6</rd:ReportID>
</Report>
Sergey Vdovin
Maybe you are looking for
-
Install Windows 7 natively on 2nd MacMini drive?
I have a 2 drive MacMini SL server which is running plain ol' SL. I want to install Windows on the second drive and not through bootcamp. Can I just go into Disk Utility, erase and reformat the 2nd drive at MS-DOS, and then copy all my files that w
-
Sir l am using a nokia lumia 520. i bought it new ,my problem is that when i try to download music from nokia store it says that u r already. Subscribed to nokia music unlimited .it only plays the music but don't download it.... Please. Help me. In t
-
HT204406 itunes match in itunes 11 gets error 4002
While attempting to upload my library for the first time to Apple Cloud using iTunes (v11) match from Win 7 PC, I get an error 4002 after looking at the screen for about 20 minutes stating: Step 1: iTunes Match Sending your information to Apple.....
-
Process chains resolution....
my process chain got stuck ,using my proces chain i found technical name for my info source and using this i found data source and inside data source i found info package for that particular infosource.. In RSA1 >in that datasource rightclick>manage
-
Photoshop Elements 6 Effects Missing
My mom is an art teacher and uses an iMac at work. She recently purchases Photoshop Elements 6 and installed in on her MacBook and iMac. No problems with the installation on her MacBook 2,1 but the Effects seem to be missing from the iMac. These are