Formula using the following string...

Hi all

Given a set of strings that can is be parsed (see format below), possible to do a TWG
a set of such strings - i.e. the chain may have the form (from
another thread (pricing using the string formula)) the chain is a bulk
dicount "record" for a product - product code not included for now.
I want to use SQL exclusively, but am open to suggestions - examples
using WITH are especially welcome - has spent time last night, a truck load
rising WITH (of no use, it must be added ;))

_100 (20) 90 (50) 80_ String format

See the code below*-20 first purchased items cost 100,.
the cost of the next 50 90 and all the foregoing is 80/unit.

What I would like is to be able to build a 'table' that I can join real Oracle
tables - imagine these "records" of the chain are coming thick and fast and for reasons x, y
or z, prices can be written to a permanent table. A product code must be
included, but I think fundamental analysis once did, adding such a code should not
be a problem.

So, if I have a set of these strings, how build a TWG?
If it is the right approach.

Any ideas, references, URL - be it, much appreciated.

What would be really cool is if the code could take a product with an arbitrary
number of discounts - 2, some 3 (that is, for example), 4... & c...

TIA

Paul...

Code-Cerca Trova of another thread
with t as(
  select '100(20)90(50)80' str from dual
)
select regexp_replace(regexp_substr(str,'\)\d*',1,2),'\)|\(','')from t  -- 80
--select regexp_replace(regexp_substr(str,'\d*(\)|\()',1,1),'\)|\(','')from t  -- 100
--select regexp_replace(regexp_substr(str,'\d*(\)|\()',1,2),'\)|\(','')from t  -- 20
--select regexp_replace(regexp_substr(str,'\d*(\)|\()',1,3),'\)|\(','')from t  -- 90 
--select regexp_replace(regexp_substr(str,'\d*(\)|\()',1,4),'\)|\(','')from t  -- 50
My own efforts (did not know that Cerca Trova had done) - even if it's rubbish, at least
I tried ;)
WITH StrTab AS  -- *returns 100* = Price1
(
  SELECT '100(20)90(50)80' iStr FROM Dual
)
  SELECT(
          TO_NUMBER(SUBSTR(iStr, 1, INSTR(iStr, '(', 1, 1) -1))
        ) AS  "Price1" FROM StrTab;
Below retrieves the number 20 - sample - allows to extract all the numbers
SELECT -- *returns 20* = Quantity 1
TO_NUMBER(
SUBSTR('100(20)90(50)80', 
(INSTR('100(20)90(50)80', '(', 1, 1) + 1) , 
(INSTR('100(20)90(50)80', ')', 1, 1) - (INSTR('100(20)90(50)80', '(', 1, 1) + 1)))) 
AS "Quantity1" FROM Dual;
Published by: Paulie 9 may 2012 12:32

Published by: Paulie 9 may 2012 12:36

Hello

Whenever you have a problem, please post a CREATE TABLE and INSERT statements for a small example of data like this:

CREATE TABLE     table_x
(      id     NUMBER (6)     PRIMARY KEY
,      txt     VARCHAR2 (30)
)
;

INSERT INTO table_x (id, txt) VALUES (0, NULL);
INSERT INTO table_x (id, txt) VALUES (1, '75');
INSERT INTO table_x (id, txt) VALUES (2, '100(10)80');
INSERT INTO table_x (id, txt) VALUES (3, '100(20)90(50)80');
COMMIT;

In addition, to say what version of Oracle you are using. The query below work Oracle 10.1 and higher:

WITH     cntr          AS
(
     SELECT     LEVEL     AS n
     FROM     dual
     CONNECT BY     LEVEL     <= 5     -- worst case
)
,     rates          AS
(
     SELECT     x.id
     ,     x.txt
     ,     c.n
     ,     TO_NUMBER ( REGEXP_SUBSTR ( '0)' || x.txt
                                 , '[^()]+'
                                 , 1
                                 , (2 * c.n) - 1
                           )
                 )        AS start_qty
     ,     TO_NUMBER ( REGEXP_SUBSTR (  x.txt
                                 , '[^()]+'
                                 , 1
                                 , (2 * c.n) - 1
                           )
                 )        AS rate
     FROM     table_x        x
     JOIN     cntr        c  ON  c.n <= LENGTH (txt)
                                 + 1
                           - LENGTH (REPLACE (txt, '('))
)
SELECT       *
FROM       rates
ORDER BY  id
,            n
;

Output:

`       ID TXT                                     N  START_QTY       RATE
---------- ------------------------------ ---------- ---------- ----------
         1 75                                      1          0         75
         2 100(10)80                               1          0        100
         2 100(10)80                               2         10         80
         3 100(20)90(50)80                         1          0        100
         3 100(20)90(50)80                         2         20         90
         3 100(20)90(50)80                         3         50         80

If you use the WITH clauses above in any question, you can use rates in table form in the following parts of the query.

This assumes you know an upper limit for the number of items in the string. I took 5 different rates above, but you can easily change that to any fixed number. You can also derive the exact number of data themselves. I'll leave that as an exercise.

You can use the analytical function of LEAD to add another column, end_qty, rates.

Published by: Frank Kulash, 9 may 2012 10:24
It also means that txt is well-formed. A space before or after the parentheses is probably correct, but in additional brackets, letters, several decimal places or sign in the same 'number' and things like that will cause all errors.

START_QTY is a misleading name; I should have used something like LOW_QTY or PREV_QTY. In the example above, the row with id = 3 and start_qty = 20 applies in reality to the amount above 20, i.e. 21 to 50 inclusively (since 50 is START_QTY for this id).

Tags: Database

Similar Questions

  • Can I use the following script should set up rman DB only or non-rman configured DB

    Hello

    I need your help this following script

    recover database using backup controlfile until Cancel;

    I can only used in configured RMAN DB.

    (or)

    Can we used above usual script on database (IE. RMAN not configured the database)

    Please suggest me. Thanks in advance.

    If you use RMAN to create backup BackupSet, you use RMAN to RESTORE the database.

    Subsequently, you can use RMAN or SQLPLUS to issue the command to RECOVER the DATABASE.

    (RMAN has no clause 'using backup controlfile' because it identifies the controlfile as a backup, while sqlplus must use the following clause if the controlfile is a backup)

    Hemant K Collette

  • Models of DW: 'this document uses the following files not in this site.

    I recently started using DW templates in CS6. It was a bit frustrating at first, but seems well wouth it. I've created quite a few pages in the folder root of hares and have no problems there. However, I created a new folder to a different section of my site (mysite.com/new_folder/new_page.htm), and then went to save a new page of the model and got the message "this document uses the following files not in this site. Its the same site, just a new folder which is placed at the root.  When I save the page in the new folder there to make a copy of duplicant images, css scripts and place them in the new folder to work? Must be a way to do it and have DW know where to find the original files surely?

    Thank you

    I downloaded a test page... It turns out that the 'message' was just misleading and all the Info page has correct links. Everything is good

  • Display the test using the output "string" indicator?

    Hi, I'm trying out the test to the indicator of string data as you can see below,

    but with 'For' the logic of loop that it is only the display last number, so if you run this, you'll see

    following output.

    Test #6

    If I move the concatenation of string outside of the loop block, you will see the result as below.

    Test #0123456

    However, I want to achieve more of output. Can someone suggest me a way to do it?

    By the way, I use the for loop.

    The output I want to display with the for loop

    Test #0

    1

    2

    3

    4

    5

    6

    Thank you

    Close but no cigar.

    You need concatenate the string using a shift register.

    This will be the output:

  • Failed to run backup using the format string

    Hi all

    Need help with RMAN, my problem as below:

    RMAN > run {}
    2 > level 1 incremental backup cumulative
    3 > format "D:\ora\rmanbackup\RCKLGC_INC < % s: T: %p % _ > .dbf.
    4 > tag data base 'DAILY_DATAFILES ';
    {5 >}

    From backup 29 June 09
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID = 145 type device = DISK
    channel ORA_DISK_1: starting from compressed data file backup set incremental level 1
    channel ORA_DISK_1: specifying datafile (s) in the backup set
    Enter a file 00005 name = E:\ORA\ORADATA\RCKLGC\MGMT = datafile number. DBF
    Enter a file name 00002 = E:\ORA\ORADATA\RCKLGC\UNDOTBS01 = datafile number. DBF
    Enter a file name 00006 = E:\ORA\ORADATA\RCKLGC\MGMT_ECM_DEPOT1 = datafile number. DBF
    Enter a number of file datafile = 00001 name = E:\ORA\ORADATA\RCKLGC\SYSTEM01. DBF
    Enter a number of file datafile = 00003 name = E:\ORA\ORADATA\RCKLGC\SYSAUX01. DBF
    Enter a file name 00007 = E:\ORA\ORADATA\RCKLGC\DATAFILE\O1_MF_RMAN_DAT_4M9QWZT5_ = datafile number. DBF
    Enter a number of file datafile = 00004 name = E:\ORA\ORADATA\RCKLGC\USERS01. DBF
    channel ORA_DISK_1: starting piece 1 to 29 June 09
    RMAN-00571: ===========================================================
    RMAN-00569: = ERROR MESSAGE STACK FOLLOWS =.
    RMAN-00571: ===========================================================
    RMAN-03009: failure of the backup command on the channel ORA_DISK_1 at 2009-06-29 18:20:49
    ORA-19504: cannot create the file '< _1097:20090629:1 > D:\ORA\RMANBACKUP\RCKLGC_INC. DBF. "
    ORA-27040: create file error, cannot create the file
    04002 - OSD: could not open the file
    S/O-error: (123 OS) the file name, directory name or volume label syntax is incorrect.

    ----------------------------------------

    If I set the format by default %U work string. Can someone help me? The sting of format I used on the database under Linux works fine without any problems.

    Hi faisal.badrom,
    Can you be more specific on the 'format string to meet backup requirement standards "?
    Are you allowed to jump ">".< :"="">
    If you can use:

    format 'D:\ora\rmanbackup\RCKLGC_INC_%s_%T_%p.dbf '.

    Or to extend it again with the name of the database:

    format 'D:\ora\rmanbackup\RCKLGC_INC_%s_%T_%p_%d.dbf '.

    to meet the standard?

    Kind regards

    Tycho

    Edited by: tychos on June 30, 2009 01:33

  • Using the variable string quickly calling several variables

    OK, I'm not entirely sure how to explain it, but I will do my best...

    I have had several similar Boolean variables which are publicly declared at the beginning of my class.

    for example

    public var _ball0_mcPlaced:Boolean = false;
    public var _ball1_mcPlaced:Boolean = false;
    public var _ball2_mcPlaced:Boolean = false; 

    This will determine whether or not a particular ball was placed in a target area.

    Now I want to use this variable again in a function... However, I do not want to write in the variable for each ball in the service.

    Is there a faster way to access this variable by using a string inside the function varibale?  Each ball becomes a target of the event if clicked, so I could use something like...

    ("_" + event.target.name + "Placé") to create the dependent variable on which ball is selected?
    So, if ball0_mc is selected it returns the _ball0_mcPlaced variable?

    How can I do this?


    See you soon

    It would be written using the array notation in the form of...

    ["_" + event.target.name + "Placé"] = true;

  • Example to use the query string in the Oracle Access Manager policy.

    Hi all

    Can is there any one please tell me what is the value of the query string and Query String Variable OAM political?

    If possible, please explain with an example of the sample.

    Thanks in advance.

    Siva NAKI.

    Let's say I have an application that has logout URL as http://abc.com/app.cgi?function=logout&user=LOGGED_USER.
    In this case, logged in user will always be different, but you want the user to sign out when this URL is hit. In this scenario, you can use query string variables and specify the function = disconnect it.

    In other scenarios where you know all the query parameters and you want to protect these URLs then the query string can be used.

    Thank you
    Kiran Thakkar

  • Extract a string and the following string

    I need to extract a word JNF and its following, if the JNF Word is found in a string.  Could someone help me with this please?

    For example.  "Proudct has this 10 oz bottle JNF 15 content."

    Here, I want to just extract JNF 15

    Hello

    In my previous answer, I assumed that JNF should be a whole word, not only the last 3 characters of another word.  In other words, taking into account this string

    ABCJNF JNF CAT DOG

    you would like to "JNF DOG".

    If you want "JNF CAT", then do this way:

    REGEXP_SUBSTR (str

    , ' JNF + [^] +'

    )

  • How to create a table of backing bean using the map &lt; String, List &lt; String &gt; &gt;?

    Hello

    I have a structured map < String, List < String > > plan in backing bean. I have a requirement to draw a table using this hash table which means map key as columns and its value is a list and it's the column values.

    Thank you

    Faizal

    Check this Create ADF Table during execution

    ~ Abhijit

  • Target using the VAR String and number

    This should be simple, how to target a VAR using a string and a number, the idea is that I can change the number to target this VAR.

    var gogo1:Number = 12

    var gogo2:Number = 89

    trace ("gogo" + 2)

    I'm after the trace to be 89 NOT gogo2

    trace(this["gogo" + 1]);
    

    --

    Kenneth Kawamoto

    http://www.materiaprima.co.UK/

  • I use the following method in tabular form, created by the wizard.

    Hello
    To change the value of a column...
    I have create a following procedure...

    declare
    number of count_em;
    BEGIN
    BECAUSE me in 1.APEX_APPLICATION. G_F01. Count
    LOOP
    apex_application.g_f05 (i): = 12;
    apex_application.g_f04 (i): = 12;
    apex_application.g_f03 (i): = "ONEYEARI";
    END LOOP;


    END;

    04's start_Number column
    then end_number is 05
    And the third column, it's offer .
    But the value donot change...

    Donot change is reflected in the database. . Any idea. What am I do wrong...
    This method of referencing the values in table form a correct method... ?
    Thanks again
    Thank you

    Published by: zycoz100 on October 19, 2012 22:00

    the source property of the element is always replace the value or only where is null?

  • using the following with oracle erp system

    Hi all

    Does anyone have experience in the use of the Infor ERP LN with oracle. They are completely compatible... the reason why I ask is to make a good argument why our society needs oracle when migrate us to our new ERP system infor ERP LN. currently sellers are trying to make us change to sql sever.

    The seller itself should be able to tell if they are certified against Oracle. I would do certainly official confirmation from the supplier it themselves, otherwise you might find yourself in a lot of trouble if it turns out that he is not certified and you have major problems.

    Saying: "I asked a guy on a forum" would do nothing to help keep your job in this case...

  • I get an error of invalid object by using the following page duplication script, no idea why?

    var app.documents.item('C:\Users\jdoe\Desktop\Source.indd = myDocument');

    var sourcePages = myDocument.pages.item (0);

    sourcePages.duplicate (LocationOptions.AFTER, app.layoutWindows [0] .activePage);

    I'm looking to duplicate a page of a specific document and place it just after the current active page.

    the document is opened?

    myDocument var = app.documents.item ('Source.indd');

    or

    var app.open (File('C:\Users\jdoe\Desktop\Source.indd'));) = myDocument

  • Help! How to load several SWF files by using the following code?

    In stock for 1 frame:

    ( var myrequest:URLRequest =new URLRequest ()'A.swf'();
    ( var myloader:Loader =new Loader()();
    myLoader. load () myrequest ();

    img1. addEventListener () MouseEvent. ( CLICK, button click();

    ( function button click ()event: MouseEvent ():void{ }
    Stadium. addChild () myloader ();
    }

    img1.addEventListener (MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_5);

    function fl_ClickToGoToAndStopAtFrame_5(event:MouseEvent):void

    {

    gotoAndStop (13).

    }

    In action to frame 13: (img2 is another button)

    img2.addEventListener (MouseEvent.CLICK, unloadFunction);

    function unloadFunction(event:Event):void {}

    stage.removeChild (myloader);

    }

    you want to load another swf (for example, B.swf) when you are in frame 13 and img2 is clicked?  If so, and you do not want A.swf continue to play, use:

    In action to frame 13: (img2 is another button)

    img2.addEventListener (MouseEvent.CLICK, loadF2);

    function loadF2(event:Event):void {}

    myLoader.Load (new URLRequest ("B.swf"));

    }

  • How to change the value of string clustered, to implement using the node value of property instead of writing directly on the flow of data or using the variable

    new to labview :-) and I have a problem when I want to change the value of a string in bunches, and I want to implement this using the node value of property instead of writing directly to the stream or by using the variable, enclosed is the picture.   No matter, I have change in cluster (control) or value of Popery out (indicator) cluster, the value (sensor 7) dataflow keeps unchanged even I gave the new value by value of property node. Thank you to give me some advice about this.

    Hi GerdW

    Thanks a lot for your answer. The reason I'm stubbornly tring to break the flow of DATA is: we have a test system that have about 100 screws, they have a few connected flow, some of them will be unbundling a cluster dataflow chain to check the value in order to make the different cases.  Now I want to insert user event by changing the control and influential cases during run time.

    As I initially uses a global variable (to control cases) instead of unbundle string data flow, it works well.  But then, I found there are a lot of screws that are using the string unbundle.  One of the 'lazy' means, I tried is to change the value via the property node (because that way, I did not need to find all the places where using the unbundle string and replace them with the global variable), then I noticed a problem with "dataflow", the value in the stream of cluster in fact will not be changed by changing the value of the property node.

    I did a test with VI simple (like the picture in last post), and after reading your advice, I tell myself that I need to understand the concept of "DATAFLOW" in labview, it seems that my "lazy" way can not work in this scenario.

    I have attached the criterion VI here, have you furthur suggestions on what I can do in this case?

    Mant thanks!

    Minyi

Maybe you are looking for