Originally posted by DimPrawn
View Post
- Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
- Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Reply to: SQL Statement Help
Collapse
You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:
- You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
- You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
- If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.
Logging in...
Previously on "SQL Statement Help"
Collapse
-
Originally posted by Spacecadet View Posteven though it's been a few years since I did any serious Oracle, that SQL it makes perfect sense to me
Of course, you shouldn't let inexperienced coders near Big Co. data mangling process
Leave a comment:
-
Originally posted by DimPrawn View PostJeez that looks horrific. The sort of thing you find with no comments in a stored proc named usp_do_work which is critical to some Big Co. data mangling process which worked for 6 months but now fails completely.
Please, don't use SQL for this sort of thing.
Of course, you shouldn't let inexperienced coders near Big Co. data mangling process
Leave a comment:
-
Originally posted by doodab View PostCode:select substr(dataset, 1, instr(dataset, chr(10))) ,substr(dataset, 1, instr(dataset, '|') - 1) tmpVal2 ,substr(dataset, instr(dataset, '|') + 1 , instr(dataset, '|', 1, 2) - instr(dataset,'|', 1, 1) - 1) tmpVal3 ,substr(dataset, instr(dataset, '|', 1, 2) + 1 ,instr(dataset, '|', 1, 3) -instr(dataset, '|', 1, 2) - 1) tmpVal4 ,nvl(substr(dataset, instr(DataSet, '|', 1, 3) + 1 ,instr(dataset, chr(10), 1, 1) -instr(dataset, '|', 1, 3) - 1), substr(dataset, instr(DataSet, '|', 1, 3) + 1)) tmpVal5 , substr(dataset, instr(dataset, chr(10))) TmpVal6 from (select 'first|12345|version745|99985 second|23456|ver666|68452 third|3456_00|v9864|7777' as dataset from dual)
Please, don't use SQL for this sort of thing.
Leave a comment:
-
in SQL Server you can use XML to solve this:
Code:declare @dataset varchar(1000) declare @dataxml xml set @dataset ='first|12345|version745|99985 second|23456|ver666|68452 third|3456_00|v9864|7777' select @dataxml =cast('<dataset><row><data>'+replace(replace(replace(@dataset,char(13),''),'|','</data><data>'),CHAR(10),'</data></row><row><data>')+'</data></row></dataset>'as xml) select dataset.a.value('data[1]','varchar(100)')as data1, dataset.a.value('data[2]','varchar(100)')as data2, dataset.a.value('data[3]','varchar(100)')as data3, dataset.a.value('data[4]','varchar(100)')as data4 from @dataxml.nodes('dataset/row')as dataset(a)
There should be similar functionality in Oracle
Leave a comment:
-
Code:select substr(dataset, 1, instr(dataset, chr(10))) ,substr(dataset, 1, instr(dataset, '|') - 1) tmpVal2 ,substr(dataset, instr(dataset, '|') + 1 , instr(dataset, '|', 1, 2) - instr(dataset,'|', 1, 1) - 1) tmpVal3 ,substr(dataset, instr(dataset, '|', 1, 2) + 1 ,instr(dataset, '|', 1, 3) -instr(dataset, '|', 1, 2) - 1) tmpVal4 ,nvl(substr(dataset, instr(DataSet, '|', 1, 3) + 1 ,instr(dataset, chr(10), 1, 1) -instr(dataset, '|', 1, 3) - 1), substr(dataset, instr(DataSet, '|', 1, 3) + 1)) tmpVal5 , substr(dataset, instr(dataset, chr(10))) TmpVal6 from (select 'first|12345|version745|99985 second|23456|ver666|68452 third|3456_00|v9864|7777' as dataset from dual)
The nvl in the tmpval5 part is to cope with the case that there is no newline on the last line BTW.Last edited by doodab; 26 February 2010, 07:40.
Leave a comment:
-
Try the following:
Code:SELECT REGEXP_SUBSTR(DataSet, '[^:cntrl:]+', 1, 1) tmpVal1 , REGEXP_SUBSTR(DataSet, '[^|]+', 1, 1) tmpVal2 , REGEXP_SUBSTR(DataSet, '[^|]+', 1, 2) tmpVal3 , REGEXP_SUBSTR(DataSet, '[^|]+', 1, 3) tmpVal4 , REGEXP_SUBSTR(DataSet, '[^|]+', 1, 4) tmpVal5 , REGEXP_SUBSTR(DataSet, '[^:cntrl:]+', 1, 2) tmpVal6 FROM (SELECT DataSet aString FROM DUAL)
Last edited by ettubrute; 25 February 2010, 23:16.
Leave a comment:
-
ok, i'm going to start burying myself in REGEXP_INSTR research..
thanks once again to all that have contributed, i very much appreciate your help
i'll check back tomorrow morning on here at 7am european time or 6 uk time to see if there's any other pointers but Im now confident i'll get it sorted with some more research..
Chef
Leave a comment:
-
Originally posted by ettubrute View PostOk, clear for now. Next question: Is this to be done in a PL/SQL block or function, or is it an embedded SQL statement somewhere? Thus, what loop mechanism do you (intend to) use?
If you can call a PL/SQL function, the solution might be easy: call the function with the dataset as a parameter, and use the function to create a temporary table with the separate rows, then us a standard SQL loop to read the table and push to the webservice. Sounds like a possibility?
EDIT: oh and welcome to CUK ettubrute if no-one else has said so so far..
Leave a comment:
-
Ok, clear for now. Next question: Is this to be done in a PL/SQL block or function, or is it an embedded SQL statement somewhere? Thus, what loop mechanism do you (intend to) use?
If you can call a PL/SQL function, the solution might be easy: call the function with the dataset as a parameter, and use the function to create a temporary table with the separate rows, then us a standard SQL loop to read the table and push to the webservice. Sounds like a possibility?
Leave a comment:
-
no not a stupid question in the slightest.
essentially the form that contains this data is a delta form, its the result of a webservice push of data from an external source.
essentially:
-external source sends data to Delta form
-delta form stores 1 group info with a Dataset field listing all products
-** SQL magic happens to parse Dataset into individual lines and 6 tmp variable fields one line per loop***
-external helpdesk system runs the SQL query/function above in a loop until -dataset is null, extracting on each loop a single line of product and product version info (stored in the tmp variable fields)
-external helpdesk system then pushes the info extracted on each loop to a seperate table/form to record information on a group/product level resulting in x amount of records where x equals the number of lines in the DataSet
My problem is i need to seperate out the products aka the DataSet field into individual lines/elements so that I can push them to a seperate form on a group/product basis
it was agreed before hand not to send x messgaes, one for each group/product combination where x equals the number of line sin the dataset as this may result in a very large number of webservice calls and also there is the issue of tracking to ensure all messages are received. so changing the way i receive data is essentially out of hte question, it comes in the relationship of 1 message per group, each message contains x number of product rows in a field called dataset which need to be extracted to form the Group/Product relationships.Last edited by chef; 25 February 2010, 21:00.
Leave a comment:
-
Hi Chef, maybe I'm stupid, but... How does your query get the data? At a complete block of text, or are you reading it from a file, or...
Leave a comment:
-
Originally posted by downsouth View Postbe good if you could pop the complete code up chef, certainly help me along
EDIT: essentially im looking for either a SQL query or a function that will result in 6 tmp variables that i can then re-run to slowly extract whatever is in the DataSet field, it's so frustrating knowing what i want but not having the skills to do it or the time to learn it.. if I can answer any q's i'll try my best, again, i appreciate your patienceLast edited by chef; 25 February 2010, 20:38.
Leave a comment:
- Home
- News & Features
- First Timers
- IR35 / S660 / BN66
- Employee Benefit Trusts
- Agency Workers Regulations
- MSC Legislation
- Limited Companies
- Dividends
- Umbrella Company
- VAT / Flat Rate VAT
- Job News & Guides
- Money News & Guides
- Guide to Contracts
- Successful Contracting
- Contracting Overseas
- Contractor Calculators
- MVL
- Contractor Expenses
Advertisers
Contractor Services
CUK News
- Gary Lineker and HMRC broker IR35 settlement on the hush Today 09:10
- IT contractor jobs market sinks to four-year low in November Yesterday 09:30
- Joke of the Day Dec 9 14:57
- How company directors can offset employer NIC rising to 15% Dec 9 10:30
- Contractors, seen Halifax’s 18-month fixed rate remortgage? Dec 5 09:59
- Contractors, don’t be fooled by HMRC Spotlight 67 on MSCs Dec 4 09:20
- HMRC warns IT consultants and others of 12 ‘payroll entities’ Dec 3 09:15
- How you think you look on LinkedIn vs what recruiters see Dec 2 09:00
- Reports of umbrella companies’ death are greatly exaggerated Nov 28 10:11
- A new hiring fraud hinges on a limited company, a passport and ‘Ade’ Nov 27 09:21
Leave a comment: