SQL >; create or replace procedure sp_Validate3 (p_acr_no IN varchar2 2)
Hi all11.2.0.1
Can you help me to debug what is that pl/sql code error? Thank you
SQL> create or replace procedure sp_Validate3(p_acr_no IN varchar2
2 ,p_recordset OUT sys_refcursor
3 ) as
4 begin
5 open p_recordset for
6 select am.acr_no as acr_no
7 ,'TEST' as lastname
8 ,nvl(a.or_no,'0') as ecc_orno
9 ,nvl(b.or_no,'0') as rp_orno
10 ,nvl(c.or_no,'0') as ar_orno
11 from tab t
12 join acr_master am on (trim(acr_no) = p_acr_no)
13 left outer join payment_master a on (payment_type = 'ECC' and trim(acr_no) = p_acr_no)
14 left outer join payment_master b on (payment_type = 'RP' and trim(acr_no) = p_acr_no)
15 left outer join payment_master c on (payment_type = 'AR' and trim(acr_no) = p_acr_no);
16 end;
17 /
Warning: Procedure created with compilation errors.
SQL> show error
Errors for PROCEDURE SP_VALIDATE3:
LINE/COL ERROR
-------- -----------------------------------------------------------------
6/5 PL/SQL: SQL Statement ignored
13/80 PL/SQL: ORA-00918: column ambiguously defined
SQL>
create table acr_master(acr_no varchar2(10))
drop table payment_master
create table payment_master(or_no varchar2(10),acr_no varchar2(10),payment_type varchar2(10))
/* Formatted on 06/06/2013 6:06:58 PM (QP5 v5.126.903.23003) */
CREATE OR REPLACE PROCEDURE sp_Validate3 (p_acr_no IN VARCHAR2,
p_recordset OUT sys_refcursor)
AS
BEGIN
OPEN p_recordset FOR
SELECT am.acr_no AS acr_no,
'TEST' AS lastname,
NVL (a.or_no, '0') AS ecc_orno,
NVL (b.or_no, '0') AS rp_orno,
NVL (c.or_no, '0') AS ar_orno
FROM tab t
JOIN
acr_master am
ON (TRIM (acr_no) = p_acr_no)
LEFT OUTER JOIN
payment_master a
ON (payment_type = 'ECC' AND TRIM (acr_no) = p_acr_no)
LEFT OUTER JOIN
payment_master b
ON (payment_type = 'RP' AND TRIM (acr_no) = p_acr_no)
LEFT OUTER JOIN
payment_master c
ON (payment_type = 'AR' AND TRIM (acr_no) = p_acr_no);
END;
/
SQL> show error
Errors for PROCEDURE SP_VALIDATE3:
LINE/COL ERROR
-------- -----------------------------------------------------------------
6/5 PL/SQL: SQL Statement ignored
13/80 PL/SQL: ORA-00918: column ambiguously defined
SQL>
--In the below code after keeping alias names of the tables, the procedure compiled successfully
/* Formatted on 06/06/2013 6:06:58 PM (QP5 v5.126.903.23003) */
CREATE OR REPLACE PROCEDURE sp_Validate3 (p_acr_no IN VARCHAR2,
p_recordset OUT sys_refcursor)
AS
BEGIN
OPEN p_recordset FOR
SELECT am.acr_no AS acr_no,
'TEST' AS lastname,
NVL (a.or_no, '0') AS ecc_orno,
NVL (b.or_no, '0') AS rp_orno,
NVL (c.or_no, '0') AS ar_orno
FROM tab t
JOIN
acr_master am
ON (TRIM (acr_no) = p_acr_no)
LEFT OUTER JOIN
payment_master a
ON (a.payment_type = 'ECC' AND TRIM (a.acr_no) = p_acr_no)
LEFT OUTER JOIN
payment_master b
ON (b.payment_type = 'RP' AND TRIM (b.acr_no) = p_acr_no)
LEFT OUTER JOIN
payment_master c
ON (c.payment_type = 'AR' AND TRIM (c.acr_no) = p_acr_no);
END;
/
Tags: Database
Similar Questions
-
Ampersand substitution in create or replace procedure statement
Hi guys,.
I wonder why my replacement ampersand works in a create or replace statement of the stored procedure.
CREATE OR REPLACE PROCEDURE UPDATE_DIM_SALES AS
Cancel the DEFINITION DimSales;
Cancel the DEFINITION FactTable;
SET DimSales = 'TESTTAB;
SET FactTable = myfact;
BEGIN
*...*
Error (5,20): PLS-00103: encountered the symbol "=" when expected as follows: =. (@ %; not null default range character)
If I assign the value with: = I get the error "invalid table" thereafter for the statemnt of INSERTION:
CREATE OR REPLACE PROCEDURE UPDATE_DIM_SALES AS
Cancel the DEFINITION DimSales;
Cancel the DEFINITION FactTable;
SET DimSales: = ' x 2';
SET FactTable: = ' x 1';
BEGIN
INSERT INTO & DimSales (column1, column2,...)
Why not the ampersand substitution work in a stored procedure?No problem with the carpet. Display. But you don't need to create and drop them again. Simply create a time and refresh just before departure if necessary. I expect the creation and updating of points of view is fast comparibly. Also access to the seller_id should be indexed.
Your original pl/sql block is slow due to several reasons. One might be that you agree to each line. Engage is an extremely slow process. He avoid as much as possible. Another part might be that you make all the changes of context of pl/sql. The obvious way to avoid this would be to BULK operations (bulk-select + Forall). It is not so difficult. The size of the collection must be limited to a lower amount.
Best way would be to measure the performance of pl/sql parts using a tool such as DBMS_PROFILER. Then you can decide what part is slow and must be granted.
A simple insert could be faster. Did you test that?
example not tested
INSERT /*+append */ INTO &DimSales (K_Sales,REG,BVL,DS, VS,RS,GS,VK) (SELECT trim(leading '0' from RS||GS) ,REG, BVL,DS, VS,RS,GS,VK from &FactTable f join &testsales s on f.SellerNo =s.Seller_No; commit;
You can run the other issues, but this is generally the fastest approach. Try to avoid the separate if possible. This requires a sort and will slow down the insert of a lot.
Published by: Sven w. on November 30, 2010 17:10
-
trying to get used to sql * more running and creating a simple procedure
Hello all;
I'm getting used to sql * more after using for a while using pl/sql developer.
I am trying to create a simple procedure and run it. See my procedure below
and then I type in run hr.test ("J", 10); to run this and then press ENTER, and it does nothing. How can I run and create a simple procedure in sql * morecreate or replace procedure test(t in varchar2(200), limit in number(30)) begin select tbl_report.id from tbl_report where tbl_report.id like '|| t ||%' and rownum <= limit; end test;
Hello
In addition to all the good points, others have done:
When you issue a SELECT statement in SQL * Plus (or any other front end) two things happen:
(1) a result set, containing the results of your query, is produced, and
(2) this result set is displayed.
Given that these two things are always done together, it is easy to forget that they are two different things.
In PL/SQL, you must explicitly do something to catch the result set, and you must explicitly do something else to view it (if you want to display it).A simple way to get the result set is to use a cursor FOR loop, to extract a line at a time and run code with this line in a record variable (called the country in the example below).
View the results is to call dbms_output.put_line.Here is an example:
CREATE OR REPLACE PROCEDURE test ( t IN VARCHAR2 , lmt IN NUMBER -- LIMIT is an Oracle keyword; best not to use it as a variable name ) IS BEGIN FOR country IN ( SELECT country_name FROM hr.countries WHERE country_name LIKE t || '%' AND ROWNUM <= lmt ) LOOP dbms_output.put_line ( country.country_name || ' = country_name' ); END LOOP; END test; / SHOW ERRORS
You can use variables, such as t and lmt, in the query without using dynamic SQL, as long as the variables do not have the same names as the columns in the table. In this case, t and lmt are good names; country_name or region_id wouldn't. (In fact, t is a reputable insofar as it cannot be confused with a column in the table of the country. T is not a good reputation in the sense that it does not give much information about what contains the variable, or how it is used. Why not call the variable target_name or name_a_trouver?
You can run the SQL procedure * more like this:
SET SERVEROUTPUT ON EXEC test ('I', 2);
If you issue the SET SERVEROUTPUT ON command, then you will not see the output of dbms_output. You must only issue the command SET SERVEROUTPUT ON once per session, but nothing bad happens if you do it more than once.
When I ran the procedure as stated above, I got this output:
Israel = country_name India = country_name
Notice that "The Italy" does not appear, because lmt has 2.
Do not create your own procedures, tables or other objects in the HR schema, or among all the other patterns created by Oracle. Create your own schema and create procedures and other objects in it.
-
Privileges differ between SQL * more and stored procedure
A user with the dba role can access dba_role_privs. But this is not possible in a stored procedure created by the same user.
Normally, the example should work fine
But with Oracle XE 11.02 - cost free database with some limitations - I get error 942
I show a simple example in SQL * more:
SQL > r
1 * select distinct dba_role_privs recipient where the recipient as "SY %.
DEALER
------------------------------
SYSTEM
SYS
SQL > create or replace procedure x as
2 start
3 for rec in (select distinct dba_role_privs dealer where the beneficiary as 'SY %')
4 loop
5 zero;
6 end of loop;
7 end;
8.
Warnung: Prozedur wurde mit Kompilierungsfehlern standing.
English translation: procedure created with compilation errors
SQL > show error
LINE/COL ERROR
-------- -----------------------------------------------------------------
3/14 PL/SQL: statement ignored
3/43 PL/SQL: ORA-00942: table or view does not exist
SQL >
How can I fix?Why do you think the example should work properly?
Normally, regardless of the version, the privileges granted through roles (such as DBA) not available for stored procedures. Stored procedure of a DEFINER rights can only take advantage of the privileges granted directly to the owner of the procedure. Stored procedure of the invoker rights can enjoy privileges granted by a role, but that requires that the appellant has independent privileges to query the table in question (and, in this case, would require dynamic SQL usage).
Generally, the simplest approach would be to grant the privilege to CHOOSE ANY DICTIONARY to the owner of the procedure.
Justin
-
insufficient privileges when using dynamic sql statements in the procedure
Hello
I use following script on oracle 10g. and get the error not enough privs. Please advice.
SQL > show user
The user is 'GRSADM '.
SQL > create or replace procedure grsadm.test_proc as
a varchar2 (2000);
Start
a: =' VIEW to CREATE or REPLACE
TEST_VIEW
IN SELECT
"FLAS" one
THE DOUBLE ';
immediately run one;
end;
Created procedure.
SQL > start
grsadm.test_proc;
end;
Start
grsadm.test_proc;
end;
Error on line 16
ORA-01031: insufficient privileges
ORA-06512: at "GRSADM. TEST_PROC', line 9
ORA-06512: at line 2
SQL > select * from session_privs
where the privilege as "VIEW %.
PRIVILEGE
----------------------------------------
CREATE A VIEW
REMOVE ANY VIEW
CREATE A MATERIALIZED VIEW
MODIFY A MATERIALIZED VIEW
REMOVE ANY MATERIALIZED VIEW
5 selected lines.
Published by: Rous Sharma on November 24, 2011 12:00GRSADM has a privilege ' CREATE (all) VIEW ' live?
And not via a role...SSM
Samir,
GRSADM is the owner of this procedure, it seems that the EXECUTE priv, that you suggested is already involved. -
Procedure crashes while create or replace!
Dear all,
My Oracle 11 g RAC database is.
I made some changes in one of my procedure and tried to recreate it using the CREATE or REPLACE procedure...
The statement hangs for a long time and simultaneity in OEM increases up to a very high level. I tried to find blocking sessions, but for some time, there was no session blocking.
I also tried to stop the activities on the tables used in this procedure.
Please suggest me what can I do in this situation. I also tried directly from the server running the query.
Best regards, ImranOh, layout of the dining Forum, I copied correctly ;)
In fact, it is not equal to '<>' operator & no '=' equql, please correct & let me know if useful
Once again his lack below, will give you session killin commnd
Select / * + CHOOSE * / ' alter system kill session "' | a.SID | ',' | a.Serial #| " « ; »
session v$, $ v b access
where a.sid = select
and b.type<>'does not EXIST.
and (b.owner is not null) and (b.owner<>'SYSTEM') and (b.owner<>'SYS') and serial No. <> 1
and upper (b.object) like '% VSNL_CORP_TASK_READY_CMPL % ';Thank you
Ajay more
http://moreajays.blogspot.com -
Synonym of ALTER with Create or replace synonym
Oracle 9i Release 2 database
I need to change the thesaurus during execution to point to a new owner of the table. But I'm running into errors of "insufficient privileges".
SQL> select grantee,owner,table_name,privilege from dba_tab_privs 2 where table_name IN ('OE4PNFGETDATA','OEBGGETDATA','OEGETDATA'); GRANTEE OWNER TABLE_NAME PRIVILEGE ------------- --------- ----------------- ----------- OEMUSER OEM2 OE4PNFGETDATA EXECUTE OEMUSER OEM2 OEBGGETDATA EXECUTE OEMUSER OEM2 OEGETDATA EXECUTE OEMUSER OEM1 OEBGGETDATA EXECUTE OEMUSER OEM1 OEGETDATA EXECUTE OEMUSER OEM1 OE4PNFGETDATA EXECUTE SQL> sho user USER is "OEMUSER" SQL> select synonym_name,table_owner,table_name from user_synonyms ; SYNONYM_NAME TABLE_OWNER TABLE_NAME ------------------------------ ------------------------------ ------------------------------ OE4PNFGETDATA OEM1 OE4PNFGETDATA OEBGGETDATA OEM1 OEBGGETDATA OEGETDATA OEM1 OEGETDATA
I need to change the owner of the table to OEM2. Using create or replace synonym in a procedure:
CREATE OR REPLACE PROCEDURE oemuser.p_switch_users ( i_nonactive_user IN VARCHAR2 , o_msg OUT VARCHAR2 ) AS v_synonym_name VARCHAR2(30) ; v_table_owner VARCHAR2(30) := i_nonactive_user ; v_table_name VARCHAR2(30) ; v_sql VARCHAR2(255); BEGIN FOR rec IN ( select synonym_name, table_owner, table_name from user_synonyms ) LOOP v_synonym_name := rec.synonym_name ; v_table_name := rec.table_name ; v_sql := 'CREATE OR REPLACE SYNONYM ' || v_synonym_name || ' FOR ' || v_table_owner || '.' || v_table_name ; EXECUTE IMMEDIATE v_sql ; END LOOP ; o_msg := 'Completed successfully' ; EXCEPTION WHEN others THEN o_msg := 'Error_Stack...' || Chr(10) || DBMS_UTILITY.FORMAT_ERROR_STACK ; RAISE ; END p_switch_users ; / var o_msg varchar2(512) var i_user varchar2(10) exec :i_user := 'OEM2' exec p_switch_users(:i_user,:o_msg) ORA-01031: insufficient privileges ORA-06512: at "OEMUSER.P_SWITCH_USE RS", line
I have not tried to drop the synonyms and re - create, but I expect the same error. Any suggestions?
Hello
the owner of the procedure should the privilege of creating its own synonyms if i_nonactive_user is defined on its own behalf (this case has no interest), and he has the privilege to create ANY synonym in other... At first glance, I would say that this is not a good idea.
Note: you can also save a job: no need to redefine a synonym to point to the same thing, so I would limit synonyms selected in the loop:
FOR rec IN (SELECT u.synonym_name, u.table_owner, u.table_name
U user_synonyms
WHERE u.table_owner! = v_table_owner
)
Best regards
Bruno Vroman
-
Cannot create the plsql procedure, fails at the cursor
He was a working procedure that would take ID and then copy the data from the source to the destination parameter parameter. Now I would like to have the NAME as a parameter, I changed the code to accommodate the new settings. But I'm not able to create the procedure. I get error 3-CURSOR (in bold red). I would really appreciate if someone can take a look and let me know what the problem is.
Thanks in advance
3 errors
1 PLS-00103: encountered the symbol "CUR_V_HSP_COLUMN_DETAIL" during the expected in the following way:
:= . ( @ % ;
The symbol ': = ' was replaced by 'CUR_V_HSP_COLUMN_DETAIL' continue.
2 PLS-00103: encountered the symbol "NUMBER" when expecting one of the following conditions:
(
The symbol "(" was substituted for "NUMBER" to continue.
3 PLS-00103: encountered the symbol "NUMBER" when expecting one of the following conditions:
(
CREATE or REPLACE procedure EPM_PLAN_PLANSAMP. Copy_Details_test1 - Arguments
( IN VARCHAR2, HSP_object in_From_Version_Name.) Object_name - Version of
in_From_Scenario_Name IN VARCHAR2, HSP_object. Object_name - scenarios of
in_From_Year_Name IN VARCHAR2, HSP_object. Object_name - year from
in_To_Version_Name IN VARCHAR2, HSP_object. Object_name - Version to
in_To_Scenario_name IN VARCHAR2, HSP_object. Object_name - scenarios
in_To_Year_Name IN VARCHAR2 - HSP_object. Object_name - year to
)
IS
number of v_From_Object_Id; -Version of
number of s_From_Object_Id; -Scenarios of
number of y_From_Object_Id; -The year of
number of v_To_Object_Id; -Version to
number of s_To_Object_Id; -Scenarios to
number of y_To_Object_Id; -The year to
BEGIN
Select object_id in v_From_Object_Id
of hsp_object
where type_objet = 35
and object_name = in_from_version_name;
Select object_id in s_From_Object_Id
of hsp_object
where type_objet = 31
and object_name = in_from_scenario_name;
Select object_id in y_From_Object_Id
of hsp_object
where type_objet = 38
and object_name = in_from_year_name;
Select object_id in v_To_Object_Id
of hsp_object
where type_objet = 35
and object_name = in_to_version_name;
Select object_id in s_To_Object_Id
of hsp_object
where type_objet = 31
and object_name = in_to_scenario_name;
Select object_id in y_To_Object_Id
of hsp_object
where type_objet = 38
and object_name = in_to_year_name;
-Select Details of support for the current Version
CURSOR Cur_V_HSP_COLUMN_DETAIL (cV_From_Object_Id in NUMBER, cS_From_Object_Id number) IS
Select DETAIL_ID in the EPM_PLAN_PLANSAMP. HSP_COLUMN_DETAIL where DIM5 = cV_From_Object_Id AND DIM1 = cS_From_Object_Id;
li_DETAIL_ID NUMBER;
Li_Next_DETAIL_ID NUMBER;
FETCH_STATUS NUMBER: = 0;
v_step_name varchar2 (200);
v_rec_cnt number: = 0;
number of v_cnt;
v_err varchar2 (2000);
-----------------------------------------Begin Copy Version ---------------------------
BEGIN
-Removed next version if already exists
v_step_name: = 'delete the HSP_COLUMN_DETAIL_ITEM ";
Remove from HSP_COLUMN_DETAIL_ITEM
Where DETAIL_ID in (Select DETAIL_ID from HSP_COLUMN_DETAIL
Where = v_To_Object_Id AND DIM1-DIM5 = s_To_Object_Id);
v_cnt: = number of lines sql %;
insert into t_copy_supporting_dtls_log values (v_step_name, v_cnt, 1, sysdate, 'success');
v_step_name: = 'delete the HSP_COLUMN_DETAIL ";
Remove from HSP_COLUMN_DETAIL
where = v_To_Object_Id AND DIM1-DIM5 = s_To_Object_Id;
v_cnt: = number of lines sql %;
insert into t_copy_supporting_dtls_log values (v_step_name, v_cnt, 1, sysdate, 'success');
Open Cur_V_HSP_COLUMN_DETAIL (v_From_Object_Id, s_From_Object_Id);
v_step_name: = "Insert";
LOOP
Look FOR Cur_V_HSP_COLUMN_DETAIL IN li_DETAIL_ID;
WHEN the OUTPUT Cur_V_HSP_COLUMN_DETAIL % NOTFOUND;
-Find the next detail_id
Select Max (DETAIL_ID) + 1 IN HSP_COLUMN_DETAIL Li_Next_DETAIL_ID;
-Insert in the Table HSP_COLUMN_DETAIL
Insert into HSP_COLUMN_DETAIL (DETAIL_ID, PLAN_TYPE, DIM1, DIM2, DIM3, DIM4, DIM5, 6,
DIM7, DIM8, DIM9, DIM10, DIM11, DIM12, DIM13, DIM14, DIM15,
DIM16, DIM17, DIM18, DIM19, DIM20)
Select Li_Next_DETAIL_ID, PLAN_TYPE, S_To_Object_Id, DIM2, DIM3, DIM4, V_To_Object_Id, 6.
DIM7, DIM8, DIM9, DIM10, DIM11, DIM12, DIM13, DIM14, DIM15,
DIM16, DIM18, DIM19, DIM17, DIM20
Of HSP_COLUMN_DETAIL
Where DETAIL_ID = li_DETAIL_ID;
v_rec_cnt: = v_rec_cnt + sql rowcount %;
-Insert in the Table HSP_COLUMN_DETAIL_ITEM
Insert into HSP_COLUMN_DETAIL_ITEM (DETAIL_ID, VALUE, POSITION, GENERATION, OPERATOR, LABEL)
Select VALUE, POSITION, GENERATION, OPERATOR, Li_Next_DETAIL_ID, LABEL
From HSP_COLUMN_DETAIL_ITEM where DETAIL_ID = li_DETAIL_ID;
v_rec_cnt: = v_rec_cnt + sql rowcount %;
END LOOP;
Close Cur_V_HSP_COLUMN_DETAIL;
insert into t_copy_supporting_dtls_log values (v_step_name, v_rec_cnt, 1, sysdate, 'success');
commit;
exception when others then
Rollback;
v_err: = substr (sqlerrm, 1, 2000);
insert into t_copy_supporting_dtls_log values (v_step_name, 0, -1, v_err, sysdate);
commit;
END;
END;
/
You DECLARE the cursor before using it.
-
Create the stored procedure with the table from another throw diagram PLS-00201
Oracle 10g. I'm new on procedures, so maybe I'm missing something obvious.
The ABC schema owner has table T2001_WRITEOFF. The SYSDBAs given SIUD Some_Update_Role and granted this role to developer user IJK. IJK user then created a private synonym T2001_WRITEOFF for ABC. T2001_WRITEOFF. It worked with the usual SQL DML commands.
When I try to create a simple procedure, it throws PLS-00201 identifier "T2001_WRITEOFF" must be declared and the points of the 2nd line.
create or replace procedure woof1(
fooname in T2001_WRITEOFF.territory%TYPE, <=== error points here
bardesc IN T2001_WRITEOFF.ind_batch_submit%TYPE) IS
BEGIN
INSERT into T2001_WRITEOFF
VALUES ( fooname, bardesc);
END woof1;
/What I am doing wrong?
Thank you
JimR
Grant the necessary rights directly to the user (not through a role):
http://asktom.Oracle.com/pls/asktom/asktom.download_file?p_file=6551289900368934430
-
How to create a stored procedure to delete and create table
Version: Oracle 10g
I am trying to create a stored procedure that is delete it and create a table based on a select statement. I can create the table, but I can't let it go.
CREATE or REPLACE procedure EC_LOAD is
Start
INSERT INTO Sales_table
(FSCL_WK,
DIV,
ACCT_TYPE)
Select
FSCL_WK,
DIV,
ACCT_TYPE
Of
sales_revenue;
end ecload;
I need to drop the Sales_table before inserting the values. How can I do this?user610131 wrote:
I need to drop the Sales_table before inserting the values. How can I do this?
If you drop off where you insert it :)? Do you mean DELETE or TRUNCATE?
If table can be truncated (and don't forget TRUNCATE is DDL then he will commit):
CREATE OR REPLACE procedure EC_LOAD is begin EXECUTE IMMEDIATE 'TRUNCATE TABLE Sales_table'; INSERT INTO Sales_table (FSCL_WK, DIV, ACCT_TYPE) Select FSCL_WK, DIV, ACCT_TYPE from sales_revenue; end ecload;
Otherwise, use DELETE:
CREATE OR REPLACE procedure EC_LOAD is begin DELETE Sales_table; INSERT INTO Sales_table (FSCL_WK, DIV, ACCT_TYPE) Select FSCL_WK, DIV, ACCT_TYPE from sales_revenue; end ecload;
SY.
-
This procedure works fine, but I want to make a stored procedure to schedule it to run over time. I'd appreciate any help?
SET SERVEROUTPUT SIZE 1000000
I tried this, but it did work ' t:
declare
cursor obj_cursor (objname Varchar2) is
Select object_name, object_type, owner
from dba_objects
where owner = 'ITA '.
and object_type IN ('TABLE', 'SEE')
and object_name like '% JOB_;
cursor c_job_status is
SELECT ownerid jobid, starttime, endtime
OF ita.tpis32_job_status
WHERE starttime < sysdate - 800
AND num_lines > 10000000;
WK_SQL VARCHAR2 (500);
WK_JOBSTR VARCHAR2 (500);
BEGIN
for c_job loop c_job_status
wk_jobstr: = 'JOB_ | c_job. JobID | '%';
for wk_rec loop obj_cursor (wk_jobstr)
If wk_rec.object_type = "TABLE" then
wk_sql: = 'drop table' |' ITA.' | wk_rec.object_name | ';';
dbms_output.put_line (wk_sql);
end if;
If wk_rec.object_type = "DISPLAY" then
wk_sql: = 'drop view ' | wk_rec.object_name | ';';
dbms_output.put_line (wk_sql);
-Wk_sql EXECUTE IMMEDIATE.
end if;
end loop;
end loop;
end;
create or replace procedure delete_table is
SET SERVEROUTPUT SIZE 1000000
declare
cursor obj_cursor (objname Varchar2) is
Select object_name, object_type, owner
from dba_objects
where owner = 'ITA '.
and object_type IN ('TABLE', 'SEE')
and object_name like '% JOB_;
cursor c_job_status is
SELECT ownerid jobid, starttime, endtime
OF ita.tpis32_job_status
WHERE starttime < sysdate - 800
AND num_lines > 10000000;
WK_SQL VARCHAR2 (500);
WK_JOBSTR VARCHAR2 (500);
BEGIN
for c_job loop c_job_status
wk_jobstr: = 'JOB_ | c_job. JobID | '%';
for wk_rec loop obj_cursor (wk_jobstr)
If wk_rec.object_type = "TABLE" then
wk_sql: = 'drop table' |' ITA.' | wk_rec.object_name | ';';
dbms_output.put_line (wk_sql);
end if;
If wk_rec.object_type = "DISPLAY" then
wk_sql: = 'drop view ' | wk_rec.object_name | ';';
dbms_output.put_line (wk_sql);
-Wk_sql EXECUTE IMMEDIATE.
end if;
end loop;
end loop;
end delete_table;create or replace procedure delete_table is cursor obj_cursor(objname Varchar2) is select object_name, object_type, owner from dba_objects where owner = 'ITA' and object_type IN ('TABLE', 'VIEW') and object_name like 'JOB_%'; cursor c_job_status is SELECT jobid, ownerid, starttime, endtime FROM ita.tpis32_job_status WHERE starttime < sysdate - 800 AND num_lines > 10000000; WK_SQL VARCHAR2(500); WK_JOBSTR VARCHAR2(500); BEGIN for c_job in c_job_status loop wk_jobstr := 'JOB_' ||c_job.jobid||'%'; for wk_rec in obj_cursor(wk_jobstr) loop if wk_rec.object_type = 'TABLE' then wk_sql := 'drop table ' ||'ita.'|| wk_rec.object_name || ';'; dbms_output.put_line(wk_sql); end if; if wk_rec.object_type = 'VIEW' then wk_sql := 'drop view ' || wk_rec.object_name || ';'; dbms_output.put_line(wk_sql); --EXECUTE IMMEDIATE wk_sql; end if; end loop; end loop; end delete_table;
-
Create a stored procedure to convert a temporary table to the current table
I have a table in oracle, named motor_assist2 with columns:
NAME
ADDRESS
PHONE
CITY
STATE
ZIP
FRIENDSHIP
SERVICE
WAIT_TIME
CONT_SERVICE
COMMENTS
DATETIME
TECHNICIAN1_RADIO
TECHNICIAN1_NAME
LOCATION
COUNTY_NAME
COUNTY_ABBR
MAV_TROOP
TECHNICIAN2_RADIO
TECHNICIAN2_NAME
ID
BEG_DATE
END_DATE
MONTH
YEAR
I have an another table (motor_assist9) in excel with similar columns I want to insert this data into my table (motor_assist2) current using a procedure but do not know how to do it. Can someone help me? Thank you
DeannaIf the number of columns and the order of the columns match on both tables, you can use:
insert into motor_assist2 select * from motor_assist9;
If this isn't the case, you will need to specify which columns of the source and/or destination:
insert into motor_assist2 (destination, column, list) select source, column, list from motor_assist9;
To make a wrap just stored as appropriate procedure insert the statement with the following code:
create or replace procedure procedure_name as begin
end; / -
Create or replace Stored procedure
Hi all
11.2.0.1
I have the HR schema/user, who is the owner of all tables in the app.
Then, all his paintings are also granted to BATCH - HR user with corresponding synonyms.
This batch user will be used by computer operators to run reports of generations.
For security reasons, they are not allowed to CONNECT to HR, but only to the BATCH - RH.
My question is, can I create a stored procedure to the BATCH - RH which has only synonymous all tables?
Or is it a good design to install it on human resources?
Stored procedures recommend to operate only on base tables?
Thank you
Petra k.
You can use everywhere in PL/SQL or external programs, because synonym is nothing more than a name new/more existing object; i.e. scott.emp table can have synonym1, synonym2, synonym3, etc.
For more information: CREATE SYNONYM
Concerning
Girish Sharma
-
Create a stored procedure in the settings view
I want to be able to create a view with the parameters of a stored procedure.
Oracle 11g.
don't know how to use the variable in immediate execution.
CREATE OR REPLACE
PROCEDURE TEST_GENERIC (TBL IN VARCHAR2, VWNAME IN VARCHAR2)
AS
BEGIN
RUN IMMEDIATELY "CREATE OR REPLACE VIEW VWNAME AS SELECT SYSDATE FROM TBL";
COMMIT;
END;
exec ('BIRD', 'DUAL') TEST_GENERIC
Thanks for any help
Hello
Single quotes enclose a literal string; in other words, the text between the quotes literally means what it says, without reference to any variables.
So, when you say:
RUN IMMEDIATELY "CREATE OR REPLACE VIEW VWNAME AS SELECT SYSDATE FROM TBL";
CREATE the word literally means to CREATE. You may or may not have also a variable called CREATE, but that is irrelevant.
The word OR means OR literally. You may or may not have also a variable called operation GOLD, but that is irrelevant.
REPLACE the word literally means REPLACE. You may or may not have also a variable called to REPLACE, but that is irrelevant.
...
The TBL Word literally means TBL. You may or may not have also a variable called TBL, but that is irrelevant.
If you want to reference a variable called TBL, then use TBL outside single quotes, like this:
...
sql_text: = "CREATE or REPLACE VIEW VWNAME AS SELECT SYSDATE FROM '
|| TBL;
dbms_output.put_line (sql_text |) "= sql_text before EXECUTE IMMEDIATE'); -For debugging
EXECUTE IMMEDIATE sql_text.
...
On the rare occasions when you use dynamic SQL statements, always put the dynamic SQL statement in a string variable (for example, sql_text, above) so that you can easily display for debugging purposes and to ensure that the command you are viewing is the same exact command that you should run.
I guess the code you posted is a first test version of something that will be much, much different when it is finished. Creating objects from database (such as views) in PL/SQL is almost always a terrible idea, and it seems that opinion that this code is attempting to produce would be very useful, anyway.
-
Problems in SQL dev with a procedure.
Hey guys, having trouble with the.following procedure Pl SQL. Is this code wrong?
create table zed (z varchar2 (30);)
declare
procedure thisway1 (p_data in varchar2)
is
Start
immediate execution
"insert into zed (z) values(:z) '.
using p_data;
end thisway1;
OK, ive tried over and over again, which is absent from this code?
The sound of a book, for its supposed to work...
Okay, I just have not found the right place to ask.
Maybe you are looking for
-
error messages &; unalbe to show em who sent in sent foler
It started today out of the blue. I can send an em 'answer' and I get the following error message:There was a problem, including the file:///C:/DOCUME~1/LOUISE~1/LOCALS~1/Temp/nsemail.html file in the message. You want to continue to send the message
-
In an event is structure there a way to determine what numbered event was executed when the button is hit? I noticed at the top of the structure of the event there is a number 0... can you can access this value some how?
-
Turnaround exit status after every 3 cycles of while loop
Hello I'm trying to return the exit status after every 3 cycles of while loop. At this point, the code would look like this: If i_quotient_of_while_loop_iterator == 0 then output_1 = not output_1 It seems that there is no way to do so, how can I ach
-
Help and Support service does not
Original title: Windows XP ServicesI would like to first of all a service that is running, but when I try to open system information, I get a message that the help and Support service is not running. How can I start the help and Support service if I
-
File error: cannot find VBRUN300. DLL
I get this message when you try to open some programs that I downloaded.