Help on Sql Script to be insert in a Package
Hi Experts,
does someone can help on this.
I need to make an export of a fact table , with a filter on Category and Time.
I make Test on the Apshell, but fail to filter on properties.
Here is my code :
select *
from [apshell].[dbo].[tblfactfinance]
where mbrcategory.[group1] = 'Actual'
Thanks for your help;
Regards
Olivia.
Hi Olivia,
I might need to research T-SQL in order to write queries... Here are a few links to a basic clauses:
SELECT - http://msdn.microsoft.com/en-us/library/ms176104.aspx
WHERE - http://msdn.microsoft.com/en-us/library/ms188047(v=sql.100).aspx
From my understanding, you are looking for something like this (even though it's not clear what you are trying to achieve):
SELECT *
FROM apshell.dbo.tblfactfinance
WHERE category = 'actual' -- you don't have to use a sub-query to select a single result from another table.
AND TIMEID IN -- if you want to include a YEAR part then it'll look like: TIMEID IN ('2012.JAN', '2012.FEB', '2012.MAR')
(SELECT [ID]
FROM [ApShell].[dbo].[mbrTime]
WHERE PERIOD in ('JAN', 'FEB', 'MAR'))
UNION ALL -- ALL is an optional keyword if you need duplicate records which could be valid in case of BPC fact data.
SELECT *
FROM apshell.dbo.tblfactfinance
WHERE category <> 'actual' -- you don't need a time filter here for months, since you want JAN to DEC, but you might need a YEAR
AND LEFT(TIMEID, 4) = '2012'
T-SQL may not be all that strait forward for beginners, so I'd advice to ask your local DBA or developer for help. Otherwise, you may end up pulling incorrect date in or out of your system.
Regards,
Akim
Similar Messages
-
Hi All,
I'm using Oracle 9.2. I have a scenario where my table has 2000+ rows, and I have to swap values of rows 3 to 36 upside down and rest of the rows remains unchanged. Therefore I need your expertise advise to do this. Any scripts would be helpful.
Please note: This table has FK, PK, Indexes.
Thanks in advance
Edited by: user10177353 on Aug 13, 2012 11:46 PMHere is the sample of the rows. E.g. the Rows COL1 value 15 to 17 should come as 2
COL1 COL2 COL3 COL4 COL5
1 1 NORMAL 1 9998
2 1 OK 138 1
4 1 OK 13 1
5 1 MAN 5 1
6 1 REJ 25 1
7 1 OK 138 5
9 1 OK 13 5
10 1 WD 29 5
11 1 REJ 25 5
12 1 OK 156 25
13 1 OK 124 138
14 1 MAN 139 138
15 1 REDO 138 139
16 1 OK 150 148
17 1 MAN 149 148
18 1 REDO 148 149
19 1 REJ 25 13
20 1 OK 9995 13
21 1 OK 15 124
22 1 REJ 25 124
23 1 MAN 125 124
24 1 REDO 138 125
25 1 REJ 25 125
26 1 OK 15 125
27 1 WD 29 125
28 1 MAN 151 150
29 1 OK 9996 150
30 1 REJ 25 150
31 1 REJ 25 151
32 1 OK 9996 151
33 1 WD 29 151
34 1 REDO 148 151
35 1 REDO 13 14
36 1 OK 9995 14
37 1 WD 29 14
38 1 REJ 25 14
39 1 MAN 16 15
40 1 OK 9997 15
41 1 REJ 25 15
42 1 REJ 25 16 -
Hi there,
What I`m trying to accomplish here is the following guys;
This would be the pseudo code that I`m trying to convert into proper SQL;
Declare @Parameter varchar(50)
now I`m trying to find out how to find whatever is in the @Parameter in the values of table column. something like this;
If @Parameter exists in (select column from table) then do something here else something else....
Thanks very much in advance for your help.do you want some thing like below
Declare @Parameter varchar(50)
If exists (select column from table where column = @Parameter)
begin
--do something here
END
else
Begin
--something
END
Thanks
Saravana Kumar C -
query #1
can anyone helpme set up two scripts.
1 i need to list all users that belong to a single role or for all roles,which would be grouped by role,the number of users in the role,when the role was granted,what options went with the grant and who granted it to them.
i need a sample or the the views that need to be involved to extract that information.
query #2
another script that i need is the following:
i need to list object privileges by user or all users,
appropriately grouped,given to the user,the name and type of the object,when the grant was given and with what options they were granted,and who granted them the privilege.
so if any body could help in these two scripts i 'll be very appreciative.
thanks in advance.You want to run reports at least for intervals of an hour. A whole day's report wouldn't contain anything that would stand out because everything levels out when looking at everything that occurred over a long period of time. AWR snapshots are automatically scheduled to be taken every hour because that's the ideal range to look at reports for.
-
hi guys ,
Got a small question , Table(test) has 4 columns ID, NAME, Definition, Notes with some data in it.And ID is identity column. Now I have to add a new column called UID.
ID NAME Definition Notes
1 xxx
xxxxx xxxx
2 xxx
xxxxx xxxx
3 xxx
xxxxx xxxx
4 xxx xxxxx
xxxx
5 xxx xxxxx
xxxx
6 xxx xxxxx
xxxx
7 xxx
xxxxx xxxx
8 xxx
xxxxx xxxx
need to add a new column in table (test) called UID. Note that this is NOT an identity column like ID. Need to Create a TRIGGER that will copy value of ID to UID ONLY upon creation of new name. If the test table is copied/migrated to different
DB or server, the UID should not be overridden with the new value of ID.
AcronyM_ID NAME Definition Notes acronym_uid
1 xxx
xxxxx
xxxx NULL
2 xxx
xxxxx
xxxx NULL
3 xxx
xxxxx
xxxx NULL
4 xxx xxxxx xxxx NULL
5 xxx xxxxx xxxx
NULL
6 xxx xxxxx xxxx
NULL
7 xxx
xxxxx
xxxx NULL
8 xxx
xxxxx
xxxx NULL
9 xxx
xxxxx
xxxx 9
10 xxx xxxxx xxxxx 10
thanks
sidhuhello siddu_123,
per your description, it does not look like you need either a trigger or another column to store acroymn_ID. since acroymn_id is an identity column, it cannot be updated.
if the database was migrated to different server either by backup restore method and data import\export method, you can still preserve the identity property on the column and hence you will have the same values.
Hope it Helps!! -
Hi All ,
Here is my usecase. I have a table of following structure (History table):
Column A - Unique key
Column B - Foreign Key
Start Date
End Date.
My Data is corrupted due to some reason . Its supposed to be
StartDate End Date
1 MyID 2010-04-01 2013-10-07
2 MyID 2013-10-07 3000-12-31
It got corrupted and now it is
StartDate End Date
1 MyID 2010-04-01 2013-10-07
2 MyID 2010-04-01 3000-12-31
Basically I want end date of first row to be updated as start date of second row. Because of some coding issue this corruption happened.
Now i want to find out all the cases for which this happened.
I could find out all the rows for which multiple entries are there using :
Select * from table where B in (
Select B from table group by b having count(*) >1)
But i need only corrupted records. Can some one help me ??
Thanks in advance.
B1Since you have not provided proper data, hope below table format matches your record set.
WITH T1 AS
( SELECT 1 COL1, 1 COL2, TO_DATE('2010-04-01','YYYY-MM-DD') START_DATE, TO_DATE('2013-10-07','YYYY-MM-DD') END_DATE FROM DUAL UNION ALL
SELECT 2, 1,TO_DATE('2013-10-07','YYYY-MM-DD'),TO_DATE('2013-11-30','YYYY-MM-DD') FROM DUAL UNION ALL
SELECT 3,1, TO_DATE('2013-10-07','YYYY-MM-DD'),TO_DATE('3000-12-31','YYYY-MM-DD') FROM DUAL UNION ALL
SELECT 4,2,TO_DATE('2014-01-01','YYYY-MM-DD'), TO_DATE('2014-03-31','YYYY-MM-DD') FROM DUAL UNION ALL
SELECT 5,2,TO_DATE('2014-01-01','YYYY-MM-DD'), TO_DATE('2014-12-31','YYYY-MM-DD') FROM DUAL)
SELECT * FROM T1;
OUTPUT:
COL1 COL2 START_DAT END_DATE
1 1 01-APR-10 07-OCT-13
2 1 07-OCT-13 30-NOV-13
3 1 07-OCT-13 31-DEC-00
4 2 01-JAN-14 31-MAR-14
5 2 01-JAN-14 31-DEC-14
Seems like you look for records whose START_DATE is not matching with the previous record's END_DATE. The logic I have used is (according to your data), the START_DATE of RECORD1=START_DATE of RECORD2. This is what you are looking for. Below is the query.
WITH T1 AS
( SELECT 1 COL1, 1 COL2, TO_DATE('2010-04-01','YYYY-MM-DD') START_DATE, TO_DATE('2013-10-07','YYYY-MM-DD') END_DATE FROM DUAL UNION ALL
SELECT 2, 1,TO_DATE('2013-10-07','YYYY-MM-DD'),TO_DATE('2013-11-30','YYYY-MM-DD') FROM DUAL UNION ALL
SELECT 3,1, TO_DATE('2013-10-07','YYYY-MM-DD'),TO_DATE('3000-12-31','YYYY-MM-DD') FROM DUAL UNION ALL
SELECT 4,2,TO_DATE('2014-01-01','YYYY-MM-DD'), TO_DATE('2014-03-31','YYYY-MM-DD') FROM DUAL UNION ALL
SELECT 5,2,TO_DATE('2014-01-01','YYYY-MM-DD'), TO_DATE('2014-12-31','YYYY-MM-DD') FROM DUAL)
SELECT COL1,COL2,START_DATE,END_DATE FROM(
SELECT COL1,COL2,START_DATE,END_DATE,
LEAD(START_DATE) OVER(PARTITION BY COL2 ORDER BY COL1,COL2) LEAD_COL
FROM T1)
WHERE
START_DATE = LEAD_COL
OR LEAD_COL IS NULL;
OUTPUT:
COL1 COL2 START_DAT END_DATE
2 1 07-OCT-13 30-NOV-13
3 1 07-OCT-13 31-DEC-00
4 2 01-JAN-14 31-MAR-14
5 2 01-JAN-14 31-DEC-14
Method 2 is also considering the condition END_DATE of record1 NOT EQUAL TO START_DATE OF record2.
WITH T1 AS
( SELECT 1 COL1, 1 COL2, TO_DATE('2010-04-01','YYYY-MM-DD') START_DATE, TO_DATE('2013-10-07','YYYY-MM-DD') END_DATE FROM DUAL UNION ALL
SELECT 2, 1,TO_DATE('2013-10-07','YYYY-MM-DD'),TO_DATE('2013-11-30','YYYY-MM-DD') FROM DUAL UNION ALL
SELECT 3,1, TO_DATE('2013-10-07','YYYY-MM-DD'),TO_DATE('3000-12-31','YYYY-MM-DD') FROM DUAL UNION ALL
SELECT 4,2,TO_DATE('2014-01-01','YYYY-MM-DD'), TO_DATE('2014-03-31','YYYY-MM-DD') FROM DUAL UNION ALL
SELECT 5,2,TO_DATE('2014-01-01','YYYY-MM-DD'), TO_DATE('2014-12-31','YYYY-MM-DD') FROM DUAL)
SELECT COL1,COL2,START_DATE,END_DATE FROM(
SELECT COL1,COL2,START_DATE,END_DATE,LAG(END_DATE)OVER(PARTITION BY COL2 ORDER BY COL1,COL2) LAG_COL,
LEAD(START_DATE) OVER(PARTITION BY COL2 ORDER BY COL1,COL2) LEAD_COL
FROM T1)
WHERE
START_DATE!=LAG_COL
OR START_DATE = LEAD_COL
OR LAG_COL IS NOT NULL
OR LEAD_COL IS NULL;
OUTPUT:
COL1 COL2 START_DAT END_DATE
2 1 07-OCT-13 30-NOV-13
3 1 07-OCT-13 31-DEC-00
4 2 01-JAN-14 31-MAR-14
5 2 01-JAN-14 31-DEC-14 -
Help Using SQL*Plus Format Commands (like TTITLE) in Packages
Where (within a package) can/should SQL*Plus format commands such as TTITLE, COLUMN & BREAK be coded?
A package is coded in PL/SQL.
TTITLE, COLUMN and BREAK are SQL*Plus commands, they cannot be used in PL/SQL.
If you want to output data (using dbms_output) in your package, you'll have to implement the features yourself. But probably just using SQL*Plus is better in your case.
Regards,
Rob. -
Error when calling a stored procedure from a SQL Script
Apologies if this is a really dumb question but I can't seem to call a procedure in package from a SQL script. I have a simple package.procedure containing a loop to populate a table. I would like to include a call to this procedure from my database install script, that also includes my CREATE and INSERT statements. I run the script using "@install_databae" and the CREATE and INSERT statements run fine. The script gives an error when it reaches the line below:
exec lazarus.PopulateGridPositions;
and gives the error.....
BEGIN lazarus.PopulateGridPositions; END;
ERROR at line 1:
ORA-04063: package body "LAZARUS.LAZARUS" has errors
ORA-06508: PL/SQL: could not find program unit being called: "LAZARUS.LAZARUS"
ORA-06512: at line 1
The procedure and package have both compiled without errors and the statement on its own works fine in SQL*Plus.
I've obviously missed some fundamental concept with scripts and SQL. Please can anybody help me?Histon FTM wrote:
ORA-04063: package body "LAZARUS.LAZARUS" has errors Above, obviously conflicts with the statement that follows:
>
The procedure and package have both compiled without errors and the statement on its own works fine in SQL*Plus.I suggest you take a look in the USER_ERRORS view to see, what the errors are.
And just checking:
You have schema called LAZARUS, which holds a package named LAZARUS, which holds a procedure called POPULATEGRIDPOSITIONS?
Edited by: Toon Koppelaars on Oct 1, 2009 5:55 PM -
How to batch create SSO accounts from Windows or a PL/SQL script
We have just converted our 6i Forms and Reports to 10g (10.1.2.0.2), and run them against a 9i database. In order to be able to securely run reports we set up and configured SSO for a few accounts via the Oracle Identity Management Provisioning Console. We do not have PORTAL – nor do we want it. However, now we need to create about 500 SSO accounts at once. We would prefer to be able to create these accounts in a batch method – eg run something from Windows command line or run a PL/SQL script. We have the DBMS_LDAP package successfully installed in that 9i database. Currently our list of 500 users is simply in a table in the 9i db.
Spent several hours looking through both this site and Metalink, but so far no luck – especially because we don’t have or want PORTAL. If anyone can help, would appreciate it very much.
ThanksUser dbms_ldap package in the database to use PL SQL to create your database
account and then an OID account with a RAD to match the database login. If you
You may have to load the DBMS_Ldap package from the database ADMIN directory first to be available in the database.
LDAP SQL Ex.
user_username := LOWER(new_user) || '@domain.com'; -
retval := dbms_ldap.search_s(my_session, ldap_base,
dbms_ldap.scope_subtree, 'uid=' || user_username, my_attrs, 0,
my_message);
retval := dbms_ldap.count_entries(my_session, my_message);
my_entry := dbms_ldap.first_entry(my_session,my_message);
my_dn := dbms_ldap.get_dn(my_session,my_entry);
dbpassword := 'PASSWD01';
isvalidrad := forms_rad.newraddefinition(radname,new_user,dbpassword,
dbtnsnames,errormessage);
sessionestablished := forms_rad.createoidsession(ldap_user, ldap_passwd,
ldap_host, ldap_port, ldap_base);
radcreated := forms_rad.createradforcn(my_dn, 'false', errormessage);
-- Create new user's database account same as RAD account.
v_sql := 'CREATE USER "' || new_user || '" IDENTIFIED BY ' || dbpassword ||
' DEFAULT TABLESPACE JLIM TEMPORARY TABLESPACE TEMP';
EXECUTE IMMEDIATE v_sql;
v_sql := 'GRANT CONNECT TO ' || new_user;
EXECUTE IMMEDIATE v_sql; -
Problem while executing script in Toad - How to use '&' in the sql script ?
I have to execute sql script in toad. Sql script has one insert query in which one insert-value is 'USA & CAN'. When I executed the script in toad by pressing F5, I got a prompt window asking for the value if 'CAN' as it is after the &.
I tried using[b] {escape '\' } .... but could not resolve the problem.
Is there any solution or workaround to overcome this problem. I have thousands of records with such values and I have to use sql script only.There is an option in TOAD to change this behaviour.
Look in VIEW/OPTIONS/SQL Editor/
Uncheck the box for "Scan statements for bound variables before execution".
In SQL*PLUS it would be SET SCAN OFF
(desupported version is SET DEFINE OFF)
Message was edited by:
Sven Weller -
Hello,
I have a sql script with an insert statement with the character '&' in the values clause, but it always prompts me for a value.
Does exist an escape character for the '&'?
ThanksHi,
Add
SET SCAN OFF
in the begining of the SQL script.
Regds,
-Sreeram -
Inserting sql scripts in Oracle Warehouse Builder 10g
Dear all,
Can anyone please tell me if we can use a process flow to insert scripts in OWB 10g..
If so, how can i do it??
I am having a problem to insert sql scripts in OWB 10g r2.
Infact, i have to write a script and insert it in OWB to populate data from a souce table to a target table.
I have checked the script in sqlplus and it's working correctly (update being done).
The problem is that how do i insert the script in OWB?? Can i use a process flow other than OMB PLUS??
Please help me!!!
Regards,
AmrishDear all,
I have inserted the following script in the sqlplus activity in my process flow.
INSERT INTO BMADW.TARGET_SALGRADE (GRADE, LOSAL, HISAL) SELECT GRADE, LOSAL, HISAL FROM SCOTT.SALGRADE;
COMMIT;
EXIT
When i run the script in sql*plus, it does the insert and the commit part successfully. I have to press 'ENTER' for SQL*PLUS to exit.
If i have to end the script, is the word 'EXIT' the right command to use??
My process flow is deploying successfully but when starting it, still no 'INSERT' has been done. It's taking too much time to run (without giving any error).
Please help me !!!
Regards,
Amrish -
Need help to redesign legacy SQL Script
Hello Experts,
I have the below code which produces a CREATE TRIGGER statement. as of now this does for updating. I need to re-design this code to add for inserting and deleting as well. I just need help in the structuring wise. I can build the logic for inserting and updating inside. I want to know how i can continue to get for "inserting" and "deleting" as well.
you will understand my question better if you go through main code, present output and required output format below.
I know this is a bad design first of all. but the below code is a legacy one. so i cant change the entire structure of the code :-( all i can do is to continue designing it to add new changes. Hence sought help from you all.
please help
SQL CODE:
WITH audit_tables
AS
(SELECT object_name,
MIN (column_id) min_col,
MAX (column_id) max_col
FROM user_objects o,
user_tab_columns c
WHERE o.object_name = 'CHR_VAL_DESC_A_T'
AND o.object_name = c.table_name
GROUP BY object_name
SELECT txt
FROM (
SELECT ' CREATE OR REPLACE TRIGGER ' || REPLACE(object_name,'_A_T') || '_ADT_TRG' || CHR(13) ||
' AFTER INSERT ' || CHR(13) ||
' OR UPDATE ' || CHR(13) ||
' OR DELETE ' || CHR(13) ||
' ON ' || REPLACE(object_name,'_A_T','_T') || CHR(13) ||
' FOR EACH ROW ' || CHR(13) ||
' DECLARE ' || CHR(13) ||
' BEGIN ' || CHR(13) ||
' IF updating THEN ' || CHR(13) ||
' INSERT INTO ' || object_name || CHR(13) ||
' (' txt, object_name, 1 disp_order, 0 column_id
FROM audit_tables
UNION ALL
SELECT txt, object_name, disp_order, column_id
FROM (SELECT
CASE
WHEN max_col = column_id THEN
' '||column_name
ELSE
' '||column_name || ','
END AS txt, object_name, 2 disp_order, column_id
FROM audit_tables t,
user_tab_columns C
WHERE c.table_name = t.object_name
ORDER BY c.column_id ASC)
UNION ALL
SELECT ' )' || CHR(13) ||
' VALUES ' || CHR(13) ||
' (', object_name, 3 disp_order, 0
FROM audit_tables t
UNION ALL
SELECT txt, object_name, disp_order, column_id
FROM (SELECT
CASE
WHEN max_col = column_id THEN
CASE
WHEN SUBSTR(column_name,1,2) = 'N_' THEN
' :NEW.'||decode(substr(column_name,1,2),'N_',substr(column_name,3))||');'
WHEN SUBSTR(column_name,1,2) = 'O_' THEN
' :OLD.'||decode(substr(column_name,1,2),'O_',substr(column_name,3))||');'
WHEN min_col = column_id THEN
' 1'
WHEN column_id = 2 THEN
' ''I'''
WHEN column_id = 3 THEN
' SYSDATE'
ELSE
' :NEW.'||column_name||');'
END
ELSE
CASE
WHEN SUBSTR(column_name,1,2) = 'N_' THEN
' :NEW.'||decode(substr(column_name,1,2),'N_',substr(column_name,3))||','
WHEN SUBSTR(column_name,1,2) = 'O_' THEN
' :OLD.'||decode(substr(column_name,1,2),'O_',substr(column_name,3))||','
WHEN min_col = column_id THEN
' 1'||','
WHEN column_id = 2 THEN
' ''I'''||','
WHEN column_id = 3 THEN
' SYSDATE' ||','
ELSE
' :NEW.'||column_name||','
END
END AS txt,object_name, 4 disp_order, column_id
FROM audit_tables t,
user_tab_columns c
WHERE c.table_name = t.object_name
ORDER BY c.column_id ASC)
UNION ALL
SELECT 'END '||REPLACE(object_name,'_A_T') || '_ADT_TRG;' || CHR(13),
object_name, 5 disp_order, 0
FROM audit_tables)
ORDER BY object_name, disp_order, column_id
PRESENT OUTPUT:
CREATE OR REPLACE TRIGGER CHR_VAL_DESC_ADT_TRG
AFTER INSERT
OR UPDATE
OR DELETE
ON CHR_VAL_DESC_T
FOR EACH ROW
DECLARE
BEGIN
IF updating THEN
INSERT INTO CHR_VAL_DESC_A_T
TXN_ID,
TXN_TYP,
ADT_DTTM,
CHR_VAL_DESC_ID,
CHR_VAL_ID,
LANG_ID,
DESC_ID,
O_CHR_VAL_DESC,
N_CHR_VAL_DESC,
O_TRANS_STATE,
N_TRANS_STATE,
CRTD_BY,
CRTD_DTTM,
O_UPD_BY,
N_UPD_BY,
O_UPD_DTTM,
N_UPD_DTTM,
O_LOCK_NUM,
N_LOCK_NUM
VALUES
1,
'I',
SYSDATE,
:NEW.CHR_VAL_DESC_ID,
:NEW.CHR_VAL_ID,
:NEW.LANG_ID,
:NEW.DESC_ID,
:OLD.CHR_VAL_DESC,
:NEW.CHR_VAL_DESC,
:OLD.TRANS_STATE,
:NEW.TRANS_STATE,
:NEW.CRTD_BY,
:NEW.CRTD_DTTM,
:OLD.UPD_BY,
:NEW.UPD_BY,
:OLD.UPD_DTTM,
:NEW.UPD_DTTM,
:OLD.LOCK_NUM,
:NEW.LOCK_NUM);
END CHR_VAL_DESC_ADT_TRG;
REQUIRED OUTPUT FORMAT:
CREATE OR REPLACE TRIGGER TRIGGER_NAME
AFTER INSERT
OR UPDATE
OR DELETE
ON TABLE_NAME
FOR EACH ROW
DECLARE
BEGIN
IF updating THEN
INSERT TABLE_NAME
list of column names
VALUES
IF inserting THEN
INSERT TABLE_NAME
list of column names
VALUES
IF deleting THEN
INSERT TABLE_NAME
list of column names
VALUES
END TRIGGER_NAME;can anyone please help?
i tried adding with inserting and updating also..but when i tried to add deleting part the final output not comes in proper structure.
WITH audit_tables
AS
(SELECT object_name,
MIN (column_id) min_col,
MAX (column_id) max_col
FROM user_objects o,
user_tab_columns c
WHERE o.object_name IN ('CHR_VAL_DESC_A_T', 'CHR_VAL_A_T')
AND o.object_name = c.table_name
GROUP BY object_name
SELECT txt
FROM (
SELECT ' CREATE OR REPLACE TRIGGER ' || REPLACE(object_name,'_A_T') || '_ADT_TRG' || CHR(13) ||
' AFTER INSERT ' || CHR(13) ||
' OR UPDATE ' || CHR(13) ||
' OR DELETE ' || CHR(13) ||
' ON ' || REPLACE(object_name,'_A_T','_T') || CHR(13) ||
' FOR EACH ROW ' || CHR(13) ||
' DECLARE ' || CHR(13) ||
' BEGIN ' || CHR(13) ||
*' IF inserting THEN '* || CHR(13) ||
' INSERT INTO ' || object_name || CHR(13) ||
' (' txt, object_name, 1 disp_order, 0 column_id
FROM audit_tables
UNION ALL
SELECT txt, object_name, disp_order, column_id
FROM (SELECT
CASE
WHEN max_col = column_id THEN
' '||column_name
ELSE
' '||column_name || ','
END AS txt, object_name, 2 disp_order, column_id
FROM audit_tables t,
user_tab_columns C
WHERE c.table_name = t.object_name
ORDER BY c.column_id ASC)
UNION ALL
SELECT ' )' || CHR(13) ||
' VALUES ' || CHR(13) ||
' (', object_name, 3 disp_order, 0
FROM audit_tables t
UNION ALL
SELECT txt, object_name, disp_order, column_id
FROM (SELECT
CASE
WHEN max_col = column_id THEN
CASE
WHEN SUBSTR(column_name,1,2) = 'N_' THEN
' :NEW.'||decode(substr(column_name,1,2),'N_',substr(column_name,3))||');'
WHEN SUBSTR(column_name,1,2) = 'O_' THEN
' NULL'||');'
WHEN min_col = column_id THEN
' 1'
WHEN column_id = 2 THEN
' ''I'''
WHEN column_id = 3 THEN
' SYSDATE'
ELSE
' :NEW.'||column_name||');'
END
ELSE
CASE
WHEN SUBSTR(column_name,1,2) = 'N_' THEN
' :NEW.'||decode(substr(column_name,1,2),'N_',substr(column_name,3))||','
WHEN SUBSTR(column_name,1,2) = 'O_' THEN
' NULL'||','
WHEN min_col = column_id THEN
' 1'||','
WHEN column_id = 2 THEN
' ''I'''||','
WHEN column_id = 3 THEN
' SYSDATE' ||','
ELSE
' :NEW.'||column_name||','
END
END AS txt,object_name, 4 disp_order, column_id
FROM audit_tables t,
user_tab_columns c
WHERE c.table_name = t.object_name
ORDER BY c.column_id ASC)
UNION ALL
SELECT txt, object_name, disp_order, column_id
FROM(SELECT *' ELSIF updating THEN '* || CHR(13) ||
' INSERT INTO ' || object_name || CHR(13) ||
' (' txt, object_name, 5 disp_order, 0 column_id
FROM audit_tables
UNION ALL
SELECT txt, object_name, disp_order, column_id
FROM (SELECT
CASE
WHEN max_col = column_id THEN
' '||column_name
ELSE
' '||column_name || ','
END AS txt, object_name, 6 disp_order, column_id
FROM audit_tables t,
user_tab_columns C
WHERE c.table_name = t.object_name
ORDER BY c.column_id ASC)
UNION ALL
SELECT ' )' || CHR(13) ||
' VALUES ' || CHR(13) ||
' (', object_name, 7 disp_order, 0
FROM audit_tables t
UNION ALL
SELECT txt, object_name, disp_order, column_id
FROM (SELECT
CASE
WHEN max_col = column_id THEN
CASE
WHEN SUBSTR(column_name,1,2) = 'N_' THEN
' :NEW.'||decode(substr(column_name,1,2),'N_',substr(column_name,3))||');'
WHEN SUBSTR(column_name,1,2) = 'O_' THEN
' :OLD.'||decode(substr(column_name,1,2),'O_',substr(column_name,3))||');'
WHEN min_col = column_id THEN
' 1'
WHEN column_id = 2 THEN
' ''U'''
WHEN column_id = 3 THEN
' SYSDATE'
ELSE
' :NEW.'||column_name||');'
END
ELSE
CASE
WHEN SUBSTR(column_name,1,2) = 'N_' THEN
' :NEW.'||decode(substr(column_name,1,2),'N_',substr(column_name,3))||','
WHEN SUBSTR(column_name,1,2) = 'O_' THEN
' :OLD.'||decode(substr(column_name,1,2),'O_',substr(column_name,3))||','
WHEN min_col = column_id THEN
' 1'||','
WHEN column_id = 2 THEN
' ''U'''||','
WHEN column_id = 3 THEN
' SYSDATE' ||','
ELSE
' :NEW.'||column_name||','
END
END AS txt,object_name, 8 disp_order, column_id
FROM audit_tables t,
user_tab_columns c
WHERE c.table_name = t.object_name
ORDER BY c.column_id ASC)
UNION ALL
SELECT 'END IF;' || CHR(13) ||
'END '||REPLACE(object_name,'_A_T') || '_ADT_TRG;' || CHR(13),
object_name, 9 disp_order, 0
FROM audit_tables)
ORDER BY object_name, disp_order, column_id) -
Sql Script containing INSERT INTO TABLE_NAME taking very long time
Version:11g
I have a .sql file which contains insert statements for the table ZIP_CODES like.
INSERT INTO ZIP_CODES (ZIP_CODE, CITY, PROV, COUNTRY_CODE, LONGITUDE, LATITUDE)
VALUES (..........);This sql file contains above 800,000 INSERT statements like these! Execution of this file takes around 20 minutes.
Our client insists that they need a script to create this table and not a dump file (export dump of just this table)
Is there any way i could speed up these INSERTs in this script. I have added a commit half way through this file because i was worried about UNDO tablespace.
This table (ZIP_CODES) is not dependant on any other table (no FKs, no FK references,..).
Edited by: Steve_74 on 03-Sep-2009 05:53One possible option is to use External Tables
1. Create a CSV file with the values to be stored in the table.
2. Create an directory object (The location where the CSV file will be stored)
3. Create an External Table pointing to the CSV file
4. Just do a INSERT INTO ZIP_CODES SELECT * FROM <external table> (may be try to use a APPEND hint)
5. Drop the Directory object and External Table. -
Hi everyone,
I want to accomplish a task in TFS that I need to auto generate the database changes as SQL script file in drop folder for every build.
For ex.: If I add a table in a database and then check in the changes, I need to get that create table script in the drop folder as .sql file extension
I want to automate the build too for every check in. Help me out and guide me a step by step procedure because since I am new to TFS build in visual studio.
ThanksCheck out SSDT:
https://msdn.microsoft.com/en-us/data/tools.aspx
It can generate a DACPAC which can be used to update a SQL Database through the commandline. To ensure that the .sql file executed is compatible with the target database schema it contains a compiled version of teh schema and will generate the change script
on-the-fly.
If you want, you call SqlPackage,exe to generate a SQL script if you want to inspect it before executing.
https://msdn.microsoft.com/en-us/library/hh550080%28v=vs.103%29.aspx
My blog: blog.jessehouwing.nl
Maybe you are looking for
-
Can 'GUI_UPLOAD' to be used to upload excel file lonely?
Hi experts, I wonder that can 'GUI_UPLOAD' to be used to upload excel file lonely. I tried and use 'asc' as the L_FILETYPE, but the data uploaded contain many '###yyy'. But if I save the excel file as a txt file, the data can be uploaded by 'GUI_UPL
-
I updated to Lion and now the Search function in Apple Mail is not working properly
Even though the "All" option is selected, when I type a string in the Mail spotlight search box, the string is not found. But I know for a fact the string is in an email and I've manually found the email (in a folder) and copied and pasted it into t
-
JVRD (VAT) is not appearing in PO
hi I am using TAXINN procedure ,for VAT calculation i have maintained JVRD condition type in taxprocedure,I have maintained condition record in FV11 for JVRD.now when i create PO ,by entering tax code V1,i have clicked on Taxes tab,in next screen al
-
Parser Error Message: Unrecognized configuration section 'system.webServer'
at the time of rum show Error Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file approp
-
Getting an iMac fixed in Mexico
This is an interesting tale about Apple. I live in Mexico, Mazatlan to be exact. I have an iMac that I bought in February 2008 just before I moved here. It is broken and there appears there is no way to get it fixed in Mexico. I have tried for a mont