Report SQL query Help
Hi,
I am trying to call a procedure from a SQL report query. Please let me know if this is correct.
SELECT gb.period_name,
cc.segment1 uec,cc.segment2 dept, cc.segment3 other,
cc.segment4 acct,cc.segment5 subacct, cc.segment6 activity,
cc.segment7 cec, cc.segment8 subelement,cc.segment9 geo,
cc.segment10 usind,cc.segment11 affiliate,cc.segment12 mpc,
DECODE ( NVL (gb.begin_balance_dr_beq, 0)
- NVL (gb.begin_balance_cr_beq, 0),
0, ( NVL (gb.begin_balance_dr, 0)
- NVL (gb.begin_balance_cr, 0)
NULL, ( NVL (gb.begin_balance_dr, 0)
- NVL (gb.begin_balance_cr, 0)
NVL (gb.begin_balance_dr_beq, 0)
- NVL (gb.begin_balance_cr_beq, 0)
) AS Begining_balance_functional,
DECODE ( NVL (gb.period_net_dr_beq, 0)
- NVL (gb.period_net_cr_beq, 0),
0, ( NVL (gb.period_net_dr, 0)
- NVL (gb.period_net_cr, 0)
NULL, ( NVL (gb.period_net_dr, 0)
- NVL (gb.period_net_cr, 0)
NVL (gb.period_net_dr_beq, 0)
- NVL (gb.period_net_cr_beq, 0)
) AS period_to_date_functional,
(DECODE ( NVL (gb.begin_balance_dr_beq, 0)
- NVL (gb.begin_balance_cr_beq, 0),
0, ( NVL (gb.begin_balance_dr, 0)
- NVL (gb.begin_balance_cr, 0)
NULL, ( NVL (gb.begin_balance_dr, 0)
- NVL (gb.begin_balance_cr, 0)
NVL (gb.begin_balance_dr_beq, 0)
- NVL (gb.begin_balance_cr_beq, 0)
+ (DECODE ( NVL (gb.period_net_dr_beq, 0)
- NVL (gb.period_net_cr_beq, 0),
0, ( NVL (gb.period_net_dr, 0)
- NVL (gb.period_net_cr, 0)
NULL, ( NVL (gb.period_net_dr, 0)
- NVL (gb.period_net_cr, 0)
NVL (gb.period_net_dr_beq, 0)
- NVL (gb.period_net_cr_beq, 0)
) AS ending_balance_functional,
NVL (gb.begin_balance_dr, 0)
- NVL (gb.begin_balance_cr, 0) AS begining_balance_entered,
NVL (gb.period_net_dr, 0)
- NVL (gb.period_net_cr, 0) AS period_to_date_entered,
( NVL (gb.begin_balance_dr, 0)
- NVL (gb.begin_balance_cr, 0)
+ (NVL (gb.period_net_dr, 0) - NVL (gb.period_net_cr, 0)
) AS ending_balance_entered,
gb.currency_code,gb.period_year, gb.period_num,
apps.afl_gl_acct.get_value_description('ALCOA UEC',cc.segment1) UEC_Description, apps.afl_gl_acct.get_value_description('ALCOA Cost Center',cc.segment2) Cost_center_Description,
apps.afl_gl_acct.get_value_description('ALCOA Other',cc.segment3) Other_Description,
apps.afl_gl_acct.get_value_description('ALCOA Account',cc.segment4) Account_Description,
apps.afl_gl_acct.get_value_description('ALCOA SubAccount',cc.segment5) SubAccount_Description,
apps.afl_gl_acct.get_value_description('ALCOA Activity',cc.segment6) Activity_Description,
apps.afl_gl_acct.get_value_description('ALCOA CEC',cc.segment7) CEC_Description,
apps.afl_gl_acct.get_value_description('ALCOA SubElement',cc.segment8) SubElement_Description,
apps.afl_gl_acct.get_value_description('ALCOA GEO',cc.segment9) GEO_Description,
apps.afl_gl_acct.get_value_description('ALCOA US Ind',cc.segment10) US_Ind_Description,
apps.afl_gl_acct.get_value_description('ALCOA Affiliate',cc.segment11) Affil_Description,
afl_gl_acct.get_value_description('ALCOA MPC',cc.segment12) MPC_Description
FROM GL.GL_BALANCES GB, GL.GL_CODE_COMBINATIONS CC,
GL.GL_Budget_Versions GBV, GL.GL_SETS_OF_BOOKS GSB
WHERE GB.CODE_COMBINATION_ID = CC.CODE_COMBINATION_ID
-- And CC.SEGMENT1 = (se
And GB.BUDGET_VERSION_ID = GBV.BUDGET_VERSION_ID (+)
And GSB.SET_OF_BOOKS_ID = GB.SET_OF_BOOKS_ID
and decode(gb.TRANSLATED_FLAG,'Y','Translated','Entered') =:p_currency_type
AND cc.segment1 =:p_uec
AND GSB.NAME = :p_sob_name
AND gb.PERIOD_NAME= :p_period
AND cc.segment2= nvl(:p_dept,cc.segment2)
AND cc.segment3=nvl(:p_other,cc.segment3)
AND cc.segment4= nvl(:p_acct,cc.segment4)
AND cc.segment5= nvl(:p_subacct,cc.segment5)
AND cc.segment6 = nvl(:p_activity,cc.segment6)
AND cc.segment7 = nvl(:p_cec,cc.segment7)
and cc.segment8= nvl(:p_subelement,cc.segment8)
and cc.segment9= nvl(:p_geo,cc.segment9)
and cc.segment10=nvl(:p_usind,cc.segment10)
and cc.segment11=nvl(:p_affil,cc.segment11)
and cc.segment12=nvl(:p_mpc,cc.segment12)
AND gb.ACTUAL_FLAG = 'A'
AND gb.CURRENCY_CODE = :p_currency;
I am not completely sure of the syntax.
Regards,
JA
Please let me know if this is correct.Does it compile? Does it run? Does it return the correct result.
Please bear in mind we do not have access to your data models so we cannot run it. Nor do we know your business requirements so we cannot assess whether it implements them correctly. And it is way too big a hunk o' code for us to go through it manually.
As a rule of thumb it is better to build a small query and get that working correctly before adding tables to it rather than building an incomprehensibly large monolith.
Cheers, APC
Blog : http://radiofreetooting.blogspot.com/
Similar Messages
-
I recently posted this in the Gallery. If anyone has any modifications or enhancements please feel free to contribute! One thing that I'd like to be able to add to it is the ability to only display information for applications/packages that are
still published, so if anyone can figure out a crafty way to do it... Thanks!
http://gallery.technet.microsoft.com/App-V-Reporting-SQL-query-6695d3c3I recently posted this in the Gallery. If anyone has any modifications or enhancements please feel free to contribute! One thing that I'd like to be able to add to it is the ability to only display information for applications/packages that are
still published, so if anyone can figure out a crafty way to do it... Thanks!
http://gallery.technet.microsoft.com/App-V-Reporting-SQL-query-6695d3c3 -
hi all,
i created links for an element but for some element links the costing and balancing codes were mistakenly given wrong and the element links are plenty so i am unable to find which is wrongly given.
can some 1 out there provide me with the sql query that will allow me to create a report to run and confirm all the links have costing and balancing codes for all the earnings or voluntary deduction elements.
Thank you for reading my issue. plz help!See if the below helps.
Change the business group id in the query below-
select ppf.payroll_name
,pj.name Job,hou.name HR_ORG,ppg.group_name People_Group
,pel.employment_category
,hra.location_code
,pet.element_name,pet.reporting_name,pec.classification_name
,pel.costable_type
,pel.link_to_all_payrolls_flag
,pcak1.concatenated_segments Element_Cost_Segments
,pcak1.segment1
,pcak1.segment2
,pcak1.segment3
,pcak1.segment4
,pcak1.segment5
,pcak1.segment6
,pcak1.segment7
,pcak1.segment8
,pcak2.concatenated_segments Balancing_Cost_Segments
,pcak2.segment1
,pcak2.segment2
,pcak2.segment3
,pcak2.segment4
,pcak2.segment5
,pcak2.segment6
,pcak2.segment7
,pcak2.segment8
from pay_element_links_f pel
,apps.PAY_COST_ALLOCATION_KEYFLEX pcak1
,apps.PAY_COST_ALLOCATION_KEYFLEX pcak2
,pay_element_types_f pet
,pay_payrolls_f ppf
,pay_element_classifications pec
,per_jobs pj
,hr_all_organization_units hou
,PAY_PEOPLE_GROUPS ppg
,hr_locations_all hra
where pel.element_type_id = pet.element_type_id
and ppf.payroll_id(+) = pel.payroll_id
and pcak1.cost_allocation_keyflex_id(+) = pel.cost_allocation_keyflex_id
and pcak2.cost_allocation_keyflex_id(+) = pel.balancing_keyflex_id
and pet.business_group_id = 0
and pet.classification_id = pec.classification_id
and pj.job_id(+) = pel.job_id
and hou.organization_id(+) = pel.organization_id
and ppg.people_group_id(+) = pel.people_group_id
and hra.location_id(+) = pel.location_id
and sysdate between pel.effective_start_date and pel.effective_end_date
and sysdate between pet.effective_start_date and pet.effective_end_date
and sysdate between ppf.effective_start_date(+) and ppf.effective_end_date(+)
order by ppf.payroll_name,pec.classification_namePlease close the thread, if your issue is resolved.
Cheers,
VB -
SCCM 2012 All Updates report sql query
Need build sql query for report about all MS Updates like SCCM configuration manager view in window by path:
\Software Library\Overview\Software Updates\All Software Updates.
But I can't find fields that can show "product" (OS that use this patch) and size of each patch in SCCM and WSUS databases. Can anybody help me?To get file size I create query for files in package:
SELECT distinct ui.Title, ui.InfoURL, ui.DatePosted,
cf.FileName, cast(cast(cf.FileSize as real)/1024/1024 as decimal(10,2)) as SizeMb, uds.AssignmentName, uds.StartTime
FROM CI_ContentFiles cf
INNER JOIN v_UpdateContents uc ON cf.Content_ID = uc.Content_ID
INNER JOIN v_UpdateInfo ui ON uc.CI_ID = ui.CI_ID
INNER JOIN vSMS_UpdateDeploymentSummary uds ON ui.CI_ID = uds.CI_ID
join CI_ContentPackages cp on cf.Content_ID=cp.Content_ID
join CI_Contents co on co.Content_ID = cp.Content_ID
Where PkgID='MKL00032'
order by ui.InfoURL -
Tweak for sql query - help needed for smalll change
Hi.
I am trying to run a script that checks for used space on all tablespaces and returns the results.
So far so good:
set lines 200 pages 2000
col tablespace_name heading 'Tablespace' format a30 truncate
col total_maxspace_mb heading 'MB|Max Size' format 9G999G999
col total_allocspace_mb heading 'MB|Allocated' format 9G999G999
col used_space_mb heading 'MB|Used' format 9G999G999D99
col free_space_mb heading 'MB|Free Till Max' like used_space_mb
col free_space_ext_mb heading 'MB|Free Till Ext' like used_space_mb
col pct_used heading '%|Used' format 999D99
col pct_free heading '%|Free' like pct_used
break on report
compute sum label 'Total Size:' of total_maxspace_mb total_allocspace_mb used_space_mb - free_space_mb (used_space_mb/total_maxspace_mb)*100 on report
select
alloc.tablespace_name,
(alloc.total_allocspace_mb - free.free_space_mb) used_space_mb,
free.free_space_mb free_space_ext_mb,
((alloc.total_allocspace_mb - free.free_space_mb)/alloc.total_maxspace_mb)*100 pct_used,
((free.free_space_mb+(alloc.total_maxspace_mb-alloc.total_allocspace_mb))/alloc.total_maxspace_mb)*100 pct_free
FROM (SELECT tablespace_name,
ROUND(SUM(CASE WHEN maxbytes = 0 THEN bytes ELSE maxbytes END)/1048576) total_maxspace_mb,
ROUND(SUM(bytes)/1048576) total_allocspace_mb
FROM dba_data_files
WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
GROUP BY tablespace_name) alloc,
(SELECT tablespace_name,
SUM(bytes)/1048576 free_space_mb
FROM dba_free_space
WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
GROUP BY tablespace_name) free
WHERE alloc.tablespace_name = free.tablespace_name (+)
ORDER BY pct_used DESC
The above returns something like this:
MB MB % %
Tablespace Used Free Till Ext Used Free
APPS_TS_ARCHIVE 1,993.13 54.88 97.32 2.68
APPS_TS_TX_IDX 14,756.13 1,086.88 91.37 8.63
APPS_TS_TX_DATA 20,525.75 594.25 80.18 19.82
APPS_TS_MEDIA 6,092.00 180.00 74.37 25.63
APPS_TS_INTERFACE 13,177.63 366.38 71.49 28.51
The above works fine, but I would like to further change the query so that only those tablespaces with free space less than 5% (or used space more than 95%) are returned.
I have been working on this all morning and wanted to open it up to the masters!
I have tried using WHERE pct_used > 95 but to no avail.
Any advice would be appreciated.
Many thanks.
10.2.0.4
Linux Red Hat 4.Thanks for that.
What is confusing is that the below query works for every other (about 10 others) database but not this one (?)
SQL> set lines 200 pages 2000
SQL>
SQL> col tablespace_name heading 'Tablespace' format a30 truncate
SQL> col total_maxspace_mb heading 'MB|Max Size' format 9G999G999
SQL> col total_allocspace_mb heading 'MB|Allocated' format 9G999G999
SQL> col used_space_mb heading 'MB|Used' format 9G999G999D99
SQL> col free_space_mb heading 'MB|Free Till Max' like used_space_mb
SQL> col free_space_ext_mb heading 'MB|Free Till Ext' like used_space_mb
SQL> col pct_used heading '%|Used' format 999D99
SQL> col pct_free heading '%|Free' like pct_used
SQL>
SQL> break on report
SQL> compute sum label 'Total Size:' of total_maxspace_mb total_allocspace_mb used_space_mb - free_space_mb (used_space_mb/total_maxspace_mb)*100 on report
SQL>
SQL> select /*+ALL_ROWS */
2 alloc.tablespace_name,
3 alloc.total_maxspace_mb,
4 alloc.total_allocspace_mb,
5 (alloc.total_allocspace_mb - free.free_space_mb) used_space_mb,
6 free.free_space_mb+(alloc.total_maxspace_mb-alloc.total_allocspace_mb) free_space_mb,
7 free.free_space_mb free_space_ext_mb,
8 ((alloc.total_allocspace_mb - free.free_space_mb)/alloc.total_maxspace_mb)*100 pct_used,
9 ((free.free_space_mb+(alloc.total_maxspace_mb-alloc.total_allocspace_mb))/alloc.total_maxspace_mb)*100 pct_free
10 FROM (SELECT tablespace_name,
11 ROUND(SUM(CASE WHEN maxbytes = 0 THEN bytes ELSE maxbytes END)/1048576) total_maxspace_mb,
12 ROUND(SUM(bytes)/1048576) total_allocspace_mb
13 FROM dba_data_files
14 WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
15 GROUP BY tablespace_name) alloc,
16 (SELECT tablespace_name,
17 SUM(bytes)/1048576 free_space_mb
18 FROM dba_free_space
19 WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
20 GROUP BY tablespace_name) free
21 WHERE alloc.tablespace_name = free.tablespace_name (+)
22 ORDER BY pct_used DESC
23 /
((alloc.total_allocspace_mb - free.free_space_mb)/alloc.total_maxspace_mb)*100 pct_used,
ERROR at line 8:
ORA-01476: divisor is equal to zero -
I'm having trouble with an SQL query. I've created a simple logon page wherein a user will enter their user name and password. The program will look in an Access database for the user name, sort it by Date/Time modified, and check to see if their password matches the most recent password. Unfortunately, the query returns no results. I'm absolutely certain that I'm doing the query correctly (I've imported it directly from my old VB6 code). Something simple is eluding me. Any help would be appreciated.
private void LogOn() {
//make sure that the user name/password is valid, then load the main menu
try {
//open the database connection
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:LawOffice2000", "", "");
Statement select = con.createStatement();
String strTemp = "Select * From EMPLOYEES Where INITIALS = '" + txtUserName.getText() + "' Order By DATE Desc, TIME Desc";
ResultSet result = select.executeQuery(strTemp);
while(result.next()) {
if (txtPassword.getPassword().toString() == result.getString("Password")) {
MenuMain.main();
else {
System.out.println("Password Bad");
System.out.println(txtUserName.getText());
System.out.println(result.getString("Password"));
break; //exit loop
//close the connection
con.close(); }
catch (Exception e) {
System.out.println("LawOfficeSuite_LogOn: " + e);
return; }
}The problem is here: "txtPassword.getPassword().toString() == result.getString("Password"))"
Don't confuse String's equals() method with the equality operator '=='. The == operator checks that two references refer to the same object. If you want to compare the contents of Strings (whether two strings contain the same characters), use equals(), e.g. if (str1.equals(str2))...
Example:String s1 = "foo";
String s2 = new String("foo");
System.out.println("s1 == s2: " + (s1 == s2)); // false
System.out.println("s1.equals(s2): " + (s1.equals(s2))); // trueFor more information, check out Comparison operators: equals() versus == -
Discoverer Report - SQL Query to retrieve list of parameters
Hi
We have around 100 Discoverer reports and I'm trying to find the list of parameters used in each report.
Is there any SQL query that I can use to find the parameters used for each report
or
should I open the reports one by one to fetch the list of parameters used.
I checked the tables in EUL4_US schema but no luck.
- Amarnath.Kgive this a try for starters. It looks at the custom folders defined in the business area, which is where any LOV's defined for you parameters would be. As far as looking at the workbooks themselves, no, there is no way to do that in sql.
select
decode(eb.ba_created_by,'ORACLE_APPS','Seeded','Custom') Origin,
eb.ba_name business_area,
eo.OBJ_TYPE,
decode(eo.obj_type, 'SOBJ','From Database', 'CUO', 'Custom Query', 'COBJ', 'Complex Folder', eo.obj_type) obj_type_desc,
eo.OBJ_NAME folder,
eo.OBJ_DESCRIPTION folder_description,
decode(eo.sobj_ext_table, NULL, NULL, eo.obj_ext_owner || '.' || eo.sobj_ext_table) base_object,
decode(es.seg_obj_id, null, UPPER(trim(eo.obj_object_sql1)||trim(eo.obj_object_sql2)||trim(eo.obj_object_sql3))
, UPPER(trim(es.seg_chunk1) || trim(es.seg_chunk2) || trim(es.seg_chunk3) || trim(es.seg_chunk4))) SQL
from
eul4_us.EUL5_BAS eb,
eul4_us.EUL5_objs eo,
eul4_us.EUL5_BA_OBJ_LINKS ebol,
eul4_us.eul5_segments es
where
eb.BA_ID = ebol.BOL_BA_ID and
ebol.BOL_OBJ_ID = eo.OBJ_ID and
eo.obj_id = es.seg_obj_id (+) and
decode(eb.ba_created_by,'ORACLE_APPS','Seeded','Custom') = 'Custom'
order by
/*decode(eb.ba_created_by,'ORACLE_APPS','Seeded','Custom'), */eb.ba_name, ebol.BOL_SEQUENCE, es.seg_sequence -
SQL Query Help - Is this possible or impossible????
Hi guys,
I need help with an SQL query that I'm trying to develop. It's very easy to explain but when trying to implement it, I'm struggling to achieve the results that I want.....
For example,
I have 2 tables
The first table is:
1) COMPANY create table company (manufacturer varchar2(25),
date_established date,
location varchar2(25) );My sample test date is:
insert into company values ('Ford', 1902, 'USA');
insert into company values ('BMW', 1910, 'Germany');
insert into company values ('Tata', 1922, 'India');The second table is:
2) MODELS create table models (manufacturer varchar(25),
model varchar2(25),
price number(10),
year date,
current_production_status varchar2(1) ) ;My sample test data is:
insert into models values ('Ford', 'Mondeo', 10000, 2010, 0);
insert into models values ('Ford', 'Galaxy', 12000, 2008, 0);
insert into models values ('Ford', 'Escort', 10000, 1992, 1);
insert into models values ('BMW', '318', 17500, 2010, 0);
insert into models values ('BMW', '535d', 32000, 2006, 0);
insert into models values ('BMW', 'Z4', 10000, 1992, 0);
insert into models values ('Tata', 'Safari', 4000, 1999, 0);
insert into models values ('Tata', 'Sumo', 5500, 1996, 1);
insert into models values ('Tata', 'Maruti', 3500, 1998, 0);And this is my query:
SELECT
com.manufacturer,
com.date_established,
com.location,
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
mod.current_production_status
FROM
company com,
models mod
WHERE
mod.manufacturer = com.manufacturer
and com.manufacturer IN ('Ford', 'BMW', 'Tata')
and mod.current_production_status IN (1,0)
ORDER BY
mod.current_production_status DESCWhat I want the query to output is this:
com.manufacturer com.date_established com.location mod.model mod.price mod.year mod.current_production_status
Ford 1902 USA Escort 10000 1992 1
BMW 1910 Germany - - - 0
Tata 1922 India Sumo 5500 1998 1If current_production_status is 1 it means this particular model has been discontinued
If current_production_status is 0 it means the manufacturer does not have any discontinued models and all are in procuction.
The rule is only one record per manufacturer is allowed to have a current_production_status of 1 (so only one model from the selection the manufactuer offers is allowed to be discontinued).
So the query should output the one row where current_production_status is 1 for each manufacturer.
If for a given manufacturer there are no discontinued models and all have a current_production_status of 0 then ouput a SINGLE row that only includes the data from the COMPANY table (as above). The rest of the columns from the MODELS table should be populated with a '-' (hyphen).
My query as it is above will output all the records where current status is 1 or 0 like this
com.manufacturer com.date_established com.location mod.model mod.price mod.year mod.current_production_status
Ford 1902 USA Escort 10000 1992 1
Tata 1922 India Sumo 5500 1998 1
Ford 1902 USA - - - 0
Ford 1902 USA - - - 0
BMW 1910 Germany - - - 0
BMW 1910 Germany - - - 0
BMW 1910 Germany - - - 0
Tata 1922 India - - - 0
Tata 1922 India - - - 0However this is not what I want.
Any ideas how I can achieve the result I need?
Thanks!
P.S. Database version is '10.2.0.1.0'Hi Vishnu,
Karthiks query helped...
But this is the problem I am facing...
SELECT
com.manufacturer,
com.date_established,
com.location,
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
mod.current_production_status
FROM
company com,
models mod
WHERE
mod.manufacturer = com.manufacturer
and com.manufacturer = 'Ford'
and mod.current_production_status IN (1,0)
ORDER BY
mod.current_production_status DESCThe value of:
and com.manufacturer = 'Ford'will be dependent on front end user input....
When I run the query above I get all the rows where current_production_status is either 1 or 0.
I only require the rows where current_production_status is 1.
So if I amend it to look like this:
and mod.current_production_status = 1This works....
BUT if a user now passes in more than one manufacturer EG:
and com.manufacturer IN ('Ford', 'BMW')The query will only return the one row for Ford where current_production_status is 1. However because BMW has no models where current_production_status is 1 (all 3 are 0), I still want this to be output - as one row....
So like this:
com.manufacturer com.date_established com.location mod.model mod.price mod.year mod.current_production_status
Ford 1902 USA Escort 10000 1992 1
BMW 1910 Germany - - - 0So (hopefully you understand), I want both cases to be catered for.....whether a user enters one manufacturer or more than one...
Thanks you so much!
This is really driving me insane :-( -
Hi,
I require help for sql query. The query will be like
"SELECT * FROM XYZ WHERE TEXT = 'h*s' "
and the results will be come like
“his”
“homes”
“houses”
“horses”,
“horticulturalists”
“herbaceous”.
Thanks,
KapilHello,
SELECT *
FROM XYZ
WHERE TEXT LIKE ('h%s');Regards
Edited by: OrionNet on Feb 2, 2009 12:33 AM -
Sql query - help reqd (new)
Hi,
I have follwing dataset
"herb with garden"
"garden without herb"
"herb with zbc"
"garden with pqr"
Now i want sql query like
select * from table where text1 = "herb and garden"
This should populate
herb with garden
garden without herb
And
select * from table where text1 = "herb or garden"
This should populate
"herb with garden"
"garden without herb"
"herb with zbc"
"garden with pqr"SQL> with t
2 as
3 (
4 select 'herb with garden' str from dual union all
5 select 'garden without herb' str from dual union all
6 select 'herb with zbc' str from dual union all
7 select 'garden with pqr' str from dual
8 )
9 select *
10 from t
11 where lower(str) like '%herb%'
12 and lower(str) like '%garden%'
13 /
STR
herb with garden
garden without herb
SQL> with t
2 as
3 (
4 select 'herb with garden' str from dual union all
5 select 'garden without herb' str from dual union all
6 select 'herb with zbc' str from dual union all
7 select 'garden with pqr' str from dual
8 )
9 select *
10 from t
11 where lower(str) like '%herb%'
12 or lower(str) like '%garden%'
13 /
STR
herb with garden
garden without herb
herb with zbc
garden with pqr -
hi guys
i have sample data as mentioned below... need to find the duplicate rows where cd=cd and dt1=dt1 and tm1 difference should be less than or equal to 4 hrs..
i can get the data with the query written below but my problem is that i am not allowed to use in-built sql server function... can you help me in writing the same without using in-built function...
CREATE TABLE #t (id INT,dt1 datetime, tm1 datetime,cd varchar(10))
INSERT INTO #t VALUES (101,'2013-04-24','1900-01-01 12:20:00.000','TC')
INSERT INTO #t VALUES (101,'2013-04-24','1900-01-01 12:30:00.000','TC')
INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 14:30:00.000','MN')
INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 15:07:00.000','MN')
INSERT INTO #t VALUES (101,'2013-07-06','1900-01-01 09:07:00.000','XY')
INSERT INTO #t VALUES (101,'2013-11-27','1900-01-01 09:50:00.000','LM')
INSERT INTO #t VALUES (101,'2013-07-06','1900-01-01 15:07:00.000','XY')
select * From #t
WITH MyCTE (rn,id, dt1, tm1, cd)
AS(
select row_number() over (partition by id ORDER BY dt1, tm1) rn,* from #t
select case when ((dt1 = lead_start_Date) and (ct <='4.0') and (base_cd = lead_cd)) then 'Duplicate_Req' else '' end dt123,* from
select abs(convert(decimal(5,1),datediff(MI,lead_Start_time,tm1)/60.00)) ct, * from
SELECT base.rn b_rn,LEAd.rn l_rn,BASE.id
,BASE.dt1
,BASE.tm1
,base.cd base_cd
,LEAD.dt1 LEAD_START_DATE
,LEAD.tm1 LEAD_START_TIME
,lead.cd lead_cd
--,DATEADD(dd,-1,LEAD.dt1) EXPECTED_END_DATE
FROM MyCTE BASE
LEFT JOIN MyCTE LEAD ON BASE.id = LEAD.id
AND BASE.rn = LEAD.rn+1
) b
)cif this code will not work for you then not sure if there are any other options
Converted the CTE into an actual temp table.
CTE and barebones T-SQL code are included in the script below.
CREATE TABLE #t (id INT,dt1 datetime, tm1 datetime,cd varchar(10))
INSERT INTO #t VALUES (101,'2013-04-24','1900-01-01 12:20:00.000','TC')
INSERT INTO #t VALUES (101,'2013-04-24','1900-01-01 12:30:00.000','TC')
INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 14:30:00.000','MN')
INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 15:07:00.000','MN')
INSERT INTO #t VALUES (101,'2013-07-06','1900-01-01 09:07:00.000','XY')
INSERT INTO #t VALUES (101,'2013-11-27','1900-01-01 09:50:00.000','LM')
INSERT INTO #t VALUES (101,'2013-07-06','1900-01-01 15:07:00.000','XY')
INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 15:07:00.000','MN')
select * From #t
;WITH MyCTE (rn,id, dt1, tm1, cd)
AS(
select row_number() over (partition by id ORDER BY dt1, tm1) rn,* from #t
select case when ((dt1 = lead_start_Date) and (ct <='4.0') and (base_cd = lead_cd)) then 'Duplicate_Req' else '' end dt123,* from
select abs(convert(decimal(5,1),datediff(MI,lead_Start_time,tm1)/60.00)) ct, * from
SELECT base.rn b_rn,LEAd.rn l_rn,BASE.id
,BASE.dt1
,BASE.tm1
,base.cd base_cd
,LEAD.dt1 LEAD_START_DATE
,LEAD.tm1 LEAD_START_TIME
,lead.cd lead_cd
--,DATEADD(dd,-1,LEAD.dt1) EXPECTED_END_DATE
FROM MyCTE BASE
LEFT JOIN MyCTE LEAD ON BASE.id = LEAD.id
AND BASE.rn = LEAD.rn+1
) b
)c
select * into #copy From #t order by id, cd, dt1, tm1
alter table #copy add seqno int identity(1,1)
select distinct y.id,y.cd,y.dt1,y.tm1,y.seqno,case when z.cd is not null then 'Duplicate_Req' else '' end dt123
from #copy y
left outer join
(select a.id,a.cd,a.dt1,a.tm1
From #copy a
left outer join #copy b
on a.id = b.id
and a.cd = b.cd
and a.dt1 = b.dt1
where a.seqno > b.seqno
and abs(datediff(MINUTE,b.tm1,a.tm1)) <= 240) z
on y.id = z.id
and y.cd = z.cd
and y.dt1 = z.dt1
and y.tm1 = z.tm1
order by y.dt1,y.tm1
drop table #copy
drop table #t -
Hi,
I was wondering if I could have some help with the query I have below for this general data set, please? I need to do it in a single SQL statement. We're currently running Oracle 10g. The piece I'm struggling with is identifying that the person has all the items in a collection and to include the collection in the resulting collection of items.
persons_items
person item
Ted cup
Ted saucer
Ted plate
Ted fork
Alice book
Alice thimble
Alice knife
Alice cup
Joe cup
Joe saucer
Joe plate
Joe knife
Joe fork
Joe spoon
Jessica spatula
Jessica dish
collections
collection_name item
crockery cup
crockery saucer
crockery plate
cutlery knife
cutlery fork
cutlery spoon
Query:
What single items and collections does Ted have? fork, crockery
What single items and collections does Alice have? book, thimble, knife, cup
What single items and collections does Joe have? crockery, cutlery
What single items and collections does Jessica have? spatula, dish
Thanks in advance.
PatExpanding on Brendan's solution...
For 11g:
SQL> ed
Wrote file afiedt.buf
1 WITH person_items AS (
2 SELECT 'Ted' person, 'cup' item FROM DUAL UNION
3 SELECT 'Ted', 'saucer' FROM DUAL UNION
4 SELECT 'Ted', 'plate' FROM DUAL UNION
5 SELECT 'Ted', 'fork' FROM DUAL UNION
6 SELECT 'Alice', 'book' FROM DUAL UNION
7 SELECT 'Alice', 'thimble' FROM DUAL UNION
8 SELECT 'Alice', 'knife' FROM DUAL UNION
9 SELECT 'Alice', 'cup' FROM DUAL UNION
10 SELECT 'Joe', 'cup' FROM DUAL UNION
11 SELECT 'Joe', 'saucer' FROM DUAL UNION
12 SELECT 'Joe', 'plate' FROM DUAL UNION
13 SELECT 'Joe', 'knife' FROM DUAL UNION
14 SELECT 'Joe', 'fork' FROM DUAL UNION
15 SELECT 'Joe', 'spoon' FROM DUAL UNION
16 SELECT 'Jessica', 'spatula' FROM DUAL UNION
17 SELECT 'Jessica', 'dish' FROM DUAL
18 ), collections AS (
19 SELECT 'crockery' collection_name, 'cup' item FROM DUAL UNION
20 SELECT 'crockery', 'saucer' FROM DUAL UNION
21 SELECT 'crockery', 'plate' FROM DUAL UNION
22 SELECT 'cutlery', 'knife' FROM DUAL UNION
23 SELECT 'cutlery', 'fork' FROM DUAL UNION
24 SELECT 'cutlery', 'spoon' FROM DUAL
25 ), person_item_colls AS (
26 SELECT pi.person, pi.item, co.collection_name,
27 Count(*) OVER (PARTITION BY pi.person, co.collection_name) n_col
28 FROM person_items pi
29 LEFT JOIN collections co
30 ON co.item = pi.item
31 )
32 select person, listagg(collection_name,',') within group (order by collection_name) as collections
33 from (
34 SELECT DISTINCT person, collection_name
35 FROM person_item_colls
36 WHERE collection_name IS NOT NULL
37 AND n_col > 1
38 UNION ALL
39 SELECT person, item
40 FROM person_item_colls
41 WHERE collection_name IS NULL
42 OR n_col = 1
43 )
44* group by person
SQL> /
PERSON COLLECTIONS
Alice book,cup,knife,thimble
Jessica dish,spatula
Joe crockery,cutlery
Ted crockery,forkFor 10g:
SQL> ed
Wrote file afiedt.buf
1 WITH person_items AS (
2 SELECT 'Ted' person, 'cup' item FROM DUAL UNION
3 SELECT 'Ted', 'saucer' FROM DUAL UNION
4 SELECT 'Ted', 'plate' FROM DUAL UNION
5 SELECT 'Ted', 'fork' FROM DUAL UNION
6 SELECT 'Alice', 'book' FROM DUAL UNION
7 SELECT 'Alice', 'thimble' FROM DUAL UNION
8 SELECT 'Alice', 'knife' FROM DUAL UNION
9 SELECT 'Alice', 'cup' FROM DUAL UNION
10 SELECT 'Joe', 'cup' FROM DUAL UNION
11 SELECT 'Joe', 'saucer' FROM DUAL UNION
12 SELECT 'Joe', 'plate' FROM DUAL UNION
13 SELECT 'Joe', 'knife' FROM DUAL UNION
14 SELECT 'Joe', 'fork' FROM DUAL UNION
15 SELECT 'Joe', 'spoon' FROM DUAL UNION
16 SELECT 'Jessica', 'spatula' FROM DUAL UNION
17 SELECT 'Jessica', 'dish' FROM DUAL
18 ), collections AS (
19 SELECT 'crockery' collection_name, 'cup' item FROM DUAL UNION
20 SELECT 'crockery', 'saucer' FROM DUAL UNION
21 SELECT 'crockery', 'plate' FROM DUAL UNION
22 SELECT 'cutlery', 'knife' FROM DUAL UNION
23 SELECT 'cutlery', 'fork' FROM DUAL UNION
24 SELECT 'cutlery', 'spoon' FROM DUAL
25 ), person_item_colls AS (
26 SELECT pi.person, pi.item, co.collection_name,
27 Count(*) OVER (PARTITION BY pi.person, co.collection_name) n_col
28 FROM person_items pi
29 LEFT JOIN collections co
30 ON co.item = pi.item
31 )
32 select person, ltrim(sys_connect_by_path(collection_name,','),',') as collections
33 from (
34 select person, collection_name, row_number() over (partition by person order by collection_name) as rn
35 from (
36 SELECT DISTINCT person, collection_name
37 FROM person_item_colls
38 WHERE collection_name IS NOT NULL
39 AND n_col > 1
40 UNION ALL
41 SELECT person, item
42 FROM person_item_colls
43 WHERE collection_name IS NULL
44 OR n_col = 1
45 )
46 )
47 where connect_by_isleaf = 1
48 connect by person = prior person and rn = prior rn + 1
49* start with rn = 1
SQL> /
PERSON COLLECTIONS
Alice book,cup,knife,thimble
Jessica dish,spatula
Joe crockery,cutlery
Ted crockery,fork -
Hello,
I need help with SQL... My database version is Oracle 10g Release 1.2.
I have two table with the exact same structure as follows...
create table t1(cust_id number(5), zone_number number(2), part_number varchar2(10))
create table t2(cust_id number(5), zone_number number(2), part_number varchar2(10))
I need a query that would give me two counts per pairs of customer between t1 and t2..
1.Count of part_number matches between the same zones in table 1 and table 2 for pairs of customers
for Customer 1 and 10 for zone 1 this total shoulb be 2 because between cust 1 and 10 for Zone 1 there are two part number matches A and B.
for Customer 1 and 10 for zone 2 this total shoulb be 0 because between cust 1 and 10 for Zone 2 there are no part number matches
for Customer 1 and 20 for zone 1 this total shoulb be 0 because between cust 1 and 20 for Zone 1 there are no part number matches
for Customer 1 and customer 20 zone 2 this total shoulb be 0 because between cust 1 and 20 for Zone 2 there is one part number matches , which is 'F'
for Customer 1 and customer 20 zone 3 this total shoulb be 0 because there is no zone 3 for Customer 1
same way
.. cust 2 and cust 10 Zone 1 counts and zone2 counts
.. for 2 and cust 20 zone 1, 2, and 3 counts
2. Total unique Part nmbers between the same zones for pairs of customers in table 1 and table2
for example
unique part numbers between cust 1 and 10 for zone 1 are A,B and C so the count should be 3
unique part numbers between cust 1 and 10 for zone 2 are B,F, D and E so the count should be 3
unique part numbers between cust 1 and 20 for zone 1 are A,B,C and G so the count should be 4
and so on so forth
insert into t1 values(1, 1, 'A')
insert into t1 values(1, 1, 'B')
insert into t1 values(1, 1, 'C')
insert into t1 values(1, 2, 'B')
insert into t1 values(1, 2, 'F')
insert into t1 values(1, 2, 'D')
insert into t1 values(1, 2, 'E')
insert into t1 values(2, 1, 'F')
insert into t1 values(2, 2, 'G')
insert into t1 values(2, 2, 'H')
insert into t2 values(10, 1, 'A')
insert into t2 values(10, 1, 'B')
insert into t2 values(10, 2, null)
insert into t2 values(20, 1, 'G')
insert into t2 values(20, 2, 'F')
insert into t2 values(20, 2, 'H')
insert into t2 values(20, 3, 'I')
insert into t2 values(20, 3, 'J')
My query result should be as follows...
cust1 cust2 zone pn_match_count total_unique_pn_count
1 10 1 2 3
1 10 2 0 4
1 20 1 0 4
1 20 2 1 5
1 20 3 0 2
2 10 1 0 3
2 10 2 0 2
2 20 1 0 2
2 20 2 1 3
2 20 3 0 2
I would really appreciate your help in writing this query.
Thanks in Advanceuser00 wrote:
No, that doesn't do it... I get no results with this query becuase the Cust_id in table 1 and table 2 are not the same.Yeah, I only realised that after I posted my query. I had interpreted pairs as "matching pairs" when what you meant was "permutations".
Cheers, APC
blog: http://radiofreetooting.blogspot.com -
SQL Query Help/ Converts seconds to day:hr:mi:se
I have query that returns value in seconds. How i will convert those seconds in DAY:HOUR:MIN:SEC in the same query? What will be the mathematical formulae or alogorithim for this?
Thanks
Munis Warsi
nullSeriously, you post 750+ lines of unformatted SQL statement and a completely unreadable and unformatted explain plan and you expect people to be able to help with that?
From what I can see it looks like some sort of query against an Oracle APPS database, and there are numerous calls to PL/SQL functions in there, so you're creating a multitude of context switches between the SQL and PL engines... that's known to cause performance problems.
Take a read of the discussions linked in the FAQ: Re: 3. How to improve the performance of my query? / My query is running slow.
And also consider if your question would be better asked in the Oracle Apps forum space instead. -
String filtering SQL Query help
We have a table set up as follows
| Type | Content | Date |
(date is unimportant for my problem, however)
I have a string which I am checking to see if it contains any of the words in the table with the type 'TEXT' using the following query.
SELECT content FROM content_blocking WHERE type = 'TEXT' and upper(?) like upper('%' || content || '%')
Basically this filter is returning words that it should not because they are contained within legitimate words. Basically I would like to filter all of the words with type 'ACCTEXT', which we have just added, out of the string before I check for the unallowed words of type 'TEXT'
I have been hacking away at getting a query that can do it, but for some reason can't put my finger on exactly how to do it. If anyone could help, it would be greatly appreciated.
Thanks,
MarshallThere is Oracle Text functionality which already does this. Check it out ...
SQL> CREATE TABLE codex_verbumum_prohibitorum (naughty_word varchar2(10))
2 /
Table created.
SQL> INSERT INTO codex_verbumum_prohibitorum VALUES ('GOSH')
2 /
1 row created.
SQL> INSERT INTO codex_verbumum_prohibitorum VALUES ('CRIPES')
2 /
1 row created.
SQL> INSERT INTO codex_verbumum_prohibitorum VALUES ('CRIVVENS')
2 /
1 row created.
SQL> INSERT INTO codex_verbumum_prohibitorum VALUES ('HECK')
2 /
1 row created.
SQL> INSERT INTO codex_verbumum_prohibitorum VALUES ('SEMEN')
2 /
SQL> CREATE TABLE what_ever (id number, some_text varchar2(100))
2 /
Table created.
SQL> INSERT INTO what_ever VALUES (1, 'Blah blah blah cripes blah')
2 /
1 row created.
SQL> INSERT INTO what_ever VALUES (2, 'Blah blah blah gosh blah')
2 /
1 row created.
SQL> INSERT INTO what_ever VALUES (3, 'Blah blah blah poop blah')
2 /
1 row created.
SQL> INSERT INTO what_ever VALUES (4, 'Blah heck blah cripes blah')
2 /
1 row created.
SQL> INSERT INTO what_ever VALUES (5, 'Blah advertisement blah')
2 /
1 row created.
SQL> COMMIT
2 /
Commit complete.
SQL> CREATE INDEX cvp_word ON codex_verbumum_prohibitorum (naughty_word)
2 INDEXTYPE IS CTXSYS.CTXRULE
3 /
Index created.
SQL>
SQL> SELECT w.id, cvp.naughty_word
2 FROM codex_verbumum_prohibitorum cvp, what_ever w
3 WHERE MATCHES(cvp.naughty_word, w.some_text)>0
4 /
ID NAUGHTY_WO
1 CRIPES
2 GOSH
4 CRIPES
4 HECK
SQL> You'll notice I have taken a flier at what I think is the naughty word in "advertisement" ;)
You may also be interested in an alternate Text implementation posted by Re: forbidden words list and intermedia index.
Cheers, APC
I see the forum nanny still thinks p00p is a dirty word :(
Message was edited by:
APC
Maybe you are looking for
-
Deploy java components error in NW7.4 installation
Hi Experts, I am installing NW 7.4, i have done all the pre-installation steps but i am getting error at deploy java components. please find the log. please help me in this it is very urgent. I need your experience. An error occurred while processing
-
ITunes 10.6.3.25 fails to install
There is no explaination as to what the problem might be. I am running WIndows 7 32 bit.
-
Disk full. Will not reboot
While exporting a large number of pictures from iPhoto on an external drive to a folder on my desktop, my system froze. I think it ran out of disk space. I had to manually power off. When I rebooted, I got only a grey screen with a tiny finder window
-
I'm on an iMac OS 10.8.5 downloading thru a 3 month old card reader from multiple CF cards, importing to LR 5. For the first time yesterday 8 of 420 images immediately looked corrupted when the import finished. To troubleshoot I copied them from th
-
Adobe Captivate 6 Error when publishing
Help! I having trouble publishing a training that my employees can view. When they open the project they are getting the first image here that is essentially blank. I have attempted to reduce the size and save to different folders etc. but nothing