Function to return in case of non matching records
Hi
CREATE TABLE [dbo].[DeptMaster](
[DeptId] [int] NULL,
[DeptName] [nvarchar](50) NULL
) ON [PRIMARY]
Insert into DeptMaster values
(1,'HeadOffice'),
(2,'BranchOffice'),
(3,'')
CREATE FUNCTION [dbo].[GetDepartmentId]
@DepartmentNameIn nvarchar(128)
RETURNS int
AS
BEGIN
DECLARE @DepartmentId INT
SELECT @DepartmentId = [DeptId] from DeptMaster where LTRIM(RTRIM([DeptName])) = @DepartmentNameIn
If @DepartmentId <0
BEGIN
SELECT @DepartmentId = [DeptId] from DeptMaster where LTRIM(RTRIM([DeptName])) = ''
END
RETURN @DepartmentId
END
select dbo.GetDepartmentId ('BranchOffice') -- will return 2, correct
select dbo.GetDepartmentId ('DivisonalOffice') --- expected 3 ... need to alter my Function so that 3 is returned.
select dbo.GetDepartmentId ('SubOffice') --- expected 3 ... need to alter my Function so that 3 is returned.
-- Reason, Whenever i get data which is not passed, i need to return the 3
kindly suggest how to pass into the If @DepartmentId <0
as i get 0 records if no data is found matching
ShanmugaRaj
ALTER FUNCTION [dbo].[GetDepartmentId]
@DepartmentNameIn nvarchar(128)
RETURNS int
AS
BEGIN
DECLARE @DepartmentId INT ,@flag int
SELECT @DepartmentId = [DeptId] from DeptMaster where LTRIM(RTRIM([DeptName])) = @DepartmentNameIn
If @@ROWCOUNT != 0
BEGIN
set @flag=1
END
ELSE
BEGIN
set @flag=0
END
if (@flag = 0)
begin
set @DepartmentId=3
end
RETURN @DepartmentId;
END
Similar Messages
-
Problem with non-matching records
I have 3 tables - TBL1 is a list of Conditions; TBL2 contains collected data; and TBL3 contains referenced details on the data in TBL2.
TBL2 contains some matching values from TBL1.
Ex.
TBL1
Condition
01 Test A
02 Test B
03 Test C
TBL2
Name, Condition, Value
Host101, 01 Test A, Yes
Host101, 02 Test B, No
Host101, 03 Test C, Yes
Host102, 01 Test A, No
Host102, 03 Test C, Yes
I have them linked TBL1 Left Outer to TBL2 and TBL2 Left Outer to TBL3.
My desire is to get the complete list of Conditions in TBL1 for each record in TBL2, even where there is no matching TBL1 value in TBL2 - so the report results of the above table data would be:
Host101
01 Test A Yes
02 Test B No
03 Test C Yes
Host102
01 Test A No
02 Test B
03 Test C Yes
So even though there is no data returned in TBL2 for Host102, 02 Test B, the record for that entry in TBL1 is still returned in the report.
Currently I have the report structured as follows -
{TBL2 Name}
TBL1 Condition TBL2 Value
Seems quite simple, but I must be missing something somewhere, as I am only able to get the data where the records match, so, in the example above, I am getting only -
Host102
01 Test A No
03 Test C Yes
Any assistance would be much appreciated. Thanks!
Also, I tried doing a simple new report using just TBL1 & TBL2 and still get the same results (also tried a Full Outer join as well).
Frustrating .......
Edited by: Dragon77 on May 17, 2010 2:05 PMAs I said, I have even tried removing TBL3 to make things even simpler - TBL1 & TBL2 Left Outer joined on the common field.
I have tried every combination that I can think of. We're talking on 4 fields in the report -
Group Header 1 = {TBL2 Name}
Group 2 = {TBL2 Unique Field}
Detail = TBL1 Condition TBL2 Value
Group Header 1 = {TBL2 Name}
Group 2 = {TBL2 Unique Field}
Group 3 = {TBL1 Condition} {TBL2 Value}
Detail Suppressed
No matter what I try, I only get matching records.
I've gone so far as to just have the minimal 3 fields
Group Header 1 = {TBL2 Name}
Group 2 = {TBL2 Unique Field}
Detail = TBL1 Condition
Group Header 1 = {TBL2 Name}
Group 2 = {TBL2 Unique Field}
Group 3 = {TBL1 Condition}
Detail Suppressed
The tables only have the 1 field in comon {TBL1, TBL2 - Condition)
This just doesn't make sense. {TBL1 Condition} should have ALL of its entries returned along with any matching records from {TBL2 Condition} - not just where they are equal. -
version 10.2.0.2
Create table A (f1 varachar2(10),f2 varachar2(10),f3 varachar2(10),f4 varachar2(10),update_date sysdate)
Create table A (f1 varachar2(10),f2 varachar2(10),f3 varachar2(10),f4 varachar2(10),sp_key vrachar2(2),update_date sysdate)
insert into a values ('a123','fdds','sas','sdss',sysdate)
insert into a values ('a124','fdsds','fsas','sds',sysdate)
insert into a values ('a125','pqx','dll','com',sysdate)
insert into b values ('a124','fdsds','fsas','sds','C',sysdate)
output table
Create table A_out (f1 varachar2(10),f2 varachar2(10),f3 varachar2(10),f4 varachar2(10),update_date sysdate)
output set :
a123,fdds,sas,sdss,sysdate
a125,pqx,dll,com,sysdate
please note joininh will be done on f1...so so i need to select the non matching receords only present in table a.Hi,
Also, test (and, if necessary, correct your CREATE TABLE and INSERT statemnets before you post them.
1003545 wrote:
Create table A (f1 varachar2(10),f2 varachar2(10),f3 varachar2(10),f4 varachar2(10),update_date sysdate)Maybe you meant to use the data types VARCHAR2 and DATE.
... please note joininh will be done on f1...so so i need to select the non matching receords only present in table a.If you're going to use a join (and a join is one good way to solve this problem) make it an OUTER join. -
UPDATE statement converting non matching records to null
Hi
I am trying to update a table that contains the columns partnerkey, timekey and is_current. At present the is_current field is set to 'N' for all records. I want to update this to 'Y' where the timekey is most recent, and leave the others as 'N'.
I wrote the following update statement:
UPDATE d_partner_all_time d
SET d.is_current =
(SELECT 'Y'
FROM (select partnerkey, max(timekey) timekey from d_partner_all_time group by partnerkey) pl
WHERE d.partnerkey = pl.partnerkey
AND d.timekey = pl.timekey
While this did update all the latest timekey records to have an is_current value of 'Y', all the other values that were previously 'N' have now been changed to null.
Can anyone explain why this is and what i should change to prevent it?
ThanksSQL> CREATE TABLE D_PARTNER_ALL_TIME
2 (
3 IS_CURRENT CHAR(1),
4 PARTNERKEY NUMBER,
5 TIMEKEY DATE
6 );
Table created.
SQL> INSERT INTO D_PARTNER_ALL_TIME VALUES ('N',1,TO_DATE('01/01/2009','DD/MM/YYYY'));
1 row created.
SQL> INSERT INTO D_PARTNER_ALL_TIME VALUES ('N',1,TO_DATE('02/01/2009','DD/MM/YYYY'));
1 row created.
SQL> INSERT INTO D_PARTNER_ALL_TIME VALUES ('N',1,TO_DATE('03/01/2009','DD/MM/YYYY'));
1 row created.
SQL> INSERT INTO D_PARTNER_ALL_TIME VALUES ('N',2,TO_DATE('01/01/2009','DD/MM/YYYY'));
1 row created.
SQL> INSERT INTO D_PARTNER_ALL_TIME VALUES ('N',2,TO_DATE('02/01/2009','DD/MM/YYYY'));
1 row created.
SQL> INSERT INTO D_PARTNER_ALL_TIME VALUES ('N',3,TO_DATE('03/01/2009','DD/MM/YYYY'));
1 row created.
SQL> commit;
Commit complete.
SQL> select * from D_PARTNER_ALL_TIME;
I PARTNERKEY TIMEKEY
N 1 01-JAN-09
N 1 02-JAN-09
N 1 03-JAN-09
N 2 01-JAN-09
N 2 02-JAN-09
N 3 03-JAN-09
6 rows selected.
SQL> UPDATE
2 D_PARTNER_ALL_TIME D
3 SET IS_CURRENT = 'Y'
4 WHERE
5 TIMEKEY =
6 (SELECT MAX(TIMEKEY) FROM D_PARTNER_ALL_TIME A
7 WHERE
8 A.PARTNERKEY = D.PARTNERKEY
9 GROUP BY PARTNERKEY);
3 rows updated.
SQL> select * from D_PARTNER_ALL_TIME;
I PARTNERKEY TIMEKEY
N 1 01-JAN-09
N 1 02-JAN-09
Y 1 03-JAN-09
N 2 01-JAN-09
Y 2 02-JAN-09
Y 3 03-JAN-09
6 rows selected. -
Function not returning database rows properly in non-database item
Hi,
I have 3 database items that I'd like to concatenate into one field and display it in a non-database item. I have setup two different methods to do this for testing purposes. First, I created three separate database items (SECTION, ROW, & SEAT_NUM) and a non-database item (SEAT). I created a formula (in SEAT) to do the concatenation and this way works fine. For my second method, I created a function where I selected the 3 fields and performed a concatenation into a single value to be returned in a seperate non-database item (SEAT_TEST).
Here's my function:
FUNCTION SeatLocation(p_id IN event.id%TYPE)
RETURN VARCHAR2 IS
CURSOR a IS
(SELECT ltrim(rtrim(event.section,' '),' ')||' '||
ltrim(rtrim(event.row,' '),' ')||' '||
ltrim(rtrim(event.seat_num,' '),' ') seat
FROM event
WHERE event.id = p_id);
BEGIN
FOR rec IN a LOOP
IF rec.seat IS NOT NULL THEN
RETURN rec.seat;
ELSE
RETURN ' ';
END IF;
END LOOP;
END SeatLocation;
And I'm calling it in a POST_QUERY trigger with the following: :event.seat_test := SeatLocation(:event.id);
I put both non-database items side-by-side, run the form, and the first method works fine. I doesn't quite work for the function to display in SEAT_TEST. For my program, an ID can have multiple seat locations and I'd like to display all those seats as I scroll through the form (for a given ID). What the function is returning is only the first records seat location even though there are two more locations (from the remaining two records) that need to be displayed, but are not. It works fine for the formula method. Is there a work around this within my function code and/or the SEAT_TEST item? I'd like to keep my function instead because I could use the code elsewhere. I thought that since there is more than one record retrieved for a particular ID, the for loop would return one value each loop iteration and display the different value seat locations as I scroll/arrow down through the form. I didn't know if you had to call the POST-QUERY trigger multiple times for the number or records you retrieve in the cursor. I hope this makes sense.
Any advice would be greatly appreciated.
Thank you,
EricEven though your function is written to loop through multiple records, as soon as it hits the first one inside the FOR loop, it returns that value. The Return command is an exit, so the function is done, and you cannot expect it to magically run a second time just because the cursor found more than one row.
You need to pass the function all the parameters to form a unique key into the row you are looking up. ID is not unique. -
Multiple Select List looping thru PL/SQL function body returning SQL query
Hi,
I have a Multiple Select List. I want to loop through the values from the Select List and process them in a PL/SQL function body returning a SQL query. Currently, my code only returns the SQL SELECT results of one item in the select list. How do I change my code to make it return the results of all of the items in the select list? (I tested it and it is definitely picking up all the values in the select list).
<b>
DECLARE
selected_items HTMLDB_APPLICATION_GLOBAL.VC_ARR2;
s VARCHAR2(20);
q varchar2(32767);
BEGIN
selected_items := HTMLDB_UTIL.STRING_TO_TABLE(:P50_SELECTED_INSTRUMENTS);
-- htp.p('COUNT: '||selected_items.count);
FOR i in 1..selected_items.count LOOP
s := TO_CHAR(selected_items(i));
-- htp.p('First: '||s);
-- htp.p('Second: '||:s);
-- htp.p('Third: '||TO_CHAR(selected_items(i)));
q:= 'SELECT '||
'SUBSTR(orig_geo_loc_sys,1,INSTR(orig_geo_loc_sys,''-'')-1) AS INSTRUMENT, '||
'SUBSTR(orig_geo_loc_sys,INSTR(orig_geo_loc_sys,''-'')+1, LENGTH'||
' (orig_geo_loc_sys)) AS ORIG_LINENUM, '||
'sum(orig_intrl) orig_intrl, '||
'sum(orig_extrl) orig_extrl, '||
'sum(recv_intrl) recv_intrl, '||
'sum(recv_extrl) recv_extrl '||
'FROM line_usage_sum_view '||
'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''' || s ||'%'' '||
--'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''2213003%'' '||
'AND switch_id = ''' || :P1_SWITCH_ID || ''' ' ||
'AND call_start_date > TO_DATE(''30-NOV-1999'') ' ||
'AND call_clear_time > TO_DATE(''30-NOV-1999'') '||
'AND '||
:SORTFIELD||' BETWEEN '||
'TO_DATE(:STARTDATE,''dd-MON-YYYY HH24:MI'') AND '||
'TO_DATE(:STOPDATE, ''dd-MON-YYYY HH24:MI'') '||
'GROUP BY GROUPING SETS (orig_geo_loc_sys)';
-- htp.p('SQL query: '||q);
RETURN q;
END LOOP;
END;</b>
Thank you,
LauraLaura,
First, I would be careful of introducing SQL Injection possibilities. Any time I see
'Select ... ' || :P123_FOO || ' ... '
I worry about sql injection. In your case you are converting :P50_SELECTED_INSTRUMENTS into selected_items and then selected_items into s. So when I see
'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''' || s ||'%'' '||
I think, "I could use sql Injection and hack this."
So, I would do some validation on :P50_SELECTED_INSTRUMENTS or some other method to avoid this.
I'm not certain I understand your query. Do you really intend to allow the user to select the beginning of a string and then find all rows that start with that string? Or, do you just want to let them find when it matches the string. This is one way if you want to do matching:
DECLARE
selected_items HTMLDB_APPLICATION_GLOBAL.VC_ARR2;
s VARCHAR2(32767);
q varchar2(32767);
BEGIN
-- Change the : separate string to be comma separated with quoted strings
s := '''' || replace(:P50_SELECTED_INSTRUMENTS, ',', ''',''')|| '''' ;
-- htp.p('COUNT: '||selected_items.count);
q:= 'SELECT '||
'SUBSTR(orig_geo_loc_sys,1,INSTR(orig_geo_loc_sys,''-'')-1) AS INSTRUMENT, '||
'SUBSTR(orig_geo_loc_sys,INSTR(orig_geo_loc_sys,''-'')+1, LENGTH'||
' (orig_geo_loc_sys)) AS ORIG_LINENUM, '||
'sum(orig_intrl) orig_intrl, '||
'sum(orig_extrl) orig_extrl, '||
'sum(recv_intrl) recv_intrl, '||
'sum(recv_extrl) recv_extrl '||
'FROM line_usage_sum_view '||
'WHERE TO_CHAR(orig_geo_loc_sys) in (' || s ||' ) '||
--'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''2213003%'' '||
'AND switch_id = ''' || :P1_SWITCH_ID || ''' ' ||
'AND call_start_date > TO_DATE(''30-NOV-1999'') ' ||
'AND call_clear_time > TO_DATE(''30-NOV-1999'') '||
'AND '||
:SORTFIELD||' BETWEEN '||
'TO_DATE(:STARTDATE,''dd-MON-YYYY HH24:MI'') AND '||
'TO_DATE(:STOPDATE, ''dd-MON-YYYY HH24:MI'') '||
'GROUP BY GROUPING SETS (orig_geo_loc_sys)';
-- htp.p('SQL query: '||q);
RETURN q;
END;
If you want to do something more like you originally stated, try this:
DECLARE
selected_items HTMLDB_APPLICATION_GLOBAL.VC_ARR2;
s VARCHAR2(20);
q varchar2(32767);
BEGIN
selected_items := HTMLDB_UTIL.STRING_TO_TABLE(:P50_SELECTED_INSTRUMENTS);
-- htp.p('COUNT: '||selected_items.count);
q:= 'SELECT '||
'SUBSTR(orig_geo_loc_sys,1,INSTR(orig_geo_loc_sys,''-'')-1) AS INSTRUMENT, '||
'SUBSTR(orig_geo_loc_sys,INSTR(orig_geo_loc_sys,''-'')+1, LENGTH'||
' (orig_geo_loc_sys)) AS ORIG_LINENUM, '||
'sum(orig_intrl) orig_intrl, '||
'sum(orig_extrl) orig_extrl, '||
'sum(recv_intrl) recv_intrl, '||
'sum(recv_extrl) recv_extrl '||
'FROM line_usage_sum_view '||
'WHERE 1=1 ';
FOR i in 1..selected_items.count LOOP
s := TO_CHAR(selected_items(i));
q := q || ' and TO_CHAR(orig_geo_loc_sys) LIKE '''|| s ||'%'' ' ;
END LOOP;
q := q || ||'%'' '||
--'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''2213003%'' '||
'AND switch_id = ''' || :P1_SWITCH_ID || ''' ' ||
'AND call_start_date > TO_DATE(''30-NOV-1999'') ' ||
'AND call_clear_time > TO_DATE(''30-NOV-1999'') '||
'AND '||
:SORTFIELD||' BETWEEN '||
'TO_DATE(:STARTDATE,''dd-MON-YYYY HH24:MI'') AND '||
'TO_DATE(:STOPDATE, ''dd-MON-YYYY HH24:MI'') '||
'GROUP BY GROUPING SETS (orig_geo_loc_sys)';
-- htp.p('SQL query: '||q);
RETURN q;
END;
Hope this helps...
Anton -
PLSQL function body returning an sql report returns ORA-01403 No Data Found
I am on APEX 3.1.2.00.02 and Oracle 10g.
I am developing a report with SQL Query (PL/SQL function body returning SQL query) type. But on running the report I am getting
report error:
ORA-01403: no data found
Region Source
declare
qry varchar2(32767);
begin
--Procedure call
my_pkg.get_query(qry);
htp.p(qry);
return /*select 1 from dual */ qry;
end;
Procedure
PROCEDURE get_query (V_QRY OUT VARCHAR2)
IS
qry varchar2(32767);
begin
qry := ' select name
, max(decode(to_char(service_date,''Mon-YY''), ''Jan-09'', value, null)) as "Jan-09"
, max(decode(to_char(service_date,''Mon-YY''), ''Jan-09'', value, null)) as "Feb-09"
from MY_TABLE
group by name ';
V_QRY := qry;
end;
The query will be enhanced later to add more months and year based on user parameters once I am successfull in running report on this.
I wish to use Query Specific Column names. I have seen this suggestion from Scott in a number of threads to use /*select 1 from dual */ with query but not working in my case.
Can someone please suggest what can I do to make it working?
Regards,
AmirFirstly, have you unit tested the procedure (namely, within the SQL Workshop, SQL*Plus, SQL Developer,etc, etc.) to see if it produces the right output in the first place?
If you have, and the query string generated is valid, try assigning the output to a page item (thus allowing you to view it in the session browser) or even pass the procedure output into the debug window (with the use of the wwv_flow.debug function). This might reveal some state or session change which is causing it not to return.You might find this easier to achieve if you change from a 'procedure and out parameter' combination to a 'function returning string' approach.
Alternatively, try re-creating the report in a new region - occasionally I've come across weird bugs with report regions which resolved themselves in this manner. -
SOLVED: How can I use or call a function that returns %ROWTYPE?
Hi
edit: you can probably skip all this guff and go straight to the bottom...In the end this is probably just a question of how to use a function that returns a %rowtype. Thanks.
Currently reading Feuerstein's tome, 5th ed. I've downloaded and run the file genaa.sp, which is a code generator. Specifically, you feed it a table name and it generates code (package header and package body) that will create a cache of the specified table's contents.
So, I ran:
HR@XE> @"C:\Documents and Settings\Jason\My Documents\Work\SQL\OPP5.WEB.CODE\OPP5.WEB.CODE\genaa.sp"
749 /
Procedure created.
HR@XE> exec genaa('EMPLOYEES');which generated a nice bunch of code, viz:
create or replace package EMPLOYEES_cache is
function onerow ( EMPLOYEE_ID_in IN HR.EMPLOYEES.EMPLOYEE_ID%TYPE) return HR.EMPLOYEES%ROWTYPE;
function onerow_by_EMP_EMAIL_UK (EMAIL_in IN HR.EMPLOYEES.EMAIL%TYPE) return HR.EMPLOYEES%ROWTYPE;
procedure test;
end EMPLOYEES_cache;
create or replace package body EMPLOYEES_cache is
TYPE EMPLOYEES_aat IS TABLE OF HR.EMPLOYEES%ROWTYPE INDEX BY PLS_INTEGER;
EMP_EMP_ID_PK_aa EMPLOYEES_aat;
TYPE EMP_EMAIL_UK_aat IS TABLE OF HR.EMPLOYEES.EMPLOYEE_ID%TYPE INDEX BY HR.EMPLOYEES.EMAIL%TYPE;
EMP_EMAIL_UK_aa EMP_EMAIL_UK_aat;
function onerow ( EMPLOYEE_ID_in IN HR.EMPLOYEES.EMPLOYEE_ID%TYPE)
return HR.EMPLOYEES%ROWTYPE is
begin
return EMP_EMP_ID_PK_aa (EMPLOYEE_ID_in);
end;
function onerow_by_EMP_EMAIL_UK (EMAIL_in IN HR.EMPLOYEES.EMAIL%TYPE)
return HR.EMPLOYEES%ROWTYPE is
begin
return EMP_EMP_ID_PK_aa (EMP_EMAIL_UK_aa (EMAIL_in));
end;
procedure load_arrays is
begin
FOR rec IN (SELECT * FROM HR.EMPLOYEES)
LOOP
EMP_EMP_ID_PK_aa(rec.EMPLOYEE_ID) := rec;
EMP_EMAIL_UK_aa(rec.EMAIL) := rec.EMPLOYEE_ID;
end loop;
END load_arrays;
procedure test is
pky_rec HR.EMPLOYEES%ROWTYPE;
EMP_EMAIL_UK_aa_rec HR.EMPLOYEES%ROWTYPE;
begin
for rec in (select * from HR.EMPLOYEES) loop
pky_rec := onerow (rec.EMPLOYEE_ID);
EMP_EMAIL_UK_aa_rec := onerow_by_EMP_EMAIL_UK (rec.EMAIL);
if rec.EMPLOYEE_ID = EMP_EMAIL_UK_aa_rec.EMPLOYEE_ID then
dbms_output.put_line ('EMP_EMAIL_UK lookup OK');
else
dbms_output.put_line ('EMP_EMAIL_UK lookup NOT OK');
end if;
end loop;
end test;
BEGIN
load_arrays;
end EMPLOYEES_cache;
/which I have run successfully:
HR@XE> @"C:\Documents and Settings\Jason\My Documents\Work\SQL\EMPLOYEES_CACHE.sql"
Package created.
Package body created.I am now trying to use the functionality within the package.
I have figured out that the section
BEGIN
load_arrays;
end EMPLOYEES_cache;
/is the initialization section, and my understanding is that this is supposed to run when any of the package variables or functions are referenced. Is that correct?
With that in mind, I'm trying to call the onerow() function, but it's not working:
HR@XE> select onerow(100) from dual;
select onerow(100) from dual
ERROR at line 1:
ORA-00904: "ONEROW": invalid identifier
HR@XE> select employees_cache.onerow(100) from dual;
select employees_cache.onerow(100) from dual
ERROR at line 1:
ORA-06553: PLS-801: internal error [55018]
HR@XE> select table(employees_cache.onerow(100)) from dual;
select table(employees_cache.onerow(100)) from dual
ERROR at line 1:
ORA-00936: missing expressionHe provides the code genaa.sp, and a very brief description of what it does, but doesn't tell us how to run the generated code!
Now, I have just done some googling, and it seems that what I am trying to do isn't possible. Apparently %ROWTYPE is PL/SQL, and not understood by SQL, so you can't call onerow() from sql. Correct?
So I try wrapping the call in an exec:
HR@XE> exec select employees_cache.onerow(100) from dual;
BEGIN select employees_cache.onerow(100) from dual; END;
ERROR at line 1:
ORA-06550: line 1, column 30:
PLS-00382: expression is of wrong type
ORA-06550: line 1, column 7:
PLS-00428: an INTO clause is expected in this SELECT statement
HR@XE> exec select table(employees_cache.onerow(100)) from dual;
BEGIN select table(employees_cache.onerow(100)) from dual; END;
ERROR at line 1:
ORA-06550: line 1, column 14:
PL/SQL: ORA-00936: missing expression
ORA-06550: line 1, column 7:
PL/SQL: SQL Statement ignored
HR@XE> exec employees_cache.onerow(100)
BEGIN employees_cache.onerow(100); END;
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00221: 'ONEROW' is not a procedure or is undefined
ORA-06550: line 1, column 7:
PL/SQL: Statement ignoredNo joy.
Of course, now that I'm looking at it again, it seems that the way to go is indicated by the first error:
PLS-00428: an INTO clause is expected in this SELECT statement
So am I supposed to create a type of EMPLOYEES%ROWTYPE in a PL/SQL procedure, and the idea of this code, is that the first call to onerow() runs the initialiation code, which populates the cache, and all subsequent calls to onerow() (whether by my session or any other) will use the cache?
I've had a stab at this, but still, no joy:
create or replace procedure testcache is
emp employees%rowtype;
begin
select employees_cache.onerow(100) from dual into emp;
dbms_output.put_line('Emp id: ' || emp.employee_id);
end testcache;
show errors
HR@XE> @testcache.sql
Warning: Procedure created with compilation errors.
Errors for PROCEDURE TESTCACHE:
LINE/COL ERROR
4/9 PL/SQL: SQL Statement ignored
4/54 PL/SQL: ORA-00933: SQL command not properly ended
HR@XE>Have a feeling this should be really easy. Can anybody help?
Many thanks in advance.
Jason
Edited by: 942375 on 08-Feb-2013 11:45>
Ha, figured it out
>
Hopefully you also figured out that the example is just that: a technical example of how to use certain Oracle functionality. Unfortunately it is also an example of what you should NOT do in an actual application.
That code isn't scaleable, uses expensive PGA memory, has no limit on the amount of memory that might be used and, contrary to your belief will result in EVERY SESSION HAVING ITS OWN CACHE of exactly the same data if the session even touches that package.
Mr. Feuerstein is an expert in SQL and PL/SQL and his books cover virtually all of the functionality available. He also does an excellent job of providing examples to illustrate how that functionality can be combined and used. But the bulk of those examples are intended solely to illustrate the 'technical' aspects of the technology. They do not necessarily reflect best practices and they often do not address performance or other issues that need to be considered when actually using those techniques in a particular application. The examples show WHAT can be done but not necessarily WHEN or even IF a given technique should be used.
It is up to the reader to learn the advantages and disadvantages of each technicalogical piece and determine when and how to use them.
>
Now, I have just done some googling, and it seems that what I am trying to do isn't possible. Apparently %ROWTYPE is PL/SQL, and not understood by SQL, so you can't call onerow() from sql. Correct?
>
That is correct. To be used by SQL you would need to create SQL types using the CREATE TYPE syntax. Currently that syntax does not support anything similar to %ROWTYPE.
>
So am I supposed to create a type of EMPLOYEES%ROWTYPE in a PL/SQL procedure, and the idea of this code, is that the first call to onerow() runs the initialiation code, which populates the cache, and all subsequent calls to onerow() (whether by my session or any other) will use the cache?
>
NO! That is a common misconception. Each session has its own set of package variables. Any session that touches that package will cause the entire EMPLOYEES table to be queried and stored in a new associative array specifically for that session.
That duplicates the cache for each session using the package. So while there might be some marginal benefit for a single session to cache data like that the benefit usually disappears if multiple sessions are involved.
The main use case that I am aware of where such caching has benefit is during ETL processing of staged data when the processing of each record is too complex to be done in SQL and the records need to be BULK loaded and the data manipulated in a loop. Then using an associative array as a lookup table to quickly get a small amount of data can be effective. And if the ETL procedure is being processed in parallel (meaning different sessions) then for a small lookup array the additional memory use is tolerable.
Mitigating against that is the fact that:
1. Such frequently used data that you might store in the array is likely to be cached by Oracle in the buffer cache anyway
2. Newer versions of Oracle now have more than one cache
3. The SQL query needed to get the data from the table will use a bind variable that eliminates repeated hard parsing.
4. The cursor and the buffer caches ARE SHARED by multiple sessions globally.
So the short story is that there would rarely be a use case where ARRAYs like that would be preferred over accessing the data from the table. -
Query on Reoprts-pl/sql function body returning sql query
Hi,
I am facing a starnge problem.. and would like to know the reason for it.
The situation is as follows:
I have a report (pl/sql function body returning sql query based). My query is as follows:
declare
l_query1 varchar2(2000);
begin
if (:P102_min_value is not null and :P102_max_value is null) then
l_query1 := 'select decode(:P102_date,'1',date1) Transaction_Date, decode(:P102_first_name,'2',first_name) First_Name from (
select * from MORTGAGE_LOAN_LEADS where APPRX_LOAN_AMOUNT >=:P102_min_value
return (l_query1);
end if;
end;
This returns the error as :
1 error has occurred
Function returning SQL query: Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the generic columns checkbox below the region source to proceed without parsing.
(ORA-06550: line 7, column 20: PLS-00103: Encountered the symbol "1" when expecting one of the following: * & = - + ; < / > at in is mod remainder not rem <> or != or ~= >= <= <> and or like LIKE2_ LIKE4_ LIKEC_ between || multiset member SUBMULTISET_)
How do i correct this? am i right in thinking that the single quotes indicating a string within a select query is creating the problem? Beacuse if i use an sql query report and use the following query, it is working fine...
select
decode(:P102_date,'1',date1) Transaction_Date,
decode(:P102_first_name,'2',first_name) First_Name
from (
select * from MORTGAGE_LOAN_LEADS where APPRX_LOAN_AMOUNT >=:P102_min_value
But i need to write pl/sql function, so that multiple report can be returned based on different conditions. Please guide me.
Thanks,
SumanaDoes that mean that both in if and else we need to have same columns selected?
if thats the case.. any idea how i can implement it in my code. The situation here is that the columns that need to be selected are dynamic and keep on changing...
if i try to implement like this and run the page, it gives the following error:
Query is:
declare
l_query1 varchar2(4000);
begin
if apex_application.get_current_flow_sgid(:APP_ID) = apex_application.get_sgid then
if (:P102_min_value is not null and :P102_max_value is null) then
l_query1 := 'select decode(' || :P102_date|| ',''1'',date1) Transaction_Date, decode(' || :P102_first_name || ',''2'',first_name) First_Name from (
select * from MORTGAGE_LOAN_LEADS where APPRX_LOAN_AMOUNT >=' || :P102_min_value ||'
elsif (:P102_min_value is null and :P102_max_value is not null) then
l_query1 := 'select decode(' || :P102_date|| ',''1'',date1) Transaction_Date, decode(' || :P102_first_name || ',''2'',first_name) First_Name from (
select * from MORTGAGE_LOAN_LEADS where APPRX_LOAN_AMOUNT >=' || :P102_max_value ||'
else
l_query1 := 'select date1,first_name from MORTGAGE_LOAN_LEADS where rownum = 1';
end if;
else
l_query1 := 'select date1,first_name from MORTGAGE_LOAN_LEADS where rownum = 1';
end if;
return l_query1;
--dbms_output.put_line( l_query1);
end;
The Error is:
failed to parse SQL query:
ORA-00936: missing expression
If i try to run the same in command prompt, it always goes to the else part... (else of outer if) -
UDPWrite in a loop. "A Windows Sockets function call returned an unexpected error."
Hello together,
i use UDP Support Library in NI CVI 9.0. When i wait for receiving a packet at the pc to send then a packet from the pc, the functions UDPRead and UDPWrite work fine. If i want to test the maximum throughput, i put the UDPWrite in a loop, but then an error occurs. It is "kUDP_UnexpectedWinsockError"
Error Popup:
"NON-FATAL RUN-TIME ERROR: "main.c", line 53, col 22, thread id
0x00000C18: Library function error (return value == -6822
[0xffffe55a]). A Windows Sockets function call returned an unexpected
error."
Line 53:
status = UDPWrite (channel, 60100, "192.168.1.10", pOutputBuffer, 1458);
the whole loop:
while(1)
status = UDPWrite (channel, 60100, "192.168.1.10", pOutputBuffer, 1458);
counter++;
if(counter>50)
break;
else{;}
The error occurs after 3-16 packets have been sent. If i step through the programm, no error occurs. So i guess its because the UDPWrite command is invoked too fast. pOutputBuffer has static data. I could use a delay in the loop, but then i dont know how to configure for maximal throughput.
Any ideas how to avoid this error?
Regards FlorianHello and thank you for your answer. Sorry that i reply a month later.
I dont know what you mean by "let 'er rip approach". Do you mean something like:
status = UDPWrite (channel, 60100, "192.168.1.10", pOutputBuffer, 1458);
if(status==0)
counter++;
else
Delay(0.00005);
I did not yet try to put the packet number in the payload, but there is just a 30 cm crossover cable between the two devices, no switch, no router. So the sequence should not be interruptet. And even if they arrive in chaos, i dont mind.
I have contacted the NI support 2 weeks ago, but no response yet.
I did some tests with a delay between the execution of UDPWrite(). The code:
float time = 0.0;
for(i = 1; i < 1000; i++)
status = UDPWrite (channel, 60100, "192.168.1.10", pOutputBuffer, 1458);
time = 1.0 / i;
Delay(time);
The results:
For i between 1 and 1000: no error, the speed of the last ten packets was about 6.5 MBit/s
For i between 1000 and 2000: error occured at i = 1585 (variable time in Delay was 0.0006313), the speed of the last ten packets was about 8 MBit/s
Then i put some constant values in Delay and ran 100 UDPWrite iterations:
Delay(0.0006): 7.48 MBit/s
Delay(0.0001): 10.7 MBit/s
Delay(0.00001): error occured at i=31, speed of 31 packets was 12.0 MBit/s
Delay(0.00008): 100 of 100 packets, speed 10.9 MBit/s
Delay(0.00005): error at i=41, speed of 41 packets 11.1 MBit/s -
Stored function not returning result set unless recompiled
Hi,
I have a strange situation going on with a basic Java (1.6.0.17) application talking to an Oracle 11g (11.2.0.1.0) database. Basically what is happening is that sometimes a stored function's return value (a result set) is not making it as far as JDBC/Java, unless I recompile the stored function (with absolutely no changes to the application or function's code). I am always able to successfully see the result set if I call the function directly from within SQL Developer, just not on the Java app/JDBC side.
I've tried running with 3 different physical Oracle 11g servers and tried running the app on a couple of machines. I'm wondering if this is either some kind of caching issue or perhaps a JDBC bug/misconfiguration.
Any help would be greatly appreciated. Attached to this message:
1. stored function code
2. snippet of Java app code
3. ODBC trace output when returned a empty result set (ie failure scenario)
4. ODBC trace out when returned the correct result set (ie success scenario)
* it's helpful if you compare the texts of 3 & 4 with Vim diff or WinMerge etc.
** as they're large I've just extracted the sections that had differences. Leave a message here and I can send you the full ones if necessary.
1. stored function code
===============
FUNCTION getRecordSet (
ActionId Number
RETURN CallingList.ref_cursor
IS
myDataCursor CallingList.ref_cursor;
ActionId_ Number;
BEGIN
ActionId_ := ActionId;
IF isActionExpired(ActionId) <= 0 THEN
ActionId_ := 0;
END IF;
OPEN myDataCursor FOR
SELECT
C.ID,
C.CUSTOMER_ID,
C.CAMPAIGN_ID,
c.phone,
C.TRANSFERDN,
(SELECT
TTS_MESSAGE
FROM CAMPAIGN CMP
WHERE CMP.CAMPAIGN_ID = C.CAMPAIGN_ID) "TTS"
FROM
CALLING_LIST C
WHERE
C.ACTION_ID = ActionId_
AND
C.CALL_STATUS = 1
AND
C.CALLCOUNT > 0
And rownum <=5;
RETURN myDataCursor;
EXCEPTION
WHEN CURSOR_ALREADY_OPEN THEN
RETURN NULL;
WHEN INVALID_CURSOR THEN
RETURN NULL;
WHEN NO_DATA_FOUND THEN
RETURN NULL;
END getRecordSet;
....and the isActionExpired function that is called from within getResultSet is (but for all my testing it's been returning 1 with no problems)
FUNCTION isActionExpired (
ActionId number
) RETURN number
AS
Today varchar2(12);
myCount number(6);
BEGIN
myCount := 0;
today := to_char(sysdate, 'dd.mm.yyyy');
SELECT
count(*)
INTO
myCount
FROM
ACTION A
where
ACTION_ID = ActionId
AND
SYSDATE BETWEEN ACTION_STARTDATETIME
AND
ACTION_STOPDATETIME
and
SYSDATE BETWEEN to_date(today || ' ' || A.STARTTIME, 'dd.mm.yyyy HH24:MI:SS') and to_date(today || ' ' || A.ENDTIME, 'dd.mm.yyyy HH24:MI:SS')
AND
ACTION_STATUS = 1;
return myCount;
END isActionExpired;
2. snippet of Java app code
=================
... db connect logic...
javax.management.MBeanServer mbs = null;
javax.management.ObjectName name = null;
try {
String loader = Thread.currentThread().getContextClassLoader().toString().replaceAll("[,=:\"]+", "");
name = new javax.management.ObjectName("com.oracle.jdbc:type=diagnosability,name="+loader);
mbs = java.lang.management.ManagementFactory.getPlatformMBeanServer();
mbs.setAttribute(name, new javax.management.Attribute("LoggingEnabled", true));
} catch (Exception e) {
System.out.println("ORACLE TRACE ERROR: " + e.getStackTrace());
try {
String query = "begin ? := CALLINGLIST.getRecordSet(?); end;";
CallableStatement stmt = conn.prepareCall(query);
stmt.registerOutParameter(1, OracleTypes.CURSOR);
stmt.setInt(2, actionId);
stmt.execute();
ResultSet rs = (ResultSet) stmt.getObject(1); // So, here it works.
// print the results
int count=0;
while (rs.next()) {
count++;
stmt.close();
System.out.println("rs count was: " + count);
} catch (SQLException e) {
System.out.println("Exception occurred: " + e.getMessage());
3. ODBC trace output when returned a empty result set (ie failure scenario)
===============================================
Jul 1, 2010 3:30:47 PM oracle.net.ns.Packet receive
TRACE_16: Enter:
Jul 1, 2010 3:30:47 PM oracle.net.ns.Packet receive
TRACE_20: Debug: type=6, length=121, flags=0
00 79 00 00 06 00 00 00 |.y......|
00 00 06 22 01 06 00 01 |..."....|
0A 00 00 00 07 03 C2 04 |........|
0E 04 C3 5E 22 03 02 C1 |...^"...|
2A 04 33 30 30 32 03 37 |*.3002.7|
37 37 05 48 65 6C 6C 6F |77.Hello|
08 01 06 00 00 01 02 00 |........|
00 00 00 00 00 04 01 05 |........|
01 01 02 05 7B 00 00 01 |....{...|
02 00 03 00 00 00 00 00 |........|
00 00 00 00 00 00 00 00 |........|
00 01 01 00 00 00 00 19 |........|
4F 52 41 2D 30 31 34 30 |ORA-0140|
33 3A 20 6E 6F 20 64 61 |3:.no.da|
74 61 20 66 6F 75 6E 64 |ta.found|
0A |. |
Jul 1, 2010 3:30:47 PM oracle.net.ns.Packet receive
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.DBConversion CHARBytesToJavaChars
TRACE_16: Enter: [B@1fa1bb6, 0, [C@1b000e7, 1, [I@1315d34, 20
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.DBConversion _CHARBytesToJavaChars
TRACE_16: Enter: [B@1fa1bb6, 0, [C@1b000e7, 1, 871, [I@1315d34, 20, oracle-character-set-830, oracle-character-set-2000, oracle-character-set-871, false
Jul 1, 2010 3:30:47 PM oracle.sql.CharacterSet convertUTFBytesToJavaChars
TRACE_16: Enter: [B@1fa1bb6, 0, [C@1b000e7, 1, [I@1315d34, true, 20
Jul 1, 2010 3:30:47 PM oracle.sql.CharacterSet convertUTFBytesToJavaChars
TRACE_16: return: 4
Jul 1, 2010 3:30:47 PM oracle.sql.CharacterSet convertUTFBytesToJavaChars
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.DBConversion _CHARBytesToJavaChars
TRACE_16: return: 4
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.DBConversion _CHARBytesToJavaChars
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.DBConversion CHARBytesToJavaChars
TRACE_16: return: 4
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.DBConversion CHARBytesToJavaChars
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.DBConversion CHARBytesToJavaChars
TRACE_16: Enter: [B@1fa1bb6, 0, [C@1b000e7, 211, [I@1de256f, 10
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.DBConversion _CHARBytesToJavaChars
TRACE_16: Enter: [B@1fa1bb6, 0, [C@1b000e7, 211, 871, [I@1de256f, 10, oracle-character-set-830, oracle-character-set-2000, oracle-character-set-871, false
Jul 1, 2010 3:30:47 PM oracle.sql.CharacterSet convertUTFBytesToJavaChars
TRACE_16: Enter: [B@1fa1bb6, 0, [C@1b000e7, 211, [I@1de256f, true, 10
Jul 1, 2010 3:30:47 PM oracle.sql.CharacterSet convertUTFBytesToJavaChars
TRACE_16: return: 3
Jul 1, 2010 3:30:47 PM oracle.sql.CharacterSet convertUTFBytesToJavaChars
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.DBConversion _CHARBytesToJavaChars
TRACE_16: return: 3
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.DBConversion _CHARBytesToJavaChars
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.DBConversion CHARBytesToJavaChars
TRACE_16: return: 3
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.DBConversion CHARBytesToJavaChars
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.DBConversion CHARBytesToJavaChars
TRACE_16: Enter: [B@1fa1bb6, 0, [C@1b000e7, 321, [I@16bd8ea, 2000
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.DBConversion _CHARBytesToJavaChars
TRACE_16: Enter: [B@1fa1bb6, 0, [C@1b000e7, 321, 871, [I@16bd8ea, 2000, oracle-character-set-830, oracle-character-set-2000, oracle-character-set-871, false
Jul 1, 2010 3:30:47 PM oracle.sql.CharacterSet convertUTFBytesToJavaChars
TRACE_16: Enter: [B@1fa1bb6, 0, [C@1b000e7, 321, [I@16bd8ea, true, 2000
Jul 1, 2010 3:30:47 PM oracle.sql.CharacterSet convertUTFBytesToJavaChars
TRACE_16: return: 5
Jul 1, 2010 3:30:47 PM oracle.sql.CharacterSet convertUTFBytesToJavaChars
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.DBConversion _CHARBytesToJavaChars
TRACE_16: return: 5
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.DBConversion _CHARBytesToJavaChars
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.DBConversion CHARBytesToJavaChars
TRACE_16: return: 5
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.DBConversion CHARBytesToJavaChars
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.T4CConnection updateSessionProperties
TRACE_16: Enter: [Loracle.jdbc.internal.KeywordValue;@16e1fb1
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.T4CConnection updateSessionProperties
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.T4CStatement fetch
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleStatement checkValidRowsStatus
TRACE_16: Enter:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleStatement checkValidRowsStatus
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleResultSetImpl <init>
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.T4CResultSetAccessor getCursor
TRACE_16: return: oracle.jdbc.driver.OracleResultSetImpl@e2cb55
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.T4CResultSetAccessor getCursor
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.ResultSetAccessor getObject
TRACE_16: return: oracle.jdbc.driver.OracleResultSetImpl@e2cb55
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.ResultSetAccessor getObject
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleCallableStatement getObject
TRACE_1: return: oracle.jdbc.driver.OracleResultSetImpl@e2cb55
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleCallableStatement getObject
TRACE_1: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleCallableStatementWrapper getObject
TRACE_30: return: oracle.jdbc.driver.OracleResultSetImpl@e2cb55
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleCallableStatementWrapper getObject
TRACE_30: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleResultSetImpl next
TRACE_1: Public Enter:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleResultSetImpl next
TRACE_20: Debug: closed=false, statement.currentRow=-1, statement.totalRowsVisited=0, statement.maxRows=0, statement.validRows=1, statement.gotLastBatch=true
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleResultSetImpl next
TRACE_1: return: true
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleResultSetImpl next
TRACE_1: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleResultSetImpl next
TRACE_1: Public Enter:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleResultSetImpl next
TRACE_20: Debug: closed=false, statement.currentRow=0, statement.totalRowsVisited=1, statement.maxRows=0, statement.validRows=1, statement.gotLastBatch=true
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleResultSetImpl internal_close
TRACE_16: Enter: false
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.BaseResultSet close
TRACE_16: Public Enter:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.BaseResultSet close
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.PhysicalConnection registerHeartbeat
TRACE_16: Enter:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.PhysicalConnection registerHeartbeat
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.PhysicalConnection needLine
TRACE_16: Enter:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.PhysicalConnection needLineUnchecked
TRACE_16: Enter:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.PhysicalConnection needLineUnchecked
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.PhysicalConnection needLine
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.T4CStatement closeQuery
TRACE_16: Enter:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.T4CConnection assertLoggedOn
TRACE_16: Enter: "oracle.jdbc.driver.T4CStatement.closeQuery"
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.T4CConnection assertLoggedOn
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.T4CStatement closeQuery
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleStatement endOfResultSet
TRACE_16: Enter: false
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleStatement prepareForNewResults
TRACE_16: Enter: false, false
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleStatement clearWarnings
TRACE_16: Public Enter:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleStatement clearWarnings
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleResultSetImpl internal_close
TRACE_16: Enter: true
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleResultSetImpl internal_close
TRACE_16: return:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleResultSetImpl internal_close
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleStatement prepareForNewResults
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.T4CStatement clearDefines
TRACE_16: Enter:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleStatement clearDefines
TRACE_16: Public Enter:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleStatement freeLine
TRACE_16: Enter:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleStatement freeLine
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleStatement cleanupDefines
TRACE_16: Enter:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.PhysicalConnection cacheBuffer
TRACE_16: Enter: [B@8e32e7
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.BufferCache put
TRACE_16: Enter: [B@8e32e7
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.BufferCache put
TRACE_30: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.PhysicalConnection cacheBuffer
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.PhysicalConnection cacheBuffer
TRACE_16: Enter: [C@1b000e7
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.BufferCache put
TRACE_16: Enter: [C@1b000e7
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.BufferCache put
TRACE_30: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.PhysicalConnection cacheBuffer
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleStatement cleanupDefines
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleStatement clearDefines
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.T4CStatement clearDefines
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleStatement endOfResultSet
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleResultSetImpl internal_close
TRACE_16: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleResultSetImpl next
TRACE_1: return: false
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleResultSetImpl next
TRACE_1: Exit
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleCallableStatementWrapper close
TRACE_16: Enter:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OraclePreparedStatementWrapper close
TRACE_16: Enter:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleStatementWrapper close
TRACE_16: Enter:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleStatement close
TRACE_1: Public Enter:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.OracleStatement closeOrCache
TRACE_16: Enter: null
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.PhysicalConnection isStatementCacheInitialized
TRACE_16: Enter:
Jul 1, 2010 3:30:47 PM oracle.jdbc.driver.PhysicalConnection isStatementCacheInitialized
4. ODBC trace out when returned the correct result set (ie success scenario)
===============================================
TRACE_16: Enter:
Jul 1, 2010 3:30:07 PM oracle.net.ns.Packet receive
TRACE_20: Debug: type=6, length=82, flags=0
00 52 00 00 06 00 00 00 |.R......|
00 00 08 01 06 00 00 01 |........|
02 00 00 00 00 00 00 04 |........|
01 05 00 02 05 7B 00 00 |.....{..|
01 02 00 03 00 00 00 00 |........|
00 00 00 00 00 00 00 00 |........|
00 00 01 01 00 00 00 00 |........|
19 4F 52 41 2D 30 31 34 |.ORA-014|
30 33 3A 20 6E 6F 20 64 |03:.no.d|
61 74 61 20 66 6F 75 6E |ata.foun|
64 0A |d. |
Jul 1, 2010 3:30:07 PM oracle.net.ns.Packet receive
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.T4CConnection updateSessionProperties
TRACE_16: Enter: [Loracle.jdbc.internal.KeywordValue;@1fa1bb6
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.T4CConnection updateSessionProperties
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.T4CStatement fetch
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleResultSetImpl internal_close
TRACE_16: Enter: false
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.BaseResultSet close
TRACE_16: Public Enter:
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.BaseResultSet close
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.PhysicalConnection registerHeartbeat
TRACE_16: Enter:
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.PhysicalConnection registerHeartbeat
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.PhysicalConnection needLine
TRACE_16: Enter:
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.PhysicalConnection needLineUnchecked
TRACE_16: Enter:
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.PhysicalConnection needLineUnchecked
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.PhysicalConnection needLine
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.T4CStatement closeQuery
TRACE_16: Enter:
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.T4CConnection assertLoggedOn
TRACE_16: Enter: "oracle.jdbc.driver.T4CStatement.closeQuery"
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.T4CConnection assertLoggedOn
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.T4CStatement closeQuery
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleStatement endOfResultSet
TRACE_16: Enter: false
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleStatement prepareForNewResults
TRACE_16: Enter: false, false
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleStatement clearWarnings
TRACE_16: Public Enter:
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleStatement clearWarnings
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleStatement prepareForNewResults
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.T4CStatement clearDefines
TRACE_16: Enter:
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleStatement clearDefines
TRACE_16: Public Enter:
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleStatement freeLine
TRACE_16: Enter:
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleStatement freeLine
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleStatement cleanupDefines
TRACE_16: Enter:
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.PhysicalConnection cacheBuffer
TRACE_16: Enter: [B@8e32e7
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.BufferCache put
TRACE_16: Enter: [B@8e32e7
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.BufferCache put
TRACE_30: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.PhysicalConnection cacheBuffer
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.PhysicalConnection cacheBuffer
TRACE_16: Enter: [C@1b000e7
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.BufferCache put
TRACE_16: Enter: [C@1b000e7
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.BufferCache put
TRACE_30: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.PhysicalConnection cacheBuffer
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleStatement cleanupDefines
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleStatement clearDefines
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.T4CStatement clearDefines
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleStatement endOfResultSet
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleResultSetImpl internal_close
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleResultSetImpl <init>
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.T4CResultSetAccessor getCursor
TRACE_16: return: oracle.jdbc.driver.OracleResultSetImpl@1315d34
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.T4CResultSetAccessor getCursor
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.ResultSetAccessor getObject
TRACE_16: return: oracle.jdbc.driver.OracleResultSetImpl@1315d34
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.ResultSetAccessor getObject
TRACE_16: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleCallableStatement getObject
TRACE_1: return: oracle.jdbc.driver.OracleResultSetImpl@1315d34
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleCallableStatement getObject
TRACE_1: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleCallableStatementWrapper getObject
TRACE_30: return: oracle.jdbc.driver.OracleResultSetImpl@1315d34
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleCallableStatementWrapper getObject
TRACE_30: Exit
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleResultSetImpl next
TRACE_1: Public Enter:
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleResultSetImpl next
TRACE_20: Debug: closed=true, statement.currentRow=-1, statement.totalRowsVisited=0, statement.maxRows=0, statement.validRows=0, statement.gotLastBatch=false
Jul 1, 2010 3:30:07 PM oracle.jdbc.driver.OracleResultSetImpl next
Edited by: user9376621 on Jul 1, 2010 1:07 AM
Edited by: user9376621 on Jul 1, 2010 1:13 AMPlease ignore this, it was a non-issue in the end.
-
COMMIT failed in RSORAADM, object JOB, function CREATE, return code 4
Dear Gurus,
When I am trying to schedule a backup through DB13, I am getting an error as
"COMMIT failed in RSORAADM, object JOB, function CREATE, return code 4"
Can any body tell me what is the error about and how to resolve it.
Thanks
Best Regards
Diliphi Kaushal,
Thanks for your reply. Yes I could solve the issue as my Operation mode was inactive, I made it active and then could schedule the DB13 jobs.
Can you tell me what is the relationship between DB13 jobs scheduling and Operation mode. Also note when I am scheduling DB13 jobs that time none of the background job is running ie my background wp is free. It is only after I activated day/night operation mode, I could schedule the backup.
Thanks once again. Your input was of great help to me.
Best Regards
Dilip -
Subquery not allowed - PL/SQL Function Body returning bolean
Is subquery is not allowed in PL/SQL Expresion.????
I am using the following query in one of my derived report column but I am getting the error.
BEGIN
if :COL1<>'abc' and :COL2 in (select deptno from dept1) then
return 1;
elsif :COL1<>'abc' and :COL2 in (select deptno from dept2) then
return 0;
elsif :COL1<>'abc' and :COL2 in (select deptno from dept3) then
return 1;
else
return 0;
end if;
END;
secondly CAN I use return value such as 'ABC' or 'XYZ' other than 0,1.
Error-
Invalid function body condition: ORA-06550: line 4, column 8: PLS-00405: subquery not allowed in this context ORA-06550: line 2, column 3: PL/SQL: Statement ignored
-----------------Hi Deepak,
There are at least methods.
1 - You could create a SQL function that returned 0 or 1 and use that in your statement
2 - You could use a CASE clause in the SQL statement
As I don't have your dept1/2/3 tables, I've tried the following on the sample EMP/DEPT tables:
SELECT EMPNO,
ENAME,
SAL,
COMM,
DEPTNO,
CASE WHEN DEPTNO IN (SELECT DEPTNO FROM DEPT) THEN
CASE WHEN ENAME LIKE '%A%' THEN NVL(SAL,0) + NVL(COMM,0) ELSE 456 END
ELSE
CASE WHEN DEPTNO NOT IN (SELECT DEPTNO FROM DEPT) THEN
CASE WHEN ENAME LIKE '%A%' THEN NVL(SAL,0) + NVL(COMM,0) ELSE 123 END
ELSE
789
END
END "TOTAL"
FROM EMPThis returns the values I expect:
EMPNO ENAME SAL COMM DEPTNO TOTAL
7936 ATD 3000 - 40 3000
7958 dino4 - - - 789
7839 KINGS 5000 - 40 456
7698 BLAKES 2850 - 30 2850
7782 CLARK 2450 - 10 2450
7566 JONES 2975 - 30 456
7788 SCOTT 3000 - 20 456
7902 FORD 3000 - 40 456
7369 SMITH 800 - 20 456
7499 ALLEN 1600 300 30 1900Obviously, you may have to experiment with the various CASE statements, but it will work using just a sql select statement.
Andy -
Function not returning right value
I have this following function, based on the return value from this function, I am inserting a row into the GROUP_MAP table.
This function is returning a value greater than zero even though constrains would not let it select any rows.
It looks as if it is not applying the "AND STRING_CODE = String_Code" constraint to the result set. If there are two records matching the groupOID I passed it is returning two as the count(*). I checked by executing the query directly and I got 0 as the result. I sounds so strange. Is there any thing I am doing wrong ?
Thanks in Advance,
-Bhasker
FUNCTION FIND_CODE_GROUP (groupOID IN NUMBER, String_Code IN VARCHAR2)
RETURN NUMBER
AS
RETURN_VAL NUMBER(10);
BEGIN
RETURN_VAL := 0;
SELECT
COUNT(*)
INTO
RETURN_VAL
FROM
GROUP_MAP
WHERE
STRING_GROUP = groupOID AND STRING_CODE = String_Code;
DBMS_OUTPUT.PUT_LINE('RETURN_VAL:'|| RETURN_VAL || ' String code : ' || STRING_CODE);
RETURN(RETURN_VAL);
EXCEPTION
WHEN OTHERS THEN
RETURN(0);
END FIND_CODE_GROUP;FUNCTION FIND_CODE_GROUP (groupOID IN NUMBER, String_Code IN VARCHAR2)
RETURN NUMBER
AS
RETURN_VAL NUMBER(10);
BEGIN
RETURN_VAL := 0;
SELECT
COUNT(*)
INTO
RETURN_VAL
FROM
GROUP_MAP
WHERE
STRING_GROUP = groupOID AND STRING_CODE = String_Code;The second parameter to your function has the same name as the column name "STRING_CODE" in your table. You should change
the name of your second parameter to something other than "STRING_CODE". -
Function with return type boolean
I have created a function with return type boolean as:
CREATE OR REPLACE FUNCTION fn RETURN BOOLEAN
AS
exp EXCEPTION;
BEGIN
return TRUE;
EXCEPTION
when OTHERS then RAISE exp;
END;
FUNCTION fn compiledThen I was trying to call this function into dbms_output.put_line procedure, I got this error:
EXECUTE DBMS_OUTPUT.PUT_LINE(fn);
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'Can someone please help me understand, why this happened?
Is this because of boolean return type?952040 wrote:
I have created a function with return type boolean as:
Then I was trying to call this function into dbms_output.put_line procedure, I got this error:
EXECUTE DBMS_OUTPUT.PUT_LINE(fn);
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
What is the parameter signature for DBMS_OUTPUT.put_line() ?
Is is string - as detailed in Oracle® Database PL/SQL Packages and Types Reference guide.
So how can you pass a boolean data type as parameter value, when the parameter's data type is string?
PL/SQL supports implicit data conversion. So you can for example pass a number or date value to DBMS_OUTPUT.put_line() - and the PL/SQL engine automatically (and implicitly) converts that (using the TO_CHAR() functions) to a string.
However, the TO_CHAR() parameter signature supports number and date - not boolean. It cannot convert a boolean value into a string.
So passing a boolean value means the implicit conversion fails - and results in the above error.
To make it work, you need to perform an explicit conversion. As as a data type conversion function from boolean to string is not available, you need to write a user defined function. E.g.
SQL> create or replace function BoolToChar( b boolean ) return varchar2 is
2 begin
3 case
4 when b then return( 'TRUE' );
5 when not b then return( 'FALSE' );
6 else
7 return( null );
8 end case;
9 end;
10 /
Function created.
SQL>
SQL> exec DBMS_OUTPUT.put_line( 'Flag is '||BoolToChar(true) );
Flag is TRUE
PL/SQL procedure successfully completed
Maybe you are looking for
-
When I read email on iPhone, I want it to be marked as read in Outlook
I keep thinking I've found an answer on here, but to no avail, I cannot find a discussion that meets my needs. Here's the deal. I have Yahoo on my iPhone, right? When I read an email in my Yahoo account on my iPhone, and later log into my Yahoo acc
-
Hi, I downloaded an html file from our server to edit the logo. However, I am unable to edit the logo part. It's like commented out. And once I opened the file on Dreamweaver CS5, I am getting this pop-up message: "This page contains some SWF objects
-
When opening a PDF file quicktime opens it instead of preview, how do I get preview back
Quick Time now opens my PDF files instead of Preview How can I get Preview to open them up?
-
CAF Business Objects in Separate Database
We currently have an application written in CAF which is using Business Objects/Entity Services using local persistence. I believe the local persistence automatically uses the default datasource defined in the SAP WAS portal server and creates the ta
-
HI ... In File to File scenarion In FTP connection Parameters how to find the server IP address venkatesh