use count (*) in EXECUTE IMMEDIATE
Hi allI use Oracle 10 g R2.
I'm trying to get the number of records in a table, whose name is given when running. I don't know how to return the value of count (*) in a variable.
I need a treatment based on this charge.
I thought I can use back in the clause, but seem to work with column names only.
Any suggestions/indiactors appreciated.
Thank you.
GK
Hello
Try this
-not tested
declare
sql_stmt VARCHAR2 (2000);
lv_output varchar2 (10);
Start
sql_stmt: = "Select count * from table_name';"
Run immediately sql_stmt into lv_output;
dbms_output.put_line (lv_output);
end;
Thank you
Tags: Database
Similar Questions
-
Hi all
I'm using Oracle 11 g Release2.
I need to use the forall with EXECUTE IMMEDIATE statement and the content of string inside EXECUTE IMMEDIATE is a SELECT instead of the usual DML statement.
Objective: In this SELECT statement, I'll be passing of data using the "USING" clause in FORALL statement
When I try to use it, am getting error found "no DATA".
Please advice if I use FORALL and EXECUTE IMMEDIATE on a SELECT statement?
I can share the scenario...
Thank you!>
Please advice if I use FORALL and EXECUTE IMMEDIATE on a SELECT statement?
>
No - you can't. See the specifications of the PL/SQL language
http://docs.Oracle.com/CD/E14072_01/AppDev.112/e10472/forall_statement.htm
>
dml_statementAn INSERT, UPDATE, or DELETE static or dynamic statement making reference at least a collection in its VALUES or the WHERE clause. Performance benefits apply only to references to the collection that use as an index index_name.
-
EXECUTE IMMEDIATE or DBMS_UTILITY. EXEC_DDL_STATEMENT
Hello
I recently became aware of DBMS_UTILITY. EXEC_DDL_STATEMENT and I was wondering if it works in pretty much the same way as EXECUTE IMMEDIATE. I'm guessing that EXECUtE IMMEDIATE offers more flexibility when putting together the command you want to run, but you are the only real difference? All opinions accepted with gratitude,
Kind regards
Kevin.This isn't an exact answer to your question, but it may be useful.
Execute Immediate is the approach privileged 9i or higher. If you decide which to use, go with EXECUTE IMMEDIATE. You never know when the other dynamic SQL methods will be deprecated. In addition, EXECUTE IMMEDIATE has also been optimized (and will continue to be optimized), so you can usually expect better performance during use.
The exact differences between EXECUTE IMMEDIATE and DBMS_UTILITY. EXEC_DDL_STATEMENT go, I can't give you an exact answer. (Also the fact that DBMS_UTILITY. EXEC_DDL_STATEMENT DDL is, of course).
You may or may not find this article helpful: http://okjsp.pe.kr/seq/9789. He did a good job to compare the differences between EXECUTE IMMEDIATE and another way inherited to the dynamic SQL statements (DBMS_SQL. RUN)
Bob
-
use of execute immediate with variables
Hello
I want to update a table with immediate execution, but I need to use the variable to run immediately. I typed a code, but the code below does not work and I m getting the error ORA-00936. Something wrong with this code?
WHILE v_acu_payment_amount > 0
LOOP
BEGIN
SELECT emplid, amount_past_due
IN v_emplid, v_vade_tutari
OF vade_temp
WHERE the sira = v_sirano AND emplid IN (r1.emplid);
END;
v_acu_payment_amount: = v_acu_payment_amount - v_vade_tutari;
Dbms_output.put_line ('paymentamount2' | v_acu_payment_amount);
IF v_acu_payment_amount > 0
THEN
EXECUTE IMMEDIATE "update vade_temp set AMOUNT_PAST_DUE = to_number('||) 0
|| ') where sira = to_number (')
|| v_sirano
|| ')';
ON THE OTHER
Temp: = v_acu_payment_amount * (-1);
Dbms_output.put_line (temp);
EXECUTE IMMEDIATE "update vade_temp set AMOUNT_PAST_DUE = to_number (')"
|| Temp
|| ') where sira = to_number (')
|| v_sirano
|| ')';
END IF;
COMMIT;
v_sirano: = v_sirano + 1;
END LOOP;
Kind regards
Gunce
In addition, you have no dynamic SQL for this
[code]
WHILE v_acu_payment_amount > 0
LOOP
BEGIN
SELECT emplid, amount_past_due
IN v_emplid, v_vade_tutari
OF vade_temp
WHERE the sira = v_sirano AND emplid IN (r1.emplid);
END;
v_acu_payment_amount: = v_acu_payment_amount - v_vade_tutari;
Dbms_output.put_line ('paymentamount2' | v_acu_payment_amount);
IF v_acu_payment_amount > 0
THEN
UPDATE vade_temp
SET amount_past_due = 0
WHERE the sira = v_sirano;
ON THE OTHER
Temp: = v_acu_payment_amount * (-1);
Dbms_output.put_line (temp);
UPDATE vade_temp
SET AMOUNT_PAST_DUE = temp
where sira = v_sirano;
END IF;
COMMIT;
v_sirano: = v_sirano + 1;
END LOOP;
[/ code]
But if you need dynamic sql statements, then you should use bind variables as
...
EXECUTE IMMEDIATE "UPDATE vade_temp SET amount_past_due =: b1 WHERE sira =: b2' using 0, v_sirano;"
...
HTH
-
Create a temporary table using EXECUTE IMMEDIATE
Hello
I need to create a report more complex which must have three different queries. I use a determined IF clause that the query that uses the report, according to the parameters.
I want to write the output to a csv file, so I created a PROCEDURE.
The first package of the procedure has the three SQL and the IF clause in order to determine the query that the report uses and stores the query code in a variable (v_sql), which is passed to the PROCEDURE that needs to write to the output of the report.
I tried to create a table with data from the request in order to make a LOOP and exit, something like this:
WRITE_FILE (errBUFF of the PROCEDURE OUT VARCHAR2, retCODE OUT VARCHAR2, v_sql IN VARCHAR2) IS
Contor NUMBER; BEGIN
EXECUTE IMMEDIATE v_sql; SLIDE G IS Select * from XXROR_REG_MF_TBL; -- -initialization -- retCode: = 0; errBUFF: = NULL; Contor: = 0; -- -cursor -- FOR X IN G LOOP APPS. FND_FILE. PUT_LINE) APPS. FND_FILE. OUTPUT, ....) I should mention that v_sql is something like:
CREATE GLOBAL TEMPORARY TABLE ACEs (SELECT * of the double);
I can't really do that, so I was wondering if you have any suggestions
Thank you
Claudiu
Hello
I don't think you need a table at all. You can set the cursor based on the SQL passed as parameter
https://docs.Oracle.com/database/121/LNPLS/dynamic.htm#LNPLS629
Concerning
Marcus
-
Use of EXECUTE IMMEDIATE with XML
Database version: 10.2.0.3.0 - 64bi
Hi all
I have an xml that is stored in a table, xmltype column.
I target insert tables including column names and xml nodes are the same.
using the table of all_tab_columns I will generate columns must be passed to xmltable.
all these data, I'll store them in variables and finally proceed to xmltable as below
I just want to know using execute immediate is good to use XML?
SQL_STMT: = 'insert'. table_name | ' ( '|| V_COLUMN_NAME |') ' ;
SQL_STMT: = SQL_STMT | ' SELECT '. V_XTAB_COLUMN_NAME |
"FOR TO_XML,
XMLTABLE(' || v_xpath ||)
"PASSAGE XML_VALUE
columns | V_COLUMNS_DATA_TYPE
||') XTAB
WHERE Seq_NO = ' | P_SEQUENCE_NO;
RUN IMMEDIATELY SQL_STMT;
Thank you and best regards,
RubyHi Ruby,
I just want to know using execute immediate is good to use XML?
Sorry, but this question does not make much sense.
Whether or not dynamic SQL means XML is not relevant, the statement will end up as a cursor in the shared pool independently and be executed or retrieved as any other.If I were you, I'd be worried on the statement do not use bind variables, or the need for dynamic SQL in the first place.
Why should you use dynamic SQL?
If it's laziness, because there are a lot of columns to write down, then it is a bad reason. -
Hi all
I have a statement i.e. Select ename from EMP; I want to run it in execute immediate command.
He return several rows at a time.
How can I run this statement with oracle execute immediate command
Please review...dipuna wrote:
Hi all
I have a statement i.e. Select ename from EMP; I want to run it in execute immediate command.
He return several rows at a time.If you have this EXACT statement, then you need not dynamic nothing :)
dipuna wrote:
How can I run this statement with oracle execute immediate command
Please review...
Examples of both methods (as previously mentioned).
TUBBY_TUBBZ? declare type l_enames_tab is table of scott.emp.ename%type; l_enames_array l_enames_tab ; begin 5 execute immediate 'select ename from scott.emp' bulk collect into l_enames_array; for x in 1 .. l_enames_array.count loop dbms_output.put_line(l_enames_array(x)); end loop; end; / SMITH ALLEN WARD JONES MARTIN BLAKE CLARK SCOTT KING TURNER ADAMS JAMES FORD MILLER PL/SQL procedure successfully completed. Elapsed: 00:00:00.00 TUBBY_TUBBZ?TUBBY_TUBBZ? declare type l_enames_tab is table of scott.emp.ename%type; l_enames_array l_enames_tab ; l_ref_cursor sys_refcursor; begin 6 open l_ref_cursor for 'select ename from scott.emp'; fetch l_ref_cursor bulk collect into l_enames_array; close l_ref_cursor; for x in 1 .. l_enames_array.count loop dbms_output.put_line(l_enames_array(x)); end loop; end; 19 / SMITH ALLEN WARD JONES MARTIN BLAKE CLARK SCOTT KING TURNER ADAMS JAMES FORD MILLER PL/SQL procedure successfully completed. Elapsed: 00:00:00.00 TUBBY_TUBBZ?
-
Problem in Using of EXECUTE IMMEDIATE clause
Hello
I tried using using the clause, but am getting an error. Any help is welcome.
Here is the code
declare
number of g_salary;
v_stm varchar2 (100);
Start
v_stm: = "insert into emp (empno, deptno, sal) values (: 1,: 2: 3)"; "
execute immediate v_stm using empno, sal, deptno;
end;
Here is the error message
ERROR on line 1:
ORA-06550: line 6, column 31:
PLS-00201: identifier 'EMPNO' must be declared.
ORA-06550: line 6, column 1:
PL/SQL: Statement ignoredYou must provide values that must be inserted into the table.
something likedeclare g_salary number ; v_stm varchar2(100); begin v_stm := 'insert into emp (empno, deptno, sal) values (:1, :2, :3)'; execute immediate v_stm using 10, 20, 30; end;
not tested
-
Pass Pl/sql table in the USING clause in the EXECUTE IMMEDIATE statement
Getting error when I try to pass the PL/SQL table in the USING clause in the EXECUTE IMMEDIATE statement:
Declare
result NUMBER;
TYPE values_tab IS TABLE OF NUMBER INDEX OF directory;
lv_tab values_tab;
lv_exp varchar2 (300);
lv_exec varchar2 (300);
BEGIN
lv_tab (1): = 5;
lv_tab (2): = 48;
lv_tab (3): = 7;
lv_tab (4): = 6;
lv_exp: = ': + b1: b2 + (: b3 *: b4)';
lv_exec: = 'SELECT'. lv_exp | ' THE DOUBLE '.
IMMEDIATE EXECUTION
lv_exec
IN
result
USING
lv_tab;
DBMS_OUTPUT. Put_line (result);
END;
/
Error on line 1
ORA-06550: line 20, column 12:
PLS-00457: expressions must be SQL types
ORA-06550: line 15, column 8:
PL/SQL: Statement ignored
I am trying to evaluate the expression ': + b1: b2 + (: b3 *: b4) "which is stored in the table. This table has different expressions (expressions about 300). I want to use the bind variable in the expression because each expression evaluated thousands of time may be more in some cases. If I use bind variable can he fill pool.
Is there a way I can pass parameters with the HELP of (IN) dynamically instead of write "help lv_tab (1), lv_tab (2), lv_tab (3), lv_tab (4)? As number of change of the input parameters depend on the expression in the table.
If it is possible please suggest any other ideas/approaches
Help, please...
Published by: satnam on June 11, 2009 11:50Well, you keep changing faster reqs that I can follow. In any case, assuming that N-th variable bind (left to right) corresponds to n-th collection item:
Declare result NUMBER; lv_tab values_tab := values_tab(); lv_exp varchar2(300); lv_exec varchar2(300); lv_i number := 0; BEGIN lv_tab.extend(4); lv_tab(1) := 5; lv_tab(2) := 48; lv_tab(3) := 7; lv_tab(4) := 6; lv_exp := ':5000135+:5403456+(:5900111*:5200456)'; lv_exec := lv_exp; While regexp_like(lv_exec,':\d+') loop lv_i := lv_i + 1; lv_exec := REGEXP_REPLACE(lv_exec,':\d+',':b(' || lv_i || ')',1,1); end loop; lv_exec := 'BEGIN :a := ' || lv_exec || '; END;'; DBMS_OUTPUT.PUT_LINE(lv_exec); EXECUTE IMMEDIATE lv_exec USING OUT result,IN lv_tab; DBMS_OUTPUT.PUT_LINE(result); END; / BEGIN :a := :b(1)+:b(2)+(:b(3)*:b(4)); END; 95 PL/SQL procedure successfully completed. SQL>
SY.
-
Creating external Tables using the EXECUTE IMMEDIATE in PL/SQL
Hi guys,.
I am trying to create an external Table using the EXECUTE IMMEDIATE in a procedure and I managed to compile and no errors were generated. But when I try to run it from sql using the exec command I get the following error:
------------------------------------------------------------------------
ERROR on line 5:
ORA-00911: invalid character
ORA-06512: at "GEO. TEST_DDL', line 4
ORA-06512: at line 5
-------------------------------------------------------------------------
I tried to check the whole statement to create the external table, but I can't find where is the error. Surprisingly, if I simply run the command table create external on sqlplus it works, but not a procedure.
If anyone can help with ideas or experience?
Geoffrey KossamiThe error means that there is an identifier somewhere that starts with a nonalphanumeric. This is a typical mistake of editing. A procedure compiles correctly is not of course because the underlying dynamic sql running is OK. Which of course only be resolved when you try to run it.
There is certainly a problem with the text you provide to be run as a piece of dynamic sql code. You should try to watch it with dbms_output and run this code in sqlplus. But your problem is with the code you run as dynamic PL/SQL, it is not itself compilable.
Jack
-
Maximum size of EXECUTE IMMEDIATE
Hellou everyone,
I would like to ask if there is a way how to run the dynamic SQL CREATE or VIEW of REPLACE command more than 32 KB of wholesale. Because the EXECUTE IMMEDIATE statement can run up to 32 k (greater length of variable plsql chain) chain
Is there a way how children Ridge or replace the command?
Or I need to revrite using DBMS_SQL.
Thank you.
(a) WHY? If you want to dynamically create views? This is not recommended because your application/database should be designed at the time of the design, not running.
(b) If you are on 11 g, you can use the CLOB datatype with immediate execution, so there is no 32 K limit.
(c) If you are before 11 g you need to update, but if you can't then the following example is how you do it using DBMS_SQL.
SQL > declare
2 v_large_sql clob.
3 v_num number: = 0;
number of v_upperbound 4;
5 v_sql dbms_sql.varchar2s;
6 whole v_cur;
number of v_ret 7;
8 v_join_sql varchar2 (100): = ' crΘer view vw_tmp as ";
9 start
10. build a very big SQL statement in the CLOB
11 loop
12 v_large_sql: = v_large_sql | v_join_sql | "select" the number of this line is: ' | TO_CHAR (v_num, 'fm0999999') | " "as col1 from dual;"
13 v_join_sql: = "union all";
14 v_num: = v_num + 1;
15 exit when dbms_lob.getlength (v_large_sql) > 40000 or v_num > 800;
16 end loop;
17 dbms_output.put_line (' length :'||) DBMS_LOB. GetLength (v_large_sql));
18 dbms_output.put_line ('Num :'|| v_num);
19-
20. now divide this big SQL statement into pieces of 256 characters and put in table VARCHAR2S
21 v_upperbound: = ceil ((v_large_sql) dbms_lob.getlength / 256);
22 because me at 1.v_upperbound
23 loop
24 v_sql (i): = dbms_lob.substr (v_large_sql
25, 256 - amount
26, ((i-1) * 256) + 1 - offset
27 );
28 end of loop;
29-
30. now analyze and execute the SQL statement
31 v_cur: = dbms_sql.open_cursor;
32 dbms_sql.parse (v_cur, v_sql, 1, v_upperbound, dbms_sql.native, false);
33 v_ret: = dbms_sql.execute (v_cur);
34 dbms_output.put_line ("' view created");
35 dbms_sql.close_cursor (v_cur);
36 end;
37.
Length: 40015
NUM:548
View created
PL/SQL procedure successfully completed.
SQL > select count (*) in the vw_tmp;
COUNT (*)
----------
548
SQL > select * from vw_tmp where rownum<=>=>
COL1
-----------------------------------
The number of this line is: 0000000
The number of this line is: 0000001
The number of this line is: 0000002
The number of this line is: 0000003
The number of this line is: 0000004
The number of this line is: 0000005
The number of this line is: 0000006
The number of this line is: 0000007
The number of this line is: 0000008
The number of this line is: 0000009
10 selected lines.
SQL >
-
Dynamic Query(execute immediate)
Greetings,
VERSION:-10 g
Name of the table column is the name of the month which I store in a condition variable that I have to pass the names of columns at runtime of the value
TABLE DEALER_MAST
NUMBER OF DEALER_DIM_ID
NUMBER OF APR
MAY ISSUE
JUNE ISSUE
NUMBER OF JUL
AUGUST ISSUE
NUMBER OF MS
I now have the code example below in my procedure
v_dealer VARCHAR2 (3);
XYZ varchar2 (2000);
SELECT TO_CHAR (SYSDATE, 'MY') IN THE DOUBLE V_DEALER;
DECLARE CURSOR a1 IS SELECT DEALER_ID FROM DEALER_MAST;BEGIN
FOR j IN a1
loopCOUNT (*) SELECT IN DEALER_COMM FROM subs_fact
WHERE TO_CHAR (ACTIVATION_DATE, 'Mon - yy') = (select to_char (add_MONTHS(sysdate,-2), 'mon-yy') FROM dual)
- AND TAB_ELEG = 1
and DEALER_ID = j.DEALER_ID;
-Dynamicaly passing the name of columnXYZ: = 'SELECT'. V_DEALER | "IN DEALER_MAST FROM DEALER_MAST WHERE DEALER_DIM_ID =' | j.DEALER_DIM_ID;
run immediately (XYZ);
/*
AFTER immediate execution of the query should be as
SEVEN ELECTED IN DEALER_MAST FROM DEALER_MAST WHERE DEALER_DIM_ID = 24345
But not to store the data in the variable & gives error like key word missing on run immediately (XYZ);
*/
If (DEALER_MAST > 2) can
---
--
end if;
ERROR:-do not store data in the variable & gives error like key word missing on run immediately (XYZ);Thanks in advance
Maybe
l_var: = j.DEALER_DIM_ID;
XYZ: = "SELECT" | TO_CHAR (sysdate, 'MY'). ' FROM DEALER_MAST WHERE DEALER_DIM_ID =: l_var';
EXECUTE IMMEDIATE XYZ
INTO DEALER_MAST
USING l_var;Concerning
Etbin
-
Execute Immediate giving in ORA-00942: table or view does not exist
Hello
I am creating a table using an immeidate in PL/SQL execute it gives table or view does not exist. When that same create table sql works well outside the PL/SQL.
g_sql: =.
'CREATE TABLE' | l_tmptable1 |' as '.
' SELECT decode (gsisource, null, "WEBSTORE", gsisource) as 'SOURCE', COUNT (1) as 'ADD_COUNT' ' |
'OF SCHEMA_NAME.t_master' |
' WHERE the add_date between to_date('''|| g_startDateChrTrunc ||'') (', "MM/DD/YYYY) ' |
' AND to_date('''|| g_endDateChrTrunc ||'') (', "MM/DD/YYYY) ' |
'GROUP BY DECODE (gsisource, null, "WEBSTORE", gsisource)';
EXECUTE IMMEDIATE g_sql;
Any help is appreciated.
ConcerningHello
It seems that you have the privileges through a role. Roles do not count in the AUTHID DEFINE stored procedures. A the owner of the table the necessary privileges directly to the owner of the proceudre.
Moreover, the creation of tables in PL/SQL is almosty never the right way to do whatever it is you need. What is the purpose of this table? Why can not be created once and be truncated if necessary?
-
EXECUTE IMMEDIATE throwing error ORA-00933
Hello
I am trying to build a PL/SQL code that implements the EXECUTE IMMEDIATE statement in a cursor for EXECUTE IMMEDIATE does not support queries for multiple records. Recursively, I want to place a single record in a variable using the INTO clause, USING a defined value. But my code keeps throwing an error that the SQL command is not properly cancel online 15; which is the line of the EXECUTE IMMEDIATE statement.
I tried to generate the SQL statement to the console to review in the effort to find the problem, but the result looks OK. I also made other variations of what I want to accomplish, but not to make any where. Could someone maybe help identify what I am doing wrong?
DECLARE
TBL VARCHAR2 (50);
Col VARCHAR2 (50);
sqlcmd VARCHAR (300);
field_value VARCHAR2 (20): = 'MEXICO ';
match_count NUMBER;
CURSOR c1 IS SELECT TABLE_NAME, COLUMN_NAME FROM USER_TAB_COLS;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO tbl, col; -extract 2 columns in variables
OUTPUT WHEN c1% NOTFOUND;
Sqlcmd: = 'SELECT COUNT (*) FROM' | TBL | ' WHERE ' | Col |' = ": col" ';
EXECUTE IMMEDIATE sqlcmd IN match_count USING field_value.
DBMS_OUTPUT. Put_line (sqlcmd);
END LOOP;
CLOSE c1;
END;
/
I am more proficient with SQL PL/SQL, but try to understand the semantics of the language.
Thanks for any help.user10251149 wrote:
I'm in class implementing the recommended code you posted Solomon and he is not sinning through out, but I'm sitting at a cursor blinking on the console.I noticed that you have placed the variables, this time taking the table_name and column_name inside quotes values, it is a possible workaround for the issue or is there another method I could use to get the same results?
If you have N tables with columns of M your code will run statements N * Mr. If the tables are large, it might take some time. Now how about double quotes. You may receive error on the basis I assumed you have names of tables/columns composed of several words. You must include these names in quotation marks. Discover Oracle naming rules.
SY.
-
How to create and insert data with Execute Immediate?
Hi guys
Am stuck on a procedure of formatting in a package... script works okay however integrating a module turns out to be difficult!
Am not used to oracle... I have the script runs, but not in the package... Well not all that... Drop Table worked
CREATE or REPLACE PACKAGE BODY is
PROCEDURE DropTable1 IS
BEGIN
run immediately ("DROP TABLE mytable1");
END;
PROCEDURE PopulateTable1 IS
BEGIN
immediately execute ('CREATE TABLE mytable1 )
AS LONG AS)
Select
substr (T1.genarea, 3, 3) as M_Class,
substr (T1.genarea, 6, 30) as M_Description,
substr (T1.genarea, 36, 3) as M_Class,
substr (T1.genarea, 39, 30) as M_Description,
substr (T1. ItemItem, 1, 3) as product_code,.
T3. CHANNEL_NUM as SALES_CHANNEL,
to_date(''t2.time_id'',''dd-mon-yyyy'') as mis_date,
Sum (T2.ap_cw_cfi_irp + T2.ap_cw_issues_irp) as ap_gross,
sum (t2. Ap_Cw_Cfi_Irp + t2. Ap_Revivals_Irp) as ap_net,
Sum (T2.sp_inc_irp + T2.sp_issues_irp) as sp_gross,
Sum (T2.sp_dec_irp + T2.sp_fs_irp) as sp_net
Of
d_pr t1, t2 age_map t3 law
where
T1.pfx = "WE"and t1.coy ="1" and t1.tabl = "T81" and substr (t1.itemitem, 1, 3) = t2.product_id and t3. AGE_NUM = t2.age_id
Group
substr (T1.genarea, 3, 3),
substr (T1.genarea, 6, 30),
substr (T1.genarea, 36, 3),
substr (T1.genarea, 39, 30),
substr (T1. ItemItem, 1, 3).
T3. CHANNEL_NUM,
to_date(''t2.time_id'',''dd-mon-yyyy'')
)');
COMMIT;
END PopulateTable1;
END test;
/
Thank you
Hello
a few notes.
1. to_date(t2.time_id,'dd-mon-yyyy')
New York T2.Time_ID Cis the varchar2 data type that contains values to JJ-me-YYYY format?
And if, in which language is used for the names of the months? Conversions are point impossible to solve in reasonable time limits without logging of dml errors and unique failure on charges of staging nightly!
2 single quote escaping "alternative in string literals.You can use Q or q to escape single quotes in strings.
http://docs.Oracle.com/database/121/SQLRF/sql_elements003.htm#SQLRF00218
3. validation
Not required because the DDL commands commit implied.
In general I recommend you write commit clauses only in calling script rather than in the code unless it connects with an autonomous transaction.
You end up with a lot of validation of code here and there and you don't know where it is and where it isn't. That is, your process may have more than one appeal process and commit the middle of the process, it is not atomic processes.
Here's the demo although I recommend also using the static table and truncate to efficiency. ETG is good choice for the purpose of maintenance table.
create or replace package testing is procedure staging_one; end; / create or replace package body testing is -- procedure staging_one is -- procedure drop_staging_one is table_does_not_exist exception; pragma exception_init(table_does_not_exist, -00942); begin execute immediate q'{ drop table staging_one purge }'; exception when table_does_not_exist then return; -- fine end; -- procedure create_staging_one is begin execute immediate q'{ -- remove >>> create table staging_one nologging as select * from dual -- <<< remove /* uncomment >>> create table staging_one nologging as select substr(t1.genarea,3,3) as m_class, substr(t1.genarea,6,30) as m_description, substr(t1.genarea,36,3) as m_class, substr(t1.genarea,39,30) as m_description, substr(t1.itemitem,1,3) as product_code, t3.channel_num as sales_channel, to_date(t2.time_id,'dd-mon-yyyy') as mis_date, sum(t2.ap_cw_cfi_irp+t2.ap_cw_issues_irp) as ap_gross, sum(t2.ap_cw_cfi_irp+t2.ap_revivals_irp) as ap_net, sum(t2.sp_inc_irp +t2.sp_issues_irp) as sp_gross, sum(t2.sp_dec_irp +t2.sp_fs_irp) as sp_net from d_pr t1, act t2, age_map t3 where t1.pfx = 'IT' and t1.coy = '1' and t1.tabl = 'T81' and substr(t1.itemitem,1,3) = t2.product_id and t3.age_num = t2.age_id group by substr(t1.genarea,3,3), substr(t1.genarea,6,30), substr(t1.genarea,36,3), substr(t1.genarea,39,30), substr(t1.itemitem,1,3), t3.channel_num, to_date(t2.time_id,'dd-mon-yyyy') <<< uncomment */ }'; -- end; -- main begin drop_staging_one; create_staging_one; end; end; / set serveroutput on exec testing.staging_one; select * from staging_one ; commit ; PACKAGE TESTING compiled PACKAGE BODY TESTING compiled anonymous block completed DUMMY ----- X committed.
Maybe you are looking for
-
How can I increase band bandwidth wifi between floors?
My Airport Extreme is on the floor at one end of the apartment (by necessity), and I need bandwidth better reach down to the other end. How can I set up multiple Airport Express units to achieve this?
-
OfficeJet 4500: HP Officejet 4500 all-in-One Printer
How can I find which edition of drivers I have download for my 4500 since there are different versions G510 (a, h g - n, etc.) and that there is no such index on my printer in order to avoid malfunctions? My serial No.: (deleted content) My FPU No.:
-
What is the best way to "clean up/free space" on my computer? Thank you
What is the best way to clean/free up space on my computer? Even do not know where to look to see how much space I use... Thank you.
-
Can someone help remove the songs from the device (as opposed to connect to the computer)? I can't find an option 'Remove' on my player.
-
Report on the last access of VM
I'm looking for a report that can leave data such as when was the last time the VM has been consulted and for how much time a virtual machine was turned off.