Can a recursive sql have a where clause
can the following sql have a where clause and I dont want to hard code the id is is that possible...
select DISPLAY_NAME, ID, PARENT_ID, display_in_parent_folder, sub_folder_sequence
from wwsbr_all_folders start with id = 8888
connect by prior id= parent_
actually g is another alias I created sorry I missed it... if I do this as a regular sub query I get three records but when I implement it as a recursive query it does not retutn any thing. Below is my regular query followed by the recursive query which I am using to organize the result but get no results:
REGULAR Query that retrieves records with parent_id = from the list of parent ids
select distinct f.DISPLAY_NAME, f.id, f.type_id, f.type_siteid, f.base_type_id, f.parent_id, f.sub_folder_sequence
from WWSBR_ALL_FOLDERS f, WWSBR_ALL_FOLDERS g
where g.parent_id = ( select g.parent_id from WWSBR_ALL_FOLDERS e
where
e.caid = 103 AND
e.parent_id <> 0 AND
e.type_id = 1 AND
e.display_in_parent_folder <> 0 AND
e.id = f.parent_id)
order by f.id, f.sub_folder_sequence;
Recursive query that results nothing:
select distinct f.DISPLAY_NAME, f.id, f.type_id, f.type_siteid, f.base_type_id, f.parent_id, f.sub_folder_sequence
from WWSBR_ALL_FOLDERS g, WWSBR_ALL_FOLDERS f start with f.id = ( select g.parent_id from WWSBR_ALL_FOLDERS e
where
e.caid = 103 AND
e.parent_id <> 0 AND
e.type_id = 1 AND
e.display_in_parent_folder <> 0 AND
e.id = f.parent_id)
connect by prior f.id= g.parent_id
order by f.id, f.sub_folder_sequence;
Similar Messages
-
How can I pass multiple condition in where clause with the join table?
Hi:
I need to collect several inputs at run time, and query the record according to the input.
How can I pass multiple conditions in where clause with the join table?
Thanks in advance for any help.
Regards,
TDIf you are using SQL-Plus or Reports you can use lexical parameters like:
SELECT * FROM emp &condition;
When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
SELECT &columns FROM &tables &condition;
But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
Best of luck! -
Change JDBC select SQL query's where clause at runtime
Hi,
I have one JDBC sender channel with Select SQL Query which helps in fetching data from JDE table. We have defined where clause to fetch some particular records i.e. if ABC = NULL then fetch the record.. and then update query is used to turn that flag to "Y" i.e. ABC ="Y" so that next time the channel don't pick the same records again.
Now the problem is that if we want to fetch some records again whose flag has been set to "Y" we cannot change the select query again and again in the production environment.
Is there any way to change the select query of the JDBC channel at runtime e.g. Picking up some flat file where the conditions for the particular records to be picked are defined (ID=123) and changing the WHERE clause of select query in the JDBC channel for those records to be picked without using BPM.
Thank you!
With regards,
SimranHi Simran,
Yes, it is possible with the help of store procedure. In SQL Server there is a IF-Else Conditional block, which you can use inside store procedure. Create a SP with 2 additional parameter something like FlagReadAgain and KeyField. Pass the flag always as True or False. For the Key field pass the record key which you want to read again if you are passing the Flag as True else pass it as 0 or whatever.
In the procedure check if the value of flag is True -> If yes, Read the entry with key name specified in where part.
In the else part put the query which you are using for the normal flow.
IF (FlagReadAgain) = TRUE
BEGIN
SELECT EmpName, EmpAddress
FROM Employee
WHERE EmpID = 'E001'
END
ELSE
BEGIN
SELECT EmpName, EmpAddress
FROM Employee
WHERE Status = 'N'
END
You may also use the approach which Srini mentioned. Create an application to restore any value to intial stage so that it can be picked up by XI when it poll again.
Choose any approach which you like.
Regards,
Jitender Chauhan -
Can I use SYSDATE in the WHERE clause to limit the date range of a query
Hi,
Basicaly the subject title(Can I use SYSDATE in the WHERE clause to limit the date range of a query) is my question.
Is this possible and if it is how can I use it. Do I need to join the table to DUAL?
Thanks in advance.
SteliosAs previous poster said, no data is null value, no value. If you want something, you have nvl function to replace null value by an other more significative value in your query.<br>
<br>
Nicolas. -
How can I avoid hard-coding this where clause in the inner select?
This is extremely fast, but I have to hard-code the inner-most where clause, and I obviously can't do that. I know how to work-around it by creating a function that takes the CUSTOMER_ID and returns the ORDER_ID from the most recent payment, and that's reasonably fast, but I thought it would be worthwhile to see if there was a way to do this in straight SQL. I also know that better design could make the problem go away.
Very much appreciate it if you could take a look and let me know if there's any way to get this kind of performance without hard-coding.
Thanks,
create or replace view customer_view as
select customer.customer_id,
customer.customer_name,
select t.order_id
from (
select payment.order_id
from payment
where payment.customer_id = 1 -- <-- Here's the line where I'm hard-coding the customer_id. Is there any way to reference the customer_id without hard-coding this?
order by payment.payment_date desc
) t
where rownum = 1
) as latest_order_id
from customer
select * from customer_view where customer_id = 1; <-- I want that inner-most select to use this customer_id, without having to hard-code it.Hi Matt,
Something like this could be a possibility (Not tested)
create or replace view customer_view as
select customer.customer_id,
customer.customer_name,
(select min (t.order_id)
keep (dense_rank first order by payment.payment_date desc)
from payment
where payment.customer_id = customer.customer_id)
as latest_order_id
from customer;Regards
Peter -
Can you help me with the WHERE clause? Any issue with this code block?
Hi,
I am looking for blogs or any document on how to implement a Lookup during data loads in BW.
The problem is that all those that I find on this site are mostly about u201CLookup in XIu201D
I have read bits and hints on different postings on this site and this is the best I could do for the scenario shown below:
I need to add the Chars: Char1, Char2, Char3 to CubeX
so that I can display the data for these 3 Chars in a report.
Char1 and Char2 are filled in ODS12 and Char3 is filled in Cube3.
Can you help me write a routine so that while loading data to CubeX, it will read Char1, Char2, Char3 from ODS12 and Cube3; and make them available in CubeX?
This is my attempt so far: continue:
u201C----
select /bic/Char1 from /bic/ODS12
select /bic/Char2 from /bic/ODS12
select /bic/Char3 from /bic/Cube3
into result
WHERE u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026
and objvers = 'A' .
end select.
u201C----
1. What should be my WHERE clause?
2. In the select statement, by studying samples on this where should there be an u201CMu201D in front of the ODS? e.g. select /bic/Char1 from /bic/MODS12
If so, what is the significance and the other options?
3. Should this code be in the Start routing of CubeX? Or any other possible location? Also, in the start routine does it matter where within the start routine this code needs to be placed?
4. Can you please fix this code and add any lines I may be missing?
Is what I am looking to do refer to as u201Cdoing a lookupu201D?
Thanksok
-
SQL Strings in Where Clause - single quotes issue
All,
Im having issues related to SQL String literals when trying to deploy to flash. The complication works fine but I then get a message (see below) stating that a ; is missing. The SQL query and the iview runs fine when we use numeric values or do not apply a where clause on the table.
I am using Visual Composer that has been packaged with NW2004sSP7_Preview
VC & Flex Version: 645.7.0.3
The Error message is get is;
Error in executing a process for Flex compilation, Error 1033: ';' expected
(C:usrsapJ2EJC01j2eeclusterserver0GUIMachine_Business_Packagestest_48731FLEX_COMPILATION_FOLEDRAADCN.mxml:269)
Error 1205: The statement 'Test' is incomplete.
(C:usrsapJ2EJC01j2eeclusterserver0GUIMachine_Business_Packagestest_48731FLEX_COMPILATION_FOLEDRAADCN.mxml:269)
Failed to compile AADCN.mxml
When I goto the deployment file it has the below line;
<i>'<Request type="EXECUTE_RELATIONAL" system="BI_JDBC" system_type="SAP_BI_JDBC" maxrows="500" templateid="BIR_SQL"><Objects type="INPUT" shape="OBJ" role="INPUT"><Object type="INPUT_FIELD" id="SQL_STATEMENT" appName="SQL" mapped="0" value=""/></Objects><Objects type="OUTPUT" shape="SET" role="OUTPUT"><Object type="OUTPUT_FIELD" id="name" appName="name"/></Objects><Objects id="1" type="TEMPLATE_PARAMETER"><Object id="2" type="SQL" value="select name from pub.srcompany where name ='Test Company'"/></Objects></Request>';</i>
It seems that the parser for the flash deployment is prematurely finishing the parse when it hits the single quotation in the SQL string!
We had a similar error where if we had a carriage return in the SQL (e.g. between the from & the where clause) then the deployment parser was stating that the line finished prematurely. In the deployment file the carriage return forced a new line thus making the message incomplete. Removing the carriage return resolve that issue
The SQL Preview in the SQL Editor within VC works fine with the string literals in the where clause.
The functionality compiles & deploys in web dynpro however it does not return the results to the table
Questions
1:> Has anyone successfully used flash with string literals in the SQL where clause or had seen this issue in the past?
2:> Is there a setting to get the SQL working on Web dynpro for the information to be returned that I may have missed?
Any assistance would be greatly appreciated.
Best Regards,
Ian.Hey,
I have worked with SQL Editor a lot. Here's a how to guide I put together on it:
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/6339e7d4-0a01-0010-1c98-db00e52e989a
Let me know if that helps...
Prakash -
Can you use boolean function in where clause
Hi,
I have a boolean function. Is it possible to use it in where clause of query.
Eg;
is_prime(13) returns boolean
select 1 from dual where is_prime(13)What about something like this
Create or replace function boolret(id number) return boolean as
begin
If id <10 then
return true;
elsif id>10 and id<100 then
return false;
else
return null;
end if;
end;
1 declare
2 id_cat boolean;
3 begin
4 id_cat:= boolret(8);
5 dbms_output.put_line(id_cat);
6* end;
SQL> /
dbms_output.put_line(id_cat);
ERROR at line 5:
ORA-06550: line 5, column 2:
PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
ORA-06550: line 5, column 2:
PL/SQL: Statement ignored
It seems PL/Sql doesn't have any datatype like Boolean,But it handles Boolean like datatype.
Regards
Raj deep.A -
How can we use DECODE function in where clause.
Hi Guys,
I have to use DECODE function in where clause.
like below
select * from tab1,tab2
where a.tab1 = b.tab2
and decode(code, 'a','approved')
in this manner its not accepting?
Can any one help me on this or any other aproach?
Thanks
-LKR>
I am looking for to decode the actual db value something in different for my report.
like if A then Accepted
elseif R then Rejected
elseif D then Denied
these conditions I have to check in where clause.
>
what are you trying to do?
may be you are looking for
select * from tab1,tab2
where a.tab1 = b.tab2
and
(decode(:code, 'A','Accepted') = <table_column>
or
decode(:code, 'R','Rejected') = <table_column>
or
decode(:code, 'D','Denied') = <table_column>
) -
How can we use form variable in where clause while personalization
Dear,
I have a requirment for using select in personalization, actully we have created temporary table, now we want to get data from select satatement on event"when-new-record-instance' trigger, now in action tab i have selected action which is property and message, in message column showing value "${item.q_res.transaction_id.value}" it shows on validate button but when this form variable use in action type(property) which is consist on select statement "=SELECT to_char(QTY) FROM TEST_TABLE where transaction_id = ${item.q_res.transaction_id.value}" system didn't get value pressing validate button although there is a single record in customize table while without where cluase was getting data perfectly.
please advice.>
I am looking for to decode the actual db value something in different for my report.
like if A then Accepted
elseif R then Rejected
elseif D then Denied
these conditions I have to check in where clause.
>
what are you trying to do?
may be you are looking for
select * from tab1,tab2
where a.tab1 = b.tab2
and
(decode(:code, 'A','Accepted') = <table_column>
or
decode(:code, 'R','Rejected') = <table_column>
or
decode(:code, 'D','Denied') = <table_column>
) -
Sql order in where clause...
i want to ask about
how oracle deal with the order of where cluase
as in select * from where tname = 'EMP'
and tabtype = 'TABLE'
oracle strat from down (tabtype) or from up (tname)
and there is difference between this order
if the where clause contains (and) or (or)
i always need to know this thing but no place i found say about it in strait way..
thanks..
nullI am sorry for the late reply.
I guess that ORDER doesn't matter in the WHERE clause. We should take 2 cases:
1) Say, in a WHERE clause, U have a limiting condition on one of the indexed field of the table, then definitely that will be executed first and the result set will be passed to the other conditions.
2) Say, in the WHERE clause, U don't have any indexed field then ORACLE will go for cost based execution. In this case, it will first go to the column, for which the SELECTIVITY is the highest ( ORACLE does so internally ) and then the result set is passed to the other conditions.
Hope this helps.
Correct me, if I am wrong. -
SQL: order of WHERE clauses important for performance?
I wonder if the order of the WHERE clauses does affect performance or if the database optimize each query so that the order is irrelevant? Example: is
SELECT *
FROM Table1
WHERE (fast condition check)
AND (slow condition check)
faster than
SELECT *
FROM Table1
WHERE (slow condition check)
AND (fast condition check)
because the first condition check might be false and therefore the second is not executed? (Some kind of Java if (fast && slow) is faster than if (slow && fast) ?)It depends on how sophisticated the database optimizer is. IBM's DB2/UDB will completely rewrite the syntax of SQL as part of optimization and does not care what the order of the where clause is. Oracle actually has two optimizers RULE and COST. The RULE based optimizer is affected by the order of the where clause, COST is not (RULE is no longer available in the newest version of Oracle, Oracle 10g).
-
Simple finder results in huge slow sql query -- why WHERE clause?
Hi all,
wondering about the poor performance of my finder methods I took a look into the SQL that went to the database.
"SELECT DISTINCT OBJECT(p) FROM Person p"
results in
SELECT PersonID, FirstName, LastName, [etc.] FROM person WHERE (PersonID='5354B71CC0A80113008BD3BB11A57FA1') OR (PersonID='5354B893C0A80113008BD3BB3C6918FF') OR (PersonID='5354B910C0A80113008BD3BBC83093BE') OR [etc.]
where all 2000 primary keys are listed. This query costs ~ 4 seconds on my box.
A query without WHERE costs ~ 0 seconds. So why this "WHERE" clause?
Is this a JBoss specific problem? I am using version 3.2.3.
thanx!
MarcusIt's not a bug - it's how JBoss implements it's own
"findAll" methodology. Whether it's a good
implementation or not is open to debate.Really strange.
Anyway all my performance problems disappeared with setting the read-ahead strategy to "on-find". Although I don't fully understand why.
Marcus -
How Can I Extract a Substring in WHERE Clause of CFQUERY ?
Is it possible to extract a substring in the WHERE clause of either <CFQUERY> or in a Query of Queries? I am trying to use the following query to find all email addresses with the domain "comcast.net" (i.e. everything after the "@" in the email address). I am querying an MS-Access database table.
<cfquery name="test" datasource="membership">
SELECT email_address
FROM tblMembers
WHERE MID(email_address, INSTR(email_address, '@') + 1) = 'comcast.net'
</cfquery>
If I attempt this as a query, I get the error message "[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression."
If I attempt it as a QoQ, I get the error message 'Encountered "MID ( email1 ,. Incorrect conditional expression, Expected one of [like|null|between|in|comparison] condition,'.
I would be very grateful for any help on finding something that works! Thanks for your help!Couldn't you do a LIKE in the where clause instead:
SELECT email_address
FROM tblMembers
WHERE email_address LIKE '%@comcast.net'
That should get you the addresses you are looking for.
-Carl V. -
SQL Plus Skipping Where Clause
Question: We are using .sql files, that are executed though SQLPlus to implement our production code, we have had instances where a developer put a extra line in the middle of his SQL statement. In the below examples, the 2nd script will execute and delete everything in the entire table, then give a error message message stating that it doesn't know what 'WHERE' is, and then commits(Only happens when executing from a .sql file, if you put the below SQL in the buffer and execute it... it doesn't happen)... does anyone know a way to tell SQLPlus to ignore carrage returns as the end of the SQL statement?
Example 1: Delete 1 Row
DELETE FROM TABLE1
WHERE ID = 1;
COMMIT;
Example 2: Delete's ALL Rows
DELETE FROM TABLE1
WHERE ID = 1;
COMMIT;set sqlblankline on
(this default value is off)
and addtional...
set sqlterminator ;
(this default value is ;)
Message was edited by:
ushitaki
Maybe you are looking for
-
Mac Book Pro Wifi Data Locked up/freezes.
Hello, i have had this problem now for about 3 months. I have tried to search for the issue but i may be missing some key terms so if this is a known topic or somone can provide a link to a solution i would love it. So i primarly use my MBP on wifi
-
I need help to get the iphoto apllication working. I reinstalled it from the iLife disc and upgraded the software as instructed but now it says I cannot open the library with this version of the iphoto app. Whats happening and how do I fix it?
-
Having problems disguising a cameramans reflection in video
Hi everybody. This is my first post and I have a little problem. I know this isn't that hard (that is what makes it so frustrating) I've watched a dozen tutorials on the subject before finally caving in and asking for help. I need to edit out the cam
-
I already posted this to a different thread and was pointed here, so apologise for doubling up. I have a pretty new intel iMac. Over the last month or so it has developed a number of quirks. First off was kernel panic, then an occasional relutance to
-
Can't use Hosting and Business Catalyst
I have full CC-Membership, but can't use Hosting and BC. Following messages appearing on my CC-Account: On the apps-Page: "Full Creative Cloud Membership comes with hosting for up to 5 sites. View and manage these sites from the sidebar on the Creati