Need help to write a query for Update statement with join
Hi there,
The following update statement gives me error as the given table in set statement is invalid. But its the right table .
Is the statement correct? Please help .
update (
select distinct(vpproadside.VEHICLE_CRED_OVERRIDE.vin)
from vpproadside.VEHICLE_CRED_OVERRIDE
join vpproadside.vpp_vehicle
on vpproadside.vpp_vehicle.vin = vpproadside.VEHICLE_CRED_OVERRIDE.vin
where VPP_CARRIER_SEQ_NUMBER = 90
and EXPIRY_DATE = '17-MAR-10'
set vpproadside.VEHICLE_CRED_OVERRIDE.EXPIRY_DATE = '15-SEP-10';Edited by: Indhu Ram on Mar 12, 2010 1:00 PM
Edited by: Indhu Ram on Mar 12, 2010 1:22 PM
Edited by: Indhu Ram on Mar 12, 2010 2:35 PM
Edited by: Indhu Ram on Mar 15, 2010 8:04 AM
Edited by: Indhu Ram on Mar 15, 2010 8:06 AM
Edited by: Indhu Ram on Mar 15, 2010 8:28 AM
Ask Tom has very good discussion about this, if UPDATE does not work for PK issue, you can use MERGE
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:760068400346785797
Similar Messages
-
Update statement with joining other tables
Hi ,
I have two table one is containing xml file , basically i need to read from those xml file then update to another table based on some condition.
UPDATE TRCB_XBRL_STG_2 STG
SET PROFIT =
case when xbrl.isconsolidatedacc='Y' and EXTRACTVALUE(XBRL.XBRLFILE,'//PROFIT ', 'xmlns:acra="..."') is not null
THEN EXTRACTVALUE(XBRL.XBRLFILE,'//PROFIT ', 'xmlns:acra="..."')
WHEN XBRL.ISCONSOLIDATEDACC='N' AND EXTRACTVALUE(XBRL.XBRLFILE,'//PROFIT ', 'xmlns:acra="..') IS NOT NULL
THEN extractValue(XBRL.xbrlfile,'//PROFIT ', 'xmlns:acra=".."')
ELSE STG.PROFIT
END,
SET REVENUE=
case when xbrl.isconsolidatedacc='Y' and EXTRACTVALUE(XBRL.XBRLFILE,'//REVENUE', 'xmlns:acra="..."') is not null
THEN EXTRACTVALUE(XBRL.XBRLFILE,'//REVENUE.', 'xmlns:acra="..."')
WHEN XBRL.ISCONSOLIDATEDACC='N' AND EXTRACTVALUE(XBRL.XBRLFILE,'//REVENUE', 'xmlns:acra="..') IS NOT NULL
THEN extractValue(XBRL.xbrlfile,'//REVENUE', 'xmlns:acra="REVENUE"')
ELSE STG.REVENUE
END,
... (around 100 columns)
FROM TRCB_XBRL xbrl ,TRCB_XBRL_STG_2 STG
WHERE STG.XBRL_ID = XBRL.XBRL_ID Number of columns are around 100 , please anyone suggest how to use update statement with joining two tables.Hi,
If all the values needed to update a given row of table_x are coming from the same row of table_y (or from the same row of a result set of a query involving any number of tables), then you can do something like this:
UPDATE table_x x
SET (col1, col2, col3, ...)
= (
SELECT NVL (y.col1, x.col1)
, NVL (y.col2, x.col2)
, NVL (y.col3, x.col3)
FROM table_y y
WHERE x.pkey = y.expr
AND ...
WHERE ...
;If the WHERE clause depends on the same row of table_y, then it will probably be simpler and more efficient to use MERGE instead of UPDATE.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Hi all, consider the tables and data below
CREATE TABLE table1 (id NUMBER, a NUMBER, b NUMBER) ;
CREATE TABLE table2 (id NUMBER, c NUMBER, d NUMBER);
INSERT INTO table1 VALUES(111,2,0);
INSERT INTO table1 VALUES(111,1,2);
INSERT INTO table1 VALUES(111,1,3);
INSERT INTO table1 VALUES(222,1,3);
INSERT INTO table2 VALUES(111,5,8);
INSERT INTO table2 VALUES(222,6,7);
what i want to do is write a UPDATE STATEMENT that joins the two tables BY id
and update table1 rows. i want to include the following CASE statement
UPDATE COLUMN a intable1 according to this logic
case
WHEN b >0
THEN nvl(c,b)
ELSE
d
END
so table1 after the update should look like this
id a b
111 8 0
111 5 2
111 5 3
222 6 3can somebody help write a update statement that update table1 according to case statement and joins both tables to get the values necessary? thanksHooray for sample tables!
SQL> alter table table2 add constraint table2_pk primary key (id);
Table altered.
SQL> update
2 (select t1.a
3 ,case when t1.b > 0 then nvl(t2.c, t1.b)
4 else t2.d
5 end new_value
6 from table1 t1
7 join table2 t2
8 on t1.id = t2.id
9 )
10 set a = new_value;
4 rows updated.
SQL> select * from table1;
ID A B
111 8 0
111 5 2
111 5 3
222 6 3 -
Help to write a query for cursor
Hi
I have a table trans_table which has records for all Credit (C) and Debit(D) entries for customers with the trans_date.
Now there is a column adj_amt which contains 0 for all D entries. But for C entries it contains current trans_amt - Prev trans_amt. If there is no prev record with C type then it is 0. i.e. If this the first C entry for a particular account then adj_amt will contain 0.
Below is the data.
create table trans_table (cust_id number, tran_date date, tran_amt number, tran_type char(1), adj_amt number);
1 01/01/2007 100 D 0
1 01/01/2007 100 D 0
1 01/02/2007 80 C 0
1 05/02/2007 200 C 120
1 08/02/2007 300 C 100
2 01/01/2007 100 D 0
2 05/01/2007 100 D 0
2 08/01/2007 100 D 0
2 09/01/2007 100 D 0
2 01/02/2007 90 C 0
2 05/02/2007 200 C 110
3 01/01/2007 100 D 0
3 05/01/2007 100 D 0
3 08/01/2007 100 D 0
4 01/01/2007 100 D 0
4 05/01/2007 100 D 0
4 06/01/2007 100 D 0
4 08/01/2007 100 D 0
4 10/01/2007 100 D 0
4 01/02/2007 100 C 0
Now hv to write a query whioch gives the cust_id , max(tran_amt) with D entry, max(trans_amt) wth C entry and if no C entry record then this column will be 0.
The output wud be klike this..
1 100 300
2 100 200
3 100 0
4 100 100
Since cust_id 3 has no C entry so 0 value in 3rd column.
Now i wrote a query for cust_id and 2nd column, but am not able to get the 3rd column.
Is it possible to get the above output..
I wud be using this query in a cursor which wud fetch from 20 million transactions.
Thanks in advance
Piks
(I am pasting the insert script if required)
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (4, to_date('01-02-2007', 'dd-mm-yyyy'), 100, 'C', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (4, to_date('05-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (4, to_date('01-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (4, to_date('10-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (4, to_date('08-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (4, to_date('06-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (3, to_date('08-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (3, to_date('05-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (3, to_date('01-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (2, to_date('05-02-2007', 'dd-mm-yyyy'), 200, 'C', 110);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (2, to_date('01-02-2007', 'dd-mm-yyyy'), 90, 'C', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (2, to_date('05-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (2, to_date('01-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (2, to_date('09-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (2, to_date('08-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (1, to_date('08-02-2007', 'dd-mm-yyyy'), 300, 'C', 100);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (1, to_date('05-02-2007', 'dd-mm-yyyy'), 200, 'C', 120);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (1, to_date('01-02-2007', 'dd-mm-yyyy'), 80, 'C', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (1, to_date('01-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (1, to_date('01-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);Hitherto an attempt:
test@ORA92>
test@ORA92> select * from trans_table;
CUST_ID TRAN_DATE TRAN_AMT T ADJ_AMT
4 02/01/2007 00:00:00 100 C 0
4 01/05/2007 00:00:00 100 D 0
4 01/01/2007 00:00:00 100 D 0
4 01/10/2007 00:00:00 100 D 0
4 01/08/2007 00:00:00 100 D 0
4 01/06/2007 00:00:00 100 D 0
3 01/08/2007 00:00:00 100 D 0
3 01/05/2007 00:00:00 100 D 0
3 01/01/2007 00:00:00 100 D 0
2 02/05/2007 00:00:00 200 C 110
2 02/01/2007 00:00:00 90 C 0
2 01/05/2007 00:00:00 100 D 0
2 01/01/2007 00:00:00 100 D 0
2 01/09/2007 00:00:00 100 D 0
2 01/08/2007 00:00:00 100 D 0
1 02/08/2007 00:00:00 300 C 100
1 02/05/2007 00:00:00 200 C 120
1 02/01/2007 00:00:00 80 C 0
1 01/01/2007 00:00:00 100 D 0
1 01/01/2007 00:00:00 100 D 0
20 rows selected.
test@ORA92>
test@ORA92> select
2 cust_id,
3 max(case when tran_type = 'D' then tran_amt else 0 end) as max_c,
4 max(case when tran_type = 'C' then tran_amt else 0 end) as max_d
5 from trans_table
6 group by cust_id;
CUST_ID MAX_C MAX_D
1 100 300
2 100 200
3 100 0
4 100 100
4 rows selected.
test@ORA92>
test@ORA92>Cheers
pratz -
Need help to write matrix query
Hi all,
I have the query . I'm getting output like this
chargetype amount start_date
DA1 170 04/01/2005
DA2 1170 04/01/2005
DA3 1730 04/01/2005
DA4 17 04/01/2005
DA5 -120 04/01/2005
DA6 0 04/01/2005
DA1 170 04/02/2005
DA2 2005 04/02/2005
DA3 590 04/02/2005
DA4 201 04/02/2005
DA5 340 04/02/2005
DA6 120 04/02/2005
I need my output like this
chargetype 04/01/2005 04/02/2005 04/03/2005 ......
DA1 170 170
DA2 1170 2005
DA3 1730 590
DA4 17 201
DA5 -120 340
DA6 0 120
pls help me out. your help is greatly appreciated.
the real query is .
SELECT st . sttl_item_nme charge_type,
SUM ( NVL ( sd . sttl_item_amt , 0 )) Adjustment ,
trunc(s . START_DT_GMT) start_date_gmt
from nm_sttl_item_dtl_type st ,
nm_sttl_item_dtl sd ,
nm_settlement s
where st . sttl_item_num = sd . sttl_item_num
and sd . sttl_id = s . sttl_id
and trunc(s . START_DT_GMT) between trunc(to_date('04/01/2005', 'mm/dd/yyyy')) and trunc(to_date('04/02/2005', 'mm/dd/yyyy'))
and s . ptcpt_cd = 'DEMO'
and s . sttl_pub_cd = ( select sttl_pub_cd
from nm_settlement c
where trunc(c.master_rpt_version_dt_sys) = (select trunc(max(ss.master_rpt_version_dt_sys))
from nm_settlement ss
where ss.ptcpt_cd = 'DEMO'
and ss.source_cd = 'ISO'
and trunc(ss.start_dt_gmt) = trunc(s.start_dt_gmt)
and sttl_id = s.sttl_id)
group by st . sttl_item_nme, trunc(s . START_DT_GMT)
order by trunc(s . START_DT_GMT), sttl_item_nme
Thanks & Regards,
Ramana.Search this site for "pivot" or "cross tab."
-
Need help in fixing the query for performance reasons
hi
I have a view in which I am calling a function to return some values I wand to get rid of the function and want to some how do all in the sql. Can I use case or something similar that will help me in avoiding the use of this function. Any help in this regard will highly be appreciated.
Query
SELECT SUBSTR(f_type_px17(ap.cidn,ap.currentstatusoid, 'DESC'), 1, 255)
from
px17_appointment ap,
/*context co_ap,*/
px17_payrollagreement pa,
px17_payrollgroup pg;
FUNCTION
CREATE OR REPLACE FUNCTION f_type_px17
fv_cidn IN px17_type_client.cidn%TYPE,
fv_oid IN px17_type_client.oid%TYPE,
fv_col IN VARCHAR2 DEFAULT NULL
) RETURN VARCHAR2 AUTHID CURRENT_USER AS
v_rtn_name px17_type_client.name%TYPE := NULL ;
v_rtn_desc px17_type_client.description%TYPE := NULL ;
BEGIN
IF fv_oid IS NOT NULL THEN
BEGIN
IF UPPER(SUBSTR(fv_oid,1,3)) = 'SYS' THEN
SELECT name, description
INTO v_rtn_name, v_rtn_desc
FROM px17_sys_type
WHERE oid = fv_oid
AND ROWNUM = 1 ;
ELSE
SELECT name, description
INTO v_rtn_name, v_rtn_desc
FROM px17_type_client
WHERE oid = fv_oid
AND cidn = fv_cidn
AND ROWNUM = 1 ;
END IF ;
EXCEPTION
WHEN no_data_found THEN
v_rtn_name := NULL ;
v_rtn_desc := NULL ;
END ;
END IF ;
IF (UPPER(NVL(fv_col, '~')) = 'NAME') THEN
RETURN v_rtn_name ;
ELSIF ((UPPER(NVL(fv_col, '~')) = 'DESC')
OR (UPPER(NVL(fv_col, '~')) = 'DESCRIPTION')) THEN
RETURN v_rtn_desc ;
ELSE
RETURN (NVL(v_rtn_name, CHR(155)) || '~' || NVL(v_rtn_desc, CHR(155))) ;
END IF ;
END f_type_px17 ;
/Well following is the whole code of a view and the functions releated, This will give you the whole picture and this query is running for long time.
create or replace view PX17_CHK_VW_SUMMARY_VW
(CIDN,BATCH_NUMBER, BUSINESS_UNIT, CHECK_VOUCHER_NUMBER, CHECK_VOUCHER_CODE, CHECKVIEW_CLOCK_NUMBER,
COMPANY_CHECKVIEW_HOME_DEPT, PERIOD_END_DATE, FEDERAL_TAX, GROSS_PAY, HOME_DEPARTMENT,
HOME_DEPARTMENT_DESC, LIVED_LOCAL_TAX_CODE, LIVED_STATE_TAX_CODE, LIVED_LOCAL_TAX, LIVED_STATE_TAX,
MEDICARE_TAX, NET_PAY, DEPARTMENT_WORKED_IN, PAY_TO_COMPANY_INDICATOR, PAY_DATE,
PAYROLL_NUMBER, SCHOOL_DISTRICT_TAX, CHECKVIEW_SCHOOL_DISTRICT, SOCIAL_SECURITY_TAX, SUI_SDI_TAX,
SUI_SDI_TAX_CODE, VOID_CHECK_INDICATOR, WEEK_NUMBER, WORKED_LOCAL_TAX_CODE, WORKED_STATE_TAX_CODE,
WORKED_LOCAL_TAX, WORKED_STATE_TAX, YEAR, COMPANY_CODE, FILE_NUMBER,
FIRST_NAME, LAST_NAME, LAST_NAME_FIRST_NAME, SOCIAL_SECURITY_NUMBER, STATUS,
OVERTIME_EARNINGS, OVERTIME_HOURS, REGULAR_EARNINGS, REGULAR_HOURS, VIEWPK,
HOME_COST_NUMBER, TAX_FREQUENCY, COMPANY_COST_NUMBER, COST_NUMBER_WORKED_IN, DISTRIBUTION_NUMBER,
TOTAL_DEDUCTIONS_AMOUNT, TOTAL_HOURS_AMOUNT, TOTAL_MEMO_AMOUNT, TOTAL_OTHER_EARNINGS, TOTAL_OTHER_HOURS,
CHECK_SEQ_NO, JOINKEY, CHECK_REVERSAL_INDICATOR
as
with user_security_homedept
AS
(select /*+ INLINE */ distinct cg.cidn,co_code,asso.oid,asso.name,department_Access ,t2.column_value dep,cg.oid
from px17_cocodegroup cg ,
px17_associate asso ,
px17_securityobject so,
px17_cocodegrp_securitygrp cs,
px17_security_group sg ,
TABLE(f_str2tbl_px17(cg.department_access)) t2
where cg.USEROID = asso.OID
and cg.co_code = substr(so.name,8,3)
and upper(asso.name) = upper(sys_context('payx_r17_app_context', 'app_userid'))
and cg.oid = cs.cocodegroupoid
and cs.securitygroupoid = sg.oid
and cg.cidn = asso.cidn
and cg.cidn = so.cidn
and cg.cidn = cs.cidn
and cs.cidn = sg.cidn
order by 2,1
user_security_cost_no
AS
(select /*+ INLINE */
cg.cidn,co_code,count(distinct cd.code)cost_no,cd.code
from px17_cocodegroup cg ,
px17_associate asso ,
px17_securityobject so,
px17_cocodegrp_securitygrp cs,
px17_security_group sg ,
px17_customaccessdetail cd
where cg.USEROID = asso.OID
and cg.co_code = substr(so.name,8,3)
and upper(asso.name) = upper(sys_context('payx_r17_app_context', 'app_userid'))
and cg.oid = cs.cocodegroupoid
and cs.securitygroupoid = sg.oid
and cg.oid = cd.cocodegroupoid(+)
and cg.cidn = cd.cidn(+)
and cg.cidn = asso.cidn
and cg.cidn = so.cidn
and cg.cidn = cs.cidn
and cs.cidn = sg.cidn
group by cg.cidn,co_code,cd.code
order by 2,1
super_user_check as
(SELECT
distinct a.cidn su_cidn,1 as su_user
FROM
px17_LINK LN
, px17_userprofile up
, px17_ASSOCIATE a
, px17_pcp_user pu
WHERE
a.oid = pu.oid
AND pu.userprofileoid = up.oid
AND LN.parentoid = up.oid
AND a.active = 1
AND a.cidn=pu.cidn
AND pu.cidn=up.cidn
AND ln.cidn=up.cidn
AND upper(a.name) = upper(sys_context('payx_r17_app_context', 'app_userid'))
AND upper(up.name) = upper('Super user')
nonsuper_user_check as
SELECT distinct a.cidn s_cidn , 1 as non_user
FROM
px17_LINK LN
, px17_userprofile up
, px17_ASSOCIATE a
, px17_pcp_user pu
WHERE
a.oid = pu.oid
AND pu.userprofileoid = up.oid
AND LN.parentoid = up.oid
AND a.active = 1
AND a.cidn=pu.cidn
AND pu.cidn=up.cidn
AND ln.cidn=up.cidn
AND upper(a.name) = upper(sys_context('payx_r17_app_context', 'app_userid'))
AND LN.childoid IN ( 'SYS:5:7478')
SELECT distinct
cidn
,batch_number Batch_Number
, business_unit Business_Unit
, check_voucher_number Check_Voucher_Number
, check_voucher_code Check_Voucher_Code
, clock_number CheckView_Clock_Number
, company_code_or_dept Company_CheckView_Home_Dept
, period_end_date Period_End_Date
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, 1, (INSTR(taxes_and_rates, '~', 1, 1) -1)), CHR(155), NULL)) Federal_Tax
, gross_pay Gross_Pay
, home_department Home_Department
, home_department_descr Home_Department_Desc
, SUBSTR(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 1) +1)
, INSTR(taxes_and_rates, '~', 1, 2) - (INSTR(taxes_and_rates, '~', 1, 1) +1)), CHR(155), NULL), 1, 32) Lived_Local_Tax_Code
, SUBSTR(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 2) +1)
, INSTR(taxes_and_rates, '~', 1, 3) - (INSTR(taxes_and_rates, '~', 1, 2) +1)), CHR(155), NULL), 1, 32) Lived_State_Tax_Code
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 3) +1)
, INSTR(taxes_and_rates, '~', 1, 4) - (INSTR(taxes_and_rates, '~', 1, 3) +1)), CHR(155), NULL)) Lived_Local_Tax
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 4) +1)
, INSTR(taxes_and_rates, '~', 1, 5) - (INSTR(taxes_and_rates, '~', 1, 4) +1)), CHR(155), NULL)) Lived_State_Tax
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 5) +1)
, INSTR(taxes_and_rates, '~', 1, 6) - (INSTR(taxes_and_rates, '~', 1, 5) +1)), CHR(155), NULL)) Medicare_Tax
, net_pay Net_Pay
, department_paid Department_Worked_In
, to_pay_indicator Pay_to_Company_Indicator
, pay_date Pay_Date
, payroll_number Payroll_Number
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 6) +1)
, INSTR(taxes_and_rates, '~', 1, 7) - (INSTR(taxes_and_rates, '~', 1, 6) +1)), CHR(155), NULL)) School_District_Tax
, SUBSTR(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 7) +1)
, INSTR(taxes_and_rates, '~', 1, 8) - (INSTR(taxes_and_rates, '~', 1, 7) +1)), CHR(155), NULL), 1, 32) CheckView_School_District
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 8) +1)
, INSTR(taxes_and_rates, '~', 1, 9) - (INSTR(taxes_and_rates, '~', 1, 8) +1)), CHR(155), NULL)) Social_Security_Tax
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 9) +1)
, INSTR(taxes_and_rates, '~', 1, 10) - (INSTR(taxes_and_rates, '~', 1, 9) +1)), CHR(155), NULL)) SUI_SDI_Tax
, SUBSTR(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 10) +1)
, INSTR(taxes_and_rates, '~', 1, 11) - (INSTR(taxes_and_rates, '~', 1, 10) +1)), CHR(155), NULL), 1, 32) SUI_SDI_Tax_Code
, void_check_indicator Void_Check_Indicator
, week_number Week_Number
, SUBSTR(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 11) +1)
, INSTR(taxes_and_rates, '~', 1, 12) - (INSTR(taxes_and_rates, '~', 1, 11) +1)), CHR(155), NULL), 1, 32) Worked_Local_Tax_Code
, SUBSTR(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 12) +1)
, INSTR(taxes_and_rates, '~', 1, 13) - (INSTR(taxes_and_rates, '~', 1, 12) +1)), CHR(155), NULL), 1, 32) Worked_State_Tax_Code
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 13) +1)
, INSTR(taxes_and_rates, '~', 1, 14) - (INSTR(taxes_and_rates, '~', 1, 13) +1)), CHR(155), NULL)) Worked_Local_Tax
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 14) +1)
, INSTR(taxes_and_rates, '~', 1, 15) - (INSTR(taxes_and_rates, '~', 1, 14) +1)), CHR(155), NULL)) Worked_State_Tax
, year Year
, company_code Company_Code
, file_number File_Number
, first_name First_Name
, last_name Last_Name
, name Last_Name_First_Name
, ssn Social_Security_Number
, status Status
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 15) +1)
, INSTR(taxes_and_rates, '~', 1, 16) - (INSTR(taxes_and_rates, '~', 1, 15) +1)), CHR(155), NULL)) Overtime_Earnings
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 16) +1)
, INSTR(taxes_and_rates, '~', 1, 17) - (INSTR(taxes_and_rates, '~', 1, 16) +1)), CHR(155), NULL)) Overtime_Hours
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 17) +1)
, INSTR(taxes_and_rates, '~', 1, 18) - (INSTR(taxes_and_rates, '~', 1, 17) +1)), CHR(155), NULL)) Regular_Earnings
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 18) +1)
, INSTR(taxes_and_rates, '~', 1, 19) - (INSTR(taxes_and_rates, '~', 1, 18) +1)), CHR(155), NULL)) Regular_Hours
, (company_code || '/' || ssn || '/' || file_number || '/' || TO_CHAR(payroll_number) || '/'
|| TO_CHAR(year) || '/' || TO_CHAR(week_number) || '/' || check_voucher_number
|| '/' || to_char(check_seq_num) || '/' || TO_CHAR(distribution_number)) Viewpk
, home_costnumber_desc Home_Cost_Number
, tax_frequency Tax_Frequency
, co_chkv_home_cost_no Company_Cost_Number
, cost_no_worked_in Cost_Number_Worked_In
, distribution_number Distribution_Number
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 19) +1)
, INSTR(taxes_and_rates, '~', 1, 20) - (INSTR(taxes_and_rates, '~', 1, 19) +1)), CHR(155), NULL)) Total_Deductions_Amount
, NVL(TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 20) +1)
, INSTR(taxes_and_rates, '~', 1, 21) - (INSTR(taxes_and_rates, '~', 1, 20) +1)), CHR(155), NULL)), 0) Total_Hours_Amount
, NVL(TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 21) +1)
, INSTR(taxes_and_rates, '~', 1, 22) - (INSTR(taxes_and_rates, '~', 1, 21) +1)), CHR(155), NULL)), 0) Total_Memo_Amount
, NVL(TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 22) +1)
, INSTR(taxes_and_rates, '~', 1, 23) - (INSTR(taxes_and_rates, '~', 1, 22) +1)), CHR(155), NULL)), 0) Total_Other_Earnings
, TO_NUMBER(REPLACE(SUBSTR(taxes_and_rates, (INSTR(taxes_and_rates, '~', 1, 23) +1)), CHR(155), NULL)) Total_Other_Hours
, check_seq_num Check_Seq_No
, (NVL(company_code, '~') || CHR(155) || NVL(file_number, '~') || CHR(155) || NVL(ssn, '~') || CHR(155) || NVL(TO_CHAR(year), '~') || CHR(155)
|| NVL(TO_CHAR(week_number), '~') || CHR(155) || NVL(TO_CHAR(payroll_number), '~')
|| CHR(155) || NVL(check_voucher_number, '~') || CHR(155) || NVL(TO_CHAR(check_seq_num), '~') || CHR(155) || NVL(TO_CHAR(distribution_number), '~')) Joinkey
, chk_reverse Check_Reversal_Indicator
FROM
SELECT
ch.cidn cidn
/*BATCH NUMBER*/
, ch.batch_nb batch_number
, /*BUSINESS UNIT*/
(select asso.description
from px17_appointment ap,
px17_jobposition jp,
px17_corporation co,
px17_associate asso,
px17_payrollagreement pa,
px17_payrollgroup pg
where
ch.cidn = pg.cidn
AND ch.cidn = pa.cidn
AND pa.cidn = pg.cidn
AND pa.cidn = ap.cidn
AND em.cidn = ap.cidn
AND ap.cidn = jp.cidn
and jp.cidn = co.cidn
and co.cidn = asso.cidn
and ch.co_code=pg.co_code
and ch.file_nb=pa.file_number
and pa.cocodeoid=pg.oid
and pa.appointmentoid=ap.oid
and em.oid=ap.employmentoid
and ap.jobpositionoid=jp.oid
and jp.corporationoid=co.oid
and co.oid=asso.oid) business_unit
, /*CHECK/VOUCHER NUMBER*/
ch.check_nb check_voucher_number
, /*CHECK/VOUCHER CODE*/
SUBSTR(f_type_px17(ch.cidn,ch.chkvchcodeoid, 'NAME'), 1, 255) check_voucher_code
, /*CLOCK NUMBER*/
ch.clock_id clock_number
, /* COMPANY CODE OR DEPT*/
ch.co_code||'/'||substr(ch.home_dept_code,1,20) company_code_or_dept
, /*PERIOD END DATE*/
ch.payroll_ending_date period_end_date
, /*GROSS PAY*/
NVL(chd.gross_pay_amt,0) gross_pay
, /*HOME DEPARTMENT*/
ch.home_dept_code home_department
, /*HOME DEPARTMENT DESCRIPTION*/
(select ty.description
from px17_type ty,px17_securityobject sc
where
ch.cidn = sc.cidn
and ty.cidn in ('COMMON', ch.cidn)
and ch.home_dept_code=ty.name
and ty.category='T_CO_DEPT'
and ty.securityoid=sc.oid
and ch.co_code=substr(sc.name,8)) home_department_descr
, /*NET PAY*/
nvl(chd.net_pay_amt,0) net_pay
, /*DEPARTMENT PAID*/
-- ch.paid_in_debt_code department_paid
chd.worked_in_dept department_paid
, /*TO PAY INDICATOR*/
decode(to_char(ch.pay_to_co),'1','Y','0','N',to_char(ch.pay_to_co)) to_pay_indicator
, /*PAY DATE*/
ch.pay_date pay_date
, /*PAYROLL NUMBER*/
to_char(ch.payroll_nb) payroll_number
, /*VOID CHECK INDICATOR*/
decode(to_char(ch.void_flag),'1','Y','0','N',to_char(ch.void_flag)) void_check_indicator
, /*WEEK NUMBER*/
TO_number(ch.week) week_number
, /*YEAR*/
to_char(ch.year) year
, /*COMPANY CODE*/
ch.co_code company_code
, /*FILE NUMBER*/
LPAD(ch.file_nb,6,0) file_number
, /*FIRST NAME*/
pe.first_name first_name
, /*LAST NAME*/
pe.last_name last_name
, /*NAME*/
pe.last_name||', '||pe.first_name name
, /*SSN*/
payx_r17_principal_info.masked_ssn(pe.unique_id, ch.cidn) ssn
, /*STATUS*/
(SELECT SUBSTR(f_type_px17(ap.cidn,ap.currentstatusoid, 'DESC'), 1, 255)
from
px17_appointment ap,
/*context co_ap,*/
px17_payrollagreement pa,
px17_payrollgroup pg
where
pg.cidn=ch.cidn
and pa.cidn=ch.cidn
and ap.cidn=pa.cidn
and ap.cidn = em.cidn
and ap.employmentoid=em.oid
and ap.active=1
and ap.oid=pa.appointmentoid
and lpad(to_char(pa.file_number),6,0)=ch.file_nb
and pa.cocodeoid=pg.oid
and pg.co_code=ch.co_code) status
-- FED TAX
-- , LIVED LOCAL TAX CODE, LIVED STATE TAX CODE, LIVED LOCAL TAX, LIVED STATE TAX, MEDICARE TAX
-- , SCHOOL DISTRICT TAX, SCHOOL DISTRICT, SOCIAL SECURITY TAX, SUI SDI TAX, SUI SDI TAX CODE
-- , WORKED LOCAL TAX CODE, WORKED STATE TAX CODE, WORKED LOCAL TAX, WORKED STATE TAX
-- , OVERTIME EARNINGS, OVERTIME HOURS, REGULAR EARNINGS, REGULAR HOURS
NVL (
(SELECT
TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2982', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
|| NVL(MAX(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2984', ci.code, NULL), NULL)), CHR(155)) || '~'
|| NVL(MAX(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2987', DECODE(ci.code,'XX',null,ci.code), NULL), NULL)), CHR(155)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2984', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2987', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:4118', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:4114', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
|| NVL(MAX(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:4114', ci.code, NULL), NULL)), CHR(155)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2988', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2989', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
|| NVL(MAX(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2989', ci.code, NULL), NULL)), CHR(155)) || '~'
|| NVL(MAX(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2983', ci.code, NULL), NULL)), CHR(155)) || '~'
|| NVL(MAX(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2986', ci.code, NULL), NULL)), CHR(155)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2983', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3709', DECODE(ci.taxcodeoid, 'SYS:4:2986', NVL(ci.amount,0), 0), 0) ), 0)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3713', NVL(ci.amount,0), 0)), 0)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3727', NVL(ci.amount,0), 0)), 0)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3715', NVL(ci.amount,0), 0)), 0)) || '~'
|| TO_CHAR(NVL(SUM(DECODE(ci.histtypeoid, 'SYS:4:3716', NVL(ci.amount,0), 0)), 0)) || '~'
-- R16 columns.
-- Total Deductions Amount === Other Deductions on UI screen.
|| TO_CHAR(NVL(SUM(DECODE(chcat.name, 'DeductionHistory'
, DECODE(NVL(ci.statutory_ded, 0), 0
, DECODE(ci.taxcodeoid, NULL
, DECODE(ci.code, NULL, 0, NVL(ci.amount,0)), 0), 0), 0)), 0)) || '~' -- "Total Deductions Amount"
|| TO_CHAR(NVL(SUM(DECODE(chcat.name, 'OvertimeHours', NVL(ci.amount,0)
, 'AdditionalHours', NVL(ci.amount,0), 'RegularHours', NVL(ci.amount,0), 0)), 0)) || '~' -- "Total Hours Amount"
|| TO_CHAR(NVL(SUM(DECODE(chcat.name, 'Memo', NVL(ci.amount,0), 0)), 0)) || '~' -- "Total Memo Amount"
|| TO_CHAR(NVL(SUM(DECODE(chcat.name, 'AdditionalEarnings', NVL(ci.amount,0), 0)), 0)) || '~' -- "Total Other Earnings"
|| TO_CHAR(NVL(SUM(DECODE(chcat.name, 'AdditionalHours', NVL(ci.amount,0), 0)), 0)) -- "Total Other Hours"
FROM
px17_checkhistoryitem ci
, px17_sys_type chcat
WHERE
ci.cidn=chd.cidn
AND ci.checkhistorydistributionoid = chd.oid
AND chcat.category = 'CheckHistoryItem'
AND chcat.oid = ci.histtypeoid
-- AND ci.histtypeoid IN ('SYS:4:3713', 'SYS:4:3727', 'SYS:4:3715', 'SYS:4:3716', 'SYS:4:3709')
), '0' || '~' || CHR(155) || '~' || CHR(155)
|| '0~0~0~0~' || CHR(155) || '~0~0~' || CHR(155) || '~' || CHR(155) || '~'
|| CHR(155) || '~0~0~0~0~0~0'
) taxes_and_rates
, ch.check_seq_num check_seq_num
, ch.home_cost_number home_costnumber_desc
, SUBSTR(f_type_px17(ch.cidn,ch.payfrequencyoid, 'NAME'), 1, 255) tax_frequency
, (ch.co_code || '/' || ch.home_cost_number) co_chkv_home_cost_no
, chd.worked_in_cost_number cost_no_worked_in
, chd.distribution_number distribution_number
, DECODE(NVL(ch.reversed_flag, 0), 1, 'Y', 'N') chk_reverse
FROM
px17_checkhistory ch
, px17_employment em
, px17_person pe
, px17_payrollgroup pg
, px17_checkhistory_dist chd
, px17_appointment ap
WHERE
ch.cidn = em.cidn
and em.cidn = pe.cidn
and pg.cidn = ch.cidn
and ch.cidn = chd.cidn
and ap.cidn(+) = em.cidn
and ch.employmentoid=em.oid
AND em.personoid=pe.oid
AND pg.co_code = ch.co_code
AND ch.active = 1
AND ch.oid = chd.checkhistoryoid
AND ap.employmentoid(+) = em.oid
AND DECODE(ap.oid, NULL, 1, NVL((SELECT 1 FROM px17_payrollagreement pa
WHERE
pa.cidn = ap.cidn
and pa.cidn = ch.cidn
and pa.cidn = pg.cidn
and pa.appointmentoid = ap.oid
AND pa.file_number = ch.file_nb
AND pa.cocodeoid = pg.oid), 0)) = 1
and ch.cidn in (select distinct s_cidn from nonsuper_user_check)
AND ( sys_context('payx_r17_app_context', 'app_role') in ('ADP', 'CSR')
or (exists (select 1 from super_user_check where su_cidn =ch.cidn))
or (ch.cidn,ch.co_code,ch.home_dept_code) in (select cidn,co_code,dep from user_security_homedept)
or (ch.cidn,ch.co_code,ch.home_cost_number) in (select cidn,co_code,code from user_security_cost_no)
or ( exists(select co_code from user_security_homedept where cidn=ch.cidn and co_code = ch.co_code and dep is null)
and exists(select co_code from user_security_cost_no where cidn=ch.cidn and co_code = ch.co_code and cost_no = 0) )
Following are the functions being called:
create or replace type myTable_17 as table of varchar2(4000);
CREATE OR REPLACE function f_str2tbl_px17( p_str in varchar2 ) return myTable_17 pipelined
as
l_str long default p_str || ',';
l_n number;
begin
loop
l_n := instr( l_str, ',' );
exit when (nvl(l_n,0) = 0);
pipe row( ltrim(rtrim(substr(l_str,1,l_n-1))) );
l_str := ltrim( substr( l_str, l_n+1 ) );
end loop;
return;
end f_str2tbl_px17;
CREATE OR REPLACE FUNCTION f_check_purge_px17
fv_cidn px17_reservedfilenumber.cidn%TYPE,
fv_file_number px17_reservedfilenumber.file_number%TYPE,
fv_cocode px17_payrollgroup.co_code%TYPE DEFAULT NULL
) RETURN NUMBER AUTHID CURRENT_USER
AS
v_val NUMBER(5) ;
BEGIN
IF fv_cocode IS NULL THEN
RETURN 0 ;
END IF ;
SELECT 1 INTO v_val
FROM px17_reservedfilenumber a,
px17_payrollgroup b
WHERE
a.cidn = fv_cidn
AND b.cidn = fv_cidn
AND a.file_number = fv_file_number
AND a.parentoid = b.oid
AND b.co_code = fv_cocode
AND ROWNUM = 1 ;
RETURN 1 ;
EXCEPTION
WHEN no_data_found THEN
RETURN 0 ;
END f_check_purge_px17 ;
CREATE OR REPLACE FUNCTION f_check_security_px17
fv_cidn IN px17_type_client.cidn%TYPE,
fv_cocode px17_cocodegroup.co_code%TYPE -- pg.cocode
, fv_home_dept px17_type_client.name%TYPE -- ap.home_dept
) RETURN NUMBER AUTHID CURRENT_USER
AS
v_val NUMBER(5) ;
v_key VARCHAR2(20) ;
v_users VARCHAR2(4000) ;
v_cocodes VARCHAR2(4000) ;
BEGIN
BEGIN
SELECT c_user_list, c_cocodes, c_run_key
INTO v_users, v_cocodes, v_key
FROM px17_t_context_vals
WHERE c_run_key = (SELECT MAX(c_run_key) FROM px17_t_context_vals)
AND ROWNUM = 1 ;
EXCEPTION
WHEN no_data_found THEN
v_cocodes := NULL ;
END ;
IF v_cocodes IS NULL THEN
RETURN 1 ;
ELSIF INSTR( (v_cocodes || ','), (fv_cocode || ',') ) = 0 THEN
RETURN 0 ;
ELSE
BEGIN
SELECT
1
INTO
v_val
FROM
px17_type_client t
, px17_securityobject s
, px17_cocodegroup c
WHERE
t.securityoid=s.oid
AND t.category='T_CO_DEPT'
AND c.useroid=(SELECT a.oid
FROM px17_associate a
WHERE a.oid = c.useroid
AND a.active=1
AND UPPER(a.name) = UPPER(v_users)
AND ROWNUM = 1)
AND SUBSTR(s.name,8,3)=c.co_code
AND (c.department_access IS NULL
OR c.department_access LIKE '%' || t.name || '%')
AND SUBSTR(s.name,8,3) = fv_cocode
AND t.name = fv_home_dept
AND ROWNUM = 1 ;
RETURN 1 ;
EXCEPTION
WHEN no_data_found THEN
BEGIN
SELECT
1
INTO
v_val
FROM
px17_cocodegroup c
, px17_associate a
WHERE
c.useroid=a.oid
AND c.department_access IS NULL
AND c.co_code = fv_cocode
AND UPPER(a.name)= UPPER(v_users)
AND a.active=1
AND ROWNUM = 1 ;
RETURN 1 ;
EXCEPTION
WHEN no_data_found THEN
RETURN 0 ;
END ;
END ;
END IF ;
RETURN 0 ;
END f_check_security_px17 ;
SELECT SUBSTR(f_type_px17(ap.cidn,ap.currentstatusoid, 'DESC'), 1, 255)
from
px17_appointment ap,
/*context co_ap,*/
px17_payrollagreement pa,
px17_payrollgroup pg
CREATE OR REPLACE FUNCTION f_type_px17
fv_cidn IN px17_type_client.cidn%TYPE,
fv_oid IN px17_type_client.oid%TYPE,
fv_col IN VARCHAR2 DEFAULT NULL
) RETURN VARCHAR2 AUTHID CURRENT_USER AS
v_rtn_name px17_type_client.name%TYPE := NULL ;
v_rtn_desc px17_type_client.description%TYPE := NULL ;
BEGIN
IF fv_oid IS NOT NULL THEN
BEGIN
IF UPPER(SUBSTR(fv_oid,1,3)) = 'SYS' THEN
SELECT name, description
INTO v_rtn_name, v_rtn_desc
FROM px17_sys_type
WHERE oid = fv_oid
AND ROWNUM = 1 ;
ELSE
SELECT name, description
INTO v_rtn_name, v_rtn_desc
FROM px17_type_client
WHERE oid = fv_oid
AND cidn = fv_cidn
AND ROWNUM = 1 ;
END IF ;
EXCEPTION
WHEN no_data_found THEN
v_rtn_name := NULL ;
v_rtn_desc := NULL ;
END ;
END IF ;
IF (UPPER(NVL(fv_col, '~')) = 'NAME') THEN
RETURN v_rtn_name ;
ELSIF ((UPPER(NVL(fv_col, '~')) = 'DESC')
OR (UPPER(NVL(fv_col, '~')) = 'DESCRIPTION')) THEN
RETURN v_rtn_desc ;
ELSE
RETURN (NVL(v_rtn_name, CHR(155)) || '~' || NVL(v_rtn_desc, CHR(155))) ;
END IF ;
END f_type_px17 ;
************************* -
Hi guys,
i have two table. here in each table data like below
tab1(id, app_id)
id app_id
1 111
2 222
tab2(id,role_id)
id role_id
1 900,901,902
and one emp(id,empid) table.
id empid
1 1234
Now i want to display app_id, role_id which are assigned a perticular empid = 1234 and which saticifies the ID join condition.
can any one help me on this
Rgds,
KLRWowwww... where is my prev post?
ok i repeat it :
1) you need this?
select e.empid, t2.role_id, t1.app_id from emp e
join tab2 t2
on t2.id = e.id
join tab1 t1
on t1.id = e.id
SQL>
19 /
EMPID ROLE_ID APP_ID
1234 900,901,902 111
2) or this?
select empid,
REGEXP_SUBSTR(role_id,'[^,]+',1,row_number() over(partition by empid order by empid)) val,
app_id
from (select e.empid, t2.role_id, t1.app_id
from emp e
join tab2 t2
on t2.id = e.id
join tab1 t1
on t1.id = e.id
connect by INSTR(t2.role_id, ',', 1, level - 1) > 0
and prior e.empid = e.empid
and prior sys_guid() is not null)
EMPID VAL APP_ID
1234 900 111
1234 901 111
1234 902 111
Ramin Hashimzade -
Hi Experts,
I have one requirement as below.
I have two tables say test_1 and test_2 with same structure
Now what i want to accomplish is loop through every record in table table_1 and look for records that have no corresponding entries in table table_2 and delete these rows from table table_1.
Thanks.Hi,
SQL> create table test_1(sno number,name varchar2(10))
2 /
Table created.
SQL> select * from test1
2 /
no rows selected
SQL> desc test1
Name Null? Type
SNO NUMBER
NAME VARCHAR2(10)
SQL> insert into test1 values(1,'vijay')
2 /
1 row created.
SQL> insert into test1 values(2,'vijay')
2 /
1 row created.
SQL> insert into test_1 values(2,'vijay')
2 /
1 row created.
SQL> insert into test_1 values(3,'vi')
2 /
1 row created.
SQL> commit
2 /
Commit complete.
SQL> select * from test1
2 /
SNO NAME
1 vijay
2 vijay
SQL> select * from test_1
2 /
SNO NAME
2 vijay
3 vi
SQL> select * from test1
2 minus
3 select * from test_1
4 /
SNO NAME
1 vijayRegards,
Vijayaraghavan K -
Need help to write a query in automation process
i want to run the scripts in automation process.Is anyone tel me wat is the solution for it?
how to run this scripts in automated process?
Edited by: 927851 on Apr 19, 2012 9:56 AMHi
If you are unix user...
you can use script like below:
# $2 is the output filename, $1 is the .sql script
runsql()
sqlplus -s user/passwd/@somewhere <<EOF > $2
start $1
exit
EOF
runsql file1.sql logfile1 &
runsql file2.sql logfile2 &
runsql anotherfile.sql logfile3 &
wait -
Need to write SQL query for hierarchy
Hi Guys,
I need help to write a query for the below scenario.
I have one organization, under that I have many branches. when i provide input to query on last branch, i need to display all parents of that branch like below
Organization ---parent
branch 1 ---child
branch11
branch 12
branch 2 ---child
branch 21
branch 3 ----child
branch 31
branch 32
branch 33
here, when i provide input as branch 3, then I need to fetch results branch 2, branch 1 till organization.
can any one help me on this.
Thanks in advance!
Regards,
LKRHi,
Is this the same question as
https://community.oracle.com/thread/2616828
Please don't post the same question over and over. Mark this thread as "Answered" right away, and continue in the other thread (if necessary; the other thread has answers.) -
Need help reformatting my hard drive for mac only
Help please
Need help reformatting my hard drive for mac only with my toshishba hard driveWhat Mac is this please, with what version of OS X?
-
i need help! i am trying to update iphoto on my macbook pro that i had bought from someone else. although i am signed into my account when trying to update it is asking me for the previous owners account details and it wont let me change it to my details how can i solve this problem please.
thank you
Jan RobinsonThat's because the Mac, OS X and the iLife apps that came preinstalled on the Mac all belong to the previous owner. The previous owner needs to call Apple care and have their Apple ID disassociated from the Mac. Then the hard drive needs to be totally erased and OS X and the iLife apps reinstalled using OS X Recovery.
-
Need help to write an interesting query
I need some help in framing the query for the following scenario.
I have three tables (in general)
Departments
DNO (PK)
DNAME
Employees
DNO (FK to DNO in Departments)
ENO (PK)
CODE
History
seqid (PK)
ENO (FK to ENO in Employees)
The summary of the data in Employees table looks like below:
DNo No of employees
10 10
20 5
30 8so there will be total of 23 records in employees table. I want to check if all the 10 employees from dept 10 are existing in history table and if exists I want to display the dno and dname from the employees and departments tables respectively. Even if the history table has 9 employees out of 10 from employees table I don't want the query to retrieve that dept details.
Can any one help me with this?
Meanwhile I will also try my level best and let you people know if I come up with anything.
Thanks for your timeHere the example that will help you.
emp_test is the history table for you. You can change ct>9SQL> SELECT * FROM
2 ( SELECT empno ,
3 ename ,
4 e.deptno,dname,
5 COUNT(*) OVER(PARTITION BY e.deptno ORDER BY e.deptno) ct
6 FROM EMP e ,DEPT d
7 WHERE e.deptno=d.deptno
8 AND EXISTS (SELECT 'x' FROM EMP_TEST T
9 WHERE T.empno=e.empno))
10 WHERE ct>3;
EMPNO ENAME DEPTNO DNAME CT
7499 ALLEN 30 SALES 4
7698 BLAKE 30 SALES 4
7654 MARTIN 30 SALES 4
7521 WARD 30 SALES 4
SQL> set linesize 300
SQL> select * from emp_test;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800.2 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7 rows selected.
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800.2 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10formatted
Message was edited by:
devmiral -
Need a help to write the query
Hi,
I need a small help to write the query.
I have a table contains couponid,coupon,createdate,expirationdate,assigndate from couponday table
i want to write the query to select the coupon whose Expiry date in the table is NOT within 30 days.
Thanks in advanceHi,
user586 wrote:
i want to write the query to select the coupon whose Expiry date in the table is NOT within 30 days.If you mean expirationdate (datatype: DATE) is not within 30 days (past or future) of run time, then:
SELECT coupon -- or whatever columns you want
FROM table_x
WHERE expirationdate NOT BETWEEN SYSDATE - 30
AND SYSDATE + 30
; -
Need help in constructing a query
Hi,
I need to generate some reports based on a table data, I tried few ways but could not able to succeed on it. Please help me.
My table:
Id time_process
1 20100101
1 20100102
2 20100201
2 20100203
Need a output like below:
ID time_process
1 20100101, 20100102
2 20100201, 20100203
I have around 10K rows in this table and I want to write a query for producing a output like above. Please help me.
Thanks.Hi,
There are a lot of questions regarding this kind of functionality in the forums can you please have a look at the forum. The latest one which has something similar to your requirement is
String aggregation
cheers
VT
Maybe you are looking for
-
The scroll bar on the .pdf forms I have created only shows up when viewing the forms on a desktop computer. How do I get it to show up when viewing the forms on a laptop, tablet, etc.?
-
iPhoto is now working very slowly. Any editing move,keyword, or any other action, starts the ball moving and takes quite a while before the action is done. And often the program stalls and I have to force a close. I have rebuilt (command - option) an
-
Error 5W 141 when using task 20000051with good movment idoc
Hi all I have made a idoc for goods movement loading coping the equivalent standard idoc, and I have activated the standard task linked to this idoc (20000051) trigged by the object IDOCAPPL with the event INPUTERROROCCURRED. SAP generate in error ca
-
Hello, It seems there are a lot of folks out there who have successfully implemented Oracle Lite solutions for their remote users and leverage database snapshot replications. Can anyone please share their input about this product from implementation/
-
hi how can i upload HR data (my client not implementing HR module) client asking that we can not say debit and credit line items it means one month may have 1000 debits and 50 credits ,how can i record in lsmw. thank you sekhar Edited by: chinna garu