decode in from clause
Hi the gems... Good evening..Can we use DECODE in clause of a SELECT FROM statement...
I give an example below:
SELECT cust_name
DECODE ((SELECT currency OF currency_master),
"INR"
(SELECT * FROM cust_master_india);
(SELECT * DE cust_master_others))
currency_master table has only one line, USD or INR.
Is it possible to write a query like this... Please help...
Explain in words what are you trying to achieve. Looks like you want to select cust_name cust_master_india if the currency in the currency_master table is "INR", otherwise, you want to select cust_name cust_master_others.
SELECT t1.cust_name
FROM cust_master_india t1,
currency_master t2
WHERE t2.currency = 'INR'
UNION ALL
SELECT t1.cust_name
FROM cust_master_others t1,
currency_master t2
WHERE t2.currency = 'USD'
/
SY.
Tags: Database
Similar Questions
-
#OWNER # in FROM clause
I currently use APEX 4.2 to create traditional and interactive reports. I noticed that in the FROM clause
generated by the wizard #OWNER # is included in addition to the explicitly specified table in the
creating reports. Why is this it is included? Is it necessary? The application seems to work even when I
manually delete #OWNER # in the list.
I found a few discussions that suggest that this is potentially a security problem and that it is better
convenient to use only the tables in the FROM clause. Is this true?
Thank you.
Hello
You can remove it from the query, it will not make a real difference. It is very likely that in a future version of the TOP wizards add it more.
Concerning
Patrick
Member of the APEX development team
My Blog: http://www.inside-oracle-apex.com
APEX Plug-Ins: http://apex.oracle.com/plugins
Twitter: http://www.twitter.com/patrickwolf
-
How can I model the RPD with the sub query that has the subquery in the from Clause.
SELECT
o948938. CONSOLIDATED_NAME,
(SUM (o948992. YTD_COMPLETED)) / (SUM (TOTAL_OCC_AP)) AS C_1,.
SUM (TOTAL_OCC_AP) AS TOTAL_OCC_AP,
Of
ORG_DIM o948938,
TIME_MONTHLY_DIM o948963,
INSPECTION_FACT o948992,
(SELECT TDS_NUM,
MONTH_ID,
SUM (TOTAL_APTS) TOTAL_AP,
OF SUMMARY_FACT
TDS_NUM GROUP,
MONTH_ID
) O949126
WHERE (o949126. MONTH_ID = o948992. MONTH_ID (+)
AND o949126. TDS_NUM = o948992. TDS_NUM (+)
AND (o948938. TDS_NUM = o949126. TDS_NUM)
AND (O948963. MONTH_ID = O949126. MONTH_ID))
Group
O948938. NEW_BOROUGH_GROUPING
Hello
You can do this via an opaque view.
You can also do this by modeling the cumulative value as a calculation LOGIC in the group by aggregation "pinned" to a specific dimension hierarchy that reflects consolidation in the online posting.
Hope this helps,
Robert.
-
Results of the query variant with unused table in the from clause
Hi all
I (processing_table2) table specified in the FROM clause in the SQL query , but I have not used any of its value in the SQL statement , but it still affects the results of the query. Please help me out here I'm naïve.
This is the provided query
SELECT SUM((CREV.sadc_extd*CSSP.redit_pcnt)/100)
OF crev revenue_lines,.
cssp sales_split,
processing_table2
WHERE crev.order_num = '7631090072'
Results of the above query : 344028065018.359
SELECT
Sum((CREV.sadc_extd*CSSP.redit_pcnt)/100)
OF crev revenue_lines,.
sales_split PCSS
WHERE crev.order_num = '7631090072'
Results of the above query : 26463697309.1046
Someone here suggest me pls!924804 wrote:
Hi allI (processing_table2) table specified in the FROM clause in the SQL query , but I have not used any of its value in the SQL statement , but it still affects the results of the query. Please help me out here I'm naïve.
This is the provided query
SELECT SUM((CREV.sadc_extd*CSSP.redit_pcnt)/100)
OF crev revenue_lines,.
cssp sales_split,
processing_table2
WHERE crev.order_num = '7631090072'Results of the above query : 344028065018.359
SELECT
Sum((CREV.sadc_extd*CSSP.redit_pcnt)/100)
OF crev revenue_lines,.
sales_split PCSSWHERE crev.order_num = '7631090072'
Results of the above query : 26463697309.1046
Someone here suggest me pls!
CARTESIAN PRODUCT of the changes result set
-
Effect of an additional table in the FROM clause in the query results?
I recently helped a colleague debug one of their SQL statements
The output was showing some very unexpected totals, and I was able to shrink down to an additional table in the FROM clause, but not used anywhere else in the application.
Thus, for example
SELECT A.ID, B.CODE
Of
EMPLOYEE,
B OF THE STATUTE,
PAY THE SAL
WHERE A.ID = B.ID
AND
A.ID = 1;
I was wondering, how can an extra table in a FROM clause influence directly on the rest of the query?
The query above is just an example of what I've seen, the my co worker was working on is a bit larger and a lot more code to read. I noticed that when I added/removed the extra table in my query to co workers and then it worked as expected.
I always thought that an additional table is not attached to what anyone would be just to do the inefficient code, but does not affect outputjust do the inefficient code
Yes, that too, you will get a Cartesian product by calling is not the entries in the where clause for this table 'disappeared' :(
-
Question on the use of expressions and aliases in the FROM clause
Hello
I have the following query
outputs (of your choice):select substr(e.ename, iter.pos, 1) as C from (select 'KING' as ename from dual) e, (select rownum as pos from dictionary where rownum <= 100) iter where iter.pos <= length(e.ename);
For the purposes of hardcode 'KING' was made for the test, IRL would be a column from other tables. Is the other piece that is hardcoded "where rownum < = 100 ' and it's the one I would like to find a way to remove.C - K I N G
I tried the following:
Unfortunately this does not work because the SQL parser has not analyzed enough of the FROM clause to know e.ename causing the length (e.ename) expression return a message identifier unknown.select substr(e.ename, iter.pos, 1) as C from (select 'KING' as ename from dual) e, (select rownum as pos from dictionary where rownum <= length(e.ename)) iter where iter.pos <= length(e.ename);
I tried to restructure the query above to make the SQL parser aware of the e.ename early enough and therefore accept it. My efforts have failed.
I would like to know if there is a way to restructure the statement length (e.ename) can be used instead of Hardcoding an artificial upper limit (for example 100 as in the first statement).
Thank you
John.Use CONNECT BY LEVEL:
SQL> select substr(ename, level, 1) 2 from ( select 'KING' ename 3 from dual 4 ) 5 connect by level <= length(ename); S - K I N G 4 rows selected.
-
Error in FROM clause (MS Access)
I am getting an "error running a database query." The query is a simple
< name cfquery = "myquery" datasource = "#application.dsn #" >
SELECT *.
OF #url.table #.
< / cfquery >
The debugging info I get is the following:
SELECT * COMMAND
VENDORERRORCODE-3506
SQLSTATE 42000
It also indicates the error is in the FROM clause and only happens when url.table is stopped, not other names of tables. I know that the order table exist because I get an error of table name that does not exist when the url table is a false table name. This implies that
He knows the order table exist but said that there is a mistake in the FROM clause. The query is successful on all other tables in my db (MS access, I use the access without unicode driver). Any ideas?the order is a keyword, you will need to avoid using brackets
[ORDER]
HTH
--
Tim Carley
www.recfusion.com
[email protected] -
How to put the subquery in the from clause
Hi all
I want to put a my from clause subquery. I want to show the details of an account, when the status is active, but I want to show the date when he opened.
Here is my report query.
Select t.acct_id, x.acct_status_Dt
of cust_acct t, (select t1.acct_id, t1.acct_status_Dt from t1 cust_acct where t1.acct_status_code = 'OPEN') x
where t.acct_id = x.acct_td
and t.acct_status_code = 'ACTIVE'
Someone knows how to impliment this kind of query in OBIEE without RPD Exchange.
Help, please...Hello
To be more clear, ask in the Advanced tab of the request, should look like:
select A.saw_0, x.saw_1 from (select acct_id saw_0 from cust_acct)A, (select acct_id saw_0, acct_status_Dt saw_1 from cust_acct where cust_acct.acct_status_code='OPEN') x where a.saw_0=x.saw_0
Actual query that you pasted:
select t.acct_id,x.acct_status_Dt from cust_acct t , (select t1.acct_id, t1.acct_status_Dt from cust_acct t1 where t1.acct_status_code='OPEN') x where t.acct_id= x.acct_td and t.acct_status_code='ACTIVE'
I think it is x.acct_id in where clause... not x.acct_td, I corrected and wrote the sql above...
Published by: Kishore Guggilla, July 17, 2009 12:00
-
Join the table orders from clause
Hi all
Who is the effective way to join the tables in from clause. I have two tables first with 20 lakh records and second containing 10 lakh recods.
Who is the effective query 1 or 2. Please suggest me if you have an idea to rewrite the query.QUERY 1: SELECT T4.ID,T4.ISO_NAME FROM T,T4 WHERE T4.ISO_NAME LIKE '%US%' AND T.ID=T4.ID; QUERY 2: SELECT T4.ID,T4.ISO_NAME FROM T4,T WHERE T4.ID=T.ID AND T4.ISO_NAME LIKE '%US%'; T(ID IS PRIMARY KEY) (20 lakh records) T4 (ID IS PRIMARY KEY ) (10 lakh records) --------------------- ID ISO_NAME 100 US,UK,IN,BR 101 UK,US,BR,IN 102 BR,UK,US,IN Note: No index on ISO_NAME .
Kind regards
Rajasekhar
Published by: SuNRiZz68 on January 29, 2009 04:22In practical terms, Alex is right. Sometimes it matter what table is selected first, but does the CBO generally a very good job of deciding what you need to select the first (assuming that your statistics are up to date) but this is the situation you are trying to avoid as much as possible.
If you specify a table main command tables in the clause is not reliable and should be used - but think before using advice and don't do that when necessary.
Which table to select depends firstly on the join method in the execution plan. Nested loops joins perform better by selecting in the smaller table first, make a loop on the largest table. Joins the smaller set hash table in memory first, and then go through the larger table, perform searches in memory. He can't make any difference, what table is read using first the merger joins and sort.
Back to your original question. Using the cost-based optimizer, both queries will probably roll the same because newer versions of Oracle (9i, 10g) often transform queries for efficiency before the execution anyway. According to what do you or do not request should probably run a nested loop or hash join. With a small set of data creaing index and using a search of nested loops will probably be faster to avoid full table scans. the '%' in the LIKE clause leader would ignore an index on the ISO_NAME column in any case if a main column may be used in a composite index. All this is based on the approximation using the information provided; Tuning questions should always be tested to unexpected developments.
-
Number of tables in the from clause
Hello
Can someone tell me how many tables can we have clause in oracle.As you can see it
http://download.Oracle.com/docs/CD/B19306_01/server.102/b14237/limits003.htm#i288032
Subqueries levels Maximum of subqueries in a unlimited SQL in the FROM clause in subqueries queries Top Level 255 in the WHERE clause
Subqueries in the FROM-> unlimited, so number of tables is also unlimited (limited only by the size of SQL and probably time of your life while waiting to join thousands of tables :)) results
-
Hello
I need to use decode condition in where clause in such a way that if the respective column is null then consider the corresponding column
for example
Fee_date Fee_refund_date 10 OCTOBER 05 12 NOVEMBER 05 11 JANUARY 06 16 FEBRUARY 06 I have a request in place as below where p_fee_flag will be passed as either FEES or set to null, I check another condition as if p_fee_flag is null then fee_date must be set to null when comparing fee_refund_date between TRUNC (BKT. ACT_START_DATE) AND TRUNC (BKT. ACT_END_DATE
SELECT 1
BUCKET BKT
WHERE DECODE (P_FEE_FLAG, 'FEES', TRUNC(FS.) FEE_DATE), TRUNC (FS. FEE_REFUND_DATE))
BETWEEN TRUNC (BKT. ACT_START_DATE) AND TRUNC (BKT. ACT_END_DATE)
944524 wrote:
Hello Alberto,.
Thank you that's what I ask but is it possible to verify the condition even using decode
Yes, it is possible, but why?
Just replace the query in this way:
select * from fee_table f where exists(select 1 from bucket b where decode(:p_fee_flag, 'FEE', f.fee_date, f.fee_refund_date) between b.act_start_date and b.act_end_date) and decode(:p_fee_flag, 'FEE', null, f.fee_date) is null;
Kind regards.
Alberto
-
Hi all
I have this code in a trigger of pre-requete:
IF: RADIO_GROUP = 1
THEN
SET_BLOCK_PROPERTY('ALL_ADMITTED_PATIENT',QUERY_DATA_SOURCE_NAME, '(SELECT PM.PATIENT_FILE_NO, PE.EPISODE_NO, DECODE(CURRENT_LANG_P_S,''P'', PATIENT_NAME_P ||'' ''||PATIENT_NAME_2_P||'' ''|| PATIENT_NAME_3_P||'' ''||PATIENT_NAME_F_P, PATIENT_NAME_S ||'' ''||PATIENT_NAME_2_S||'' ''|| PATIENT_NAME_3_S||'' ''||PATIENT_NAME_F_S ) PATIENT_NAME , EXSYS.GET_AGE(PM.DATE_OF_BIRTH,SYSDATE) AGE , CODES_PKG.GET_DESCRIPTION(PM.GENDER,103) GENDER, CODES_PKG.GET_DESCRIPTION(PM.PATIENT_CATEGORY,110) PATIENT_CATEGORY, PE.ATTENDANCE_TYPE , PE.START_DATE , PE.END_DATE END_DATE, PE.PATIENT_INVOICE_NO ENCOUNTER_ID FROM RC_PATIENTS PM, RC_PATIENT_EPISODES PE WHERE PM.PATIENT_FILE_NO = PE.PATIENT_FILE_NO
There is a block that has points for each column in the select statement, next to an another element called ' clinical discharge Date "which I can't delete,.
because there is another code in the same trigger before query selects the column "Date of clinical discharge", the code is:
ELSIF: RADIO_GROUP = 2
THEN
SET_BLOCK_PROPERTY('ALL_ADMITTED_PATIENT',QUERY_DATA_SOURCE_NAME, '(SELECT PM.PATIENT_FILE_NO, PE.EPISODE_NO, DECODE(CURRENT_LANG_P_S,''P'', PATIENT_NAME_P ||'' ''||PATIENT_NAME_2_P||'' ''|| PATIENT_NAME_3_P||'' ''||PATIENT_NAME_F_P, PATIENT_NAME_S ||'' ''||PATIENT_NAME_2_S||'' ''|| PATIENT_NAME_3_S||'' ''||PATIENT_NAME_F_S ) PATIENT_NAME , EXSYS.GET_AGE(PM.DATE_OF_BIRTH,SYSDATE) AGE , CODES_PKG.GET_DESCRIPTION(PM.GENDER,103) GENDER, CODES_PKG.GET_DESCRIPTION(PM.PATIENT_CATEGORY,110) PATIENT_CATEGORY, PE.ATTENDANCE_TYPE , PE.START_DATE , NVL(PE.ACTUAL_END_DATE,PE.END_DATE)END_DATE , PE.PATIENT_INVOICE_NO ENCOUNTER_ID , PA.CLINICAL_DISCHARGE_DATE ----------------------------------------------------------------------------------------- this is the column FROM RC_PATIENTS PM, RC_PATIENT_EPISODES PE, AD_PATIENT_ADMISSIONS PA WHERE PA.ADMISSION_NO = PE.ADMISSION_NO AND PM.PATIENT_FILE_NO =PE.PATIENT_FILE_NO
So the only situation I have is to include the column 'CLINICAL_DISCHARGE_DATE' in the first select statement see you and add the table and then enclose it with other tables, but
I can't do this becaue if not done the join, it retrieves no data, so I can't add, and
of course, I see an error when I click on the: radio_group (1) because the element is existed without a column in the select list.
How to solve this problem,
I can't delete the point, and I can not add the column in the first select statement?
How?
Thank you
I found it, thank you,
I can add
To_date (null) or ANY DATE in the select statement.
Thank you
-
With the help of DECODE in WHERE clause
Hi, I have a query which goes like this but does not work:
{
SELECT NVL (SUM (NVL(r.cload,0) * NVL(r.duration,0)), 0)
IN saidi_sum_trip_caused_by
SPM_REL_IND_TMP r
WHERE substr(r.scode_trip_caused_by,6,4) in ('N001', 'N002', 'N003', 'N004', 'N005', "N006", "N007")
AND (r.cload 0 GOLD r.cload IS NOT NULL)
AND DECODE (R.CLASSIFICATION_TRIP, 't', r.duration < = 5,)
r.Duration > 5);
}
It seems that there is a problem with my DECODE statement since I've noticed that when you use the DECODE function, a column is assimilated before the DECODE. However, in this case I can't equate the value of r.duration for DECODING since if the value of R.CLASSIFICATION_TRIP is ' t "then I should use < = I use >." How can I go about it? I tried to post in the forums of PL/SQL, but I think that very few people access this area. I get answers faster from here. Thank you.Fact
-
Hello
Need help to form a request to meet the below condition.
I have to update the columns in table1 from table2, joining the table1 and table2 based on the primary key.
Similar to:
Update entire table1 (table1.champ1, table1.champ2) = (select Field1, Field2 from table2 where field3 = 'value')
where table1.pk_field = table2.pk_field
But table2 is not identified in the where clause. Please advice.
My database is oracle9i.
Thank you.Merge stmt is a good solution
-
Thanks in advance
I have table TAbleaa
Input parameter when = 1 then my where clause is a > 1
Input parameter when = 2 then my where clause is a < 1
Select * from tableaa
where (when case & 1 = 1 then a 1 >)
When & 1 = 2 then a < 1)
create table TABLEAA
(
A NUMBER,
PLEASE THE NUMBER,
NUMBER OF END,
NUMBER OF TEACHER,
AVERAGE NUMBER
)
;
Fast loading TABLEAA...
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (10, 1.5,.6,, 499, 500);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (1, 0,.1, 159, 159);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (2,.1,.2,, 159, 168);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (3,.2,.3, 179, 159);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (4,.1,.2, 250, 300);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (5,.2,.3, 320, 250);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (6,.3,.4,, 250, 380);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (7,.2,.3, 388, 379);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (8,.3,.4,, 379, 388);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (9,.4,.5, 388, 400);
insert into TABLEAA (A, START, END, TEACHER, AVERAGE)
values (11.5.6, 420, 448);
commit;
Published by: user1849 on August 26, 2009 14:32Select * from tableaa
cases where when & 1 = 1 and a > 1 then 1
When 1 = 2 & one< 1="" then="">
end = 1
Maybe you are looking for
-
HP 15 laptop: flickering horizontal line at the top of the screen
Hi, I bought this laptop 10 months ago and its been great until about a month ago. A month ago the hard drive doesn't work faster (Super slow r/w) and is noisy. 2 days ago a horizontal line at the top of the screen started flashing when I started the
-
How can I communicate with "Hotmail"?
I received this message by hotmail. Is - is this legitimate? I don't think I should send my password to anyone! -MR H. Welcome to Hotmail The effective way of the email Welcome to Hotmail. Windows MSN Hotmail is fast, more secure than ever before
-
Every time I restart my PC, I was above error... Then when I try and download the toolbar from Road runner, I get this (windows cannot access the specified device, path or file. You don't have permission from the appropriate permissions to access the
-
WINDOWS 10 AUDIO FOR DELL DRIVERS
So I did a clean install of Windows 10 on my Dell OptiPlex GX620 and there is no display drivers. I went to update in the Manager of devices but found nothing. I googled only to get this information from Dell. product not tested for Windows 10 upgrad
-
Problem of cloud creative instalation
Hello, I recently delete all adobe in my computer products, using select and cut into my c:/programfilesI want to download now, but when I run the Setup with the execution of the administrator, nothing happened.Then I try adobe cleaner but already th