SQL report for LIKE SEARCH
hello all ,
The below SQL seems to running fine in the SQL developer but acts different in APEX.
I have 2 select lists
1, :P40_C
2, :P40_CONTRACTOR
When I do not enter any value for the above select list, I do not return any records . I would like to get all the records when both the fields are left empty.
SELECT VS.LNAME||', '||VS.FNAME as "NAME",
VS.TEAM as "TEAM", VS.C_NO as "C_NO", VS.HOURLY_RATE as "HOURLY_RATE",
VS.WEEK_ENDING as "WEEK_ENDING",VS.PIN, sum(VS.TOTAL) as "TOTAL",
(sum(VS.TOTAL) * VS.HOURLY_RATE) "TOTAL_COST"
from VS
where
( instr(upper(VS.C_NO), upper(nvl(:P40_C,upper(VS.C_NO)))) > 0
AND_
instr(upper(VS.AD_ID), upper(nvl(:P40_CONTRACTOR,upper(VS.AD_ID)))) > 0 )
group by
VS.LNAME||', '||VS.FNAME, VS.FIRM, VS.MANAGER_NAME, VS.TEAM,
VS.C_NO, VS.POSITION_NO, VS.HOURLY_RATE,VS.WEEK_ENDING,VS.PIN,VS.PIN_DESCRIPTION
Any help in this regard will be highly appriciated.
Andy ,
Thank you.
Now I am getting ORA-00904: "V_C": invalid identifier_ ERROR from the below SQL .
DECLARE
v_sql VARCHAR2(4000);
v_c VARCHAR2(100);
v_co VARCHAR2(100);
v_from date;
v_to date;
BEGIN
v_from:= to_date(:P49_FROM,'DD-MON-YY');
v_to := to_date(:P49_TO,'DD-MON-YY');
v_c := UPPER(:P49_CONTRACT_NO);
v_co := UPPER(:P49_CONTRACTOR);
v_sql := ' SELECT LNAME||'', ''||FNAME CONTRACTOR,'
||' VS.TEAM as TEAM,'
||' VS.CONTRACT_NO as CONTRACT_NO,'
||' VS.POSITION_NO as POSITION_NO,'
||' VS.HOURLY_RATE as HOURLY_RATE,'
||' VS.WEEK_ENDING as WEEK_ENDING,'
||' VS.PIN,'
||' sum(VS.MON) as MON,'
||' sum(VS.TUE) as TUE,'
||' sum(VS.WED) as WED,'
||' sum(VS.THU) as THU,'
||' sum(VS.FRI) as FRI,'
||' sum(VS.SAT) as SAT,'
||' sum(VS.SUN) as SUN,'
||' sum(VS.TOTAL) as TOTAL, '
||' (sum(VS.TOTAL) * VS.HOURLY_RATE) TOTAL_COST '
||' FROM VS '
||' WHERE (VS.WEEK_ENDING) BETWEEN v_from AND v_to ';
IF v_c != 'NULL' THEN
v_sql := v_sql || ' AND INSTR(UPPER(VS.CONTRACT_NO),v_c) > 0';
END IF;
IF v_co != 'NULL' THEN
v_sql := v_sql||' AND instr(upper(VS.AD_ID), v_co) > 0';
END IF;
v_sql := v_sql ||' AND VS.EMP_APPROVAL = "Y" '
||' AND VS.MGR_APPROVAL = "Y" '
|| 'group by LNAME||'', ''||FNAME,'
|| 'VS.FIRM,'
|| 'VS.MANAGER_NAME,'
|| 'VS.TEAM,'
|| 'VS.CONTRACT_NO,'
|| 'VS.POSITION_NO,'
|| 'VS.HOURLY_RATE,'
|| 'VS.WEEK_ENDING,'
|| 'VS.PIN,'
|| 'VS.PIN_DESCRIPTION';
execute immediate v_sql;
END;
Similar Messages
-
How is it possible to use Index Seek for LIKE %search-string% case?
Hello,
I have the following SP:
CREATE PROCEDURE dbo.USP_SAMPLE_PROCEDURE(@Beginning nvarchar(15))
AS
SELECT * FROM HumanResources.Employee
WHERE NationalIDNumber LIKE @Beginning + N'%';
GO
If I run the sp first time with param: N'94', then the following plan is generated and added to the cache:
SQL Server "sniffs" the input value (94) when compiling the query. So for this param using Index Seek for AK_Employee_NationalIDNumber index will be the best option. On the other hand, the query plan should be generic enough to be able to handle
any values specified in the @Beginning param.
If I call the sp with @Beginning =N'%94':
EXEC dbo.USP_SAMPLE_PROCEDURE N'%94'
I see the same execution plan as above. The question is how is it possible to reuse this execution plan in this case? To be more precise, how
Index Seek can be used in case LIKE %search-string% case. I expected that
ONLY Index Scan operation can be used here.
AlexeyThe key is that the index seek operator includes both seek (greater than and less than) and a predicate (LIKE). With the leading wildcard, the seek is effectively returning all rows just like a scan and the filter returns only rows matching
the LIKE expression.
Do you want to say that in case of leading wildcard, expressions Expr1007 and Expr1008 (see image below) calculated such a way that
Seek Predicates retrieve all rows from the index. And only
Predicate does the real job by taking only rows matching the Like expression? If this is the case, then it explains how
Index Seek can be used to resolve such queries: LIKE N'%94'.
However, it leads me to another question: Since
Index Seek in
this particular case scans
all the rows, what is the difference between
Index Seek and Index Scan?
According to
MSDN:
The Index Seek operator uses the seeking ability of indexes to retrieve rows from a nonclustered index.
The storage engine uses the index to process
only those rows that satisfy the SEEK:() predicate. It optionally may include a WHERE:() predicate, which the storage engine will evaluate against all rows that satisfy the SEEK:() predicate (it does not use the indexes to do this).
The Index Scan operator retrieves
all rows from the nonclustered index specified in the Argument column. If an optional WHERE:() predicate appears in the Argument column, only those rows that satisfy the predicate are returned.
It seems like Index Scan is a special case of Index Seek,
which means that when we see Index Seek in the execution plan, it does NOT mean that storage engine does NOT scan all rows. Right?
Alexey -
PL/SQL code for a search button
i'm trying to write a PL/SQL for a search button , like in this picture
http://uppix.net/f/7/1/484994cbbb235d7041484588c2463.jpg
i tried this
begin
SELECT employee_id , first_name , last_name , manager_id , department_id
into
:employee_id , :first_name , :last_name , :manager_id , :department_id
FROM EMPLOYEES WHERE :DEP_ID = :DEPARTMENT_ID;
end;
but it didn't work
hope someone can help
thanks.Welcome to the forum.
From your link it shows you're using Form Builder as your development tool.
Therefore your question belongs to the Forms Forum @ Forms and not so much in this forum.
Keep in mind to read the FAQ's you'll stumble upon in several forums, so you know what to post and what not to post.
For example, here's the SQL and PL/SQL FAQ:
Re: 3. How to improve the performance of my query? / My query is running slow.
but it didn't workThat;s something you should not post.
Be more specific.
If you get an error message, then post the exact error code and message.
Always mention your database version and your Forms version (if Forms is involved). -
SQL report region and search capability
1) I have a report and I would like to be able to cat two fields together but the problem occurs is that the query will no longer search for that field once they are "catted " together.. The field is a combo of staff id (initials) and the full name, when you search it will find staff_id but it will not search on name.
An example is listed here: http://htmldb.oracle.com/pls/otn/f?p=860:21
workspace:epic
select B."BASE_UNIT_ID",S."NAME" || S."ACCESS_ACCOUNT_ID" AS STAFF_ID_combo_of_Name_and_Id, ST."ACCESS_ACCOUNT_ID" AS IMAGE_INSTALLED_BY
from "#OWNER#"."BASE_UNIT" B LEFT OUTER JOIN "#OWNER#"."IP" I ON B."IP_ID" = I."IP_ID"
LEFT OUTER JOIN "#OWNER#"."STAFF" ST ON B."IMAGE_INSTALLED_BY" = ST."STAFF_ID"
LEFT OUTER JOIN "#OWNER#"."STAFF" S ON B."STAFF_ID" = S."STAFF_ID"
where
instr(upper(B."BASE_UNIT_ID"),upper(nvl(:P21_SEARCH,B."BASE_UNIT_ID"))) > 0 OR
instr(upper(S."ACCESS_ACCOUNT_ID"),upper(nvl(:P21_SEARCH,S."ACCESS_ACCOUNT_ID"))) > 0 OR
instr(upper(ST."ACCESS_ACCOUNT_ID"),upper(nvl(:P21_SEARCH,ST."ACCESS_ACCOUNT_ID"))) > 0
2) On a side note does anyone know how to concat a space or dash between two fields for a report? I tried doing this column1 || '--' || column2 but when I tried to run the report it gave me an error and says all variables are not bound. (The query does work however in sqlplus) Currently I have managed to get by with column1 || '< /br >' || column2 but I would like both values on the same line.I have similar problem, my search is not working with the sql query below. Can someone tell me what wrong I am doing.
I have 3 text fields for users to enter different search criteria, and I "GO" button to submit their search. Hope to see your reply soon. Thank you.
select
"BUSINESS_UNIT",
"TURNKEY_PN_FORMULA_VER",
"TURNKEY_DESIGNATOR_FLAG",
"TECH_CODE_PREFIX",
"TECH_CODE",
"PART_NUMBER",
"DESCRIPTION",
"PKG",
"NO_OF_LEADS",
"METRIC_BODY_SIZE",
"NO_OF_DIE",
"NO_OF_WIRES",
"WIRE_SIZE",
"PB_FREE_FLAG"
from "TURNKEY_CODES"
where
instr(upper("BUSINESS_UNIT"),upper(nvl(:P1_REPORT_SEARCH,"BUSINESS_UNIT"))) > 0 or
instr(upper("TURNKEY_PN_FORMULA_VER"),upper(nvl(:P1_REPORT_SEARCH,"TURNKEY_PN_FORMULA_VER"))) > 0 or
instr(upper("TURNKEY_DESIGNATOR_FLAG"),upper(nvl(:P1_REPORT_SEARCH,"TURNKEY_DESIGNATOR_FLAG"))) > 0 or
instr(upper("TECH_CODE"),upper(nvl(:P1_REPORT_SEARCH,"TECH_CODE"))) > 0 or
instr(upper("PART_NUMBER"),upper(nvl(:P1_REPORT_SEARCH,"PART_NUMBER"))) > 0
or
instr(upper("DESCRIPTION"),upper(nvl(:P1_REPORT_SEARCH,"DESCRIPTION"))) > 0
or
instr(upper("PKG"),upper(nvl(:P1_REPORT_SEARCH,"PKG"))) > 0
or
instr(upper("NO_OF_LEADS"),upper(nvl(:P1_REPORT_SEARCH,"NO_OF_LEADS"))) > 0 or
instr(upper("METRIC_BODY_SIZE"),upper(nvl(:P1_REPORT_SEARCH,"METRIC_BODY_SIZE"))) > 0 or
instr(upper("NO_OF_DIE"),upper(nvl(:P1_REPORT_SEARCH,"NO_OF_DIE"))) > 0 or
instr(upper("NO_OF_WIRES"),upper(nvl(:P1_REPORT_SEARCH,"NO_OF_WIRES"))) > 0 or
instr(upper("PB_FREE_FLAG"),upper(nvl(:P1_REPORT_SEARCH,"PB_FREE_FLAG")))> 0
or
instr(upper("PKG"),upper(nvl(:P1_W_PKG,"PKG"))) > 0
and
instr(upper("NO_OF_LEADS"),upper(nvl(:P1_W_LEADS,"NO_OF_LEADS"))) > 0
) -
Hi,
it seems that many adobe products are based on an SQL-database. So I was wondering whether this was also the case for the Bridge database. If so, would it be possible to add an sql-prompt in addition to the normal image search options? For those who know SQL, this would creatly enhance flexibility and possibly also convenience of doing more complex searches.
Thanks and best regards
- spitfireI've just learned that Bridge indeed uses MySQL as its database. So, please, developpers, bless us with an SQL-Prompt!
regards
- spitfire -
Update button in sql report for each row can only get the report value
I have to added Update for each row of records like:
select a.*,'Update' button from (
select c.*,d.login from country c,champ d
where c.champ_id=d.champ_id(+)
order by c.name) a
then go to the report->edit button ->Column Link
I added some items P40_REGION, P40_CHAMPID,P40_ACTIVE,P40_CODE and assign the value like #region#,#active# ,#code# to these item, but when I click the update button in the report I found the values such as #region#,#active# ,#code# is the report value not the select list selected value(the region, active column are displayed as select list lov).
Can anyone tell me how to sort this knid of problem?
Thanks a lot!Sorry, it doesn't work. I also tried apex_application.g_f01(i), but not everytime I can get the value or get the incorrect value. If you have time you can try to create it like what I have described. Our team use two days now but still can not sort this problem.
-
Need sql query for like operation.
Hi All,
i have table like name column and contain the data like
ibm 100
ibm 200
ibm 300
a2b
a
b
c
like this ....
but sql query need search using like or any regular expression---
select * from table where name like (ibm 200 and ibm 300).
and i don't want use like this select * from table where name like' ibm 200' or name like 'ibm 300').
can you please any body help to correct the above query...
Edited by: anbarasan on Oct 16, 2011 10:02 PMWITH t AS
(SELECT 'ibm 100' NAME
FROM DUAL
UNION ALL
SELECT 'ibm 200' NAME
FROM DUAL
UNION ALL
SELECT 'ibm 300' NAME
FROM DUAL
UNION ALL
SELECT 'a2b' NAME
FROM DUAL)
SELECT *from t where REGEXP_LIKE (name, 'ibm')
and REGEXP_LIKE (name, '100|200') -
SQL query for formatted search
Hi guys and expertise,
I have this one problem where i need to do the formatted search,below is my example query that i have done
declare @itemcode varchar (20)
set @itemcode = (select x.itemcode from OITM x where x.ItemCode=[%])
declare @itmgrp varchar(50)
set @itmgrp=(select y.itmsgrpnam from OITB y where y.ItmsGrpNam=[%1])
select
CASE
when @itemcode = 'Item Descriptions 1' then @itmgrp
else t0.ItmsGrpNam
end
from OITB t0 inner join
OITM t1 on t0.ItmsGrpCod=t1.ItmsGrpCod
where t1.itemcode=@itemcode
***correct me if i'm wrong
the condition is :-
whenever the user selection is 'Item Descriptions 1' user will have to select the product group name else
if the user selection is not equal to "Item Descriptions 1", automatically the product group name will be default according
to the item code itself.
i wonder if it's possible? if it is, then i suppose there should be a way,right?Hi Gordon...
Thanks a lot for the answer,
I did try some research and manage to find a way out for the query that I want, the query is as below:-
BEGIN
IF
$[$38.1.0]='Item Descriptions' or $[$38.1.0]='Item Descriptions 1' or $[$38.1.0]='Item Descriptions 2' or
$[$38.1.0]='Item Descriptions 3' or $[$38.1.0]='Item Descriptions 4'
SELECT T0.ItmsGrpNam FROM OITB T0 inner join OITM T1 ON T0.ItmsGrpCod=T1.ItmsGrpCod
Group By T0.ItmsGrpNam
ELSE
SELECT T0.ItmsGrpNam FROM OITB T0 inner join OITM T1
ON T0.ItmsGrpCod=T1.ItmsGrpCod where T1.ItemCode=$[$38.1.0]
END
regards,
Asyraf -
Can we use xml Publisher reporting for sql* Plus in EBS
Hello All,
The current report is designed in Sql* Plus Executable report and the output is in txt format, Now the requirement is to have the output in Excel format.
So is it possible to use the xml reporting and make the output as Excel from the word template we design from MSword as we do for rdf(I have done few reports created in rdf to xml publisher reports in EBS and stand alone as well.).
Do the same procedure will suit for Sql*Plus reports tooo or Is there any work around to achieve this.
Thanks and Regards
Balaji.Hi
Thanks for the reply..
I tried to do the follwoing
1. changed the output to xml in the conc. prog.
2. ran the same report but i am getting the follwoing error in the output file
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
Invalid at the top level of the document. Error processing resource
Other reports which are using the Oracle Reports(rdf) as source, i am able to generated the xml as expected....
So my question is whether we can use sql* reports executable and generate xml in the conc.prog.
if any one has used the sql*reports for xml publisher reporting... please let me know, so that if its possible i will check my sql needs some validation or tuning...
thanks in advance
Balaji. -
How to pass parameter to a report for Operator 'LIKE'
I need to pass a parameter to a report for "LIKE" operator. the parameter for "equal to or is in" operator is 'eq':
'https://secure-ausomxfts.crmondemand.com/OnDemand/user/analytics/saw.dll?Go&Path=/shared/Company_AFTA-D78SR_Shared_Folder/Work Order Asset Lookup&Options=r&Action=Navigate&P0=2&P1=eq&P2=Account.TEXT_61&P3=&p4=
What would 'p1' value for 'LIKE' operator?
ThanksHi, Hope the below helps
neq - Not equal to or not in
lt - Less than
gt - Greater than
ge - Greater than or equal to
le - Less than or equal to
bwith - Begins with
ewith - Ends with
cany - Contains any (of the values in &P3)
call - Contains all (of the values in &P3)
like - Is like (Type %25 rather than the % wildcard)
top - In the top n (&P3 contains 1+n, where n is the number of top items)
bottom - In the bottom n (&P3 contains 1+n, where n is the number of bottom
items)
bet - Between (&P3 must have two values)
null - Is null (&P3 must be 0 or omitted)
nnul - Is not null (&P3 must be 0 or omitted)
Venky CRMIT -
How to frame the select query for wildcard search.
Hi Experts,
I have an input field P_USERALIAS.This value could contain the actual value or the wildcard for example : user can enter P_USERALIAS as SAP123 or S or SAPABC123 . I need to generate a dynamic search on table USREFUS depending on what has been entered.Please help.
Useful answers will be rewarded.
Regards,
Shrita Sharma.THIS IS A TEST REPORT FOR WILDCARD SEARCH**
TABLES: USREFUS.
PARAMETERS: P_NAME1 TYPE string.
RANGES: R_NAME1 FOR USREFUS-USERALIAS.
DATA: T_usrefus LIKE usrefus OCCURS 0 WITH HEADER LINE.
*replace
if p_name1 cs '*'.
replace all occurrences of '*' in p_name1 with '%'.
SELECT * FROM usrefus
INTO TABLE T_usrefus
WHERE useralias like P_NAME1.
else.
SELECT * FROM usrefus
INTO TABLE T_usrefus
WHERE useralias = p_name1.
endif.
LOOP AT T_usrefus.
WRITE: / T_usrefus-useralias.
ENDLOOP.
**THANKS & REGARDS
SHRITA SHARMA. -
Help required for doing LIKE search in SQL
Hello All,
I have situation like below
DECLARE @TempTable TABLE (Name1 VarCHar(100), Name2 VarChar(100))
INSERT INTO @TempTable(Name1, Name2)
VALUES('_HASKAR','BHASK_R')
SELECT *
FROM @TempTable
WHERE Name1 LIKE Name2
Both the columns are having WildCard (underscores). How can I do like search so that the where condition will be TRUE?
Regards,
Amar Ankatha
amar ankathaHi,
If I understand correctly, the position of H, A, S, K, R is fixed in the strings and you can use
SUBSTRING function.
DECLARE @TempTable TABLE (Name1 VarCHar(100), Name2 VarChar(100))
INSERT INTO @TempTable(Name1, Name2)
VALUES('_HASKAR','BHASK_R')
SELECT *
FROM @TempTable
WHERE substring(Name1,2,4) = substring (name2,2,4) and right(Name1, 1) = right(Name2, 1)
Thanks.
Tracy Cai
TechNet Community Support -
Solution to allow users to specify which columns of a sql report to search
Starting Point:
1) You have an existing SQL Report.
2) You want to provide functionality to search through the result set.
Start -----
1) add a text_item for searching PX_search where X is page number
2) add a button which resubmits the page. Go
3) You modify your query by adding the following to the end of the where clause.
and (PX_SEARCH is null or instr(column_name1,PX_SEARCH) > 0 )
4) So far so good but it only allows searches on 1 column, so you add a few other columns
and (PX_SEARCH is null or instr(column_name1,PX_SEARCH) > 0 or instr(column_name2,PX_SEARCH) > 0 or instr(column_name3,PX_SEARCH) > 0 )
Now when you enter some text if it is in any of the columns that row will be displayed.
This can be good or bad depending on your requirement. lets say my users want to specify the column they are searching on.
5)further enhancement
i) add a LOV to your page which queries the all_users data dictionary view
select column_name d, column_name r from all_users where table_name = 'MY_TABLE_NAME' and column_name not in ('COLUMN_NAME1,COLUMN_NAME2) order by column_name
The idea here is to use the oracle data dictionary to get all the columns for your table(s) and ignore the columns you do not want.
ii) add an item to your page e.g. PX_select_column which gets populated from the list of values.
Now for each column you are going to allow a search on, the sql needs to be modified.
Lets pretend that my firstcolumn is called member_id, my second column is called firstname and my third column is lastname
Before we had this SQL
(select * from table where 1=1)
and (PX_SEARCH is null or instr(memberid,PX_SEARCH) > 0 or instr(firstname,PX_SEARCH) > 0 or instr(lastname,PX_SEARCH) > 0 )
Remember we have added PX_SELECT_COLUMN which should contain what we have selected from the LOV.
iii) So now we modify the query to be as follows:
and (PX_SEARCH is null or decode(:PX_SELECT_COLUMN,'MEMBERID',instr(memberid,PX_SEARCH),0) > 0 or
decode(:PX_SELECT_COLUMN,'FIRSTNAME',instr(firstname,PX_SEARCH),0) > 0 or
decode(:PX_SELECT_COLUMN,'LASTNAME',instr(lastname,PX_SEARCH),0) > 0 )
The user can now choose which column to filter their results on.Here is a basic one (http://apex.oracle.com/pls/otn/f?p=2230:1). You can select an object type and put in criteria for the object name like '%b%'. The SELECT statement is dynamically generated with only the pieces of the WHERE clause that are needed. You do not need all the DECODE and INSTR OR logic.
The main part of this example is the computation of the SQL SELECT statement:
DECLARE
v_sql VARCHAR2(2000) := 'SELECT *'||CHR(10)||' FROM USER_OBJECTS';
v_and BOOLEAN := FALSE;
v_where VARCHAR2(2000);
BEGIN
-- P1_OBJECT_TYPE has value of 'ALL' for '%'
IF (:p1_object_type != 'ALL') THEN
v_sql := v_sql || chr(10) ||
' WHERE object_type = '''||:p1_object_type||'''';
v_and := TRUE;
END IF;
IF (:p1_object_name IS NOT NULL) THEN
IF (v_and) THEN
v_sql := v_sql || chr(10) ||
' AND object_name LIKE UPPER('''||:p1_object_name||''')';
ELSE
v_sql := v_sql || chr(10) ||
' WHERE object_name LIKE UPPER('''||:p1_object_name||''')';
END IF;
v_and := TRUE;
END IF;
:p1_sql := v_sql;
RETURN (v_sql);
END;Mike -
Need advise on SQL Report base for APEX or jasper
Hello everyone,
I need some advise on how to approach this below report requirement. It has been bugging me for nearly 2 weeks now, and my time is running out.
Here is a simplified version of the database
Four tables: Defendant, Engagement, Service, Event.
A defendant can have more than 1 engagement, but they have only one open engagement at a time.
For each engagement, they will have services and events.
These events can be just general events or events that relates to the service.
Here is the script for the tables and sample data
CREATE TABLE "DEFENDANT"
("DEF_ID" NUMBER,
"FIRST_NAME" VARCHAR2(50 BYTE),
"LAST_NAME" VARCHAR2(50 BYTE),
"ACTIVE" NUMBER DEFAULT 1
Insert into DEFENDANT (DEF_ID,FIRST_NAME,LAST_NAME,ACTIVE) values (1,'Joe','Bloggs',1);
Insert into DEFENDANT (DEF_ID,FIRST_NAME,LAST_NAME,ACTIVE) values (2,'John','Doe',1);
CREATE TABLE "ENGAGEMENT"
("ENG_ID" NUMBER,
"DEF_ID" NUMBER,
"COURT_NAME" VARCHAR2(20 BYTE),
"DATE_JOINED" DATE,
"DATE_TERMINATED" DATE,
"ETHNICITY" VARCHAR2(50 BYTE),
"ACTIVE" VARCHAR2(20 BYTE)
Insert into ENGAGEMENT (ENG_ID,DEF_ID,COURT_NAME,DATE_JOINED,DATE_TERMINATED,ETHNICITY,ACTIVE) values (1,1,'AAA',to_date('01/09/12','DD/MM/RR'),to_date('20/09/12','DD/MM/RR'),'European','1');
Insert into ENGAGEMENT (ENG_ID,DEF_ID,COURT_NAME,DATE_JOINED,DATE_TERMINATED,ETHNICITY,ACTIVE) values (2,2,'BBB',to_date('01/10/12','DD/MM/RR'),null,'Asian','1');
Insert into ENGAGEMENT (ENG_ID,DEF_ID,COURT_NAME,DATE_JOINED,DATE_TERMINATED,ETHNICITY,ACTIVE) values (3,1,'AAA',to_date('22/09/12','DD/MM/RR'),null,'European','1');
CREATE TABLE "EVENT"
("EVENT_ID" NUMBER,
"ENG_ID" NUMBER,
"NOTES" VARCHAR2(20 BYTE),
"RELATED_SERVICE_ID" NUMBER,
"START_DATE" DATE,
"END_DATE" DATE,
"ACTIVE" NUMBER DEFAULT 1
Insert into EVENT (EVENT_ID,ENG_ID,NOTES,RELATED_SERVICE_ID,START_DATE,END_DATE,ACTIVE) values (1,1,null,1,to_date('01/09/12','DD/MM/RR'),to_date('02/09/12','DD/MM/RR'),1);
Insert into EVENT (EVENT_ID,ENG_ID,NOTES,RELATED_SERVICE_ID,START_DATE,END_DATE,ACTIVE) values (2,1,null,1,to_date('23/09/12','DD/MM/RR'),null,1);
Insert into EVENT (EVENT_ID,ENG_ID,NOTES,RELATED_SERVICE_ID,START_DATE,END_DATE,ACTIVE) values (3,1,null,2,to_date('15/10/12','DD/MM/RR'),to_date('16/10/12','DD/MM/RR'),1);
Insert into EVENT (EVENT_ID,ENG_ID,NOTES,RELATED_SERVICE_ID,START_DATE,END_DATE,ACTIVE) values (4,2,null,null,to_date('02/10/12','DD/MM/RR'),null,1);
Insert into EVENT (EVENT_ID,ENG_ID,NOTES,RELATED_SERVICE_ID,START_DATE,END_DATE,ACTIVE) values (5,2,null,2,to_date('03/10/12','DD/MM/RR'),null,1);
Insert into EVENT (EVENT_ID,ENG_ID,NOTES,RELATED_SERVICE_ID,START_DATE,END_DATE,ACTIVE) values (6,3,null,null,to_date('22/09/12','DD/MM/RR'),to_date('23/09/12','DD/MM/RR'),1);
Insert into EVENT (EVENT_ID,ENG_ID,NOTES,RELATED_SERVICE_ID,START_DATE,END_DATE,ACTIVE) values (7,3,null,4,to_date('23/09/12','DD/MM/RR'),null,1);
Insert into EVENT (EVENT_ID,ENG_ID,NOTES,RELATED_SERVICE_ID,START_DATE,END_DATE,ACTIVE) values (8,2,null,null,to_date('12/10/12','DD/MM/RR'),null,1);
CREATE TABLE "SERVICE"
( "SERVICE_ID" NUMBER,
"ENG_ID" NUMBER,
"DESCRIPTION" VARCHAR2(200 BYTE),
"DATE_STARTED" DATE,
"DATE_TERMINATED" DATE,
"ACTIVE" NUMBER DEFAULT 1
Insert into SERVICE (SERVICE_ID,ENG_ID,DESCRIPTION,DATE_STARTED,DATE_TERMINATED,ACTIVE) values (1,1,'Counselling',to_date('15/09/12','DD/MM/RR'),to_date('18/09/12','DD/MM/RR'),1);
Insert into SERVICE (SERVICE_ID,ENG_ID,DESCRIPTION,DATE_STARTED,DATE_TERMINATED,ACTIVE) values (2,1,'Housing',to_date('20/09/12','DD/MM/RR'),null,1);
Insert into SERVICE (SERVICE_ID,ENG_ID,DESCRIPTION,DATE_STARTED,DATE_TERMINATED,ACTIVE) values (3,2,'Treatment',to_date('01/10/12','DD/MM/RR'),to_date('15/10/12','DD/MM/RR'),1);
Insert into SERVICE (SERVICE_ID,ENG_ID,DESCRIPTION,DATE_STARTED,DATE_TERMINATED,ACTIVE) values (4,3,'Housing',null,null,1);
Insert into SERVICE (SERVICE_ID,ENG_ID,DESCRIPTION,DATE_STARTED,DATE_TERMINATED,ACTIVE) values (5,1,'Other',to_date('05/10/12','DD/MM/RR'),null,0);
Insert into SERVICE (SERVICE_ID,ENG_ID,DESCRIPTION,DATE_STARTED,DATE_TERMINATED,ACTIVE) values (6,2,'Treatment',to_date('16/10/12','DD/MM/RR'),null,1);****
And this is the view I am thinking to use as the base for the report
CREATE OR REPLACE FORCE VIEW "BASE_VW"
AS
SELECT Def.Def_Id,
Def.First_Name,
Def.Last_Name,
Eng.Eng_Id,
Eng.Court_Name,
Eng.Date_Joined,
Eng.Date_Terminated,
Eng.Ethnicity,
Ser.Service_Id,
Ser.Description,
Ser.Date_Started AS Service_Start_Date,
Ser.Date_Terminated AS Service_Date_Terminated,
Ser.Active AS Service_Active,
Ev.Event_Id,
Ev.Related_Service_Id,
Ev.Start_Date,
Ev.End_Date,
Ev.Notes,
ev.active AS event_active
FROM Defendant Def
LEFT OUTER JOIN Engagement Eng
ON Def.Def_Id = Eng.Def_Id
LEFT OUTER JOIN Service Ser
ON Eng.Eng_Id = Ser.Eng_Id
LEFT OUTER JOIN Event Ev
ON Ev.Eng_Id = Eng.Eng_Id;****
Requirement:
Report parameter: Start Date, End Date, Court_name
From chosen Court_name, list defendants who currently engage in the court.
For each defendant display
Section 1: Identifying Details: First Name, Last Name, Ethnicity, Date Joined Court
Section 2: All Services currently active that the defendant attend
Section 3: All Events that related to the service that the defendant attend
Section 4: All other events (don't have Related Service ID)
User must be able to download the whole report in spreadsheet or PDF format.
I did try to create a set of union selects (but the format is not that good, when no data return it display nothing, I would rather show some messages like "There is no associated events, rather than nothing")
and it only produces report for 1 defendant at a time.
We use Oracle APEX , so only select statement or PL/SQL Code return select statement is valid for report source.
In our place we use Jasper Report adjacent to APEX, but I have very little experience with Jasper report.
The developer who knows a lot about jasper report is too busy to help me.
Currently, I use union selects like below:
With Current_Engagement As
( Select Eng_Id From Engagement
Where Def_Id =2
And Date_Joined Is Not Null
And ( Date_Terminated Is Null Or Date_Terminated > Sysdate)
And Rownum =1
Select '1.Defendant ID' as col1, 'First Name' as col2, 'Last Name' as col3, 'Court Name' as col4, 'Ethnicity' as col5, 'Date Joined' as col6, 'Date Terminated' as col7
From Dual
Union All
Select Distinct to_char(Def_Id), First_Name, Last_Name, Court_Name, Ethnicity, to_char(Date_Joined), to_char(Date_Terminated)
From Base_Vw Inner Join Current_Engagement Ce On Base_Vw.Eng_Id = Ce.Eng_Id
Union All
select '2.Service ID', 'Service Description', 'Start Date', 'End Date', Null, Null, Null
from dual
Union All
Select distinct to_char(service_id), description, to_char(service_start_date), to_char(service_date_terminated), null, null, null
From Base_Vw Inner Join Current_Engagement Ce On Base_Vw.Eng_Id = Ce.Eng_Id
where service_active =1
Union All
Select '3.Event ID', 'Related Service ID', 'Start Date', 'End date', 'Notes', null, null
From Dual
Union All
Select distinct to_char(event_id), to_char(related_service_id), to_char(start_date), to_char(end_date), notes, null, null
from Base_Vw Inner Join Current_Engagement Ce On Base_Vw.Eng_Id = Ce.Eng_Id
Where Event_Active = 1
and related_service_id is not null
Union All
Select '4.Event ID', 'Start Date', 'End date', 'Notes', null, null, null
From Dual
Union All
Select distinct to_char(event_id), to_char(start_date), to_char(end_date), notes, null, null, null
From Base_Vw Inner Join Current_Engagement Ce On Base_Vw.Eng_Id = Ce.Eng_Id
Where Event_Active = 1
and related_service_id is nulland the result is kind of what I try to achieve (except that I need to work on display a message 'No data found' rather than nothing), But it seems that my code works only for one defendant.
COL1 COL2 COL3 COL4 COL5 COL6 COL7
1.Defendant ID First Name Last Name Court Name Ethnicity Date Joined Date Terminated
2 John Doe BBB Asian 01/10/12
2.Service ID Service Description Start Date End Date
3 Treatment 01/10/12 15/10/12
6 Treatment 16/10/12
3.Event ID Related Service ID Start Date End date Notes
5 2 03/10/12
4.Event ID Start Date End date Notes
4 02/10/12
8 12/10/12
10 rows selected
However, I struggle to find a way to apply this to more than 1 defendant and still keep the format.
Defendant 1
All details related to defendant 1
Defendant 2
All details relayed to defendant 2
Defendant n
All details relayed to defendant nIs it possible to display a report as above by using only SQL script ?
Thanks a lot in advance. I am willing to compensate financially to someone who can give me a solution.
Edited by: Ann586341. View base_vw SQL script is fixed.Thanks a lot Jeneesh. (You are really a guru.)
It is nearly 98% what the requirements ask for.
I just have one more question.
If I add more information into the database, just one more defendant
Insert into DEFENDANT (DEF_ID,FIRST_NAME,LAST_NAME,ACTIVE) values (3,'Minnie','Mouse',1);
--and one in Engagement table
Insert into ENGAGEMENT (ENG_ID,DEF_ID,COURT_NAME,DATE_JOINED,DATE_TERMINATED,ETHNICITY,ACTIVE) values (4,3,'BBB',to_date('05/10/12','DD/MM/RR'),null,'Latin America','1');Then I run the select statment again (without changing anything)
With Current_Engagement As
( Select Eng_Id
From Engagement
Where /*Def_Id =2
And*/ Date_Joined Is Not Null
And ( Date_Terminated Is Null Or Date_Terminated > Sysdate)
--And Rownum =1
titles as
( Select .9 dummy_rn,'1.Defendant ID' as col1, 'First Name' as col2, 'Last Name' as col3,
'Court Name' as col4, 'Ethnicity' as col5, 'Date Joined' as col6,
'Date Terminated' as col7
From Dual
union all
select 1.9,'2.Service ID', 'Service Description', 'Start Date', 'End Date',
Null, Null, Null
from dual
union all
Select 2.9,'3.Event ID', 'Related Service ID', 'Start Date', 'End date', 'Notes',
null, null
From Dual
Union All
Select 3.9,'4.Event ID', 'Start Date', 'End date', 'Notes', null, null, null
From Dual
all_titles as
( select dummy_rn,eng_id,col1,col2,col3,col4,col5,col6,col7
from current_engagement,titles
select col1,col2,col3,col4,col5,col6,col7
from (
select dummy_rn,eng_id,col1,col2,col3,col4,col5,col6,col7
from all_titles
Union All
Select Distinct 1,ce.eng_id,decode(Base_Vw.Eng_Id,null,'No Data',to_char(Def_Id)) def_id,
decode(Base_Vw.Eng_Id,null,'No Data',First_Name) First_Name,
decode(Base_Vw.Eng_Id,null,'No Data',last_Name) Last_Name,
decode(Base_Vw.Eng_Id,null,'No Data',court_Name) Court_Name,
decode(Base_Vw.Eng_Id,null,'No Data',ethnicity) Ethnicity,
to_char(Date_Joined), to_char(Date_Terminated)
From Base_Vw
right outer join Current_Engagement Ce
On Base_Vw.Eng_Id = Ce.Eng_Id
Union All
Select distinct 2,ce.eng_id,
decode(Base_Vw.Eng_Id,null,'No Data',to_char(service_id)),
decode(Base_Vw.Eng_Id,null,'No Data',description) ,
decode(Base_Vw.Eng_Id,null,'No Data',to_char(service_start_date)),
decode(Base_Vw.Eng_Id,null,'No Data',to_char(service_date_terminated)) ,
decode(Base_Vw.Eng_Id,null,'No Data',null),
decode(Base_Vw.Eng_Id,null,'No Data',null),
decode(Base_Vw.Eng_Id,null,'No Data',null)
From Base_Vw
right outer Join Current_Engagement Ce
On Base_Vw.Eng_Id = Ce.Eng_Id
where service_active =1
Union All
Select distinct 3,ce.eng_id,
decode(Base_Vw.Eng_Id,null,'No Data',to_char(event_id)),
decode(Base_Vw.Eng_Id,null,'No Data',to_char(related_service_id)),
decode(Base_Vw.Eng_Id,null,'No Data',to_char(start_date)),
decode(Base_Vw.Eng_Id,null,'No Data',to_char(end_date)),
decode(Base_Vw.Eng_Id,null,'No Data',notes),
decode(Base_Vw.Eng_Id,null,'No Data',null),
decode(Base_Vw.Eng_Id,null,'No Data',null)
from Base_Vw
right outer Join Current_Engagement Ce
On Base_Vw.Eng_Id = Ce.Eng_Id
Where Event_Active = 1
and related_service_id is not null
Union All
Select distinct 4,ce.eng_id,
decode(Base_Vw.Eng_Id,null,'No Data',to_char(event_id)),
decode(Base_Vw.Eng_Id,null,'No Data',to_char(start_date)),
decode(Base_Vw.Eng_Id,null,'No Data',to_char(end_date)),
decode(Base_Vw.Eng_Id,null,'No Data',notes),
decode(Base_Vw.Eng_Id,null,'No Data',null),
decode(Base_Vw.Eng_Id,null,'No Data',null),
decode(Base_Vw.Eng_Id,null,'No Data',null)
From Base_Vw
right outer Join Current_Engagement Ce
On Base_Vw.Eng_Id = Ce.Eng_Id
Where Event_Active = 1
and related_service_id is null
order by eng_id,dummy_rn,col1
;The result is
COL1 COL2 COL3 COL4 COL5 COL6 COL7
1.Defendant ID First Name Last Name Court Name Ethnicity Date Joined Date Terminated
2 John Doe BBB Asian 01/10/12
2.Service ID Service Description Start Date End Date
3 Treatment 01/10/12 15/10/12
6 Treatment 16/10/12
3.Event ID Related Service ID Start Date End date Notes
5 2 03/10/12
4.Event ID Start Date End date Notes
4 02/10/12
8 12/10/12
1.Defendant ID First Name Last Name Court Name Ethnicity Date Joined Date Terminated
1 Joe Bloggs AAA European 22/09/12
2.Service ID Service Description Start Date End Date
4 Housing
3.Event ID Related Service ID Start Date End date Notes
7 4 23/09/12
4.Event ID Start Date End date Notes
6 22/09/12 23/09/12
1.Defendant ID First Name Last Name Court Name Ethnicity Date Joined Date Terminated
3 Minnie Mouse BBB Latin America 05/10/12
2.Service ID Service Description Start Date End Date
3.Event ID Related Service ID Start Date End date Notes
4.Event ID Start Date End date Notes
23 rows selected Is it possible in SQL to display it like this
COL1 COL2 COL3 COL4 COL5 COL6 COL7
1.Defendant ID First Name Last Name Court Name Ethnicity Date Joined Date Terminated
2 John Doe BBB Asian 01/10/12
2.Service ID Service Description Start Date End Date
3 Treatment 01/10/12 15/10/12
6 Treatment 16/10/12
3.Event ID Related Service ID Start Date End date Notes
5 2 03/10/12
4.Event ID Start Date End date Notes
4 02/10/12
8 12/10/12
1.Defendant ID First Name Last Name Court Name Ethnicity Date Joined Date Terminated
1 Joe Bloggs AAA European 22/09/12
2.Service ID Service Description Start Date End Date
4 Housing
3.Event ID Related Service ID Start Date End date Notes
7 4 23/09/12
4.Event ID Start Date End date Notes
6 22/09/12 23/09/12
1.Defendant ID First Name Last Name Court Name Ethnicity Date Joined Date Terminated
3 Minnie Mouse BBB Latin America 05/10/12
2.Service ID Service Description Start Date End Date
No Service Found
3.Event ID Related Service ID Start Date End date Notes
No Event Found
4.Event ID Start Date End date Notes
No Event FoundOr just a 'No data found' would do. I am thinking about create a dummy table which contains only one row with text "There is no data found". And so the outer join with the result, but I still cannot work out how to integrate with the condition in your select statement.
I really appreciate your help. -
Creating tabs for a single SQL report type region
I would like to find a way to use tabs in a single SQL report type region. The problem I have is that there are too many columns to be displayed so the report looks very cluttered. I would like to find a way to assign say columns 1 - 5 to tab 1, 6-10 to tab 2 etc so the user can find the columns they need by simply clicking on the various tabs without having to execute the query again.
I have looked at JQuery tabs but that seems to only be applicable to more or less unrelated regions. I tried to create different regions using the same query with different columns and that kind of works, but the regions don't stay in sync if say the user change the order for column 2 in tab 1, when they click on tab 2 everything displays in a different order.
Another wrinkle is that this is an updatable report so some of the columns are updatable.
I also looked at the hide / display column solution which is described in a few threads and that may also sort of work, but it is also not quite what I am looking for.
Any help is greatly appreciatedDoes anybody know if this can be accomplished using APEX? What I am really looking for is very similar to an old fashioned client / server screen developed using say Oracle Forms. Consider an order line screen where say columns line number, SKU and SKU description is to the left of the tabs so these columns are visible no matter which tab is active. Then the first tab has say pricing information including UOM, quantity, list price, unit selling price, price list. The next tab has say customer information including customer number, name, bill to and ship to addresses. the next tab has say shipping information with say the warehouse, shipping instructions and shipping method.
Maybe you are looking for
-
Open Directory Master creation failure.
I am running into consistent Failures while attempting to setup Open Directory Master on 10.8 server. It seems to fail in creating an Intermidiary CA and suggests there is already one. I have combed Keychain for, and removed any entires that refer to
-
I have 3 sql statements in my application (1 select/1 update and 1 insert) where I've noticed that after some time of working properly, all of a sudden these statements stop handling negative integers and instead process them as positive integers. i.
-
Hi! I would to edit on a JTree but my program doesn't work properly, the problem is that I don't know how many clicks I need to catch and assign a new name to the selected node. What I would like to do is with a double click to change the name of thi
-
Need a dump on indexes for a table
RDBMS novice here asking what is probably an easy one. How, in SQLPlus, can I get a spill on all the indexes of a specific table. In Oracle Rdb, the statement "show table (indexes) foo;" did the job. Looking for something similar in RDBMS. I need to
-
How do I create a smart playlist of songs that are not in any playlist?
I have zillions of songs and many playlists to manage them. So how do I create a smart playlist that shows songs that are not in any playlist? An easier answer would be " Playlist > is > None" but this option is not available. Any other creative solu