Home » SQL & PL/SQL » SQL & PL/SQL » Breaking up an expression to evaluate (Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit )
Breaking up an expression to evaluate [message #595003] Wed, 04 September 2013 16:09 Go to next message
dwitisabat@gmail.com
Messages: 5
Registered: September 2013
Junior Member
Hi,



I have a complex expression coming as an input and I have to break that into smaller one to evaluate each of them. Explained in example:



Let's assume, I have an input string as "(({A}&{B})||({C}||{D})&({E}||({F}&{G})))". My requirement is to break into logical smaller groups like

1. ({F}&{G})

2. ({E}||({F}&{G}))

3. ({C}||{D})

4. (({A}&{B})



Can anybody please provide me a solution to it.



Thanks

DS
Re: Breaking up an expression to evaluate [message #595004 is a reply to message #595003] Wed, 04 September 2013 17:41 Go to previous messageGo to next message
BlackSwan
Messages: 22793
Registered: January 2009
Senior Member
Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/

Re: Breaking up an expression to evaluate [message #595011 is a reply to message #595003] Thu, 05 September 2013 00:44 Go to previous messageGo to next message
Michel Cadot
Messages: 59149
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Welcome to the forum.

Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" or "Preview Quick Reply" button to verify.
Also always post your Oracle version, with 4 decimals.

With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

All SQL functions are described in Database SQL Reference.
You can have a look to INSTR, SUBST, REGEXP_SUBSTR...
You also need a row generator.

Regards
Michel
Re: Breaking up an expression to evaluate [message #595048 is a reply to message #595003] Thu, 05 September 2013 12:41 Go to previous messageGo to next message
Lalit Kumar B
Messages: 2348
Registered: May 2013
Location: World Wide on the Web
Senior Member
dwitisabat@gmail.com wrote on Thu, 05 September 2013 02:39

Let's assume, I have an input string as "(({A}&{B})||({C}||{D})&({E}||({F}&{G})))". My requirement is to break into logical smaller groups like

1. ({F}&{G})

2. ({E}||({F}&{G}))

3. ({C}||{D})

4. (({A}&{B})



Can anybody please provide me a solution to it.


I read, re-read, and again reading your post. Initially i thought it is just a silly task of regular expressions. Now, what I fail to understand is that, your output is not based on a specific rule. I found 2 special characters in your output as a base to create a rule to write the SQL code.

Point 1,3 and 4 seems legitimate to arrive to a rule. But point 2 has a combination of rules based on other points. Is it an OR condition for "&" and "||". Because, regular expression purely depends on the parameters you decide. So please post an example of set of rules to derive the desired output.
Re: Breaking up an expression to evaluate [message #595051 is a reply to message #595048] Thu, 05 September 2013 12:59 Go to previous messageGo to next message
dwitisabat@gmail.com
Messages: 5
Registered: September 2013
Junior Member
Thanks for answering.

I think the rule should be based on "(" and ")". I want to break the expression if possible through regular expression to logical groups which will help me to evaluate individual expressions and then the final expression. Like:

1. ({F}&{G}) --> T

2. ({E}||({F}&{G})) --> F

3. ({C}||{D}) --> F

4. (({A}&{B}) --> T

THen I will have to evaluate the entire expression using the above values. SO logical group break is essential.

Thanks
DS
Re: Breaking up an expression to evaluate [message #595052 is a reply to message #595051] Thu, 05 September 2013 13:08 Go to previous messageGo to next message
BlackSwan
Messages: 22793
Registered: January 2009
Senior Member
I give up.
What is the significance of the rightmost "T" & "F" characters above?

Re: Breaking up an expression to evaluate [message #595053 is a reply to message #595051] Thu, 05 September 2013 13:18 Go to previous messageGo to next message
Michel Cadot
Messages: 59149
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
I give you clues and hints, what did you try from them?

Regards
Michel
Re: Breaking up an expression to evaluate [message #595054 is a reply to message #595052] Thu, 05 September 2013 13:26 Go to previous messageGo to next message
dwitisabat@gmail.com
Messages: 5
Registered: September 2013
Junior Member
T is True and F is False. Each expression will have a value and then the final expression value would be evaluated.
Re: Breaking up an expression to evaluate [message #595055 is a reply to message #595054] Thu, 05 September 2013 13:38 Go to previous messageGo to next message
John Watson
Messages: 4570
Registered: January 2010
Location: Global Village
Senior Member
Can you explain your notation? For example, should I assume this:

The uppercase letters are variables, which may be true or false
& is AND
|| is OR
You do not seem to have a NOT
The {} appear to be redundant.

Given a grammar like that (which is only my guess) you can build up a truth table for any expression.
Re: Breaking up an expression to evaluate [message #595056 is a reply to message #595055] Thu, 05 September 2013 13:44 Go to previous messageGo to next message
BlackSwan
Messages: 22793
Registered: January 2009
Senior Member
>2. ({E}||({F}&{G}))
precedence?

which has precedence; AND, OR, neither?
which has precedence; right to left, left to right, inside out?
Re: Breaking up an expression to evaluate [message #595057 is a reply to message #595056] Thu, 05 September 2013 13:56 Go to previous messageGo to next message
John Watson
Messages: 4570
Registered: January 2010
Location: Global Village
Senior Member
Exactly. I remember when studying Boolean algebra and propositional logic that it really doesn't matter what rules you use, as long as all parties use the same rules. So what you have to do, DS, is explain the rules.
Re: Breaking up an expression to evaluate [message #595058 is a reply to message #595057] Thu, 05 September 2013 14:51 Go to previous messageGo to next message
dwitisabat@gmail.com
Messages: 5
Registered: September 2013
Junior Member
The capital letters with in {} are conditions for example {A}, {B}....are individual conditions which are nested using AND (&),OR (||) and "( )".
Re: Breaking up an expression to evaluate [message #595059 is a reply to message #595058] Thu, 05 September 2013 15:10 Go to previous messageGo to next message
John Watson
Messages: 4570
Registered: January 2010
Location: Global Village
Senior Member
This sounds like a straightforward Boolean algebra, but you have not yet given a complete description.
What about your variables? Are the values TRUE, FALSE, and NULL? How do you handle comparisons with NULL? ("three valued logic" is probably the term you need to Google)
Get the rules right, and you can parse the entire string into a form that pl/sql can evaluate, no problem.
Re: Breaking up an expression to evaluate [message #595060 is a reply to message #595051] Thu, 05 September 2013 15:31 Go to previous messageGo to next message
Lalit Kumar B
Messages: 2348
Registered: May 2013
Location: World Wide on the Web
Senior Member
DS -

I asked you to provide exact rules to derive the output, you have again just provided the output in a different fashion.

Rules in SQL or PL/SQL are the conditions on the basis of which we write the code to get the desired output. Just work a bit on preparing a test case, and then come again with your code. A lot of senior members have replied, let's not make their efforts go into vain.

[EDIT : fixed typo errors]

[Updated on: Thu, 05 September 2013 15:39]

Report message to a moderator

Re: Breaking up an expression to evaluate [message #595117 is a reply to message #595060] Fri, 06 September 2013 15:39 Go to previous messageGo to next message
dwitisabat@gmail.com
Messages: 5
Registered: September 2013
Junior Member
I got an approach to break the expression as I need. Many of inputs i got form here helped me to break it down. I appreciate all of your help

Please let me know if you would be interested to know.

Thanks
DS
Re: Breaking up an expression to evaluate [message #595120 is a reply to message #595117] Fri, 06 September 2013 22:53 Go to previous message
Lalit Kumar B
Messages: 2348
Registered: May 2013
Location: World Wide on the Web
Senior Member
dwitisabat@gmail.com wrote on Sat, 07 September 2013 02:09
I got an approach to break the expression as I need. Many of inputs i got form here helped me to break it down. I appreciate all of your help

Please let me know if you would be interested to know.


Yes. Please post your solution, it will help other folks searching the forum for similar questions. And I insist, you also mention the rules by which you are breaking the expression.
Previous Topic: Enabling the Constraint With Enable No Validate
Next Topic: Plsql update query
Goto Forum:
  


Current Time: Sun Sep 21 15:20:18 CDT 2014

Total time taken to generate the page: 0.05043 seconds