How to split a varchar parameter say (2,4,7,24) and get each of the value
Hi
I have to create a function which takes in 2 paramters,
first one is date
second one is a list of codes within parentheses (varchar2) ex:- '(2,4,7,24)'
Each of this number value brings out a table information such as
table name
where condition
start and end dates and soon
I need to build a dynamic SQL ..for each table information got from each value.
In this case, their will be 4 select queries which needs to be joined.
To start of, I want to know, how many codes have been passed in the second parm.
Please let me know, if their is a function which contains the number of delimiters and a function which can be used to get each value
basically from (2,4,7,24)
I want
the count of delimiters (here it is 3)
using the count of delimiters (3+1 , will be giving me the count of numbers present)
using the delimiter, I want to get each number
ie.,
2 first time and create the SQL
4
7
24
Atlast will join all 4 sql queries and create one which runs to produce my output
Thank You
I appreciate your help
Sir,
I did the same think, what you have posted, but I want some simpler way, and I dont know how to do it.
create or replace
PACKAGE BODY PKG_EXTRACT_FACILITY AS
-- GET THE FACILITY INFO FOR A GIVEN YEAR .
FUNCTION F_MAIN_FACILITY(PI_DATE DATE,PI_ORGEXT_ID varchar2) RETURN GC_RESULT_SET AS
C_RESULT_SET GC_RESULT_SET;
VN_TABLE VARCHAR2(20);
VN_COLUMN VARCHAR2(40);
VN_WHERE VARCHAR2(20);
VD_START VARCHAR2(40);
VD_END VARCHAR2(40);
VN_MULTI NUMBER(2);
VN_SQL VARCHAR2(4000);
VC_QUERY VARCHAR2(2000);
BEGIN
DBMS_OUTPUT.PUT_LINE(PI_ORGEXT_ID);
DBMS_OUTPUT.PUT_LINE(''''|| PI_ORGEXT_ID ||'''');
--VN_SQL := 'SELECT REPLACE(' PI_ORGEXT_ID ','"' ,'') FROM dual' ;
--DBMS_OUTPUT.PUT_LINE(VN_SQL);
--PI_ORGEXT_ID := EXECUTE IMMEDIATE(VN_SQL);
OPEN C_RESULT_SET FOR
--SELECT ORGEXT_TABLE,count(*), ORGEXT_COLUMN, ORGEXT_WHERE,
-- ORGEXT_START, ORGEXT_END, ORGEXT_MULTI
-- FROM ORG_EXTRACT
-- WHERE ORGEXT_ID IN
-- (SELECT regexp_substr(''''|| PI_ORGEXT_ID ||'''','[^,]+', 1, level) from dual connect by regexp_substr(''''|| PI_ORGEXT_ID ||'''', '[^,]+', 1, level) is not null )
-- group by ORGEXT_TABLE, ORGEXT_COLUMN, ORGEXT_WHERE,
-- ORGEXT_START, ORGEXT_END, ORGEXT_MULTI;
--SELECT ORGEXT_ID,ORGEXT_TABLE, ORGEXT_COLUMN, ORGEXT_WHERE,
-- ORGEXT_START, ORGEXT_END, ORGEXT_MULTI
-- FROM ORG_EXTRACT
-- WHERE INSTR(''''|| PI_ORGEXT_ID ||'''',ORGEXT_ID) > 0 ORDER BY ORGEXT_ID;
SELECT ORGEXT_TABLE, ORGEXT_COLUMN, ORGEXT_WHERE,
ORGEXT_START, ORGEXT_END, ORGEXT_MULTI
FROM ORG_EXTRACT
WHERE ORGEXT_ID IN
(SELECT * FROM TABLE(in_list(PI_ORGEXT_ID)));
-- DBMS_OUTPUT.PUT_LINE(VN_SQL);
LOOP
FETCH C_RESULT_SET INTO VN_TABLE, VN_COLUMN, VN_WHERE, VD_START, VD_END, VN_MULTI;
EXIT WHEN C_RESULT_SET%NOTFOUND;
-- dbms_output.put_line('record '|| VN_TABLE || ' ' || VN_COLUMN );
IF ( VN_MULTI > 0 ) THEN
IF ( VD_START IS NULL AND VN_WHERE IS NOT NULL ) THEN
--SELECT QUERY WITH XML FUNC NOT INCLUDING START AND END DATES.
VC_QUERY := 'SELECT ORG_MAIN.ORG_ID, Q1.' || VN_COLUMN || '
FROM ORG_MAIN,
(SELECT ORG_ID, RTRIM(XMLAGG(XMLELEMENT(E, ' || VN_COLUMN || ' || '','')
ORDER BY ' || VN_COLUMN || ').EXTRACT(''//text()''), '','') AS ' || VN_COLUMN || '
FROM ' || VN_TABLE || '
WHERE ' || VN_WHERE || '
GROUP BY ORG_ID) Q1
WHERE M.ORG_MAIN.ORG_ID = Q1.ORG_ID(+)
ORDER BY ORG_ID';
DBMS_OUTPUT.PUT_LINE('FIRST CONDITION ' || VC_QUERY);
EXECUTE IMMEDIATE VC_QUERY;
ELSIF ( VD_START IS NULL AND VN_WHERE IS NULL ) THEN
--SELECT QUERY WITH XML FUNC INCLUDING START AND END DATES.
VC_QUERY := 'SELECT ORG_MAIN.ORG_ID, Q1.' || VN_COLUMN || '
FROM ORG_MAIN,
(SELECT ORG_ID, RTRIM(XMLAGG(XMLELEMENT(E, ' || VN_COLUMN || ' || '','')
ORDER BY ' || VN_COLUMN || ').EXTRACT(''//text()''), '','') AS ' || VN_COLUMN || '
FROM rateprep.' || VN_TABLE || '
GROUP BY ORG_ID) Q1
WHERE ORG_MAIN.ORG_ID = Q1.ORG_ID(+)
ORDER BY ORG_ID';
DBMS_OUTPUT.PUT_LINE('SECOND CONDITION ' || VC_QUERY);
EXECUTE IMMEDIATE VC_QUERY;
ELSIF ( VD_START IS NOT NULL AND VN_WHERE IS NOT NULL ) THEN
--SELECT QUERY WITH XML FUNC INCLUDING START AND END DATES, BUT NOT INCLUDING WHERE CLAUSE.
VC_QUERY := 'SELECT ORG_MAIN.ORG_ID, Q1.' || VN_COLUMN || '
FROM ORG_MAIN,
(SELECT ORG_ID, RTRIM(XMLAGG(XMLELEMENT(E, ' || VN_COLUMN || ' || '','')
ORDER BY ' || VN_COLUMN || ').EXTRACT(''//text()''), '','') AS ' || VN_COLUMN || '
FROM ' || VN_TABLE || '
WHERE ' || VN_WHERE || ' AND
(TO_DATE( ' ||''''|| PI_DATE ||''''|| ', ''DD-MON-YY'') BETWEEN ' ||''|| VD_START ||''|| ' AND ' ||''|| VD_END ||''|| ')
GROUP BY ORG_ID) Q1
WHERE ORG_MAIN.ORG_ID = Q1.ORG_ID(+)
ORDER BY ORG_ID';
DBMS_OUTPUT.PUT_LINE('THIRD CONDITION ' || VC_QUERY);
EXECUTE IMMEDIATE VC_QUERY;
ELSIF ( VD_START IS NOT NULL AND VN_WHERE IS NULL ) THEN
--SELECT QUERY WITH XML FUNC INCLUDING START AND END DATES, AND INCLUDING WHERE CLAUSE.
VC_QUERY := 'SELECT ORG_MAIN.ORG_ID, Q1.' || VN_COLUMN || '
FROM ORG_MAIN,
(SELECT ORG_ID, RTRIM(XMLAGG(XMLELEMENT(E, ' || VN_COLUMN || ' || '','')
ORDER BY ' || VN_COLUMN || ').EXTRACT(''//text()''), '','') AS ' || VN_COLUMN || '
FROM ' || VN_TABLE || '
WHERE (TO_DATE( ' ||''''|| PI_DATE ||''''|| ', ''DD-MON-YY'') BETWEEN ' ||''|| VD_START ||''|| ' AND ' ||''|| VD_END ||''|| ')
GROUP BY ORG_ID) Q1
WHERE ORG_MAIN.ORG_ID = Q1.ORG_ID(+)
ORDER BY ORG_ID';
DBMS_OUTPUT.PUT_LINE('FOURTH CONDITION ' || VC_QUERY);
EXECUTE IMMEDIATE VC_QUERY;
END IF;
ELSE
IF ( VD_START IS NULL AND VN_WHERE IS NOT NULL ) THEN
--SELECT QUERY WITHOUT XML FUNC AND WITHOUT START AND END DATES.
VC_QUERY := 'SELECT ORG_MAIN.ORG_ID, Q1.' || VN_COLUMN || '
FROM ORG_MAIN,
( SELECT ORG_ID, ' || VN_COLUMN || '
FROM ' || VN_TABLE || '
WHERE ' ||VN_WHERE || '
) Q1
WHERE M.ORG_MAIN.ORG_ID = Q1.ORG_ID(+)
ORDER BY ORG_ID';
DBMS_OUTPUT.PUT_LINE('FIFTH CONDITION ' || VC_QUERY);
EXECUTE IMMEDIATE VC_QUERY;
ELSIF ( VD_START IS NULL AND VN_WHERE IS NULL ) THEN
--SELECT QUERY WITHOUT XML FUNC AND WITHOUT WHERE CLAUSE AND START AND END DATES.
VC_QUERY := 'SELECT ORG_MAIN.ORG_ID,Q1.' || VN_COLUMN || '
FROM ORG_MAIN,
( SELECT ORG_ID, ' || VN_COLUMN || '
FROM ' || VN_TABLE || '
) Q1
WHERE ORG_MAIN.ORG_ID = Q1.ORG_ID(+)
ORDER BY ORG_ID';
DBMS_OUTPUT.PUT_LINE('SIXTH CONDITION ' || VC_QUERY);
EXECUTE IMMEDIATE VC_QUERY;
ELSIF ( VD_START IS NOT NULL AND VN_WHERE IS NOT NULL ) THEN
VC_QUERY := 'SELECT ORG_MAIN.ORG_ID,Q1.' || VN_COLUMN || '
FROM ORG_MAIN,
( SELECT ORG_ID, ' || VN_COLUMN || '
FROM ' || VN_TABLE || '
WHERE ' || VN_WHERE || ' AND
(TO_DATE( ' ||''''|| PI_DATE ||''''|| ', ''DD-MON-YY'') BETWEEN ' ||''|| VD_START ||''|| ' AND ' ||''|| VD_END ||''|| ')
) Q1
WHERE ORG_MAIN.ORG_ID = Q1.ORG_ID(+)
ORDER BY ORG_ID';
DBMS_OUTPUT.PUT_LINE('SEVENTH CONDITION ' || VC_QUERY);
EXECUTE IMMEDIATE VC_QUERY;
ELSIF ( VD_START IS NOT NULL AND VN_WHERE IS NULL ) THEN
VC_QUERY := 'SELECT ORG_MAIN.ORG_ID,Q1.' || VN_COLUMN || '
FROM ORG_MAIN,
( SELECT ORG_ID, ' || VN_COLUMN || '
FROM ' || VN_TABLE || '
WHERE TO_DATE( ' ||''''|| PI_DATE ||''''|| ', ''DD-MON-YY'') BETWEEN ' ||''|| VD_START ||''|| ' AND ' ||''|| VD_END ||''|| '
) Q1
WHERE ORG_MAIN.ORG_ID = Q1.ORG_ID(+)
ORDER BY ORG_ID';
DBMS_OUTPUT.PUT_LINE('EIGHTH CONDITION ' || VC_QUERY);
EXECUTE IMMEDIATE VC_QUERY;
END IF;
END IF;
-- VC_SQL := 'SELECT ORG_MAIN.ORG_ID,' ||
-- VC_EXT :=
END LOOP;
OPEN C_RESULT_SET FOR VC_QUERY;
RETURN C_RESULT_SET;
CLOSE C_RESULT_SET;
END F_MAIN_FACILITY;
FUNCTION in_list (p_in_list IN VARCHAR2) RETURN t_in_list_tab PIPELINED
AS
l_text VARCHAR2(32767) := p_in_list || ',';
l_idx NUMBER;
BEGIN
LOOP
l_idx := INSTR(l_text, ',');
EXIT WHEN NVL(l_idx, 0) = 0;
PIPE ROW (TRIM(SUBSTR(l_text, 1, l_idx - 1)));
l_text := SUBSTR(l_text, l_idx 1);+
END LOOP;
RETURN;
END;
END PKG_EXTRACT_FACILITY;
SET SERVEROUTPUT ON;
Declare
VC_OUT NUMBER;
VC_OUT1 VARCHAR2(80);
VC_RES PKG_EXTRACT_FACILITY.GC_RESULT_SET;
begin
VC_RES := PKG_EXTRACT_FACILITY.F_MAIN_FACILITY('01-JAN-10','9,2,3');
LOOP
fetch VC_RES INTO VC_OUT,VC_OUT1;
EXIT WHEN VC_RES%NOTFOUND;
dbms_output.put_line('data ' || VC_OUT ||' ' || VC_OUT1 );
END LOOP;
close VC_RES;
end;
The function I wrote, right now is at building each Select query from each result record produced from passing the second parm to the select query to extract all other table information from
ORG_EXTRACT table.
Any help to solve the business role I wrote in my earlier mail, is appreciated.Thank You.
Edited by: user8703472 on Sep 21, 2012 7:37 AM
Edited by: user8703472 on Sep 21, 2012 7:40 AM
Edited by: user8703472 on Sep 21, 2012 7:44 AM
Edited by: user8703472 on Sep 21, 2012 7:44 AM
Edited by: user8703472 on Sep 21, 2012 7:46 AM
Similar Messages
-
Every time I fire up my iMac a window pops up saying "Mount notification quit unexpectedly" and it gives me the option to either "Reopen" it or click OK, which gets rid of it. What is this please and how can i stop it?
Hopefully this will help you. Try placing your iPad in recovery mode again. You may have to try this a few times.
iOS: Unable to update or restore -
I share an Apple ID with someone but we are now on iOS8 and getting each others messages on our iphones and ipad. How can I split the account safely as well as protect icloud backed up data?
Use different Apple IDs for iMessage (and also FaceTime) to avoid getting each others text messages (and FaceTime calls). One of you should go to Settings>Messages>Send & Receive (and Settings>FaceTime), tap the ID, sign out, then sign back in with a different ID. You can continue to shared the same ID for the iTunes store and other services.
-
You know how you download apps, well let's say you have two devices and get an app on one and it goes to the other, how do you remove it from doing that?
Click here and use the instructions to turn off the automatic downloads.
(120206) -
Had my computer serviced recently and had to reinstall itunes. Now its saying I have two accounts. How can I switch to my original account where all my music that I imported is and get rid of the new one that only shows my purchased music?
Had my computer serviced recently and had to reinstall itunes. Now its saying I have two accounts. How can I switch to my original account where all my music that I imported is and get rid of the new one that only shows my purchased music?
-
How do I convert mail merge documents to individual pdf docs and save each with a field in the merge?
Is this an actual field, or just some piece of static text somewhere? Either way, you can't do it using the Split Document command. You'll need to use a custom-made script to read the value of this "field" and use it when extracting pages from the file.
-
hi, i purchased a 2 dvd digital set. i cant just download it straight to my ipad. they said i have to down load it to my i tunes, then can transfer to i pad. im not seeing how to click the files from my email, and get them into the i tunes acct... ugh.
i do not have a mac home pc. just a regular pcI had the same problem after I gave my old iPad to my parents and tried to install Netflix. This is what you have to do: Open iTunes on your computer, the one you sync your iPad to. Then go to iTunes Store and search for and download Netflix app. After you download it, if your iPad is set to download new purchases it may start downloading on your iPad. If so, tap and hold to delete the app (because it is trying to install the new version on the iPad) Next step, go to the App Store on your iPad and find Netflix and it should say install since you already purchased it on the computer. Tap to install, and it will say the version is not compatible, tap to download a previous version. Click that and it will install the older version! One more thing, if and when you sync to your computer again it will say something like " Unable to install Netflix on your iPad" Just click the box to never remind you again, because it's trying to sync the newer Netflix app to your iPad, but it doesn't work so it displays the message. The old app will remain on the ipad. Hope this helps, good luck
-
My iPad is frozen with a message on the screen that says "iCloud backup is full" and it gives me the option of cancel or settings but will not go to either one or allow me to exit the message. How can I restart? It will not let me turn off or doesn't help to plug into computer
Try a reset:
Hold the Sleep and Home button down until you see the Apple logo.
Data will not be affected. -
How do I remove an incorrect apple ID from an iPad and replace it with the correct one?
How can I remove an incorrect Apple ID from my ipad and replace it with the correct one?
Hello Shy guy,
You can try this:
1. Go to the iTunes Store or App Store
2. Scroll down, there you will see Apple ID: "your email" (below Redeem and Send Gift)
3. Tap on that button
4. Tap on Sign Out
Now you should be able to use another Apple ID.
Cedric -
The wifi has been lost or disconnected on my iPad. It's the iPad 2 and has not been updated yet. It's IOS 6.1.3 .. how do I add a network back onto it? I have typed in the name and chosen each of the securities and still hasn't connected!
Hey there Luba_kalstad,
It sounds like you are unable to join your network and cannot see it in the Wi-Fi list in Settings. I would try the troubleshooting outlined in this article named:
iOS: Troubleshooting Wi-Fi networks and connections
http://support.apple.com/kb/ts1398
Be sure you're in range of your Wi-Fi router (access point).
Tap Settings > Wi-Fi and turn Wi-Fi off and on. If your Wi-Fi setting is dimmed, follow these steps.
Confirm that your Wi-Fi router and cable or DSL modem are connected to power, turned on, and connected to the Internet. If not, refer to your network administrator or Internet service provider (ISP) for assistance.
Restart your iOS device.
Tap Settings > Wi-Fi and locate the Wi-Fi network to which you're connected.
Tap and Forget this Network.
Try to connect to your desired Wi-Fi network.
Note: You may need to enter your Wi-Fi password again if your network requires one.
Turn your Wi-Fi router off and on2. If your ISP also provides cable or phone service, check with them before attempting this step to avoid interruption of service.
Update your device to the latest version of software.
Update your Wi-Fi router to the latest firmware2. For AirPort Base Stations, install updates using the AirPort Utility.
And this section down toward the bottom if needed:
Unable to locate a Wi-Fi network
Verify that the network is available by tapping Settings > Wi-Fi and choosing from the available networks.Note: It may take a few seconds for the Wi-Fi network name to appear.
Move closer to your wireless router (access point) and attempt to locate the Wi-Fi network.
If you do not see the network you would like to join, you may be attempting to connect to a hidden network. Learn how to join a hidden network.
Supported Wi-Fi configurations vary by iOS device model. Find out which standards your device supports3.
Reset network settings by tapping Settings > General > Reset > Reset Network Settings. Note: This will reset all network settings including:
previously connected Wi-Fi networks and passwords
recently used Bluetooth accessories
VPN and APN settings
Thank you for using Apple Support Communities.
Take care,
Sterling -
How do I create a new account and get stuff from the old account to the new account
How do I create a new account and get stuff from the old account to the new account
There are instructions on this page for creating a new account : Set up an Apple ID in iTunes
Or if you don't want to give credit card details : Create an iTunes Store, App Store, or iBooks Store account without a credit card or other payment method
But you won't be able to transfer purchases from your old account to it, all content that you download from the store will remain tied to the account that downloaded it. -
I recently updated my iphone 5 to IOS 8.0.2 and now it wont turn on it just says to connect to itunes and when i do the only option it gives me is to restore iphone because it is in "recovery mode". It says it will delete all my media but i didn't do a back up and i don't want to lose my photos, what should i do? (I never used iCloud to back them up either).
If it's in recovery mode, the data is already gone. Why did you never back up your important data?
-
How do I have itunes use/detect my external hard drive and place music on the external drive from the itunes store? There are no music files on my pc yet. I will like to do this after installing itunes 11 on my pc for the first time. I am using windows 7. HP computer intel Dual Core. Thanks for any help!
Hey idw3,
Welcome to Apple Support Communities, and thanks for the question. Follow the instructions on this article to move your iTunes Media folder to an external hard drive:
iTunes for Windows: Moving your iTunes Media folder
http://support.apple.com/kb/HT1364
Regards,
David -
I have not synced my iphone to my new computer. My old computer is dead. How do I keep the music from disappearing and get synced to the new computer?
This will cost you http://www.wideanglesoftware.com/touchcopy/index.php
or see this doc http://discussions.apple.com/docs/DOC-3141 -
How to include the promotion and sales deal in the value contract ?
Question : Can a value contract contain other special pricing agreement ?
If yes, how to include the promotion and sales deal in the value contract ?
Thanks for your input.
OscarHi Oscar,
I have not worked on this aspect as such but once you create a value contract I think you as well create a promotion and sales deal for the customer with whom you have value contract with in the validity period of the contract and system should pick up data accordingly as the customer is same (Contract) and is within the validity period.
Pl give feed back.
regards
Srini
Maybe you are looking for
-
When I try to change the burn format under preferences, advanced, burning, i change it to what i want then hit ok. iTunes then freezes and becomes non-responsive.
-
Can i use Oracle9i 9.2.0.5 JDBC on oracle8i ??
Hi all!! My java app is developed under Weblogic 6.1 and oracle 8i, but we are migrating it to weblogic 8.1, and we have some deprecated classes in ojdbc14.jar (those are Clob and Blob classes) and some troubles with Oracle Types definitions, so, we
-
Where do imported files reside?
I'm sure this is an incredibly basic "newbie" question but I can't find a clear answer anywhere, so I'd be grateful for any feedback. When you import a file (video, graphic, image, audio) into a Premiere project, does it copy the data or does it simp
-
I get an error message "General exception" everyime i use a java based webs
Everytime i go onto a java based website, a this pops up saying Java error, general exception... and when i right click on the coffe cup in the lower right hand corner, i click on open console, and this is what i see basic: Registered modality listen
-
Unable to update IOS 4.3.2 from IOS 4.3
Unable to update IPhone 4 version 4.3 to version 4.3.2 from itunes. When I'm plug IPhone to PC, ITunes notification me whether want to update software. I clicked 'Download and Update' option and it take 1~2 hours to download but when downloaded finis