Can somebody help me to understand the syntax of "using" in oracle martialized view in below code? I have given the mview code below.
CREATE MATERIALIZED VIEW "mymview" ("fld1", "fld2", "fld3", "fld4")
USING ( mymview, (10, 'xyzdb', 2, 0, 0, "xyzdb_user", "table1", '2022-08-23 02:16:39', 33024, 234165, '2022-08-23 02:16:39', '', 0, 15128024780689, 0, NULL, 1, "xyzdb_user", "table2", '2022-08-23 02:16:40', 33024, 323356, '2022-08-23 02:16:40', '', 0, 15128024780689, 0, NULL),
2105409, 10, ('1950-01-01 12:00:00', 15, 0, 0, 15128024780689, 0, 2097216, 0, 2, NULL, NULL))
REFRESH FORCE AS (SELECT
/*+ PARALLEL(SERVICE_HOLD 8) PARALLEL(EVT 8) */
SERVICE_HOLD.fld1,
SERVICE_HOLD.fld2,
EVT.fld3,
EVT.fld4
FROM xyzdb_user.table1 SERVICE_HOLD,
xyzdb_user.table2 EVT
WHERE SERVICE_HOLD.fld =EVT.fld
);
Thanks
Related
I've a package which references many objects from the same schema and other schemas. I want to find all the dependencies of the package. I can get only first level dependencies from user_dependencies. Also utldtree would give me the objects which are dependent on my current object.utldtree also gives only the referenced objects in the same schema.
While I'm trying to find the solution for this on the net, I came across the following link
http://rodgersnotes.wordpress.com/2012/01/05/notes-on-deptree/
where he mentioned that, he uses his own script to find the multi level dependencies of an object.
Could you please help me out, how to proceed for such a script which will get us the multi-level dependencies of an object,(for example if the package is referencing views, then our script should mention the views and the tables/views upon which our view is build as we get in deptree)
You can use a connect by on user_dependencies for most cases.
Determining dependencies
Sample which works for any Oracle user since PUBLIC has been granted select access on user_dependencies:
select name
, type
, prior name
, prior type
from user_dependencies
start
with name='BUBS#MUNT_EENHEDEN'
and type='PACKAGE'
connect
by nocycle
name = prior referenced_name
and type = prior referenced_type
Sample output
Level 1: BUBS#MUNT_EENHEDEN PACKAGE
Level 2: BUBS_MUNT_EENHEDEN_V VIEW BUBS#MUNT_EENHEDEN PACKAGE
Level 3: BUBS#VERTALINGEN PACKAGE BUBS_MUNT_EENHEDEN_V VIEW
Level 4: ITGEN_LANGUAGES_V VIEW BUBS#VERTALINGEN PACKAGE
Complex scenarios
For complex scenarios I've found it necessary to use an own view directly on the data dictionary. Do this only when you know what you are doing and what RDBMS version you want to support! For instance, datamodel versions introduced major changes in the data dictionary.
Sample:
create or replace force view itgen_object_tree_changes_r
as
select o_master.obj# ojt#
, o_master.name ojt_name
, o.mtime ojt_ref_mtime
, o.name ojt_ref_name
, o.owner# ojt_ref_owner#
, decode
( o.type#
, 0, 'NEXT OBJECT'
, 1, 'INDEX'
, 2, 'TABLE'
, 3, 'CLUSTER'
, 4, 'VIEW'
, 5, 'SYNONYM'
, 6, 'SEQUENCE'
, 7, 'PROCEDURE'
, 8, 'FUNCTION'
, 9, 'PACKAGE'
, 11, 'PACKAGE BODY'
, 12, 'TRIGGER'
, 13, 'TYPE'
, 14, 'TYPE BODY'
, 19, 'TABLE PARTITION'
, 20, 'INDEX PARTITION'
, 21, 'LOB'
, 22, 'LIBRARY'
, 23, 'DIRECTORY'
, 24, 'QUEUE'
, 28, 'JAVA SOURCE'
, 29, 'JAVA CLASS'
, 30, 'JAVA RESOURCE'
, 32, 'INDEXTYPE'
, 33, 'OPERATOR'
, 34, 'TABLE SUBPARTITION'
, 35, 'INDEX SUBPARTITION'
, 40, 'LOB PARTITION'
, 41, 'LOB SUBPARTITION'
, 42, nvl
( ( select 'REWRITE EQUIVALENCE'
from sys.sum$ s
where s.obj# = o.obj#
and bitand ( s.xpflags, 8388608 ) = 8388608 ), 'MATERIALIZED VIEW'
)
, 43, 'DIMENSION'
, 44, 'CONTEXT'
, 46, 'RULE SET'
, 47, 'RESOURCE PLAN'
, 48, 'CONSUMER GROUP'
, 51, 'SUBSCRIPTION'
, 52, 'LOCATION'
, 55, 'XML SCHEMA'
, 56, 'JAVA DATA'
, 57, 'EDITION'
, 59, 'RULE'
, 60, 'CAPTURE'
, 61, 'APPLY'
, 62, 'EVALUATION CONTEXT'
, 66, 'JOB'
, 67, 'PROGRAM'
, 68, 'JOB CLASS'
, 69, 'WINDOW'
, 72, 'WINDOW GROUP'
, 74, 'SCHEDULE'
, 79, 'CHAIN'
, 81, 'FILE GROUP'
, 82, 'MINING MODEL'
, 87, 'ASSEMBLY'
, 90, 'CREDENTIAL'
, 92, 'CUBE DIMENSION'
, 93, 'CUBE'
, 94, 'MEASURE FOLDER'
, 95, 'CUBE BUILD PROCESS'
, 'UNDEFINED'
)
ojt_ref_type
from sys.obj$ o
, ( /* All dependencies from the object if there are any. */
select distinct connect_by_root d_obj# obj#, dep.p_obj# obj_ref#
from sys.dependency$ dep
connect
by nocycle dep.d_obj# = prior dep.p_obj#
start
with dep.d_obj# in ( select obj.obj# from itgen_schemas_r sma, sys.obj$ obj where obj.owner# = sma.owner# )
union all /* Union all allowed, 'in' ignores duplicates. */
/* The object itself. */
select obj.obj#
, obj.obj#
from itgen_schemas_r sma
, sys.obj$ obj
where obj.owner# = sma.owner#
) deps
, sys.obj$ o_master
where o_master.obj# = deps.obj#
and o.obj# = deps.obj_ref#
--
-- View: itgen_object_tree_changes_r
--
-- Overview of dependencies between a master object and all objects used by it. It can be used to analyze the reason why a project version views must be recalculated.
--
-- Code (alias): ote_r
--
-- Category: Hardcoded.
--
-- Example:
--
-- The object 'X' is invalid, since 'Y' is invalid.
--
My sqlite database has only one table. This is what I am gonna do: Create the database with one table inside it, insert 10,000 records in that table, create the required indices on some columns and then close the connection to the database. I am inserting the records into database within a transaction (between BEGIN and END). I am also creating indices after insert to make the insert operation faster. My question is: Is anything written to disk before I execute the COMMIT command? I need to create the database and its table on the memory, insert records and create indices again on the memory, and then write all the data to the dist altogether at once. Am I achieving my purpose with the following code? If not, how can I improve it?
sqlite3 *db;
char *zErrMsg = 0;
int rc;
char sql[500];
/* Open database */
rc = sqlite3_open("test.db", &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
exit(0);
}else{
fprintf(stderr, "Opened database successfully\n");
}
rc = sqlite3_exec(db, "PRAGMA synchronous = OFF", NULL, NULL, &zErrMsg);
rc = sqlite3_exec(db, "PRAGMA journal_mode = MEMORY", NULL, NULL, &zErrMsg);
rc = sqlite3_exec(db, "BEGIN", NULL, 0, &zErrMsg);
sql = "CREATE TABLE MyTable (Col1 NUMERIC, Col2 NUMERIC, Col3 NUMERIC);";
rc = sqlite3_exec(db, sql, NULL, 0, &zErrMsg);
/* Create SQL statement */
for(int i=0; i<10000; i++)
{
sprintf(sql, "INSERT INTO MyTable (Col1, Col2, Col3, ..., ColN"
"VALUES ( Val1, Val2, Val3, ..., ValN); ");
/* Execute SQL statement */
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if( rc != SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
//fprintf(stdout, "Records created successfully\n");
}
}
sql = "CREATE INDEX ix_Col1 ON MyTable(Col1 ASC);"
"CREATE INDEX ix_Col2 ON MyTable(Col2 ASC);";
rc = sqlite3_exec(db, sql, NULL, 0, &zErrMsg);
rc = sqlite3_exec(db, "COMMIT", NULL, 0, &zErrMsg);
fprintf(stdout, "Records created successfully\n");
sqlite3_close(db);
When SQLite's page cache overflows, changed data is written to disk even before the transaction ends.
However, this is usually not a problem because that data would have to be written to disk anyway, and it is still in the operating system's file cache if it needs to be read again.
If you really want to increase the page cache size, you can use PRAGMA cache_size.
But you have to measure yourself if this will make any difference.
I have 2 collections - invitedUserAllowedTimes and meeting.AllowedTimes. Collection invitedUserAllowedTimes has collection invitedUserAllowedTimes.Times.
Collection invitedUserAllowedTimes.Times has values TimeID = 1, TimeID = 2, TimeID = 3, TimeID = 4, TimeID = 5, TimeID = 6.
Collection meeting.AllowedTimes has values TimeID = 2, TimeID = 3, TimeID = 4.
I want to select from invitedUserAllowedTimes all records, which has all meeting.AllowedTimes TimeIDs.
I try to do following:
var times = (
from i in invitedUserAllowedTimes
where i.Times.All(p => meeting.AllowedTimes.Any(k=>k.TimeID == p.TimeID))
select i).ToList();
but get no records. Why? What is incorrect in my code?
It's not returning anything because you're asking it to return all invitedUserAllowedTimes where all of its times are in meeting.AllowedTimes. So your example won't return it because meeting.AllowedTimes doesn't have TimeID 1, 5, or 6.
Instead you need to do this:
var times = (
from i in invitedUserAllowedTimes
where meeting.AllowedTimes.All(k=> i.Times.Contains(k.TimeID))
select i).ToList();
Or, using extension methods:
var times = invitedUserAllowedTimes.Where(i => meeting.AllowedTimes.All(k => i.Times.Contains(k.TimeID)).ToList();
Try this:
var times = (from i in invitedUserAllowedTimes
where meeting.AllowedTimes.All(k => i.Times.Contains(k.TimeID))
select i).ToList();
I'm trying to accomplish something similar to the following SQL, but using the Doctrine API.
SELECT * FROM table_name WHERE column_name NOT IN (1, 2, 3);
I was thinking of something like this:
$entityManager->getRepository($entity)->findBy(array('ID' => array('NOT IN' => array(1, 2, 3))));
... How far am I?
You can do this with a DQL:
$result = $entityManager->createQuery("SELECT e FROM $entity e
WHERE e.ID NOT IN (:ids)")
->setParameter('ids', array(1, 2, 3), \Doctrine\DBAL\Connection::PARAM_INT_ARRAY)
->getResult();
Passing arrays as parameters is supported since Doctrine version 2.1.
I have large Oracle query, but I would like to have a RIGHT JOIN on the below line of code, I tried to use (+) but does not work:
AND SUBSTR(IBT_LINE.USER_1, 0, INSTR(IBT_LINE.USER_1, '-', +1, 3)-1) =
SUBSTR(WORK_ORDER.USER_1, 0, INSTR(WORK_ORDER.USER_1, '-', +1, 3)-1)
The total query:
FROM
CUSTOMER_ORDER, IBT, IBT_LINE,PART, WORK_ORDER
WHERE
CUSTOMER_ORDER.ID = REPLACE(IBT.ID,'X','C')
AND IBT.ID = IBT_LINE.IBT_ID
AND IBT_LINE.PART_ID=PART.ID
AND SUBSTR(IBT_LINE.USER_1, 0, INSTR(IBT_LINE.USER_1, '-', +1, 3)-1) = SUBSTR(WORK_ORDER.USER_1, 0, INSTR(WORK_ORDER.USER_1, '-', +1, 3)-1)
AND WORK_ORDER.WAREHOUSE_ID ='MEX-04' AND WORK_ORDER.STATUS ='R'
It's impossible to do a right/left join with two tables, and have a mandatory value on a field of that table in the same select.
Your problem is not with sintax (+ or JOIN), yout problem is with your select.
You're trying to get an outer join in WORK_ORDER and IBT_LINE, but you are telling oracle to do a full join with this sentence:
....
AND WORK_ORDER.WAREHOUSE_ID ='MEX-04' AND WORK_ORDER.STATUS ='R'
You can try a subselect in your FROM,
....
FROM
CUSTOMER_ORDER, IBT, IBT_LINE,PART,
(SELECT SUBSTR(WORK_ORDER.USER_1, 0, INSTR(WORK_ORDER.USER_1, '-', +1, 3)-1) user_1_formatted
from WORK_ORDER
where WORK_ORDER.WAREHOUSE_ID ='MEX-04'
AND WORK_ORDER.STATUS ='R') sub_work_order
WHERE
CUSTOMER_ORDER.ID = REPLACE(IBT.ID,'X','C')
AND IBT.ID = IBT_LINE.IBT_ID
AND IBT_LINE.PART_ID=PART.ID
AND SUBSTR(IBT_LINE.USER_1, 0, INSTR(IBT_LINE.USER_1, '-', +1, 3)-1) = sub_work_order.user_1_formatted(+)
or a subselect and then filter your results, as you wish.
select *
from (select ... from
CUSTOMER_ORDER, IBT, IBT_LINE,PART, WORK_ORDER
WHERE
CUSTOMER_ORDER.ID = REPLACE(IBT.ID,'X','C')
AND IBT.ID = IBT_LINE.IBT_ID
AND IBT_LINE.PART_ID=PART.ID
AND SUBSTR(IBT_LINE.USER_1, 0, INSTR(IBT_LINE.USER_1, '-', +1, 3)-1) = SUBSTR(WORK_ORDER.USER_1, 0, INSTR(WORK_ORDER.USER_1, '-', +1, 3)-1) (+))
where (work_order is null or (WORK_ORDER.WAREHOUSE_ID ='MEX-04' AND WORK_ORDER.STATUS ='R'))