SQL & PL/SQL :: Using Decode Function With Group By Rollup?

Oct 18, 2010

I am trying to use decode funtion with GROUP BY ROLLUP.

MY query is working fine when i use this two queris individually

SELECT SUM(SAL),DEPTNO,JOB FROM EMP GROUP BY ROLLUP ((DEPTNO),(DEPTNO,JOB));
SELECT SUM(SAL),DEPTNO,JOB FROM EMP GROUP BY ROLLUP((JOB),(DEPTNO,JOB));
But when i use Decode funtion so that i can combine above two scenarios it is not working
SELECT SUM(SAL),DEPTNO,JOB FROM EMP GROUP BY ROLLUP ( DECODE(:A,'S',((DEPTNO),(DEPTNO,JOB) ),((JOB),(DEPTNO,JOB) ) ) )

View 3 Replies


ADVERTISEMENT

PL/SQL :: Group By Using Decode And Case?

May 14, 2013

my query is some thing like this but having more column in select. when i am firing this query it is giving result but that is not proper,\.

my problem is , like if there are 3 more values for uh.sflowtype (0,1,2) then group by is not working for them and those are coming in different row , i need them to be combined

query is :
select substr(uh.sstartdatetime,1,8) DateTime,
( case
when uh.sflowtype=7 then 'sms'
when uh.sflowtype=9 then 'mms'
when uh.sflowtype=10 then 'gprs'

[code]....

result :

DATETIME FLOWTYPE
-------- --------
20130507 voice
20130507 voice
20130507 voice
20130507 sms
20130507 mms

but i need

20130507 voice
20130507 sms
20130507 mms

so what should i do?

View 8 Replies View Related

SQL & PL/SQL :: How To Use Decode Function

Oct 31, 2011

How can i use the decode function?

for example

I have the value of 1000 then the numbers 50-100 will be 'A' and 1-49 = 'B'?

View 9 Replies View Related

SQL & PL/SQL :: Decode Function

Apr 4, 2013

DECODE(:P_PERIOD_TYPE,'PJTD','PROJECT-TO-DATE','PTD','PERIOD-TO-DATE','YTD','YEAR-TO-DATE')

what does it mean..

View 3 Replies View Related

SQL & PL/SQL :: Use Decode Function

Aug 19, 2010

select
DECODE(PAA.C_TYPE_DESC,'TXIS CASUAL LEAVE',NVL(PAA.ABSENCE_DAYS,0)) TCL,
DECODE(PAA.C_TYPE_DESC,'TXIS SICK LEAVE',NVL(PAA.ABSENCE_DAYS,0)) TSL,
DECODE(PAA.C_TYPE_DESC,'TXIS PRIVELEGE LEAVE',NVL(PAA.ABSENCE_DAYS,0)) TPL
from PER_ABSENCE_ATTENDANCES_V PAA

i want to use nvl function within decode function

means if C_TYPE_DESC is 'TXIS CAUSAL LEAVE' it return ABSENCE_DAYS but if ABSENCE_DAYS are null it will be return 0 else it should be return Absence_days

View 12 Replies View Related

PL/SQL :: To Create Function Based Index For Group Function Columns

Jun 15, 2012

Is anyway to create function based index for group function columns.

For example

select max(timestamp),min(age),averge(sal).... ... .. from tab;

View 5 Replies View Related

Using 2 Tables With Decode Function

Nov 8, 2009

What I have to do is this:

List supplier�s name, id, number of pending orders, number of completed orders and number of all orders from this supplier. (my query doesn't include the last part yet).

My tables are as follows:

Suppliers:
S_ID
NAME
ADDRESS
PROVINCE
PHONE_NUMBER

Orders:
ORD_ID
SUPPLIER_ID
ISSUING_EMP_ID
ORDER_DATE
ORDER_STATUS

and this is what I have so far:
select name, s_id
sum(decode(order_status, 'P',1,0)) pending,
sum(decode(order_status, 'C',1,0)) completed
from suppliers
where s_id in
(select supplier_id from orders);

but I still get an error that says "sum(decode(order_status, 'P',1,0)) pending,
*
ERROR at line 2:
ORA-00923: FROM keyword not found where expected"

I assume this is because I'm not properly referencing the orders table.

View 1 Replies View Related

SQL & PL/SQL :: Use DECODE Function For Getting Result

Aug 28, 2012

I have a table like Create temptbl (Client_status CHAR(1), Rollbak NUMERIC(3), count_org NUMERIC(3), count_member NUMERIC(3))

With Values
Cliet_Status Rollbak count_org count_member
------ ------- --------- ------------
Z 3 7 5
P 39 5 8
R 49 1 6
S 5 6 4

I need to use DECODE function for getting the result like

IF client_status NOT IN('Z', 'P')
THEN rollbak in(7, 39,49,10)and count_org is not null and count_member is not null.
ELSE NULL

View 3 Replies View Related

SQL & PL/SQL :: Assignment In Result In Decode Function

Dec 13, 2011

I have 3 tables.

Table 1 have 3 columns
ID, CUS_NAME, LOC
insert into table1 values (001,ABC,North);
insert into table1 values (002,DEF,South);
insert into table1 values (003,GHI,West);

Table 2 have 3 columns
ID, CUS_NAME, LOC
insert into table2 values (001,ABC,North);
insert into table1 values (002,DEF,East);
insert into table1 values (003,JKL,South);

Table 3 is Result_Tab table having 8 columns
ID, TAB1_CUS_NAME, TAB2_CUS_NAME, Cus_Name_Res, TAB1_CUS_LOC, TAB2_CUS_LOC, Cus_LOC_Res, Comment.

I have written two cursors which fetches data from both the tables and compares each data between each other and inserts the value into the result table.

the code is as follow:

Insert into Result_Tab values
(T1.ID, T1.Cus_Name, T2.Cus_Name, decode(T1.Cus_Name,T2.Cus_Name,'Y','N'),T1.LOC, T2.LOC, decode(T1.LOC,T2.LOC,'Y','N'),Null);

Now I want the resul as follows:
ID T1.N T2.N N_Res T1.L T2.L L_Res Comment
001 ABC ABC Y North North Y Null
002 DEF DEF Y South East N Loc
003 GHI JKL N West South N Name, Loc

Is there a way wherein i could capture the column names in decode function when it doesn't match, so that I can insert the same in the comment column.

View 4 Replies View Related

SQL & PL/SQL :: Can Call A Function Within Decode Statement

Oct 19, 2011

Can we call a function within decode statement. I am able to do the same for simple example function . But In my actual procedure it's giving the error message . Are there any restrictions to call function with in decode statement?

View 4 Replies View Related

SQL & PL/SQL :: Using Select Statement In Decode Function?

May 11, 2010

I am trying to use decode function in sql and inside decode function can I use select statement ?

here is my sql

select we.wf_entity_id, decode(object_type_id,
1, select audit_number from ea_audit_general where sys_audit_id=object_id
2,'test',
object_type_id
) from wf_entity we
where

[code]....

see this

decode(object_type_id,
1, select audit_number from ea_audit_general where sys_audit_id=object_id
2,'test',
object_type_id
)

will this work? Its not working for me?

View 2 Replies View Related

PL/SQL :: Using Function On Decode Or Case In Query

Mar 3, 2013

I am using oracle 11G database,I have to check length of name column value from employee table and if length(name) > 39 then value should be substr(name,0,39) else value should be name only. i tried below code

select CASE when length(name) > 39,substr(name,0,39)
else name
END

from employee but its not working ..can I do this using decode too ? ,,which one would be better or this is not a right way ?

View 3 Replies View Related

Forms :: Two Cursor Record Block - Decode Function

Sep 16, 2010

I have Two cursor record block..which is attached in form..

My TASK IS

In my first Block, When DBCR Column = 'D' Then in backend this column value should be save as a '1'
WHEN DBCR Column = 'C' Then Then in backend this column value should be save as a '2'

My Both Field is on Data Block...

In Property palette of this field can we write any decode condition..so it reflects directly on database.

View 2 Replies View Related

PL/SQL :: Group Function Is Not Allowed Here

Mar 3, 2013

Am running the below query and getting the error below :

ORA-00934: group function is not allowed here
SELECT   CONTRNO,
            SUBNO AS USER_CODE,
            TOTAL_POINTS AS AMOUNT,
            STARTDATE + 30 AS DATE_F,
            'SUB' USER_TYPE

[Code]....

View 4 Replies View Related

SQL & PL/SQL :: Rollup And Sorting

Jul 2, 2012

I have the following query

SQL>
SQL> SELECT DECODE(act.statement_flag, NULL, 'Total',act.statement_flag) "Monthly Statement?",
2 COUNT(account_id) "Count",
3 ROUND(((COUNT(account_id)/
(SELECT COUNT(account_id) FROM accounts
WHERE account_status_id = consts$.acct_sts_active))* 100),2) || '%' "Percent of Active Accounts"
4 FROM accounts act
5 WHERE act.account_status_id = consts$.ACCT_STS_active
6 GROUP BY ROLLUP(act.statement_flag)
SQL> /

Monthly Statement? Count Percent of Active Accounts
------------------ ---------- -----------------------------------------
N 1892 98.08%
Y 37 1.92%
Total 1929 100%

I want the output to be in the following fashion:

Monthly Statement? Count Percent of Active Accounts
------------------ ---------- -----------------------------------------
Y 37 1.92%
N 1892 98.08%
Total 1929

And I would also like to know is there another way to find the Percent of Active accounts in the query.

View 3 Replies View Related

SQL & PL/SQL :: How To Use Common Group By Function While Using Union All

Aug 12, 2010

i am having two sql query which i have made union of it but i need group by common.

select
distinct ac.CUSTOMER_NAME cust_name,
ac.CUSTOMER_NUMBER cust_no,
ps.CUSTOMER_SITE_USE_ID,
raa_ship_ps.PARTY_SITE_NAME loc,
sum(days_30.AMOUNT_DUE_REMAINING) D_30,

[code]........

View 9 Replies View Related

SQL & PL/SQL :: Analytical Function Instead Of Group By Clause?

Sep 18, 2012

I want to use Analytical function instead of group by clause for below query..

select
CASE
WHEN ADMT.SOURCESYSTEM ='CLU'
THEN COUNT(ADMT.TOTAL_COUNT)*5
ELSE COUNT(ADMT.TOTAL_COUNT)
END TOTAL_COUNT
from ESMARTABC.ABC_DRVR_MFAILS_TMP ADMT
group by ADMT.SOURCESYSTEM

View 1 Replies View Related

PL/SQL :: Cannot Get Wanted Data With MAX And GROUP BY Function

Jun 15, 2012

I have a table like below:

COLUMN     TYPE
USER_ID     VARCHAR2 (10 Byte)
PROCESS_ID     VARCHAR2 (30 Byte)
END_TIME     DATE(STAMP)
TO_LOC     VARCHAR2 (12 Byte)
TO_LOC_TYPE     VARCHAR2 (15 Byte)
FROM_LOC      VARCHAR2 (12 Byte)
ITEM_ID     VARCHAR2 (25 Byte)
CASES     NUMBER (12,4)
LMS_UDA1      VARCHAR2 (250 Byte)
ZONE     VARCHAR2 (2 Byte)

I only want get one record with all columns, only have one clause MAX(END_TIME) But the other column have difference value. when i use MAX(END_TIME) and GROUP BY USER_ID,PROCESS_ID,CASES,... the sql didnot give one record, It give many records

View 6 Replies View Related

SQL & PL/SQL :: Difference Between Rollup And Cube?

May 22, 2011

difference between rollup and cube with simple example.

View 2 Replies View Related

PL/SQL :: Rollup Grand Total?

Aug 8, 2013

I am trying to use rollup for a total, but it doesn't work because what I'm totaling is too conditional.  I even tried adding on the totals to the end using a union and a specialized function, but for some reason, the order by stops working when I do the union (all field aliases and types are the same).I know the structure of the query itself probably isn't the best, how I can get the grand total, The subtotals from the rollup work fine, though.

The order by query runs fine against both parts of the union when they are run individually, but once I make it part of the union - the first part of the order by is an unknown field and the second is not a SELECTed list expression.  I've commented out the union here.  The statement works fine without it except for the grand total being all 0s.  I kind of understand why it's all 0s, but not how to get around that.This is running in Oracle 10g2. I am trying to get totals for decisions by each of the four component values: ex_land, ex_imp,tx_land,tx_imp and then subtotals for each component values. 

That works for the following query, but I cannot get a grand total through the rollup.

CREATE  TABLE "FL_APP"   (    "APP_ID"                  NUMBER(*,0),    "FL_STAT_CODE"           VARCHAR2(20 BYTE),    CONSTRAINT "FL_APP PK" PRIMARY KEY ("APP_ID") ENABLE,    CONSTRAINT "FL_APP_FL_STAT_DIM_FK1" FOREIGN KEY ("FL_STAT_CODE")    REFERENCES "FL"."FL_STAT_DIM" ("FL_STAT_CODE") ON  DELETE    CASCADE ENABLE  ) ;CREATE  TABLE "FL_APP_PROP"  (    "APP_ID"            NUMBER(*,0),   "FL_DECISION_CODE" VARCHAR2(10

[code]....

View 8 Replies View Related

SQL & PL/SQL :: Pivot Query - ORA-00937 - Not A Single Group Function?

May 8, 2012

I am having the following pivot query but I am not able to run it is giving error msg

ORA-00937: not a single-group group function

SELECT DISTINCT
C.SHORT_NAME,
MAX (
COUNT (DECODE (TO_CHAR (a.reg_date_cur, 'MON'), 'JAN', A.CAR_NO))

[code]...

View 6 Replies View Related

SQL & PL/SQL :: Select Columns Of 3 Tables In Such A Way That Period Column Should Be In Group By Function

Aug 16, 2011

i want to select columns of 3 tables in such a way that period column should be in the group by function.

create view allocated_budgets_detail as
select ba.ba_fin_year, ba.ba_start_date, ba.ba_end_date, ba.ba_rev_no,
bh.bh_budget_code,
bd.bd_period,
bb.bb_entered_amount
from budget_header bh, budget_allocation ba, budget_distribution bd, budget_balance bb
where bh.bh_budget_id = ba.ba_budget_id
and ba.ba_line_id = bd.bd_budget_line_id
and ba.ba_line_id = bb.bb_budget_line_id
group by bd.bd_period

View 13 Replies View Related

JDeveloper, Java & XML :: Missing Expression And Then Group Function Not Allowed Error

Feb 23, 2011

I have 2 tables used in this problem: ODETAILS and ORDERS.

ODETAILS has the following columns: ONO, PNO, QTY, COST
ORDERS has the following columns: ONO, CNO, ENO, RECEIVED, SHIPPED, ORDER_COST

UPDATE ORDERS
SET ORDER_COST= 1 * ( select SUM(
SELECT COST
FROM ODETAILS
WHERE ORDERS.PNO=ODETAILS.PNO
)
);

In ODETAILS there can be more than 1 row for 1 order. So I'm trying to add all the COSTs in ODETAILS.

View 3 Replies View Related

Group Records With Less Than One Hour Separation And Count How Many Per Group

Nov 1, 2013

I'm trying to group sets of data based on time separations between records and then count how many records are in each group.

In the example below, I want to return the count for each group of data, so Group 1=5, Group 2=5 and Group 3=5

SELECT AREA_ID AS "AREA ID",
LOC_ID AS "LOCATION ID",
TEST_DATE AS "DATE",
TEST_TIME AS "TIME"
FROM MON_TEST_MASTER
WHERE AREA_ID =89
AND LOC_ID ='3015'
AND TEST_DATE ='10/19/1994';

[code]....

Group 1 = 8:00:22 to 8:41:22

Group 2 = 11:35:47 to 11:35:47

Group 3 = 15:13:46 to 15:13:46

Keep in mind the times will always change, and sometime go over the one hour mark, but no group will have more then a one hour separation between records.

View 4 Replies View Related

SQL & PL/SQL :: Combining Rownum And Group By Gives - Not A Group By Expression

Jun 23, 2011

I read that rownum is applied after the selection is made and before "order by". So, in order to get the sum of salaries for all employees in all departments with a row number starting from 1, i wrote :

select ROWNUM,department_id,sum(salary) from employees group by department_id

If i remove rownum, it gives the correct output. Why can't rownum be used here ?

View 16 Replies View Related

SQL & PL/SQL :: Group Through Expression Inside Group By?

May 17, 2011

Refer to the txt file to create table and insert data.

I executed the following query-

SELECT priority, detail, COUNT(1) FROM TEST GROUP BY priority, detail

and got the following result-

PRIORITYDETAIL COUNT(1)

StandardPatch 27
StandardInitial TSS 1
StandardInitial development 10
StandardProduction deployment5
High PriorPatch 1

Now I want that Initial TSS and Initial development should be combined as Initial together and I should get the result as follows:

PRIORITYDETAIL COUNT(1)

StandardPatch 27
StandardInitial 11
StandardProduction deployment5
High PriorPatch 1

View 3 Replies View Related

How To Use Decode And Sum

Nov 16, 2009

Which warehouses have pending orders for products, which are not in stock at the warehouse at the moment? Provide warehouse number, id of the product that is not in stock, number of orders issued for this product and total quantity ordered.

The tables I am using are

Warehouses:
Name Type
----------------------------------------
W_ID NUMBER(38)
CITY VARCHAR2(20)
W_SIZE NUMBER(38)

Inventories:
Name Type
-----------------------------------------
P_ID NUMBER(38)
W_ID NUMBER(38)
QUANTITY NUMBER(38)

Orders:
Name Type
-----------------------------------------
ORD_ID NUMBER(38)
SUPPLIER_ID NUMBER(38)
ISSUING_EMP_ID NUMBER(38)
ORDER_DATE DATE
ORDER_STATUS CHAR(1)

This is my code so far:

select w.w_id, i.p_id,
sum(decode(o.ord_id, ' ', i.p_id, 0)) Orders_issued,
select sum(i.quantity)
from
inventories i
orders o,

[code]...

but I get this error:

select sum(i.quantity)
*
ERROR at line 3:
ORA-00936: missing expression

View 2 Replies View Related

SQL & PL/SQL :: What Does DECODE Do

Sep 7, 2011

Just working with Unix for the first time and trying to understand this decode statement?

cursor l_cursor is select decode(type||'-'||to_char(line,'fm99999'),
'PACKAGE BODY-1','/'||chr(10), null) ||
decode(line,1,'create or replace ', '') ||
decode(type||'-'||to_char(line,'fm99999'),
'JAVA SOURCE-1','and compile ' || type || ' named "' ||
name || '"' || chr(10) || 'AS' || chr(10), '') ||
text text
from user_source
where upper(name) = upper(p_name)
order by type, line;

View 8 Replies View Related

SQL & PL/SQL :: Use Of Decode

Feb 28, 2011

In my Hard code i saw decode like this

DECODE(tablename.columnname,'k',text,NULL,text, NULL)

can I use decode like this.

View 6 Replies View Related

Alternative To DECODE In Regards To Just SQL (not PL)

Jul 1, 2007

im used to using PL SQL via oracle. but lately ive been doing a lot of mysql and PHP and i really need to use something similar to DECODE in my queries. or am i forced to do the checks via PHP.

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved