Required SQL query
Hello
Suppose I need to check the number of records of 30 tables in the oracle database in a particular schema, it may have hundreds of tables.
How to check with simple sql query.
I know that under method,
Select count (*) from
Table1, table2, table3... table30;
But I need in format below. If I use Group by we will get but we must specify all 30 tables to groupby, is any alternative group instead of keep all 30 tables
SELECT TABLENAME, COUNT (*)
OF table1, table2, table3... table30
Group of table1, table2, table3... table30;
Try the following query if all tables are present in the same pattern in the case otherwise you must use dba_tables:
SELECT table_name, to_number( extractvalue( XMLTYPE( dbms_xmlgen.getxml('select count(*) c from '||table_name)) ,'/ROWSET/ROW/C')) count FROM user_tables WHERE table_name IN ('A','B','C') ORDER BY table_name;
Tags: Database
Similar Questions
-
What can be the SQL query for this requirement?
Hello
I have a table with the fields like this:
ID DESC PARENT
01 02 ABC
02 01 ABC1
03 01 ABC2
04 02 ABC4
In the table above column PARENT refers to the column ID, but actually in the SQL query, I want to have ID DESC and PARENTDESC (i.e., desc ID value corresponding)
Output real I need is
SELECT ID, DESC? from table where ID = someValue. Now, if I provided ID = 01 then output should be like this:
ID DESC PARDESC
ABC1 ABC 01
Can anyone help on what may be the required sql query?
Published by: bootstrap on April 29, 2011 06:15SELECT T1.ID, T1. DESC, T2. / / DESC
FROM TABLEA T1, T2 TABLEA
WHERE T1.ID = '01'
AND T2.ID = T1. PARENT; -
SQL query to retrieve only numbers to a string variable
Dear all Experts,
I have a requirement in one of my projects where I need to extract only the numbers present in the variable.
for example:
BANK_ACCOUNT_NUMBER = 12345-67890';
BANK_ACCOUNT_NUMBER = 12345 67890';
BANK_ACCOUNT_NUMBER = "123.456.7890";
BANK_ACCOUNT_NUMBER = 123-A456BC7890D';
In all these cases, I need to retrieve only numbers such as BANK_ACCOUNT_NUMBER = 1234567890 and I am looking for SQL query only.
Please suggest me the query how to extract numeric values from varchar variable.
Thank you
Knockaert
select regexp_replace('123-A456BC7890D','[^0-9]') from dual;
See you soon,.
Manik.
-
How to do a validation based on the SQL query?
Hello
I have a requirement to perform a validation on a field (messageTextinput) in my page OAF.
When I click the button apply, the value in this field is validated based on a SQL query (for example, the value in the field NOT IN (value1 select from table1).)
Help, please.
Best regards
Joe
1. create a SQL query based VO, XXVO. For example:-SQL query is select xx_table;
2. Enter the "Apply" button click event in the controller and run the AM method passing the value entered by the user in the given field, for example:-value is VAL1
3. in the method of the AM, get a handle of the VO, the whereClause and run.
OAViewObjectImpl vo = findViewObject ("XXVO1"); XXVO1 is the name of the instance of the VO above, XXVO
vo.executeEmptyRowSet ();
vo.setWhereClause (null);
vo.setWhereClause ("value =" + VAL1 + "'");
vo.executeQuery ();
If (VO. GetRowCount() > 0)
A record is with the value of VAL1. Perform the required action
I hope this helps.
-
Feature of the parallel execution of SQL query
Hello guys,.
I installed a 11 GR 2 Oracle RAC (11.2.0.3) database, but I see the use of the feature of running parallel SQL queries, but I never used that.
I would like to know if this feature is enabled by default on CCR environments and if it does not require me to pay for Enterprise Edition.
NAME DETECTED_USAGES FIRST_USA LAST_USAG CURRE
---------------------------------------------------------------- --------------- ----- --------- ---------
Checking Options 1 TRUE 9 October 15 October 9, 15
BMG Auto setting 1 TRUE 9 October 15 October 9, 15
Memory of the execution of SQL auto 1 TRUE 9 October 15 October 9, 15
Automatic management of the space Segment (System) 1 TRUE 9 October 15 October 9, 15
Automatic Storage Management 1 TRUE 9 October 15 October 9, 15
Management of the Undo Automatic 1 TRUE 9 October 15 October 9, 15
Character set 1 TRUE 9 October 15 October 9, 15
Deferred Segment creation 1 TRUE 9 October 15 October 9, 15
Locally managed tablespaces (System) 1 TRUE 9 October 15 October 9, 15
Locally managed tablespaces (user) 1 TRUE 9 October 15 October 9, 15
Logfile multiplexing 1 TRUE 9 October 15 October 9, 15
Oracle Java Virtual Machine (System) 1 TRUE 9 October 15 October 9, 15
Oracle utility of metadata API 1 TRUE 9 October 15 October 9, 15
1 SQL query in parallel TRUE 9 October 15 October 9, 15
Partitioning (System) 1 TRUE 9 October 15 October 9, 15
Real Application Clusters (RAC) 1 TRUE 9 October 15 October 9, 15
Recovery zone 1 TRUE 9 October 15 October 9, 15
SECUREFICHIERS (System) 1 TRUE 9 October 15 October 9, 15
SECUREFICHIERS (user) 1 TRUE 9 October 15 October 9, 15
The parameter server file 1 TRUE 9 October 15 October 9, 15
Thanks in advance,
Franky
You are not, but Oracle is, since you are using RAC. Oracle relies on execution in parallel against the gv$ views so even if you can't use it in SE way common Oracle can when it comes to query against one of the points of view gv$. That's why DBA_FEATURE_USAGE_STATISTICS reports that you see.
David Fitzjarrell
-
SQL query for the region of the tree
Hello
I was wondering if someone is able to help me work on a SQL query, to format the data in the table required in a part of the tree... I've never used a tree and I'm fighting to get the right data (if possible).
The data in the table looks like this:
I want to put it in a tree, using level 1 level6 with a final layout that would look like this:
As you can see, the data are formatted in level6 down in the tree, but are filled in the table from level 1. Not all of the columns will be filled, so level2 for anyone 4 (France) is the equivalent of level in the tree like level6 to person 1 (Spain).
This is Apex 4.2.5
Oracle 11.2.0.3.0
Sample data:
CREATE TABLE employees ( employee VARCHAR2(100), level1 VARCHAR2(100), level2 VARCHAR2(100), level3 VARCHAR2(100), level4 VARCHAR2(100), level5 VARCHAR2(100), level6 VARCHAR2(100) ); INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person1','Team One','Recruitment','Human Resources','Fictituous Company','Murcia','Spain'); INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person2','Team Four','Testing','IT','Big Corporate','Hanover','Germany'); INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person3','Big Corporate','Hanover','Germany', null, null, null); INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person4','Brittany','France', null, null, null, null); INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person5','Team Three','Testing','IT','Big Corporate','Hanover','Germany'); INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person6','Public Relations','Government Agency','Brittany','France', null, null);
Added example given.
Hello
Apex-user wrote:
Thanks Frank, this is a good example, I can work with that! Your assumptions are correct.
A question I came, however, is that I have a data segment that comes across poorly formatted so to speak... where only the lower levels (1-2, etc.) have been filled from the bottom up.
An example of this data would be:
- INSERT INTO employees (employee, level 1, 2, level3, level4, level5, level6) VALUES ('Person7', 'One Team', 'Test', null, null, null, null);
As you can see that if you rerun the select, the test team is now duplicated, both at the level of the root in the tree as it should.
You are not sure if the sql can be adjusted to account for this, or if it's too hard?
It is obviously a question of data and I am trying to solve this separately (extracted data from another system out of my control).
Thank you!
Sorry, I'm confused.
You say that my assumptions were correct. What includes supported that "If test ' occurs under 'IT' in a row, then the extent of the 'Testing' occurs, it must be under"IT "? Right after you say that assumptions are correct, you give an example where 'Testing' occurs under 'IT' to a single line, but it is not less 'IT' to another line and where is 'One Team' under 'Testing' in a line, but is 'One Team' under 'Recruitment' in another row.
When a situation like this occurs, how you cope? Whenever you have a problem, please post the exact results you want from the given sample data, and an explanation of how you get these results. If you don't know about what would be the ideal results, or if you are flexible on the exact results, then at least give an example and explain your reasons.
Maybe you want to change the got_parent of subquery like this:
WITH unpivoted_data AS
(
SELECT *.
Employees
UNPIVOT (node_name
FOR lvl (level1 AS 1
level2 AS 2
level3 AS 3
level4 AS 4
level5 AS 5
level6 AS-6
)
)
)
got_parent AS
(
SELECT c.node_name
MIN (p.node_name) AS a parent
Of unpivoted_data c
LEFT OUTER JOIN unpivoted_data p ON p.employee = c.employee
AND p.lvl = c.lvl + 1
GROUP BY c.node_name
)
SELECT LPAD (' ' ')
2 * (LEVEL - 1)
) || Node_name AS entity
OF got_parent
START WITH parent IS NULL
Parent = node_name PRIOR CONNECTION
;
In this way, if 'Test' is current 'IT' in one line, but not under what in another line, whether under would consider the 'IT' request and not to be a root. If 'One Team' sudden 'Testing' in a line, but under "Recruitment" in another line, it will be (arbitrarily) consider it under "recruitment".
-
SQl query to find out time between the different lines of transactions
(See both images from an attachment to get the clear picture of the data and understand the question correctly.)
I have a set of data like this in one of my paintings. (This is a simple representation of the original data.)
Reference table1.jpg
Id | Type | Value | Start_date | End_date
----------------------------------------------------------------------------------------------------------------------
ZTR0098 | ALLOW | 0 | 1 JUN | 2 JUN |
ZTR0098 | ADTAX | 0 | 1 JUN | 2 JUN |
ZTR0098 | MXTAX | 0 | 1 JUN | 9 JUN |
ZTR0098 | ALLOW | 4. 3 JUN | 15 JUN |
ZTR0098 | ADTAX | 44.00 | 3 JUN | 17-JUNE |
ZTR0098 | MXTAX | 2. 10 JUN | 17-JUNE |
ZTR0098 | ALLOW | 5. 16-JUNE | 20 JUN |
ZTR0098 | ADTAX | 55,34 | 18 JUN | 22 JUN |
ZTR0098 | MXTAX | 1. 18 JUN | 25 JUN |
ZTR0098 | MXTAX | 6. 26 JUN | 31 AUG |
ZTR0098 | ADTAX | 20.09. 23 JUN | 23 JUL |
ZTR0098 | ALLOW | 8. 21 JUN | 31 AUG |
ZTR0098 | ADTAX | 45. 24 JUL | 31 AUG |
each line has a type and a rasthaus id to it. ID belongs to other parent tables. the value of each type is given, and the validity of each value is followed by a field start_date and end_date.
All values start from 1 - JUN and expires on 31 - AUG. Now my requirement is to obtain a report that gives three columns for three different types (ALLOW, ADTAX and MXTAX) with combination of unique values in the effective time interval. Let me put the result below.
Reference table2.jpg
Id | ALLOW | ADTAX | MXTAX | Start_date | End_date
--------------------------------------------------------------------------------------------------------------------------------------------------
ZTR0098 | 0 | 0 | 0 | 1 JUN | 2 JUN |
ZTR0098 | 4. 44.00 | 0 | 3 JUN | 9 JUN |
ZTR0098 | 4. 44.00 | 2. 10 JUN | 15 JUN |
ZTR0098 | 5. 44.00 | 2. 16-JUNE | 17-JUNE |
ZTR0098 | 5. 55,34 | 1. 18 JUN | 20 JUN |
ZTR0098 | 8. 55,34 | 1. 21 JUN | 22 JUN |
ZTR0098 | 8. 20.09. 1. 23 JUN | 25 JUN |
ZTR0098 | 8. 20.09. 6. 26 JUN | 23 JUL |
ZTR0098 | 8. 45. 6. 23 JUL | 31 AUG |
As you can see there are no duplicate rows for a combination of (ALLOW, ADTAX and MXTAX) with their respective dates in force. resulting in the above table. the first step is to convert lines to the column which is pretty obvious to do that by grouping on start_date and end_date colum, but the real deal is the time interval during which the combination of the values (ALLOW, ADTAX, and MXTAX) has remained constant.
I wrote under query using Group by.
Select
ID,
NVL (max (decode (type, "ALLOW", value)), 0) as ALLOW
NVL (max (decode (type, 'ADTAX', value)), 0) as ADTAX
NVL (max (decode (type, 'MXTAX', value)), 0) as MXTAX
Start_date,
End_date
from my_table
Group of start_date, end_date, id
start_date, end_date
the results it gives are like this:
Reference table3.jpg
Id | ALLOW | ADTAX | MXTAX | Start_date | End_date
------------------------------------------------------------------------------------------------------------------------------------------------
ZTR0098 | 0 | 0 | 0 | 1 JUN | 2 JUN |
ZTR0098 | 0 | 0 | 2. 1 JUN | 9 JUN |
ZTR0098 | 4. 0 | 0 | 3 JUN | 15 JUN |
ZTR0098 | 0 | 44.00 | 0 | 3 JUN | 17-JUNE |
ZTR0098 | 0 | 0 | 2. 10 JUN | 17-JUNE |
ZTR0098 | 5. 0 | 0 | 16-JUNE | 20 JUN |
ZTR0098 | 0 | 55,34 | 0 | 18 JUN | 22 JUN |
. .
. .
like wise
but I'm not able to determine the time intervals by using the SQL query.
with
Table1 as
(select the id 'ZTR0098', 'ALLOW' type, 0 val, to_date('1-JUN','dd-MON') start_date, end_date Union to_date('2-JUN','dd-MON') double all the)
Select 'ZTR0098', 'ADTAX', 0, to_date('1-JUN','dd-MON'), to_date('2-JUN','dd-MON') of all the double union
Select 'ZTR0098', 'MXTAX', 0, to_date('1-JUN','dd-MON'), to_date('9-JUN','dd-MON') of all the double union
Select 'ZTR0098', 'ALLOW', 4, to_date('3-JUN','dd-MON'), to_date('15-JUN','dd-MON') of all the double union
Select 'ZTR0098', 'ADTAX', 44.00, to_date('3-JUN','dd-MON'), to_date('17-JUN','dd-MON') of all the double union
Select 'ZTR0098', 'MXTAX', 2, to_date('10-JUN','dd-MON'), to_date('17-JUN','dd-MON') of all the double union
Select 'ZTR0098', 'ALLOW', 5, to_date('16-JUN','dd-MON'), to_date('20-JUN','dd-MON') of all the double union
Select 'ZTR0098', 'ADTAX', 55.34, to_date('18-JUN','dd-MON'), to_date('22-JUN','dd-MON') of all the double union
Select 'ZTR0098', 'MXTAX', 1, to_date('18-JUN','dd-MON'), to_date('25-JUN','dd-MON') of all the double union
Select 'ZTR0098', 'MXTAX', 6, to_date('26-JUN','dd-MON'), to_date('31-AUG','dd-MON') of all the double union
Select 'ZTR0098', 'ADTAX', 20.09, to_date('23-JUN','dd-MON'), to_date('23-JUL','dd-MON') of all the double union
Select 'ZTR0098', 'ALLOW', 8, to_date('21-JUN','dd-MON'), to_date('31-AUG','dd-MON') of all the double union
Select 'ZTR0098', 'ADTAX', 45, to_date('24-JUL','dd-MON'), to_date('31-AUG','dd-MON') of the double
),
days like
(select level - 1 dte + to_date('1-JUN','dd-MON')
of the double
connect by level<= to_date('31-aug','dd-mon')="" -="" to_date('1-jun','dd-mon')="" +="">=>
)
Select id, allow, adtax, mxtax, min (dte) start_date, max (dte) end_date
(select ID, dte, max (allow) allow, max (adtax) adtax, max (mxtax) mxtax,
ROW_NUMBER() over (order by dte) row_number() - courses (partition by order max (allow), max (adtax), max (mxtax) by dte) gr
go (select id, dte,
-case when type = 'ALLOW' and dte between start_date and end_date then end val 0 otherwise allow.
-case when type = "ADTAX" and dte between start_date and end_date then val 0 otherwise end adtax.
-case when type = "MXTAX" and dte between start_date and end_date then val 0 otherwise end mxtax
Table 1 t,
days d
where d.dte between t.start_date and t.end_date
)
Group by id, dte
)
Group by id, gr, allow, adtax, mxtax
order by id, gr
ID ALLOW ADTAX MXTAX START_DATE END_DATE ZTR0098 0 0 0 01/06/2015 02/06/2015 ZTR0098 4 44 0 03/06/2015 09/06/2015 ZTR0098 4 44 2 10/06/2015 15/06/2015 ZTR0098 5 44 2 16/06/2015 17/06/2015 ZTR0098 5 55,34 1 18/06/2015 20/06/2015 ZTR0098 8 55,34 1 21/06/2015 22/06/2015 ZTR0098 8 20.09 1 23/06/2015 25/06/2015 ZTR0098 8 20.09 6 26/06/2015 23/07/2015 ZTR0098 8 45 6 24/07/2015 31/08/2015 Concerning
Etbin
-
SQL query to represent the data in the graph bar
Hello
JDev 11.1.1.5.0
We must create a dashboard to track the translation. We have created the ADF table with buttons 'Create', 'Update' and 'Delete' to manipulate the table.
Our DB table structure is
File_id (PK), File_Name, ToSpanish - ARE (YES/NO), beginning of the ToSpanish, ToChina(YES/No), ToChina-Date... etc.
Once the translated file required language then user must update the DB table using the button "Update".
So far, we have implemented the requirement above.
We need represent the status of the translation in the graph bar with the language as X access and file count get access Ex: Spanish-100 China - 200 files files
Please suggest the sql query to retrieve the necessary info from the DB table that can be represented in the graph bar. Also, it would be great, if you can provide a pointers to create a bar chart.
Thanks in advance,
MSR.
If you set your major increment and minor than 1, then you won't not show decimal points. You can try setting these 10 or 100 to reach your goal.
Subtype = "BAR_VERT_CLUST" >
-
How to display time in 010403 format if the entry is transmitted as ' 1 hour, 4 minutes, 3 seconds"sql query @.
Hello
You can try:
Select lpad (regexp_substr ('1 hour, 4 minutes, 3 seconds ',' [[: digit:]] + ""), 2, '0')
|| LPAD (regexp_substr ('1 hour, 4 minutes, 3 seconds ',' [[: digit:]] +', 1, 2), 2, '0')
|| LPAD (regexp_substr ('1 hour, 4 minutes, 3 seconds ',' [[: digit:]] +' 1, 3), 2, '0')
Double;
but this requires maximum 99 hours/minutes/seconds ago in your entry.
-
Hello
I have a data in table (raj_table) with columns (char11) raj_id, raj_number (varchar2 (15)), raj_format (NUMBER), Primary_ID (identity with the values of the primary key column)
Primary_ID raj_id Raj_number Raj_format
1 raj rajvend 1
2 raj rajvend 1
3 raj rajvendor1 2
4 raj rajvendor1 2
5 raj rajvendor1 2
6 raj rajvendor2 3
I used under SQL to get query output as below, but has not achieved the required result:
Select client_id vendor_number, vendor_format, primary_id, row_number() on sl_no (client_id partition, primary_id, vendor_format order of client_id primary_id, vendor_format, vendor_number, vendor_number)
from raj_table by sl_no asc
SL_NO raj_id raj_number raj_format primary_id
1 1 raj rajvendor 1
1 2 raj rajvendor 1
2 3 raj rajvendor1 2
2 4 raj rajvendor1 2
2 5 raj rajvendor1 2
3 6 raj rajvendor2 3
I need help with a SQL query to get the result as above without using the group by clause. I want to bring together the combination of separate line of the three columns (raj_id, raj_number, raj_format) and add a unique serial number for each online game (SL_NO column below). So, above there are 3 unique set of (raj_id, raj_number, raj_format) I can get in a group by clause, but I can not add prmiary_id, SL_NO values if I group by clause. I used the analytical functions like row_number() but no luck. Need solution for this.
with t as)
Select 'raj' raj_id, 'rajvend' raj_number, 1 raj_format, 1 primary_id Union double all the
Select option 2, 'raj', 'rajvend', 1 double Union all
Select 3, 'raj', 'rajvendor1', 2 double Union all
Select 4, 'raj', 'rajvendor1', 2 double Union all
Select 5, 'raj', 'rajvendor1', 2 double Union all
Select 6, 'raj', 'rajvendor2', 3 double
)
Select dense_rank() over (order of raj_id, raj_number, raj_format) sl_no,
t.*
t
order by primary_id
/
PRIMARY_ID RAJ RAJ_NUMBER RAJ_FORMAT SL_NO
---------- ---------- --- ---------- ----------
1 1 raj rajvend 1
1 2 raj rajvend 1
2 3 raj rajvendor1 2
2 4 raj rajvendor1 2
2 5 raj rajvendor1 2
3 6 raj rajvendor2 36 selected lines.
SQL >
SY.
-
SQL QUERY THAT RETURNS THE PL/SQL
Hello
I'm putting in 4.2 below apex
DECLARE
date of frdate: =: P22_FROMDATE;
date date: =: P22_TODATE;
l_date1 varchar2 (11): = to_char(frdate,'dd-mon-yyyy');
l_date2 varchar2 (11): = to_char(todate,'dd-mon-yyyy');
v_sql varchar2 (32000);
v_Name varchar2 (4000): = months_name (frdate, todate);
char (1) of the v1: = q "[']";
number of lbr1 (6): =: P22_FROMBRANCH;
number of LBR2 (6): =: P22_TOBRANCH;
number of M1 (6): = 11;
Start
v_sql: ='SELECT * FROM (SELECT LBRCODE, PRDACCTID, MN, AVGX FROM (SELECT LBRCODE, PRDACCTID, MN, SUM (BALL) BALL, COUNT (MN) DAYS, ROUND (SUM (BAL) count (MN), 2) AVGX ';))
v_sql: = v_sql | "FROM (SELECT LBRCODE, PRDACCTID, TO_CHAR (BALDATE,'|)) CHR (39) | ' MM' | CHR (39) |') ' | ' ||'|| CHR (39) | » _'|| CHR (39) |' | ' || «TO_CHAR (BALDATE,'|)» CHR (39) | ' AAAA '. CHR (39) |') MN, BALL ';
V_SQL: = V_SQL | "(SELECT Q2. LBRCODE, Q2. PRDACCTID, T1. BALDATE, T_OST_NEW (Q2. LBRCODE, Q2. PRDACCTID, T1. BALDATE) BALL ';
V_SQL: = V_SQL | "FROM (select TO_DATE('||) Chr (39) | l_date1 | Chr (39) | «, » || CHR (39) | ' DD-MON-YYYY ' | CHR (39) |') baldate FROM DUAL Union all the ';
V_SQL: = V_SQL |' select (TO_DATE('||) Chr (39) | l_date1 | Chr (39) | «, » || CHR (39) | ' DD-MON-YYYY ' | CHR (39) |') + level) double baldate ';
V_SQL: = V_SQL |' connect by level < = (TO_DATE('||) Chr (39) | l_date2 | Chr (39) | «, » || CHR (39) | ' DD-MON-YYYY ' | CHR (39) |') -TO_DATE('||) Chr (39) | l_date1 | Chr (39) | «, » || CHR (39) | ' Dd-mon-yyyy ' | CHR (39) |')) ) Q1,';
V_SQL: = V_SQL | "(SELECT LBRCODE,'|) ' (rpad (prdcd, 8,'|)) V1 ||'' || v1 |') || LTRIM (rpad('|| v1 ||) » x'|| V1 | «, 25, » || v1 | » 0' || v1||'),'|| v1 | » x'|| v1 |')) prdacctid OF D009021 WHERE the LBRCODE between ' | : P22_FROMBRANCH |' and ' | : P22_TOBRANCH | "AND moduleinfo =' | TO_NUMBER(:P22_SELECTLIST);
V_SQL: = V_SQL |') ((Q2)) GROUP BY LBRCODE, PRDACCTID, MN))';
V_SQL: = V_SQL | "PIVOT (MAX (AVGX) (MN) IN (';))
V_SQL: = V_SQL | V_NAME;
V_SQL: = V_SQL |')) ORDER OF LBRCODE, PRDACCTID ';
RETURN V_SQL;
END;
I created all the elements of the required page
I get the error message like missing expression
to test, I created a function to return the query, it works very well know to return a query that gives me desired report
am I missing something?
Help, please
HEMU wrote:
Hello Sir
Sorry to bother you again
I tried to use «function that returns colon-delimited topics»
and I got following error
unable to determine query headings: ORA-06550: line 1, column 138: PLS-00103: Encountered the symbol ";" when expecting one of the following: . ( ) , * % & = - + < / > at in is mod remainder not rem => <> or != or ~= >= <= <> and or like like2 like4 likec between || multiset member submultiset The symbol ")" was substituted for ";" to continue.
failed to parse SQL query:
can take you a look at page901 once again please and a function named months_namex
is it feasible that I'm looking for?
The immediate cause of this error is simply incorrect report headings function call syntax:
return months_namex(to_date(:p901_fromdate,'dd-mon-yyyy'),to_date(:p901_todate,'dd-mon-yyyy')
This should be:
return months_namex(to_date(:p901_fromdate,'dd-mon-yyyy'),to_date(:p901_todate,'dd-mon-yyyy'));
However there is no
months_namex
function defined in the workspace. -
What is the best way to optimize a SQL query: call a function or doing a join?
Hi, I want to know what is the best way to optimize a SQL query, call a function inside the SELECT statement, or make a simple join?
It depends on. Could be a. Could be the other. Could be no difference. You would need to compare with your tables in your environment with your settings.
If you put a gun to my head, I was given no other information and required that I answered the question, I would tend to wait that the join would be more effective. In general, if you can do something in pure SQL, it will be more effective than if you call PL/SQL.
Justin
-
Hello
Here's my data in the table for itm_id = 1000
ITM_ID ADD_ATR DEL_ATR 1000 a: b:c:d 1000 d 1000 d 1000 e:f:g 1000 e:f:g My required return is (a: b:c:d) d = a: b: c + d = a: = a +(e:f:g) b:c:d: b:c:d:e:f:g-(e:f:g) = a: b: c; d
Output ITM_ID
1000A: b:c:d
can we get the output using the sql query above?
I had tried with union but could not able to get the required result.
Please let me know if there is no possible solution
Thank you
David
I have the impression that you are looking to treat each character in 'RTA' as an individual item and then add or delete depending on whether they are an ADD_ATR or DEL_ATR.
So something like...
SQL > ed
A written file afiedt.buf1 with t as (select 1000 as itm_id, ' a: b/c: some like add_atr, null as del_atr of all the double union)
2 select 1000, null, would be "union double all the"
3 select 1000, 'd', null of union double all the
4 select 1000, 'e:f:g', null of union double all the
5 select 1000, null, "e:f:g" of all the double union
6 select 1234, null, "x: y: z" of all the double union
7 select 1234, 'u: v: w', null of union double all the
8 select 1234, null, 'u' of all the double union
9 select 1234, "x: y", null of union double all the
10. Select 1234, "x: z", null of union double all the
11. Select 1234, 'p', the double null
12 )
13-
14. end of test data
15-
16. Select itm_id
17, cast (listagg(atr,':') within the Group (order by atr) as varchar2 (40)) output
18 of)
19 select itm_id
20, atr
21, sum (add_del)
22 of)
23 select itm_id
24, coalesce(add_atr,del_atr) as full_atr
25, decode (add_atr, null,-1, 1) as add_del
26, regexp_substr (coalesce(add_atr,del_atr),'[^:] +', 1, level) RTA
27, flat surface that l
28 t
29 to connect by level<= (length(coalesce(add_atr,del_atr)="">=>
30 and itm_id = prior itm_id
31 and coalesce(add_atr,del_atr) = prior coalesce(add_atr,del_atr)
sys_guid() 32 and prior is not null
33 )
34 group by itm_id, atr
35 having sum (add_del) > 0
36 )
37 * group by itm_id
SQL > /.ITM_ID OUTPUT
---------- ----------------------------------------
1000A: b:c:d
1234 p:v:w:xthat just shows how stupidly data is as it should be divided every thing in the different elements so that you can then group to determine how many of each, you have (and whether to add or subtract) and then re - combine results again in a combined string.
-
Need for SQL query to get the result.
Region
Month Trx type Summary of the resolution AMERICAS -13 may Adjustments Fix EMEA -13 may Adjustments Incorrect AMERICAS -13 may Credit memo Incorrect EMEA -13 may Invoice Fix AMERICAS -13 may Credit memo Fix OFD -13 may Adjustments Fix AMERICAS -13 may Invoice Incorrect DVL -13 may Adjustments Fix DVL -13 may Adjustments Fix OFD -13 may Adjustments Fix Above my Table and here is the result required. Similarly for other regions as well. Can someone help me with the SQL query?
Region Summary of the resolution Setting Credit memo Invoice Total general AMERICAS Fix 1 1 2 Incorrect 0 1 1 2 Like this?
SQL > select * from transaction_audit;
MTH TRX_TYPE REGION BOARD
-------- ------ ----------- ---------
AMERICAS-13 may SETTINGS CORRECT
EMEA-13 may INCORRECT ADJUSTMENT
AMERICAS-13 may CREDIT MEMO INCORRECT
EMEA-13 may INVOICE CORRECT
AMERICAS-13 may CREDIT MEMO CORRECT
OFD-13 may SETTINGS CORRECT
AMERICAS-13 may INVOICE INCORRECTE
LAD-13 may SETTINGS CORRECT
LAD-13 may SETTINGS CORRECT
OFD-13 may SETTINGS CORRECT10 selected lines.
SQL > select region
2, resolution_summary
3, count (decode (trx_type, "ADJUSTMENTS", trx_type)) adjustments
4, County (decode (trx_type, 'HAVING', trx_type)) credit_memo
5, County (decode (trx_type, "BILL", trx_type)) Bill
transaction_audit 6
Group 7
8 by region
9, resolution_summary
10 Decree
11 by region
12, resolution_summary
13.REGION TAKE ADJUSTMENTS CREDIT_MEMO INVOICE
-------- --------- ----------- ----------- ----------
CORRECT THE AMERICAS 1 1 0
0 1 1 INCORRECT AMERICAS
EMEA CORRECT 0 0 1
INCORRECT EMEA 1 0 0
DAL ADDRESS 2 0 0
OFD CORRECT 2 0 06 selected lines.
SQL >
-
SQL query for the mapping of a set of prizes to a group of classrooms
Hi all
I use Oracle database 11g Release 2.
I have the following data set:
Classrooms
ClassId ClassName ability group
------ ---------------------------------------------- -------------- -----------
Babbage/software Engg Lab 1 24 1
Basement 2 - block PG 63 1
3 1 56 1 class
Class 4 1 24 10
Class 5 1 24 11
Class 6 1 35 12
7 13 42 1 class
8 14 42 1 class
9 15 42 1 class
10 2 35 1 class
11 3 35 1 class
12 4 35 1 classroom
13 5 35 1 class
14 6 25 1 class
15 7 25 1 class
16 1 24 8 class
17 9 24 1 class
18 control Sys Lab 1 24
19 dig & Embd Sys Lab 20 1
20 PSD & Comm 20 1 Lab
21 electromechanical system Lab 28 1
Farabi 22/Web Tech Lab 1 36
23 gen purpose Lab 40 1
Shirazi/24dB Tech Lab 1 36
ADV 25 elect Lab 30 2
26 16 42 2 class
27 17 49 2 class
28 18 56 2 class
29 19 42 2 class
30 20 49 2 class
Class 31 21 35 3
32 22 35 3 class
33 20 3 MDA lab
DegreeBatches
BatchId BatchName force
--------------- ----------------------- --------------
1 BIT - 11 79
2 BIT - 12 28
3 BS (CS)-1 35
4 BS (CS) 78-2
5 BE (SE)-1 69
6. BE (SE) 84-2
7 BE (SE) 64-3
8 84 BYTČA-7
9 43 BYTČA-8
BEE-1 10, 112
11 151 BEE-2
BEE-3 12, 157
13 BEE-4 157
I want to map a combination of batch of degree for a class rooms group of such distance that they make full use of the maximum capacity of the class rooms within a group (ideally), or as close to this as possible. Can it be done with a SQL query?
Any response will be appreciated.
The SQL Scripts to generate the required tables and populate data is less to:
CREATE TABLE classrooms (ClassId NUMBER, ClassName VARCHAR2 (50), capacity NUMBER, group NUMBER);
INSERT INTO the classrooms of the VALUES (1, "Babbage/software Engg Lab', 24, 1");
INSERT INTO the classrooms of the VALUES (2, 'basement - PG block', 63, 1);
INSERT INTO the classrooms of the VALUES (3, '1 class room', 56, 1);
INSERT INTO the classrooms of the VALUES (4, '10 class room', 24, 1);
INSERT INTO the classrooms of the VALUES (5, '11 class room', 24, 1);
INSERT INTO the classrooms of the VALUES (6, 'class room 12', 35, 1);
INSERT INTO the classrooms of the VALUES (7, 'class room 13', 42, 1);
INSERT INTO the classrooms of the VALUES (8, 'class room 14', 42, 1);
INSERT INTO the classrooms of the VALUES (9, '15 'class, 42, 1);
INSERT INTO the classrooms of the VALUES (10, 'class 2', 35, 1);
INSERT INTO the classrooms of the VALUES (11, 'class room 3', 35, 1);
INSERT INTO the classrooms of the VALUES (12, 'class room 4', 35, 1);
INSERT INTO the classrooms of the VALUES (13, 'class room 5', 35, 1);
INSERT INTO the classrooms of the VALUES (14, 'class room 6', 25, 1);
INSERT INTO the classrooms of the VALUES (15, '7 class room', 25, 1);
INSERT INTO the classrooms of the VALUES (16, 'class Room 8', 24, 1);
INSERT INTO the classrooms of the VALUES (17, 'class room 9', 24, 1);
INSERT INTO the classrooms of the VALUES (18, 'Control Sys Lab', 24, 1);
INSERT INTO the classrooms of the VALUES (19, 'Dig & Embd Sys Lab', 20, 1);
INSERT INTO the classrooms of the VALUES (20, 'DSP & Comm Lab', 20, 1);
INSERT INTO the classrooms of the VALUES (21, 'system ELECTROMECHANICAL Lab', 28, 1);
INSERT INTO the classrooms of the VALUES (22, ' Farabi/Web Tech Lab', 36, 1);
INSERT INTO the classrooms of the VALUES (23, 'Gen purpose Lab', 40, 1);
INSERT INTO the classrooms of the VALUES (24, ' Shirazi/DB Tech Lab', 36, 1);
INSERT INTO the classrooms of the VALUES (25, 'Elected Adv Lab', 30, 2);
INSERT INTO the classrooms of the VALUES (26, 'class room 16', 42, 2);
INSERT INTO the classrooms of the VALUES (27, 'class room 17', 49, 2);
INSERT INTO the classrooms of the VALUES (28, '18 'class, 56, 2);
INSERT INTO the classrooms of the VALUES (29, '19 'class, 42, 2);
INSERT INTO the classrooms of the VALUES (30, 'class room 20', 49, 2);
INSERT INTO the classrooms of the VALUES (31, 'class room 21', 35, 3);
INSERT INTO the classrooms of the VALUES (32, 'room 22', 35, 3);
INSERT INTO the classrooms of the VALUES (33, 'MDA Lab', 20, 3);
CREATE TABLE DegreeBatches (BatchId NUMBER, BatchName VARCHAR2 (50), membership NUMBER);
INSERT INTO DegreeBatches VALUES(1,'BIT-11',79);
INSERT INTO DegreeBatches VALUES(2,'BIT-12',28);
INSERT INTO DegreeBatches VALUES (3, 'BS (CS) - 1', 35);
INSERT INTO DegreeBatches VALUES (4, 'BS (CS) - 2', 78);
INSERT INTO DegreeBatches VALUES (5,'BE (SE) - 1', 69);
INSERT INTO DegreeBatches VALUES (6,'BE (SE) - 2', 84);
INSERT INTO DegreeBatches VALUES (7,'BE (SE) - 3', 64);
INSERT INTO DegreeBatches VALUES(8,'BICSE-7',84);
INSERT INTO DegreeBatches VALUES(9,'BICSE-8',43);
INSERT INTO DegreeBatches VALUES(10,'BEE-1',112);
INSERT INTO DegreeBatches VALUES(11,'BEE-2',151);
INSERT INTO DegreeBatches VALUES(12,'BEE-3',157);
INSERT INTO DegreeBatches VALUES(13,'BEE-4',157);
Best regards
Bilal
Published by: Bilal on December 27, 2012 09:52
Published by: Bilal on December 27, 2012 10:07Bilal, thanks for the nice problem! Another possibility to double check is to write a small PL/SQL function that returns 1 if a duplicate id is found, then equate to 0: "NUMBER of RETURN of Duplicate_Token_Found (p_str_main in VARCHAR2, p_str_trial VARCHAR2). It should analyze the second string and could use p_str_main LIKE '%', | l_id | ', %' for each id. In any case, the query complete (without that) is given below:
Solution with names SQL> WITH rsf_itm (con_id, max_weight, nxt_id, lev, tot_weight, tot_profit, path, root_id, lev_1_id) AS ( 2 SELECT c.id, 3 c.max_weight, 4 i.id, 5 0, 6 i.item_weight, 7 i.item_profit, 8 ',' || i.id || ',', 9 i.id, 10 0 11 FROM items i 12 CROSS JOIN containers c 13 UNION ALL 14 SELECT r.con_id, 15 r.max_weight, 16 i.id, 17 r.lev + 1, 18 r.tot_weight + i.item_weight, 19 r.tot_profit + i.item_profit, 20 r.path || i.id || ',', 21 r.root_id, 22 CASE WHEN r.lev = 0 THEN i.id ELSE r.nxt_id END 23 FROM rsf_itm r 24 JOIN items i 25 ON i.id > r.nxt_id 26 AND r.tot_weight + i.item_weight <= r.max_weight 27 ORDER BY 1, 2 28 ) SEARCH DEPTH FIRST BY nxt_id SET line_no 29 , rsf_con (nxt_con_id, nxt_line_no, con_path, itm_path, tot_weight, tot_profit, lev) AS ( 30 SELECT con_id, 31 line_no, 32 To_Char(con_id), 33 ':' || con_id || '-' || (lev + 1) || ':' || path, 34 tot_weight, 35 tot_profit, 36 0 37 FROM rsf_itm 38 UNION ALL 39 SELECT r_i.con_id, 40 r_i.line_no, 41 r_c.con_path || ',' || r_i.con_id, 42 r_c.itm_path || ':' || r_i.con_id || '-' || (r_i.lev + 1) || ':' || r_i.path, 43 r_c.tot_weight + r_i.tot_weight, 44 r_c.tot_profit + r_i.tot_profit, 45 r_c.lev + 1 46 FROM rsf_con r_c 47 JOIN rsf_itm r_i 48 ON r_i.con_id > r_c.nxt_con_id 49 WHERE r_c.itm_path NOT LIKE '%,' || r_i.root_id || ',%' 50 AND r_c.itm_path NOT LIKE '%,' || r_i.lev_1_id || ',%' 51 AND r_c.itm_path NOT LIKE '%,' || r_i.nxt_id || ',%' 52 ) 53 , paths_ranked AS ( 54 SELECT itm_path || ':' itm_path, tot_weight, tot_profit, lev + 1 n_cons, 55 Rank () OVER (ORDER BY tot_profit DESC) rnk, 56 Row_Number () OVER (ORDER BY tot_profit DESC) sol_id 57 FROM rsf_con 58 ), best_paths AS ( 59 SELECT itm_path, tot_weight, tot_profit, n_cons, sol_id 60 FROM paths_ranked 61 WHERE rnk = 1 62 ), row_gen AS ( 63 SELECT LEVEL lev 64 FROM DUAL 65 CONNECT BY LEVEL <= (SELECT Count(*) FROM items) 66 ), con_v AS ( 67 SELECT b.itm_path, r.lev con_ind, b.sol_id, b.tot_weight, b.tot_profit, 68 Substr (b.itm_path, Instr (b.itm_path, ':', 1, 2*r.lev - 1) + 1, 69 Instr (b.itm_path, ':', 1, 2*r.lev) - Instr (b.itm_path, ':', 1, 2*r.lev - 1) - 1) 70 con_nit_id, 71 Substr (b.itm_path, Instr (b.itm_path, ':', 1, 2*r.lev) + 1, 72 Instr (b.itm_path, ':', 1, 2*r.lev + 1) - Instr (b.itm_path, ':', 1, 2*r.lev) - 1) 73 itm_str 74 FROM best_paths b 75 JOIN row_gen r 76 ON r.lev <= b.n_cons 77 ), con_split AS ( 78 SELECT itm_path, con_ind, sol_id, tot_weight, tot_profit, 79 Substr (con_nit_id, 1, Instr (con_nit_id, '-', 1) - 1) con_id, 80 Substr (con_nit_id, Instr (con_nit_id, '-', 1) + 1) n_items, 81 itm_str 82 FROM con_v 83 ), itm_v AS ( 84 SELECT c.itm_path, c.con_ind, c.sol_id, c.con_id, c.tot_weight, c.tot_profit, 85 Substr (c.itm_str, Instr (c.itm_str, ',', 1, r.lev) + 1, 86 Instr (c.itm_str, ',', 1, r.lev + 1) - Instr (c.itm_str, ',', 1, r.lev) - 1) 87 itm_id 88 FROM con_split c 89 JOIN row_gen r 90 ON r.lev <= c.n_items 91 ) 92 SELECT v.sol_id, 93 v.tot_weight s_wt, v.tot_profit s_pr, c.id c_id, c.name c_name, c.max_weight m_wt, 94 Sum (i.item_weight) OVER (PARTITION BY v.sol_id, c.id) c_wt, 95 i.id i_id, i.name i_name, i.item_weight i_wt, i.item_profit i_pr 96 FROM itm_v v 97 JOIN containers c 98 ON c.id = To_Number (v.con_id) 99 JOIN items i 100 ON i.id = To_Number (v.itm_id) 101 ORDER BY sol_id, con_id, itm_id 102 / SOL_ID S_WT S_PR C_ID C_NAME M_WT C_WT I_ID I_NAME I_WT I_PR ---------- ---- ---- ----- --------------- ---- ---- ----- ---------- ---- ---- 1 255 255 1 SEECS UG Block 100 100 1 BIT-10 35 35 2 BIT-11 40 40 6 BICSE-7 25 25 2 IAEC Building 70 70 4 BSCS-3 40 40 7 BESE-3 30 30 3 RIMMS Building 90 85 3 BSCS-2 35 35 5 BEE-4 50 50 2 255 255 1 SEECS UG Block 100 95 4 BSCS-3 40 40 6 BICSE-7 25 25 7 BESE-3 30 30 2 IAEC Building 70 70 1 BIT-10 35 35 3 BSCS-2 35 35 3 RIMMS Building 90 90 2 BIT-11 40 40 5 BEE-4 50 50 3 255 255 1 SEECS UG Block 100 100 3 BSCS-2 35 35 4 BSCS-3 40 40 6 BICSE-7 25 25 2 IAEC Building 70 65 1 BIT-10 35 35 7 BESE-3 30 30 3 RIMMS Building 90 90 2 BIT-11 40 40 5 BEE-4 50 50 4 255 255 1 SEECS UG Block 100 100 3 BSCS-2 35 35 4 BSCS-3 40 40 6 BICSE-7 25 25 2 IAEC Building 70 70 2 BIT-11 40 40 7 BESE-3 30 30 3 RIMMS Building 90 85 1 BIT-10 35 35 5 BEE-4 50 50 5 255 255 1 SEECS UG Block 100 95 2 BIT-11 40 40 6 BICSE-7 25 25 7 BESE-3 30 30 2 IAEC Building 70 70 1 BIT-10 35 35 3 BSCS-2 35 35 3 RIMMS Building 90 90 4 BSCS-3 40 40 5 BEE-4 50 50 6 255 255 1 SEECS UG Block 100 100 2 BIT-11 40 40 3 BSCS-2 35 35 6 BICSE-7 25 25 2 IAEC Building 70 65 1 BIT-10 35 35 7 BESE-3 30 30 3 RIMMS Building 90 90 4 BSCS-3 40 40 5 BEE-4 50 50 7 255 255 1 SEECS UG Block 100 100 2 BIT-11 40 40 3 BSCS-2 35 35 6 BICSE-7 25 25 2 IAEC Building 70 70 4 BSCS-3 40 40 7 BESE-3 30 30 3 RIMMS Building 90 85 1 BIT-10 35 35 5 BEE-4 50 50 8 255 255 1 SEECS UG Block 100 100 1 BIT-10 35 35 4 BSCS-3 40 40 6 BICSE-7 25 25 2 IAEC Building 70 70 2 BIT-11 40 40 7 BESE-3 30 30 3 RIMMS Building 90 85 3 BSCS-2 35 35 5 BEE-4 50 50 9 255 255 1 SEECS UG Block 100 100 1 BIT-10 35 35 4 BSCS-3 40 40 6 BICSE-7 25 25 2 IAEC Building 70 65 3 BSCS-2 35 35 7 BESE-3 30 30 3 RIMMS Building 90 90 2 BIT-11 40 40 5 BEE-4 50 50 10 255 255 1 SEECS UG Block 100 100 1 BIT-10 35 35 3 BSCS-2 35 35 7 BESE-3 30 30 2 IAEC Building 70 65 2 BIT-11 40 40 6 BICSE-7 25 25 3 RIMMS Building 90 90 4 BSCS-3 40 40 5 BEE-4 50 50 11 255 255 1 SEECS UG Block 100 100 1 BIT-10 35 35 3 BSCS-2 35 35 7 BESE-3 30 30 2 IAEC Building 70 65 4 BSCS-3 40 40 6 BICSE-7 25 25 3 RIMMS Building 90 90 2 BIT-11 40 40 5 BEE-4 50 50 12 255 255 1 SEECS UG Block 100 95 1 BIT-10 35 35 3 BSCS-2 35 35 6 BICSE-7 25 25 2 IAEC Building 70 70 2 BIT-11 40 40 7 BESE-3 30 30 3 RIMMS Building 90 90 4 BSCS-3 40 40 5 BEE-4 50 50 13 255 255 1 SEECS UG Block 100 95 1 BIT-10 35 35 3 BSCS-2 35 35 6 BICSE-7 25 25 2 IAEC Building 70 70 4 BSCS-3 40 40 7 BESE-3 30 30 3 RIMMS Building 90 90 2 BIT-11 40 40 5 BEE-4 50 50 14 255 255 1 SEECS UG Block 100 100 1 BIT-10 35 35 2 BIT-11 40 40 6 BICSE-7 25 25 2 IAEC Building 70 65 3 BSCS-2 35 35 7 BESE-3 30 30 3 RIMMS Building 90 90 4 BSCS-3 40 40 5 BEE-4 50 50 98 rows selected. Elapsed: 00:00:01.42
Published by: BrendanP on January 20, 2013 11:25
I found the need to deduplicate regular expression:AND RegExp_Instr (r_c.itm_path | r_i.path, ',(\d+),.*?,\1,') = 0)
Maybe you are looking for
-
OpenDNS causing internet failures
Here's my problem. I had my R7000 for about a year. In recent weeks, the Internet has been VERY uneven. A moment very well, the next STEP. Sometimes a single session (such as streaming video in a browser works) while the next browser session cannot c
-
It seems to have locked the keys on my keyboard on my laptop (do not type) how can I fix
I seem to be able to do everything, but when I hit any key, it does not appear on the screen. I can't type anything, including a website to go to.
-
Latest version of Windows update breaks Messenger
I noticed this problem a week ago. After that the automatic windows update, Live Messenger gives a fatal startup error. The error message reads "Windows Live Messenger has encountered a problem and needs to close. We are sorry for the inconvenience.
-
Remove Windows 10 W510 without recovery disk
I made the mistake of 10 windows installation without creating recovery media. I am desperate to return to windows 8.1, but how can I, please can you help me? God I wish that companies have given discs like the old days. Help, please
-
Need to move files user from C: to D:
My computer is a laptop dv9700 Entertainment HPPavilion, with intel t7250 Core (TM) 2 Duo CPU @2.00 GHz, 3 GB of memory, 64-bit, Vista Home Premium SP2 operating system. The system has 2 physical disks: C: is 135 GB labeled "OS"; D: is 149 GB labele