Access two DB in single SQL statement
I need to insert rows from a table on one DB into a table on a second DB (residing on a separate server). Is that possible?
lujate wrote:
I have a table on one DB that needs to periodically be copied to a second DB. The DB's are from different vendors, running on different OS's.Stating it again...this has nothing to do with java.
Either the database does it or it doesn't. If it does then you use that functionality (of the database, not java). It if doesn't then your stated requirement (one statement) will not work.
Let me provide you and example that seems like it should work but in fact will not.
You can use the MS Access GUI to set up an ODBC connection to anything that you have a ODBC driver for - so say Oracle.
Once you have that then it would appear that you could set up structures that makes it look like an oracle table exists in MS Access.
One problem - that is a trick of the GUI. It will not work with JDBC because the GUI does that and not the MS Access "database".
I think you can do something similar with MS SQL Server. In that case it really does exist in the database. So you could call it from JDBC.
Similar Messages
-
Produce report NOT based on a single sql statement
I want to produce a tabular report based on a series of sql statments. Specifically, a report of managers that wil include counts of employees that are in other tables using differing criterias.
Name Count Count
using using
criteria 1 criteria 2
Manager1 35 242
I would expect to write an anonymous pl/sql block with a driving cursor determining the managers to report on. Within that cursor, I would execute a number of other queries to derive the count for each of the two columns.
I have tried creating a report region based on a sql statement, but that requires a single sql statement. I also tried creating a report region based on plsql, but it required an into statement of defined items. This option looks like it can provide multiple rows, but since it selected 'INTO' named fields, it only creates a report with the last row of data.
I must be missing something. Any suggestions are greatly appreciated!!!If you want a wizard to create the form and report for you then yes you need to have a table. One thing that you can do is define a view that contains the data you need and define an Instead Of trigger on that view so the automatic fetch and dml will work but you can have the data stored into the different objects. basically the view and the trigger work as a router/dispatcher for the data.
*edit*
I should also add that you can write a pl/sql package which does the fetch and the dml operations with the form items as input. This is the solution I would typically use for any form that was not a simple CRUD form for a table. One thing to note is for the fetch I prefer to use out parameters for the form items so it requires the developer to map the item to the param in the app so it will show up when you are searching through the app. I highly discourage hiding item references inside of packaged code.
Good Luck!
Tyson
Message was edited by: TysonJouglet -
Can you really update two tables in one SQL statement
Ok a post in the forum has got me awefully curious:
Can you update two tables in one update statement i.e something like this
update table a , b
set b.<column> = something
a.<column> = something
Something to this effect.
If you are curious to know what post I am talking about it is called "updating a single row"No. You can only update one table in one SQL statement.
-
Single SQL statement that does multiple column checks
I have multiple sql statements (see below) that do value and format checking on different columns within the same table. I am trying to condense these checks into one SQL statement, anyone know how to do this?
select colx, coly, col1 from table1 where col1 not in ('A','B','C')
select colx, coly, col2 from table1 where col2 not in ('X','Y','Z')
etc
Note that I am looking for the value of the offending column (e,g col1 or col2) as the last of the three columns outputted,
Thanks in advancePerhaps;
SQL> create table t (colx number, coly number, col1 varchar2(1),
col2 varchar2(1), col3 varchar2(1), col4 varchar2(1))
Table created.
SQL> insert all
into t values(1,1,'A','D','G','J')
into t values(1,2,'*','D','G','J')
into t values(1,3,'A','D','G','J')
into t values(1,4,'A','*','G','J')
into t values(1,5,'A','D','G','J')
into t values(1,6,'A','D','*','J')
into t values(1,7,'A','D','G','J')
into t values(1,8,'_','-','/','*')
select * from dual
8 rows created.
SQL> select colx, coly,
trim(regexp_replace('Col1' || col1,'(Col1)([^A|B|C])|(Col1)([A|B|C])', '\1 ') ||
regexp_replace('Col2' || col2,'(Col2)([^D|E|F])|(Col2)([D|E|F])', '\1 ') ||
regexp_replace('Col3' || col3,'(Col3)([^G|H|I])|(Col3)([G|H|I])', '\1 ') ||
regexp_replace('Col4' || col4,'(Col4)([^J|K|L])|(Col4)([J|K|L])', '\1')) offending_column,
trim(regexp_replace(col1,'([^A|B|C])|([A|B|C])', '\1 ') ||
regexp_replace(col2,'([^D|E|F])|([D|E|F])', '\1 ') ||
regexp_replace(col3,'([^G|H|I])|([G|H|I])', '\1 ') ||
regexp_replace(col4,'([^J|K|L])|([J|K|L])', '\1')) offending_value
from t
where regexp_replace(col1||col2||col3||col4,
'(A|B|C)(D|E|F)(G|H|I)(J|K|L)') is not null
COLX COLY OFFENDING_COLUMN OFFENDING_VALUE
1 2 Col1 *
1 4 Col2 *
1 6 Col3 *
1 8 Col1 Col2 Col3 Col4 _ - / *
4 rows selected.Message was edited by:
MScallion
Added offending_value
NOTE* this query only works on single character columns and requires modification for multi character columns -
How to run a single sql statement
I want to run a simple sql statement to get some data in my Controller or AM.
Is there some way, other than creating a VO with the SQL statement, to get some data from the database. My sql query will always return a single row.Hi,
here you have an example I use to call a function in a package (note how you can pass parameters and read results):
Connection conn = this.getOADBTransaction().getJdbcConnection();
OracleCallableStatement ocs = null;
String param = null;
try {
String stmt = "BEGIN :1 := <PkgName>.<FunctionName>(:2); end;";
ocs = (OracleCallableStatement)conn.prepareCall(stmt);
ocs.registerOutParameter(1, OracleTypes.CHAR);
ocs.setString(2, <param>);
ocs.execute();
param = ocs.getString(1);
} catch(SQLException se) {
throw OAException.wrapperException(se);
finally {
try {
ocs.close();
return(param);
} catch(Exception e) {
throw OAException.wrapperException(e);
}Hope this helps you
Bye
Raffy -
CONCATENATING TWO OTR IN SINGLE ALERT STATEMENT
HI,
I want to concatenate two OTR or one OTR with single variable in single alert statement using javascript. I tried with the mentioned below. But, when i click the link in portal, empty page opens. when i remove anyone of them , it works properly. can anyone please suggest me how to do it. its urgent.....
<script language = "javascript" >
alert( ' <%= otr(PAOC_HAP_DOCUMENT_UI/LOCK MESSAGE) %> <%= LV_lck_usr %> ' );
</script>About Key-Preserved Tables
Nicolas. -
MS Access queries different to Java SQL statements
Ok, i dont understand something:
My program is connected to a MSAccess datasource. The query in MSAccess is
SELECT *
FROM Food_Data
WHERE Description Like 'Cheese*';
...but this wont work with a Java SQl query. I have to use this instead:
String query = "SELECT * FROM Food_Data " +
"WHERE Description LIKE 'Cheese%'";
Surely java would just passes the string query to MSAccess. But no. Java needs '%' as the wildcard, and MSAccess needs '*' as the wildcard.
Can anyone please explain this to me?Well % is the standard wildcard character for SQL as defined by the ANSI standard. MS Access just doesn't conform to this standard.
Having said that, I'm still kind of astonished that it doesn't work :-)
The JDBC driver should pass the statement "as is" to the underlying DBMS, but obviously the JDBC/ODBC bridge does some "quirking". But maybe it
s the ODBC datasource. I can see a "ExtendedAnsiSQL" setting in one of my Access ODBC settings, maybe that changes something. -
Do I need Distributed Transaction Scope when I have Two Database in Single SQL Server Instance
Dear Sirs.
I have Two Database in SQL Server Express 2008 R2, I Move Row From Database 1 Table 1 to Database 2 Table 1
Do I need Distributed Transaction or just regular Transaction.
Thank you in Advance.
Irakli LomidzeDear Sirs.
I have Two Database in SQL Server Express 2008 R2, I Move Row From Database 1 Table 1 to Database 2 Table 1
Do I need Distributed Transaction or just regular Transaction.
Thank you in Advance.
Irakli Lomidze
Whats you are doing does not qualify under distributed transaction. Please read about distributed transaction from below link
http://technet.microsoft.com/en-us/library/ms188721%28v=sql.105%29.aspx
Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it.
My TechNet Wiki Articles -
How to SUM two count(*) values in a single sql tatement?
How can I get a single SQL statement to sum two values from a count(*)
I want something like this:
SELECT COUNT(*) FROM MYTABLE
UNION
SELECT COUNT(*) FROM MYOTHERTABLE;
but instead of getting
111
222
I want to see the sum of the two values.
333can such a thing be done with one statement. I know I can do stuff inside a BEGIN END and have vars but wonder if there is simple single statement solution.
Thanks in advance,
David MillerSQL> select count(*) from user_indexes;
COUNT(*)
30
SQL> select count(*) from user_tables;
COUNT(*)
43
SQL> select (select count(*) from user_indexes) + (select count(*) from user_tables)
2 from dual;
(SELECTCOUNT(*)FROMUSER_INDEXES)+(SELECTCOUNT(*)FROMUSER_TABLES)
73 -
HOW TO: Post a SQL statement tuning request - template posting
This post is not a question, but similar to Rob van Wijk's "When your query takes too long ..." post should help to improve the quality of the requests for SQL statement tuning here on OTN.
On the OTN forum very often tuning requests about single SQL statements are posted, but the information provided is rather limited, and therefore it's not that simple to provide a meaningful advice. Instead of writing the same requests for additional information over and over again I thought I put together a post that describes how a "useful" post for such a request should look like and what information it should cover.
I've also prepared very detailed step-by-step instructions how to obtain that information on my blog, which can be used to easily gather the required information. It also covers again the details how to post the information properly here, in particular how to use the \ tag to preserve formatting and get a fixed font output:
http://oracle-randolf.blogspot.com/2009/02/basic-sql-statement-performance.html
So again: This post here describes how a "useful" post should look like and what information it ideally covers. The blog post explains in detail how to obtain that information.
In the future, rather than requesting the same additional information and explaining how to obtain it, I'll simply refer to this HOW TO post and the corresponding blog post which describes in detail how to get that information.
*Very important:*
Use the \ tag to enclose any output that should have its formatting preserved as shown below.
So if you want to use fixed font formatting that preserves the spaces etc., do the following:
\ This preserves formatting
\And it will look like this:
This preserves formatting
. . .Your post should cover the following information:
1. The SQL and a short description of its purpose
2. The version of your database with 4-digits (e.g. 10.2.0.4)
3. Optimizer related parameters
4. The TIMING and AUTOTRACE output
5. The EXPLAIN PLAN output
6. The TKPROF output snippet that corresponds to your statement
7. If you're on 10g or later, the DBMS_XPLAN.DISPLAY_CURSOR output
The above mentioned blog post describes in detail how to obtain that information.
Your post should have a meaningful subject, e.g. "SQL statement tuning request", and the message body should look similar to the following:
*-- Start of template body --*
The following SQL statement has been identified to perform poorly. It currently takes up to 10 seconds to execute, but it's supposed to take a second at most.
This is the statement:
select
from
t_demo
where
type = 'VIEW'
order by
id;It should return data from a table in a specific order.
The version of the database is 11.1.0.7.
These are the parameters relevant to the optimizer:
SQL>
SQL> show parameter optimizer
NAME TYPE VALUE
optimizer_capture_sql_plan_baselines boolean FALSE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 11.1.0.7
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
optimizer_use_invisible_indexes boolean FALSE
optimizer_use_pending_statistics boolean FALSE
optimizer_use_sql_plan_baselines boolean TRUE
SQL>
SQL> show parameter db_file_multi
NAME TYPE VALUE
db_file_multiblock_read_count integer 8
SQL>
SQL> show parameter db_block_size
NAME TYPE VALUE
db_block_size integer 8192
SQL>
SQL> show parameter cursor_sharing
NAME TYPE VALUE
cursor_sharing string EXACT
SQL>
SQL> column sname format a20
SQL> column pname format a20
SQL> column pval2 format a20
SQL>
SQL> select
2 sname
3 , pname
4 , pval1
5 , pval2
6 from
7 sys.aux_stats$;
SNAME PNAME PVAL1 PVAL2
SYSSTATS_INFO STATUS COMPLETED
SYSSTATS_INFO DSTART 01-30-2009 16:25
SYSSTATS_INFO DSTOP 01-30-2009 16:25
SYSSTATS_INFO FLAGS 0
SYSSTATS_MAIN CPUSPEEDNW 494,397
SYSSTATS_MAIN IOSEEKTIM 10
SYSSTATS_MAIN IOTFRSPEED 4096
SYSSTATS_MAIN SREADTIM
SYSSTATS_MAIN MREADTIM
SYSSTATS_MAIN CPUSPEED
SYSSTATS_MAIN MBRC
SYSSTATS_MAIN MAXTHR
SYSSTATS_MAIN SLAVETHR
13 rows selected.Here is the output of EXPLAIN PLAN:
SQL> explain plan for
2 -- put your statement here
3 select
4 *
5 from
6 t_demo
7 where
8 type = 'VIEW'
9 order by
10 id;
Explained.
Elapsed: 00:00:00.01
SQL>
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 1390505571
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 60 | 0 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T_DEMO | 1 | 60 | 0 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_DEMO | 1 | | 0 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("TYPE"='VIEW')
14 rows selected.Here is the output of SQL*Plus AUTOTRACE including the TIMING information:
SQL> rem Set the ARRAYSIZE according to your application
SQL> set autotrace traceonly arraysize 100
SQL> select
2 *
3 from
4 t_demo
5 where
6 type = 'VIEW'
7 order by
8 id;
149938 rows selected.
Elapsed: 00:00:02.21
Execution Plan
Plan hash value: 1390505571
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 60 | 0 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T_DEMO | 1 | 60 | 0 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_DEMO | 1 | | 0 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("TYPE"='VIEW')
Statistics
0 recursive calls
0 db block gets
149101 consistent gets
800 physical reads
196 redo size
1077830 bytes sent via SQL*Net to client
16905 bytes received via SQL*Net from client
1501 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
149938 rows processed
SQL>
SQL> disconnect
Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing optionsThe TKPROF output for this statement looks like the following:
TKPROF: Release 11.1.0.7.0 - Production on Mo Feb 23 10:23:08 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Trace file: orcl11_ora_3376_mytrace1.trc
Sort options: default
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
select
from
t_demo
where
type = 'VIEW'
order by
id
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1501 0.53 1.36 800 149101 0 149938
total 1503 0.53 1.36 800 149101 0 149938
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 88
Rows Row Source Operation
149938 TABLE ACCESS BY INDEX ROWID T_DEMO (cr=149101 pr=800 pw=0 time=60042 us cost=0 size=60 card=1)
149938 INDEX RANGE SCAN IDX_DEMO (cr=1881 pr=1 pw=0 time=0 us cost=0 size=0 card=1)(object id 74895)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 1501 0.00 0.00
db file sequential read 800 0.05 0.80
SQL*Net message from client 1501 0.00 0.69
********************************************************************************The DBMS_XPLAN.DISPLAY_CURSOR output:
SQL> -- put your statement here
SQL> -- use the GATHER_PLAN_STATISTICS hint
SQL> -- if you're not using STATISTICS_LEVEL = ALL
SQL> select /*+ gather_plan_statistics */
2 *
3 from
4 t_demo
5 where
6 type = 'VIEW'
7 order by
8 id;
149938 rows selected.
Elapsed: 00:00:02.21
SQL>
SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
PLAN_TABLE_OUTPUT
SQL_ID d4k5acu783vu8, child number 0
select /*+ gather_plan_statistics */ * from t_demo
where type = 'VIEW' order by id
Plan hash value: 1390505571
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads |
| 0 | SELECT STATEMENT | | 1 | | 149K|00:00:00.02 | 149K| 1183 |
| 1 | TABLE ACCESS BY INDEX ROWID| T_DEMO | 1 | 1 | 149K|00:00:00.02 | 149K| 1183 |
|* 2 | INDEX RANGE SCAN | IDX_DEMO | 1 | 1 | 149K|00:00:00.02 | 1880 | 383 |
Predicate Information (identified by operation id):
2 - access("TYPE"='VIEW')
20 rows selected.I'm looking forward for suggestions how to improve the performance of this statement.
*-- End of template body --*
I'm sure that if you follow these instructions and obtain the information described, post them using a proper formatting (don't forget about the \ tag) you'll receive meaningful advice very soon.
So, just to make sure you didn't miss this point:Use proper formatting!
If you think I missed something important in this sample post let me know so that I can improve it.
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/Alex Nuijten wrote:
...you missed the proper formatting of the Autotrace section ;-)Alex,
can't reproduce, does it still look unformatted? Or are you simply kidding? :-)
Randolf
PS: Just noticed that it actually sometimes doesn't show the proper formatting although the code tags are there. Changing to the \ tag helped in this case, but it seems to be odd.
Edited by: Randolf Geist on Feb 23, 2009 11:28 AM
Odd behaviour of forum software -
Multiple Executions Plans for the same SQL statement
Dear experts,
awrsqrpt.sql is showing multiple executions plans for a single SQL statement. How is it possible that one SQL statement will have multiple Executions Plans within the same AWR report.
Below is the awrsqrpt's output for your reference.
WORKLOAD REPOSITORY SQL Report
Snapshot Period Summary
DB Name DB Id Instance Inst Num Release RAC Host
TESTDB 2157605839 TESTDB1 1 10.2.0.3.0 YES testhost1
Snap Id Snap Time Sessions Curs/Sess
Begin Snap: 32541 11-Oct-08 21:00:13 248 141.1
End Snap: 32542 11-Oct-08 21:15:06 245 143.4
Elapsed: 14.88 (mins)
DB Time: 12.18 (mins)
SQL Summary DB/Inst: TESTDB/TESTDB1 Snaps: 32541-32542
Elapsed
SQL Id Time (ms)
51szt7b736bmg 25,131
Module: SQL*Plus
UPDATE TEST SET TEST_TRN_DAY_CL = (SELECT (NVL(ACCT_CR_BAL,0) + NVL(ACCT_DR_BAL,
0)) FROM ACCT WHERE ACCT_TRN_DT = (:B1 ) AND TEST_ACC_NB = ACCT_ACC_NB(+)) WHERE
TEST_BATCH_DT = (:B1 )
SQL ID: 51szt7b736bmg DB/Inst: TESTDB/TESTDB1 Snaps: 32541-32542
-> 1st Capture and Last Capture Snap IDs
refer to Snapshot IDs witin the snapshot range
-> UPDATE TEST SET TEST_TRN_DAY_CL = (SELECT (NVL(ACCT_CR_BAL,0) + NVL(AC...
Plan Hash Total Elapsed 1st Capture Last Capture
# Value Time(ms) Executions Snap ID Snap ID
1 2960830398 25,131 1 32542 32542
2 3834848140 0 0 32542 32542
Plan 1(PHV: 2960830398)
Plan Statistics DB/Inst: TESTDB/TESTDB1 Snaps: 32541-32542
-> % Total DB Time is the Elapsed Time of the SQL statement divided
into the Total Database Time multiplied by 100
Stat Name Statement Per Execution % Snap
Elapsed Time (ms) 25,131 25,130.7 3.4
CPU Time (ms) 23,270 23,270.2 3.9
Executions 1 N/A N/A
Buffer Gets 2,626,166 2,626,166.0 14.6
Disk Reads 305 305.0 0.3
Parse Calls 1 1.0 0.0
Rows 371,735 371,735.0 N/A
User I/O Wait Time (ms) 564 N/A N/A
Cluster Wait Time (ms) 0 N/A N/A
Application Wait Time (ms) 0 N/A N/A
Concurrency Wait Time (ms) 0 N/A N/A
Invalidations 0 N/A N/A
Version Count 2 N/A N/A
Sharable Mem(KB) 26 N/A N/A
Execution Plan
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | UPDATE STATEMENT | | | | 1110 (100)| |
| 1 | UPDATE | TEST | | | | |
| 2 | TABLE ACCESS FULL | TEST | 116K| 2740K| 1110 (2)| 00:00:14 |
| 3 | TABLE ACCESS BY INDEX ROWID| ACCT | 1 | 26 | 5 (0)| 00:00:01 |
| 4 | INDEX RANGE SCAN | ACCT_DT_ACC_IDX | 1 | | 4 (0)| 00:00:01 |
Plan 2(PHV: 3834848140)
Plan Statistics DB/Inst: TESTDB/TESTDB1 Snaps: 32541-32542
-> % Total DB Time is the Elapsed Time of the SQL statement divided
into the Total Database Time multiplied by 100
Stat Name Statement Per Execution % Snap
Elapsed Time (ms) 0 N/A 0.0
CPU Time (ms) 0 N/A 0.0
Executions 0 N/A N/A
Buffer Gets 0 N/A 0.0
Disk Reads 0 N/A 0.0
Parse Calls 0 N/A 0.0
Rows 0 N/A N/A
User I/O Wait Time (ms) 0 N/A N/A
Cluster Wait Time (ms) 0 N/A N/A
Application Wait Time (ms) 0 N/A N/A
Concurrency Wait Time (ms) 0 N/A N/A
Invalidations 0 N/A N/A
Version Count 2 N/A N/A
Sharable Mem(KB) 26 N/A N/A
Execution Plan
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | UPDATE STATEMENT | | | | 2 (100)| |
| 1 | UPDATE | TEST | | | | |
| 2 | TABLE ACCESS BY INDEX ROWID| TEST | 1 | 28 | 2 (0)| 00:00:01 |
| 3 | INDEX RANGE SCAN | TEST_DT_IND | 1 | | 1 (0)| 00:00:01 |
| 4 | TABLE ACCESS BY INDEX ROWID| ACCT | 1 | 26 | 4 (0)| 00:00:01 |
| 5 | INDEX RANGE SCAN | INDX_ACCT_DT | 1 | | 3 (0)| 00:00:01 |
Full SQL Text
SQL ID SQL Text
51szt7b736bm UPDATE TEST SET TEST_TRN_DAY_CL = (SELECT (NVL(ACCT_CR_BAL, 0) +
NVL(ACCT_DR_BAL, 0)) FROM ACCT WHERE ACCT_TRN_DT = (:B1 ) AND PB
RN_ACC_NB = ACCT_ACC_NB(+)) WHERE TEST_BATCH_DT = (:B1 )Your input is highly appreciated.
Thanks for taking your time in answering my question.
RegardsOracle Lover3 wrote:
Dear experts,
awrsqrpt.sql is showing multiple executions plans for a single SQL statement. How is it possible that one SQL statement will have multiple Executions Plans within the same AWR report.If you're using bind variables and you've histograms on your columns which can be created by default in 10g due to the "SIZE AUTO" default "method_opt" parameter of DBMS_STATS.GATHER__STATS it is quite normal that you get different execution plans for the same SQL statement. Depending on the values passed when the statement is hard parsed (this feature is called "bind variable peeking" and enabled by default since 9i) an execution plan is determined and re-used for all further executions of the same "shared" SQL statement.
If now your statement ages out of the shared pool or is invalidated due to some DDL or statistics gathering activity it will be re-parsed and again the values passed in that particular moment will determine the execution plan. If you have skewed data distribution and a histogram in place that reflects that skewness you might get different execution plans depending on the actual values used.
Since this "flip-flop" behaviour can sometimes be counter-productive if you're unlucky and the values used to hard parse the statement leading to a plan that is unsuitable for the majority of values used afterwards, 11g introduced the "adaptive" cursor sharing that attempts to detect such a situation and can automatically re-evaluate the execution plan of the statement.
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
Self referencing table and SQL statement
In my database, I have a self-referencing table, the table itself is for projects, and it allows users to get a hierarchical view of the company.
Here is the SQL (modifier is the term we use for project code, BBCI is the top project)
SELECT
modifier, modifierDescription, level
FROM
modifier
WHERE
level <= 2
CONNECT BY PRIOR
modifier = parentModifier
START WITH modifier = 'BBCI'
ORDER BY level
That perticular query gets the first two levels in the structure. I use this information to produce a tree structure in a web app.
But users have requested it would be good if in the tree structure is showed an + or - depending on whether there were anymore children under each parent, or better still the number of children under it, for example
BBCI
+ BBCI_CHILD
+ BBCI_CHILD2
- BBCI_CHILD3
or
BBCI
+ BBCI_CHILD (3 projects underneath)
+ BBCI_CHILD2 (2 projects underneath)
- BBCI_CHILD3 (0 projects underneath)
I am really stumped on this issue, and I am sure there is a way to do this in the web app, so for example do a query for each child node to see how many child nodes are underneath, but I figure it would be a lot tidier and faster if I could do it from a single SQL statement. Unfortunately I have tried to do this and am very much stuck.
If you need more information please let me know
Thanks!
JonYou may be able to do this using analytical functions but it depends on the Oracle version you are using. It can also be done with standard SQL - you just need to count the number of child rows for each modifier/project first and supply that list as an in-line view:
SELECT decode(modifier,'X',null,decode(child_rows,null,'-','+')),
m.modifier,
decode(modifier,'X',null,'('||nvl(cq.child_rows,0)||' projects underneath)')
FROM modifier m,
(select parentModifier,
count(parentModifier) child_rows
from modifier
where parentModifier is not null
group by parentModifier) cq
WHERE m.modifier=cq.parentModifier(+)
AND level <= 2
CONNECT BY PRIOR
m.modifier = m.parentModifier
START WITH modifier = 'X'
ORDER BY level, modifier;
which gives you something like...
D MODIFIER DECODE(MODIFIER,'X',NULL
X
- Y1 (0 projects underneath)
+ Y2 (2 projects underneath)
+ Y3 (3 projects underneath)
The decode stuff is just to show you the result, you can format the output in your calling code. Just extend the columns to include everything you want, modifierDescription etc..
Hope this helps. -
Popluating Unique data with a SQL Statement
I have a table with millions of rows.Now i have to populate the
data from that table into another table with the same
structure,but with primary key defined on two columns. In the
process of populating,data loss should not take place.
How can this be achieved with a single SQL statement without
effectin performance?
Thanx in advance ...If you are sure that there a no violations of the new primary
key, then something like
INSERT INTO new nologging
SELECT * from old
will work. If you think there may be violations of the new
primary key, then disable the primary key before doing the
insert. After the insert completes
ALTER table new
ENABLE CONSTRAINT pk
EXCEPTIONS INTO exptable
You will need to use utlexcpt.sql to create the exceptions table.
The primary key will not enable, but the exceptions table will
hold rowids of the rows that violate the key. You can use this
to fix them. -
How to generate synthetic rows (raw(16) guid cols) in one SQL statement?
We're populating a table containing two GUID columns:
create table object
( object_guid raw(16) primary key
, project_guid raw(16)
)All object GUIDs are unique (thus the PK), and each object belongs to a given project (should be a FK to some project table). We want N objects / rows, belonging to only 100 projects, i.e. 1% of the rows of the object table belong to the project #1, 1% to #2, etc...
Right now we're using about 25 lines of C++/OCI code to do that (one query doing a "select sys_guid() from dual", and using the generated GUIDs to do inserts into object), but I suspect it's possible to do this using a single SQL statement using mysterious connect by or some other Oracle SQL magic. (our OCI code does quite a few round-trips to do the equivalent).
Would anyone please demonstrate how to generate the rows as explained above, and possibly describe how it works for the non-initiated?
Thanks, --DD
PS: I'm sure it can be done in PL/SQL as well, but I'm interested in a SQL version if one's possible.I've found two ways, both taking a few SQL statements, but somehow I think this ought to be possible without intermediary tables... I'm sure there's a better way.
#1drop table project_tmp;
create table project_tmp
as select rownum pid, sys_guid() guid from dual
connect by level <= 100;
drop table object_tmp;
create table object_tmp
as select mod(rownum, 100) + 1 pid, sys_guid() guid from dual
connect by level <= 1000;
drop table object;
create table object
as select o.guid object_guid, p.guid project_guid
from object_tmp o, project_tmp p
where o.pid = p.pid;
drop table project_tmp;
drop table object_tmp;#2:drop table project;
create table project
as select mod(rownum, 100) + 1 prj_id, sys_guid() guid from dual
connect by level <= 100;
drop table object;
create table object
as select mod(rownum, 100) + 1 prj_id, sys_guid() object_guid from dual
connect by level <= 1000;
alter table object add project_guid raw(16);
update object o set o.project_guid = (select guid from project p where p.prj_id = o.prj_id);
drop table project;
alter table object drop column prj_id;Verification:select count(distinct project_guid) from object;
select project_guid, count(OBJECT_GUID) from object group by project_guid; -
SQL statement for calculating performance targets
Hi
I have taken of the admin of a database which stores project goals and scores. I have to develop a way to calculate how well all projects meet these scores. The table concerned is called goal and looks like this:
goal
goal_name
project_code
current_value
good_value
bad_value
This can be for many different goals, for example if a project wants to get up a goal of having no more than 5 bugs in the project. I can also set a bad value, say 20, so if any projects have 20 or more bugs, triggers or alerts can be sent So I can enter into this table. The reason for putting 5 for good not 20 is because these scores are to be realistic.
project_code = foo
goal_name = software bugs
good_value = 5
bad_value = 20
However, some goals may have the values switched and be in a much higher range, or may even be a percentage. For example one for number of sales could be
project_code = foo
goal_name = software sales
good_value = 200
bad_value = 50
or project delay
project_code = foo
goal_name = sproject delay
good_value = 0%
bad_value = 50%
i am trying to develop a SQL statement so I can get a % score of how well a goal is performing, so I can see
What is the goal % for all foo goals
Or what is the goal % for goal 'software sales'
And also more importantly, how well are the goals doing globally.
The requirement for doing this is using a single SQL statement, well, one SQL statement for the requirements I listed above, so for example the semantics are
SELECT average(goal perforance) WHERE .... project = foo .... or goal = software sales... etc
I am having trouble doing this, I have been banging my head against mydesk all day. the biggest thing is thowing me off is that the good value can be higher or lower than the bad value, and I am having trouble visualizing how to but this conditional statement in SQL
One more thing, the percentage returned should never be more than 0% or 100%.
If anyone has any ideas or pointers, please help me out,
Thanks for your time,
Message was edited by:
user473327I am having trouble doing this, I have been banging
my head against mydesk all day. the biggest thing is
thowing me off is that the good value can be higher
or lower than the bad value, and I am having trouble
visualizing how to but this conditional statement in
SQLI haven't looked at your requirements in detail cos I don't have time for such cumbersome tasks. However, you could have two UNION'd select statements, one which caters for the good > bad and one which caters for the good < bad. Also and alternative would be the use of DECODE or CASE statements in your select which are good for switching things around based on conditions.
;)
Maybe you are looking for
-
+/- buttons stopped working in Project 2010
I'm running Project Pro 2010 on a Windows 7 laptop, but not connected to a server. This morning when I came in an opened up my project I couldn't show subtasks in my project by clicking on the + sign in front of the summary task. The cursor was a out
-
Load balancing multiple SSO mid-tier with single SSO database
I want to load balance SSO middle tier servers and have them access a single SSO database. When you install infrastructure and select SSO only it creates a new infrastructure database. How can I install multiple SSO servers and point them to a single
-
Address book is empty after hard drive failure followed by timeline backup from Drobo
Imac has been running very hot, hot enough to fry an egg. It had a HD failure during this time and when the HD was replaced I expected the heating issue to be resolved as well. However it was not and so it has been at Apple store for a week as they
-
Problem regarding SAP Script Template
Hi All, In SAP 4.7, after creating TEMPLATE when I am applying any pattern on that TEMPLATE the border line of that TEMPLATE becomes very thick. But when I am doing the same in E.C.C 6.0 the border line is displayed as normal. How to solve the proble
-
Default columns in default form
Hi, I want to add default fields to default form while creating UDO by code. I can add only one column i.e. "Code" to default form. I want to add multiple fields on it. Can anybody help me for this on priority basis?