Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on two different query does same thing but one query fails after running powershell twice. First query:
SQL
'{0,-59}{1,20}' -f "DROP table $worktablename",(Get-Date -Format yyyyMMdd:hhmmss);
try {
INVOKE-SQLPLUS -MESSAGEONFAIL 'DROP WORK TABLE FAILED' -QUERY @"
SET SERVEROUT ON;
SET TERM ON;
SET TIMING ON;
SET SERVEROUTPUT on;

WHENEVER SQLERROR EXIT SQL.SQLCODE;
EXEC DROP TABLE $('amiuser1.$worktablename');
COMMIT;
"@
@"
try { $null = Execute-NonQuery-Oracle "DROP TABLE $('amiuser1.$worktablename')" 
} Catch { } Finally { }


But running following query works everytime :
SQL
'{0,-59}{1,20}' -f "Create work table WRK_UCMU073_SU_EDIT_DETAIL",(Get-Date -Format yyyyMMdd:hhmmss);

Invoke-SqlPlus -MessageOnFail 'Create work table WRK_UCMU073_SU_EDIT_DETAIL failed' -Query @"
SET PAGES 60;
SET LINES 170;
SET ECHO ON;
SET serveroutput on;
WHENEVER sqlerror exit sql.sqlcode;
EXEC drop_work_table('WRK_UCMU073_SU_EDIT_DETAIL');
create table amiuser1.WRK_UCMU073_SU_EDIT_DETAIL as
select * from SU_EDIT_DETAIL where 1 = 0;
grant select on amiuser1.WRK_UCMU073_SU_EDIT_DETAIL to misdev;
commit;
"@
Posted
Updated 28-Feb-14 9:48am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900