Auto-relation (Simple query) SQL statement
HelloI just want to know is the following: auto-relation SQL statement
SELECT ROWID,ACCOUNT_ID,ACCOUNT_NAME,IS_CLOSED,TYPE_ID,ACCOUNT_ID_PARENT
FROM GL_ACCOUNTS
WHERE GL_ACCOUNTS.TYPE_ID = GL_ACCOUNTS_PARENT.TYPE_ID AND
GL_ACCOUNTS.ACCOUNT_ID_PARENT = GL_ACCOUNTS_PARENT.ACCOUNT_ID
If not pls I want to create aThanks in advance,
Kind regards
Abdetu...
Abdetu wrote:
HelloI just want to know is the following: auto-relation SQL statement
SELECT ROWID,ACCOUNT_ID,ACCOUNT_NAME,IS_CLOSED,TYPE_ID,ACCOUNT_ID_PARENT FROM GL_ACCOUNTS WHERE GL_ACCOUNTS.TYPE_ID = GL_ACCOUNTS_PARENT.TYPE_ID AND GL_ACCOUNTS.ACCOUNT_ID_PARENT = GL_ACCOUNTS_PARENT.ACCOUNT_ID
If not pls I want to create a
Thanks in advance,
Kind regards
Abdetu...
Do you want a self-join or query CONNECT BY (a particular type of self-join that runs recursively).
Both are described in the documentation
Tags: Database
Similar Questions
-
Create a simple query (SQL)
Hi experts,
I have a table with data as follows:
Database version: 10.2.0.4
Table name: TRANSACTION_HIST_TAB
and I want to create a single query (SQL) which can get data grouped by LOT_NO and only the first transaction by LOT_NOTRANS_ID LOT_NO PART_NO QTY TRANSACTION LOCATION_NO ROWVERSION --------- ------- -------- ---- ----------------- ------------ ---------------------- T00000X1 L001 ABC 10 CHANGE LOCATION WRH_1 01/01/13 08:00:00 AM T00000X2 L001 ABC 10 CHANGE LOCATION WRH_2 01/02/13 10:00:00 AM T00000X3 L002 XYZ 20 CHANGE LOCATION WRH_3 01/03/13 11:00:00 AM
Expected results:
Someone has an idea?TRANS_ID LOT_NO PART_NO QTY TRANSACTION LOCATION_NO ROWVERSION --------- ------- -------- ---- ----------------- ------------ ---------------------- T00000X1 L001 ABC 10 CHANGE LOCATION WRH_1 01/01/13 08:00:00 AM T00000X3 L002 XYZ 20 CHANGE LOCATION WRH_3 01/03/13 11:00:00 AM
Kind regards
RobHi, Rob.
Here's one way:
WITH got_r_num AS ( SELECT t.* -- or list columns you want , ROW_NUMBER () OVER ( PARTITION BY lot_no ORDER BY rowversion ) AS r_num FROM transaction_hist_tab t ) SELECT * -- or list all columns except r_num FROM got_r_num WHERE r_num = 1 ;
Depending on your data and your needs, match Sub like Manik suggested, might work. I think that you want to GROUP BY lot_no only, no transid.
I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements), and the results you want from this data.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum {message identifier: = 9360002} -
I'm trying to do a COUNT for each time the word "Suspended" appears in a column.
Use: Oracle 10g
Example:
Output should look likeName Comments Tim Johnson Suspended for 1 game Tim Johnson Suspended for 4 games Rob Johnson Suspended for 3 games
Any thoughts?Name Suspensions Tim Johnson 2 Rob Johnson 1
Published by: user652714 on December 11, 2008 13:29Yes, me taking into account:
with t as ( select 'Tim Johnson' nme, 'Suspended for 1 game' txt from dual UNION ALL select 'Tim Johnson' nme, 'Suspended for 4 games' txt from dual UNION ALL select 'Tim Johnson' nme, 'Given Warning' txt from dual UNION ALL select 'Rob Johnson' nme, 'Suspended for 3 games' txt from dual ) select nme Name, COUNT(*) Suspensions from t where txt like 'Suspend%' group by nme; NAME SUSPENSIONS ----------- ---------------------- Tim Johnson 2 Rob Johnson 1 2 rows selected
-
Capture the SQL statement before it runs
Hello world
I have a question about the capture of query sql statement in Oracle before he run? Is it possible to do and can give you the answer to this problem? Enter here means I can catch the declaration of all applications (like SQL, I * sqlplus or another application making the request to the database). I want to do this because my teacher asks me to analyze the request and if it violates any policy = > stop before Oracle run it.
I tried this solution
[Select trigger for Oracle | http://technology.amis.nl/2005/09/26/select-trigger-in-oracle-database-introducing-fine-grained-auditing/].
but I think he looks not the answer. Because for the audit of the refined, the event handler is called when the first row is obtained. This is the average Oracle a analyze this quere and run to get the first row.
Please help me with this problem
Edited by: pirent420 at 04:05 06/05/2012Hello
That's what you ask...www.Oracle.com/technetwork/Products/Database-Firewall/index.html
Some other related things are:
the database Vault control many things related to this in terms of what time of the day and access where data etc.
Resource Manager can block statements if they want to use too many resources.
The standard model of privilege/role/grant prevents access you something, that you are not allowed to see.
Views can hide columns if necessary.
DTV and RLS can hide lines
It depends exactly on the requirement.
See you soon,.
Harry -
Order of execution of SQL statements
Hello
I have two SQL statements where the first statement executes on a table with more than 40 million lines, the second statement is running on a table more 6 million lines. When they are running their own each take about 0.15 seconds to run, but when combined they take 20 minutes to run, (the second SQL statement is inserted in the WHERE clause of the statement of first). It would seem that after combining these statements, the first statement goes through all 40 million lines before it performs the SELECT in the WHERE clause. I think that what is necessary is to ensure the SELECT in the WHERE clause is executed first... or something like that! Anyone has any ideas on how to combine these statements but not suffer from the performance impact?
The first statement is:
Select csi.instance_id,
OEL.ordered_item
of apps.csi_item_instances csi,.
Apps.oe_order_lines_all oel
where csi.instance_id in
(1718000,3698000,48740202)
and csi.last_oe_order_line_id = oel.line_id;
The second statement is:
Select / * + INDEX (IEA (attribute_id)) * /.
IEA.instance_id
apps.csi_iea_values do
where iea.attribute_id = 10004
and iea.attribute_value is not null;
The joint return is:
Select csi.instance_id,
OEL.ordered_item
of apps.csi_item_instances csi,.
Apps.oe_order_lines_all oel
where csi.instance_id in
(select / * + INDEX (IEA (attribute_id)) * /)
IEA.instance_id
apps.csi_iea_values do
where iea.attribute_id = 10004
and iea.attribute_value is not null)
and csi.last_oe_order_line_id = oel.line_id;
Thanks for any help,
Mike
Your subquery returns probably just two values that you did originally as constants - but the optimizer thinks that you're going to get 564 K lines. This is why the indicator for the simple query has a beneficial effect, it forces the Oracle to use an index when it would otherwise make a search.
When the subquery is incorporated, however, the optimizer uses its cardinality expected to decide whether to use a nested loop join or the hash join to CSI_ITEM_INSTANCES, since the large enough estimate, he uses the hash with a join analysis complete. That's why I pointed out that the fact to tell the optimizer to how many lines outside the subquery should make a difference.
Have you tried the "common table expression" approach, rather than approach no_merge, but it would not help because it does not change the optimizer for cardinality estimate. If you want to repeat the method CTE adding boards / * + materialize cardinality (2) * / to the query in the WITH clause, you should get the desired result.
Concerning
Jonathan Lewis
-
I see a source code for web site developers to use SQL Builder to build about 300 queries to SQL Server, but it can be done by a stored procedure or a group clause in the SQL statement.
The performance of the web site seems OK,
I would like to know ColdFusion runs the SQL Server 300 times or he is smart enough to know and convert it to face once the server only once.
Is there a performance impact ColdFusion or SQL Server-side?
Your information and your help is much appreciated,
Kind regards
iccsi,
iccsi wrote:
My question is that 300 queries can be simplified as a simple SQL as
Select MyName, count (MyID) from myTable
where myname = "Name1".
Group by MyName
Select MyName, count (MyID) from myTable
where myname = "Name2".
Group by MyName
Select MyName, count (MyID) from myTable
where myName = 'Name3 '.
Group by MyName
Maybe a couple of uses as follows
Select MyName, count (MyID) from myTable
Group by MyName
or save it as a stored procedure that the web server or web page only the database server a hit instead of 300 times.
I would like to know ColdFusion is smart enough to know the SQL are similar and only execute SQL against dabase server.
In my view, query-of-a-query is a smart enough solution for the problem. In the following example, ColdFusion visits the database only once!
Select MyName, count (MyID) from myTable
Group by MyName
Select *.
from myQuery
where myname = "Name1".
Select *.
from myQuery
where myname = "Name2".
...
...
Select *.
from myQuery
where myname = "Name300."
-
Not sure if I can do this with a simple query.
CREATE TABLE primary_table (SSN VARCHAR2 (15) VARCHAR2 (30) FIRST_NAME, LAST_NAME VARCHAR2 (30), VARCHAR2 (20)) of the STATE;
insert into primary_table VALUES ('111-11-1111, 'Elvis', 'Presley', 'ACTIVE');
insert into primary_table VALUES (222-22-2222', 'Gift', 'King', 'ACTIVE');
insert into primary_table VALUES ('33-333-3333, 'Lex', 'Harrison', 'ACTIVE');
CREATE TABLE secondary_table (SSN VARCHAR2 (15) NOT NULL, ARRIVAL DATE, NUMBER of LENGTH_OF_STAY);
insert into secondary_table VALUES ('11-111-1111 ", 1 January 2011", 10);
insert into secondary_table VALUES (' ' 222-22-2222 ", March 1, 2011", 10);
insert into secondary_table VALUES (' ' 222-22-2222 ", June 1, 2011", 20);
insert into secondary_table VALUES ('' 33-333-3333, January 1, 2011 ", 10);
========================================================================================
Hello
I created two very simple tables for this exercise. I don't know if I can do this with a simple query, or must use pl/sql.
I want to join primary_table secondary_table of SSNand list the fields of primary_table, but only if the join returns only a line.
In other words, I would like to create a list of data primary_table for primary_table lines that have only one line on the secondary table.
ConcerningRF25 wrote:
CREATE TABLE primary_table (SSN VARCHAR2 (15) VARCHAR2 (30) FIRST_NAME, LAST_NAME VARCHAR2 (30), VARCHAR2 (20)) of the STATE;insert into primary_table VALUES ('111-11-1111, 'Elvis', 'Presley', 'ACTIVE');
insert into primary_table VALUES (222-22-2222', 'Gift', 'King', 'ACTIVE');
insert into primary_table VALUES ('33-333-3333, 'Lex', 'Harrison', 'ACTIVE');CREATE TABLE secondary_table (SSN VARCHAR2 (15) NOT NULL, ARRIVAL DATE, NUMBER of LENGTH_OF_STAY);
insert into secondary_table VALUES ('11-111-1111 ", 1 January 2011", 10);
insert into secondary_table VALUES (' ' 222-22-2222 ", March 1, 2011", 10);
insert into secondary_table VALUES (' ' 222-22-2222 ", June 1, 2011", 20);
insert into secondary_table VALUES ('' 33-333-3333, January 1, 2011 ", 10);========================================================================================
Hello
I created two very simple tables for this exercise. I don't know if I can do this with a simple query, or must use pl/sql.
I want to join primary_table to secondary_table of NSSand the list of fields in the primary_table, but only if the join returns only a line.
In other words, I would like to create a list of data primary_table for primary_table lines that have only one line on the secondary table.
Concerning
Something like...
select p.
from primary_table p where p.ssn in (select s.ssn from secondary_table s group by s.ssn having count(*) = 1) -
Run the second sql statement only if the first sql statement is set to zero.
Hey guys I seem to have a mental block here. I have two sql statements. I would like to than the second to run only if the first sql statement is set to zero. I know that I can use PLsql but I would really like to see if I can do this with sql upward. Your answers are very much appreciated.
This is the first sql
second sql statementSelect ft.fund_code, ft.orgn_code, ft.acct_code, ft.amount, fb.owner_pidm, ft.prog_code from ftrbremb fb , ftcractg ft where fb.doc_code = 'TR000038' and fb.ftpbport_id = ft.ftpbport_id
How can I combine these two statements together so that when the first is null the second run. As a bonus, I want to get just the first line as well.Select ft.fund_code, ft.orgn_code, ft.acct_code, ft.amount, fb.owner_pidm, ft.prog_code from ftrbremb fb , ftcractg ft, ftprexps fx where fb.doc_code = 'TR000038' --and fb.ftpbport_id = ft.ftpbport_id and fx.ftrbremb_id = fb.id and ft.ftprexps_id = fx.id;
Any help would be greatly appreciated. I tried to accomplish with the case statement but it dosent everything seems to work for me.
Thank youMiguel,
the idea is simple: join the two queries (via the union of all) and to change the second part as to return only the rows if the first query returns no rows by changing the NOT EXISTS (first request). Hope I made it clear... ;)
-
SQL statement to retrieve value from the attribute using XPATH
Hi all
I think this is the right place to post this request since it is related to oracle and xpath.
I'm writing a sql statement of xpath that will extract the value of the column attribute is what type of clob data. Here is the xml example (xml_content is the column name)
< RAFSCREEN >
< Home >
< clientnumber reference = "123123" >
< / servant >
< RAFSCREEN >
I need to output query should return 123123.
I'm using query
Select extract (xmltype (xml_content), 'RAFSCREEN, Domestic, @clientnumber') as clientnumber from table_name
It will be very useful if someone answer this question.
Thank youIt is Possible...
10g> with form_content 2 as 3 ( 4 select 212 form_content_id , '
Your request (you need)
select form_content_id, extractValue(xmltype(xml_content),'/RAF/XBorderRAF/ReviewReferences/@clientLegalName') as clientnumber from form_content ;
-
Using a Bind Variable in the FROM of a SQL statement part?
Hi all
I have a problem, I am trying to execute a SQL statement. However, I need the FROM part of the SQL statement in a variable binding. This is because the end user will have to choose between 2 views of database.
I tried this:
Select CON_ID from: P23_DB_NAME where CON_LEGACY_ID =: P23_CONLEG_NO
I had no chance. The error I got was,
'+ The query cannot be parsed in the generator. If you believe that your request is
syntactically correct, choose the generic "columns" box below the
the source of the region without analysis.
"ORA-00903: invalid table name +".
What makes sence, but now I'm a little stuck.
Does anyone have ideas for a workaround?
Thanks in advance.
-N.S.N.O.
The example I gave you is quite simple. You must take some time to study it to see where you need to be very careful what put you where. Now, of course your example does not work becaues you have several errors. It will work for you:
DECLARE x VARCHAR2 (4000); BEGIN x := x || 'SELECT CON_ID FROM '; x := x || :p23_db_name; x := x || ' WHERE CON_LEGACY_ID = ' || :p23_conleg_no; RETURN (x); END;
Denes Kubicek
-------------------------------------------------------------------
http://deneskubicek.blogspot.com/
http://www.Opal-consulting.de/training
http://Apex.Oracle.com/pls/OTN/f?p=31517:1
------------------------------------------------------------------- -
Pinning on SQl statement in the library cache
Hello
Do to pin frequently used SQL statement to the shared pool...
I know that dbms_shared_pool.keep does the job for PL/SQL, but on simple SQL statements.
Experts from the clues?
Thank you
KingSee more of scripts:
-- Get address and hash_value of SQL statement select address, hash_value from v$sql where sql_text like 'your query to keep'; ------------------------------------------------------------------------------------------------ 00000000858CA2B0 2239673969 exec dbms_shared_pool.keep('00000000858CA2B0, 2239673969','C');
I think you want to pin the SQL statement that is specific to the moment analysis of long abovid.
I see no reason to pin the SQL more.Dion Cho
-
I have this PreExpression at a stage of SQL statement:
Locals.SQL_LatestResult = "SELECT UUT_RESULT.ID, UUT_RESULT. UUT_SERIAL_NUMBER, UUT_RESULT. START_DATE_TIME UUT_RESULT WHERE (((UUT_RESULT. UUT_SERIAL_NUMBER) =------"' + Locals.serial + ' \ ') AND ((UUT_RESULT." START_DATE_TIME) = (SELECT MAX (UUT_RESULT2. START_DATE_TIME) OF UUT_RESULT AS UUT_RESULT2 WHERE UUT_RESULT. UUT_SERIAL_NUMBER = UUT_RESULT2. UUT_SERIAL_NUMBER))); »
Locals.SQL_LatestResult has this value after the PreExpression:
SELECT UUT_RESULT.ID, UUT_RESULT. UUT_SERIAL_NUMBER, UUT_RESULT. START_DATE_TIME UUT_RESULT WHERE (((UUT_RESULT. UUT_SERIAL_NUMBER) = "15514011") AND ((UUT_RESULT. START_DATE_TIME) = (SELECT MAX (UUT_RESULT2. START_DATE_TIME) OF UUT_RESULT AS UUT_RESULT2 WHERE UUT_RESULT. UUT_SERIAL_NUMBER = UUT_RESULT2. UUT_SERIAL_NUMBER)));
I get the number of records = 0, if I run the sequence.
If I copy the exact same SQL query in access I get what I want to know a record.
If I remove that part of the query:
((UUT_RESULT. UUT_SERIAL_NUMBER) =------"" + Locals.serial + "\") "
I get 388 records which is correct and it run directly in access.
What's not here?
I was too fast for this post... it's my fault, the database link was wrong, so data were there...
Statements are very good!
-
Game of demand does not pick up the good period open to active fixed from the SQL statement
Hello
We have a demand that could kick off the simultaneous application of the value: Ixr: list of asset by period and Ixr: reserve book report.
ON overall demand, we set the parameter: default period based on a SQL = select period_name from FA_DEPRN_PERIODS where book_type_code = 'PER2011' and period_close_date is null
The query runs with the good period, until we open the new period, the game application will still come closed period.
When I run this script on the database, it gives the correct name of the open period.
Why all the demand does not pick up the open period?
Rock
Hello
When planning, the parameter values that you gave when planning will not change.
For the test, for a simultaneous program, I create a parameter and has given the value 100 tank and default type sql statement and the value as below.
Select to_char (sysdate, 'dd-mon-yyyy hh24:mi:ss') of double
If, at the time of the program, it shows a default value such as the date and time with seconds. Then I planned it for every minute.
When you check in for each race it is seen the first time only, it does not.
so in your case, you must plan its new after change of period.
Hope this will help you...
-
Vo SQL statement will not use aliases
Hello!
When I tried to enter the following code in the SQL statement in my definition of VO, it gave me an error in column ambiguously defined:
SELECT a.PERSON_ID,
a.EFFECTIVE_START_DATE,
a.EFFECTIVE_END_DATE,
a.EFFECTIVE_START_DATE,
a.EFFECTIVE_END_DATE,
a.EMPLOYEE_NUMBER,
a.FULL_NAME
OF PER_ALL_PEOPLE_F one
I need to put an alias because I need to refer to one of its columns inside the place where the condition. What is supposed to be the right way to set it?
Thank you.
whatever the dynamic where clause you add with setwhereclause, it is added on top of the query you mentioned in the original Version, so your alias doesn't work
Now if you look at the care of error fully you can see you are querying VO got closed in support () and another alias has been given by the framework (OAF) so all adding the whereclause by setwherelcause dynamically delete pls the 'a'., of the Sub statement
setWhereClause ("a.employee_number =: 1 and a.effective_end_date = (select max (effective_end_date) in the per_all_people_f where employee_number = a.employee_number) '");
ratther write like
setWhereClause ("employee_number =: 1 and effective_end_date = (select max (effective_end_date) in the per_all_people_f b where b.employee_number =: 2)" ");
setWhereClauseParams (null); Always reset
setWhereClauseParam (0, EmpNumber);
setWhereClauseParam (1, EmpNumber);
I hope that is clear, if not please let me know.
Kind regards
Hemant
-
How to run a SQL statement to use a specific implementation plan
Hi all
I have a SQL that has recently been run badly. I tried the Advisor tuning SQL for the given SQL query and it gives the following information:
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Name of the task of tuning: 2q94zb7djr2xn
The owner task of tuning: LMDBPROD
Type of work: single SQL statement
County of execution: 2
The current run: EXEC_8869
Type of execution: TUNE SQL
Scope: COMPLETE
Time Limit (seconds): 60
Status: COMPLETED
Started on the: 03/02/2014-20:43:39
To the: 03/02/2014 20:44:25
-------------------------------------------------------------------------------
Name of the schema: LMDBPROD
SQL ID: 2q94zb7djr2xn
SQL text: SELECT NPCOMMON. FGET_ACTION_CODE (ORDNUM) ACTIONCODE, STATUS,
SUMA COUNT (*) FROM SORDER, WHERE HEADORDNUM IS NOT NULL AND
NPCOMMON. FGET_PRODUCTOFFER4ORDER (ORDNUM) IN (SELECT ID FROM)
PRODUCTOFFER WHERE PPSPECIFICATION_ID IN (SELECT ID FROM)
PPSPECIFICATION WHERE PCLASS_CODE IN (SELECT PCLASS_CODE FROM)
ARUSERGROUP WHERE CODE IN (SELECT ARUSERGROUP_CODE FROM)
ARUSER_ARUSERGROUP WHERE ARUSER_USERNAME =: B1 AND STATUS = '1')
AND STATUS = '1'))) GROUP BY NPCOMMON. FGET_ACTION_CODE (ORDNUM),
STATUS
-------------------------------------------------------------------------------
RESULTS SECTION (1 result)
-------------------------------------------------------------------------------
1-alternative Plan conclusion
---------------------------
Some implementation plans alternative for this statement was found by searching
performance data in real-time and historical of the system.
The following table lists these plans sorted by their average time.
See "SECTION of ALTERNATIVE PLANS" section for detailed information on each
plan.
plan ID hash last visit elapsed note of origin (s)
-- ---------- -------------------- ------------ --------------- ----------------
1 617797893 2013-07-11/07: 45:20 9.555 no reproducible STS
2 1311086720 2014-01-31/04: 00:44 19.569 AWR
3 1226863820 2014-01-31/18: 00:24 AWR 21.158
4 1359606848 2014-02-03/16: 00:34 21.492 AWR original plan
The plan with hash 617797893 seems the most efficient one and is based on some specific SQL Tuning Set I ran on this time. But the note says that the plan is not reproducible. Is there anyway how can I force the SQL statement to execute the plan? The database version is Standard Edition 11.2.0.1.0
Best regards
Rodriguez
Hello
I think you can use this
before 11 g, we used to create an outline stored for this.
concerning
Maybe you are looking for
-
Filters stopped working after deleting the .msf files
Thunderbird has become slow and unresponsive so I used a tool to correct the problem, thunderfix.(probably it was preferable to delete the files manually, as in almost every case XD) Mailboxes are smooth now, however, the filter not covered more.When
-
I tried to download the new version of firefox and it downloaded but then replaced my old version and now it works everything simply. I want my old version back - this has worked. I'm on an old macbook 10.4 (2005).
-
Satellite A660 will not start again until I turn safe mode
Just buy the toshiba Satellite A660: I tell the story to compensate closely in my answer, I hope... I just buy new, run the Setup for first use. When its up and running only in that day, that I noticed it start to hang up when I plugged the drive ext
-
the airport does not connect to the internet new
I moved and now my airport does not connect to my new internet provider. Can anyone suggestion solutions?
-
Cannot connect to the administrator account because the password is not valid
Original title: I HAVE VISTA... ALL OF A SUDDEN FOR A DAY, I TRIED TO LOG INTO MY ADMIN PAGE AND MY PASSWORD IS NO LONGER VALID HOW TO RETURN TO THE PAGE OF MY ADMIN WITH ALL MY MUSIC PROGRAMS, ETC.? I tried to connect to my admin page and it will no