USING CASE STATEMENT IN SQL LOADER CONTROL FILE - oracle

I have a control file that loads text to oracle but i am trying to strip first 3 digits of Phone number example 1-469-428-5920 to 469-428-5920, please see below control file. what should be the syntax?
I keep getting error below, Please help
thanks
options (ERRORS=1000, SKIP=2)
load data
infile '/clients/vca2/data/API/ADHOC_LOAD/VCA_RP_Hospital_Website_Master_List_VCA.CSV'
replace
into table VCABARK_CDI_DV.RP_HOSPITAL_MASTER_LIST
fields terminated by '|'
OPTIONALLY ENCLOSED BY '"' AND '"'
trailing nullcols
(
HOSPITAL_EXT_NUMBER,
REGION,
HOSPITAL_NAME,
ADDRESS_1,
CITY ,
STATE,
POSTAL_CODE,
PHONE "CASE WHEN SUBSTR(:PHONE,1,2) = '1-' THEN ‘SUBSTR(:PHONE,3)’ ELSE ‘:PHONE’ END",
RCF_PHONE,
FAX ,
EMAIL ,
WEBSITE_CLASS,
DOMAIN,
SHORTNAME,
PMS,
INDICATOR_24_HOUR,
CARECLUB,
HOME_DELIVERY,
APPOINTMENT_CTA,
FREE_FIRST_EXAM,
AAHA ,
AAFP_MEMBER,
CAT_FRIENDLY,
FEAR_FREE ,
LOW_STRESS, E
VECCS,
FACEBOOK_URL,
GMB_URL ,
YELP_URL,
BOOK_URL,
REQUEST_URL,
HOURS_OPERATIONS_URL,
HD_URL_SUBDOMAIN,
HD_URL_ORIGINAL,
PET_PORTAL_URL,
AIS_CLINIC_ID,
AIS_TOKEN
)

You haven't said what error you are getting, but you should have quotes - curly or otherwise - within your case expression. Instead of:
PHONE "CASE WHEN SUBSTR(:PHONE,1,2) = '1-' THEN ‘SUBSTR(:PHONE,3)’ ELSE ‘:PHONE’ END",
use:
PHONE "CASE WHEN SUBSTR(:PHONE,1,2) = '1-' THEN SUBSTR(:PHONE,3) ELSE :PHONE END",

You could also just keep the last 12:
PHONE "SUBSTR(:PHONE, -12, 12)",

Related

not in condition not working with Case statement PLSQL

NOT IN condition, it is not working. I have these records in the table
proj_comp_id
proj_no
1050-WE-0005
8661
TOGG0000001
1581
5207-00GAC01AA502
8662
so it should add an error for the 2nd value..but not working pls help. below code is adding errors for 1 and 3rd lines also.
SELECT p.proj_comp_no AS primarykey,
p.proj_comp_id AS proj_comp_id,
pr.proj_id AS proj_id,
p.proj_no,
CASE
WHEN p.proj_comp_id NOT IN ('5207-%',
'1051-%',
'1050-%',
'1048-%',
'1049-%',
'2006-%',
'5203-%',
'1055-%',
'1056-%',
'1054-%') and p.proj_no NOT like (1581)
THEN
'1TAG_ID does not start with project prefix, pls add project prefix(5207-, 1049-,1048)'
ELSE
'NO ERROR'
END AS tag_ID_ERROR,
p.descr AS descr
FROM proj_comp p
LEFT JOIN std_mat_cls l
ON l.std_mat_cls_no = p.std_mat_cls_no
LEFT JOIN std_mat b
ON p.proj_comp_id = b.std_mat_id
LEFT JOIN proj pr
ON p.proj_no = pr.proj_no
WHERE (SELECT m.mat_stat_ext_id
FROM mat_stat_ext m
WHERE p.mat_stat_ext_no = m.mat_stat_ext_no) IN ('N', 'P')
AND b.std_mat_id IS NULL
***
That must be because IN isn't appropriate in this context. You should switch to something else, e.g. separate LIKE conditions:
No:
WHEN p.proj_comp_id NOT IN ( '5207-%', '1051-%', '1050-%', etc.
Yes:
WHEN p.proj_comp_id NOT LIKE '5207-%'
AND p.proj_comp_id NOT LIKE '1051-%'
AND p.proj_comp_id NOT LIKE '1050-%'
etc.
The other way to test this could be solved using the InStr() function...
WHEN
InStr('5207-, 1051-. 1050-, 1048-, 1049-, 2006-, 5203-, 1055-, 1056-, 1054-', SubStr(p.proj_comp_id, 1, 5)) = 0

How to remove enter in oracle utf file

The problem is to remove enter and join in one line for ': 86:', which lasts until ': 61:'
http://wklejto.pl/840401
:86:770 PRZELEW KRAJOWY SP; Z RACH.: 78105000861000309030383012; OD:
DOZ SPÓŁKA AKCYJNA DIRECT SPÓŁKA KOMANDYTOWA KINGA C.GILLETTE 11
94-406 ŁÓD¬; TYT.:
/VAT/10655,40/IDC/6252315798/INV/FV/334/PL/2001/TXT/FAKTURA;
DATA STEMPLA: 30.04.2020; TNR: 191181084638228.280001
:61:2005040504DN12655,40NTRFNONREF//EL011880-016890
368-PODATEK VAT

field in data file exceeds maximum length in sql loader. I am using in linux. we are getting the data from sybase and using it for oracle

I am facing the field in data file exceeds maximum length in sql loader error while loading the data to oracle.
//Below control file is used for sqlldr
// Control File: Product_Routing_26664.ctl
//Data File: phxcase1.pr
//Bad File: Product_Routing_26664.bad
LOAD DATA
APPEND INTO TABLE PEGASUSDB_SCHEMA.PRODUCT_ROUTING
FIELDS TERMINATED BY "^"
TRAILING NULLCOLS
(
OID_INST
,SEQ
,ROUTING_TYPE CHAR "(CASE WHEN trim(:ROUTING_TYPE) IS NULL THEN ' ' ELSE trim(:ROUTING_TYPE) END)"
,ODPD_KEY
,PROD_OFFSET
,EFF_DAYS_Z CHAR "(CASE WHEN trim(:EFF_DAYS_Z) IS NULL THEN ' ' ELSE trim(:EFF_DAYS_Z) END)"
,NETWORK_RTG_ID "substr(trim(:NETWORK_RTG_ID), 3, 26)"
,WT0
,WT1
,WT2
,WT3
,WT4
,WT5
,WT6
,WT7
,WT8
,WT9
,WT10
,WT11
,WT12
,WT13
,WT14
,WT15
,WT16
,WT17
,WT18
,WT19
,WT20
,WT21
,WT22
,WT23
,WT24
,WT25
,WT26
,WT27
,WT28
,WT29
,WT30
,WT31
,WT32
,WT33
,WT34
,WT35
,PCS0
,PCS1
,PCS2
,PCS3
,PCS4
,PCS5
,PCS6
,PCS7
,PCS8
,PCS9
,PCS10
,PCS11
,PCS12
,PCS13
,PCS14
,PCS15
,PCS16
,PCS17
,PCS18
,PCS19
,PCS20
,PCS21
,PCS22
,PCS23
,PCS24
,PCS25
,PCS26
,PCS27
,PCS28
,PCS29
,PCS30
,PCS31
,PCS32
,PCS33
,PCS34
,PCS35
,PR_TYPE CHAR "(CASE WHEN trim(:PR_TYPE) IS NULL THEN ' ' ELSE trim(:PR_TYPE) END)"
,PRODUCT_ROUTING_OID "PRODUCT_ROUTING_SQ.nextval"
,COMMON_CASE_OID CONSTANT "1"
,NETWORK_RTG_OID "(select NETWORK_RTG_OID from NETWORK_RTG where NETWORK_RTG_ID = substr(TRIM(:NETWORK_RTG_ID), 3, 26) and COMMON_CASE_OID = 1)"
)
Error: Record 2: Rejected - Error on table
PEGASUSDB_SCHEMA.PRODUCT_ROUTING, column OID_INST. Field in data file
exceeds maximum length
I have tried changing the OID_INST column to OID_INST CHAR(4000) but it shows the same error.
Please help me in resolving this.

Oracle Apex Reports shows data of different user

I am working on Oracle Apex and not that familiar with it. The application I am working on has already been developed by some other developer who has left the company. The issue is - There is a main/super user with which the actual db connection is made (using DADS.conf file entry). After that, user is presented with a Login screen where he enters db subuser credentials. We have few application level contexts defined, so after subuser login we set the context like username for that subuser. In the application there is a report that is supposed to show data for logged in subuser. Now, when first user logs in, the reports shows correct data. When second user logs in from a different machine report starts showing data for the second user in both the application instances. Sometimes second user's report shows data for first user. This behavior is random. Apart from the report other application works fine. I seems that Apex in this case is using same physical database connection and hence the contexts are getting overwritten. I might be wrong here. I am very confused and unable to find any solution. Any help is appreciated.
Here is the report query (much complicated) -
With
Date_range as (
select * from X_LOHAC_DateRANGE_WK
)
--
,Haud_a
AS ( select wor_works_order_no haud_pk_id, WOR_CHAR_ATTRIB110 HAUD_NEW_VALUE, WOR_DATE_ATTRIB131 HAUD_TIMESTAMP
from work_orders
where 1=1
AND WOR_CHAR_ATTRIB110 in ('REV', 'REVUPD','REVCOMM','APPCOMM','APP','REJCOMM','REJ','INTREJ','APPUN')
AND WOR_DATE_ATTRIB131 BETWEEN (select min(st_range) from Date_range) AND (select max(end_range) from Date_range)
)
, haud as (
select h.*, range_value from haud_a h, Date_range
where HAUD_TIMESTAMP BETWEEN st_range AND end_range
)
--
--
--
, claims as
(
select a.woc_works_order_no, a.woc_interim_no, woc_claim_value, claim_previous from
(select woc_works_order_no, woc_interim_no, woc_claim_value
, lag(woc_claim_value) over (partition by woc_works_order_no order by woc_interim_no Asc) as claim_previous
from work_order_claims
order by woc_works_order_no, woc_interim_no asc) a
, (select woc_works_order_no, max(woc_interim_no) woc_interim_no from work_order_claims group by woc_works_order_no) b
where a.woc_works_order_no = b.woc_works_order_no
and a. woc_interim_no = b.woc_interim_no
)
--
, main as (
SELECT DISTINCT
'<p title="Click for forms" id="'||works_order_number||'" onmouseover="showWOLDetails(this);">'|| WORKs_ORDER_NUMBER||'</p>' WORKS_ORDER_NUMBER
,decode( DECODE (mai_sdo_util.wo_has_shape (hig.get_sysopt ('SDOWOLNTH'), wor.works_order_number),
'TRUE', 'Y','N'),
'N',
'<img width=24 height=24 src="/im4_framework/images/grey_globe.png" title="No Location">'
,'') map
,decode(im_framework.has_doc(works_order_number,'WORK_ORDERS'),0,
'<img width=24 height=24 src="/im4_framework/images/mfclosed.gif" title="No Documents">'
,'') DOCS
,(select ial_meaning from nm_inv_attri_lookup where ial_domain = 'INVOICE_STATUS' and ial_value = wor_char_attrib110) INVOICE_STATUS
,WOR_CHAR_ATTRIB111 as "INVOICE_STATUS_COMMENT"
,works_order_description
, claim_previous Previous_Claim_Amount
, woc_claim_value New_Claim_Amount
, WOR_CHAR_ATTRIB111 Claim_Comments
,bud.work_category_description Budget_Description
, 'BOQ' BOQ
,WOR_CHAR_ATTRIB115 "Correct area of work "
,WOR_CHAR_ATTRIB116 "Quality of Work OK"
,WOR_CHAR_ATTRIB70 "Correct BOQ_Uplifts"
,WOR_CHAR_ATTRIB113 "Before_After_Photos_Present" --"Before After Photos Present"
,WOR_CHAR_ATTRIB114 "Certification Comments"
--,(select hus_name from hig_audits, hig_users where haud_pk_id = haud.haud_pk_id and haud_timestamp = haud.haud_timestamp and haud_new_value = haud.haud_new_value and haud_attribute_name = haud.haud_attribute_name and rownum =1) Reviewed_By
, (select HUS_NAME from hig_users where hus_user_id = WOR_NUM_ATTRIB04 ) Reviewed_By
, works_order_number wor_number
, 'Edit' rec_edit
--
FROM imf_mai_work_orders_all_attrib wor,
imf_mai_work_order_lines wol,
haud
,claims
,imf_mai_budgets bud
,pod_nm_element_security,
pod_budget_security
WHERE 1=1
and wol.budget_id = bud.budget_id
AND works_order_number = haud_pk_id
AND works_order_number = claims.woc_works_order_no(+)
AND works_order_number = work_order_number
AND pod_nm_element_security.element_id = wol.network_element_id
AND pod_budget_security.BUDGET_CODE = wol.work_category
AND WOR_CHAR_ATTRIB110 = haud_new_value
AND range_value = :P40_DAYS
AND WOR_CHAR_ATTRIB110 = :P40_PRIORITY
)
--
Select * from main;
Setting Context just uses DBMS_SESSION package as follows -
DBMS_SESSION.SET_CONTEXT('NM3SEC', p_attribute, p_value);
In this case - p_attribute is USERNAME
You can't use DBMS_SESSION with apex since it's a stateless framework pooling multiple connections between multiple sessions.
Apex uses url based session-id's.
You should rather
1) Create an application item in Shared Components.
2) Set the value of the item as a post login procedure using apex_util.set_session_state
Use the value of that item in your SQL code.

Suppress ORA-01403: no data found excpetion

I have the following code
SELECT SUM(nvl(book_value,
0))
INTO v_balance
FROM account_details
WHERE currency = 'UGX';
--Write the balance away
SELECT SUM(nvl(book_value,
0))
INTO v_balance
FROM account_details
WHERE currency = 'USD';
--Write the balance away
Now the problem is, there might not be data in the table for that specific currency, but there might be data for the 'USD' currency. So basically I want to select the sum into my variable and if there is no data I want my stored proc to continue and not throw the 01403 exception.
I don't want to put every select into statement in a BEGIN EXCEPTION END block either, so is there some way I can suppress the exception and just leave the v_balance variable in an undefined (NULL) state without the need for exception blocks?
select nvl(balance,0)
into v_balance
from
(
select sum(nvl(book_value,0)) as balance
from account_details
where currency = 'UGX'
);
SELECT L1.PKCODE L1CD, L1.NAME L1N, L1.LVL L1LVL,
L2.PKCODE L2CD, L2.NAME L2N, L2.LVL L2LVL,
L5.PKCODE L5CD, L5.NAME L5N,
INFOTBLM.OPBAL ( L5.PKCODE, :PSTDT, :PSTUC, :PENUC, :PSTVT, :PENVT ) OPBAL,
INFOTBLM.DEBIT ( L5.PKCODE, :PSTDT,:PENDT, :PSTUC, :PENUC, :PSTVT, :PENVT ) AMNTDR,
INFOTBLM.CREDIT ( L5.PKCODE, :PSTDT,:PENDT, :PSTUC, :PENUC, :PSTVT, :PENVT ) AMNTCR
FROM FSLVL L1, FSLVL L2, FSMAST L5
WHERE L2.FKCODE = L1.PKCODE
AND L5.FKCODE = L2.PKCODE
AND L5.PKCODE Between :PSTCD AND NVL(:PENCD,:PSTCD)
GROUP BY L1.PKCODE , L1.NAME , L1.LVL ,
L2.PKCODE , L2.NAME , L2.LVL ,
L5.PKCODE , L5.NAME
ORDER BY L1.PKCODE, L2.PKCODE, L5.PKCODE

Resources