can we create a procedure in a procedure
DB version: 11 gHello
I just wanted to ask guys like can create us a procedure in a procedure... If not is there another solution?
in db2, it is therefore permissible cela oracle support?
Thank you
Can you? Sure. Should you? Usually not.
You can do something like
CREATE OR REPLACE PROCEDURE p1
AS
<>
PROCEDURE p2
IS
BEGIN
<>
END p2;
BEGIN
p2;
END;
It is rarely indicated, however, to declare nested blocks that way. As always, you should be setting out procedures in packages in any case, it would be much more sensible to define a private procedure in the package body you are calling.
Justin
Tags: Database
Similar Questions
-
Create a procedure SQL with SQL toolkit
Hello
I use the SQL Toolbox to get data from a MySQL database (using ODBC connectors).
I would like to automatically create a procedure on my DB when lauching my application software, so that I do not know there is when I use it.
But I can't figure out how to do with the SQL Toolbox.
Indeed, you try to run this script (which works by operating on MySQL workbench) returns the following error:
DELIMITER $$
CREATE DEFINER='indus'@'%' PROCEDURE ' FPY'(datetime IN START_DATETIME, IN END_DATETIME datetime)
BEGIN
CREATE a temporary table ListingUUT
(
UUT_SERIAL_NUMBER VARCHAR (127).
TEST_COUNTER INT,
DateTime TEST_TIME,
UUT_STATUS VARCHAR (32)
);CREATE a temporary table Stat_FPY
(
TESTED INT,
TESTED_ONCE INT,
REPORT / FLOAT
);INSERT INTO Stat_FPY VALUES (0,0,0).
INSERT INTO ListingUUT
(
SELECT
UUT_SERIAL_NUMBER, SUM (1), START_DATE_TIME, UUT_STATUS
OF booster_results.uut_result
WHERE START_DATE_TIME BETWEEN START_DATETIME AND END_DATETIME
UUT_SERIAL_NUMBER GROUP
ORDER BY DESC START_DATE_TIME
)
;END
-Online error-2147217900 took place at NI_Database_API.lvlib:Conn Execute.vi-> Untitled 1
Possible reasons:
ADO error: 0x80040E14
Exception occurred in the Microsoft OLE DB provider for ODBC drivers: [MySQL] [ODBC 5.2.a Driver] [mysqld - 5.6.10 - log] you have an error in your syntax SQL; consult the manual for your version of the MySQL server for the right syntax to use near ' DELIMITER $$CREATE DEFINER='indus'@'%' PROCEDURE ' FPY '(IN START_DATETIME datet' à la ligne 1 en NI_Database_API.lvlib:Conn Execute.vi-> sans titre 1)
An idea so that I can create the procedure?
Finally, give up on the creation of the procedure with SQL Toolkit functions.
In fact using exec.vi system to address directly the command-line mysql server...
-
Create a procedure stored via CMD
How can I create stored via cmd procedure? A few reasons, I could not use SQL DEVELOPER or TOAD in the production server, so I create a sql file that contain SP then call sql via cmd file, but it does not work. Here is the sql file
SET pages 0
coil D:\SP\LOG\output_log.txt
Create or Replace procedure TRUNCATE_DATA
IS
BEGIN
RUN IMMEDIATELY 'TRUNCATE TABLE DONNEES_1;
RUN IMMEDIATELY 'TRUNCATE TABLE DATA_2. "
COMMIT;
END;
spool off
output
user11432758 wrote:
How can I create stored via cmd procedure? A few reasons, I could not use SQL DEVELOPER or TOAD in the production server, so I create a sql file that contain SP then call sql via cmd file, but it does not work. Here is the sql file
SET pages 0
coil D:\SP\LOG\output_log.txt
Create or Replace procedure TRUNCATE_DATA
IS
BEGIN
RUN IMMEDIATELY 'TRUNCATE TABLE DONNEES_1;
RUN IMMEDIATELY 'TRUNCATE TABLE DATA_2. "
COMMIT;
END;
spool off
output
COMMIT after that DDL is superfluous.
You must actually run the code as below by adding a slash on the END following line: statement
[oracle@localhost ~] $ cat make_it.sql
coil output_log.txt
Create or Replace procedure TRUNCATE_DATA
IS
BEGIN
RUN IMMEDIATELY 'TRUNCATE TABLE DONNEES_1;
RUN IMMEDIATELY 'TRUNCATE TABLE DATA_2. "
COMMIT;
END;
/
spool off
output
[oracle@localhost ~] $ sqlplus User1/User1 @make_it.sql
SQL * more: Release 11.2.0.2.0-Production on Mon Dec 16 19:56:41 2013
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With partitioning, OLAP, Data Mining and Real Application Testing options
Created procedure.
Disconnected from the database to Oracle 11 g Enterprise Edition Release 11.2.0.2.0 - Production
With partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@localhost ~] $
-
Create the procedure using time as a variable
Dear team,
Please find below the details.
Database version:-11g Release 2
I want to create a procedure to help if another condition. Can someone help me how declare TIME as variable. just for example
If the time < 6 pm.
Start-> run, loop
Another thing,
end of the program.
My doubt is how to initialize with time as a variable
Dear Sybrand,
k do not write the code for free... And I don't do any kind of work. I'm a businessman. Just for Oracle knowledge point of view, I asked the question. And the next time suggest me.
Kind regards
Vivek
Director-general
-
Create the privilege granted procedure, but cannot create the procedure
I have a user that I have given the following privileges:
CREATE THE SESION
SELECT ANY TABLE
CREATE A PROCEDURE
CREATE PROCEDURE
RUN THE PROGRAM
RUN THE PROCEDURE
But when I try to create a procedure with this user I get, error proveleges not enough. What I am doing wrong?What's wrong? You open the doors of barn proverbial ito security. This isn't how security should be made - allowing a schema create any code of procedure anywhere in the database. Or select data from any table.
How do you think that Sony's PS network has been hacked and millions of stolen credit card data users?
By this precarious type of stuff-security approach to security.
A schema has the minimum privileges in order to achieve its goals and its requirements. Nothing more.
For example
// standard logical database schema, 10Gb space allocation create user HRDB identified by
default tablespace USERS quota 10G on USERS; // configure the basic security layer for the schema grant create session, --// allow client-server connections to schema create table, create trigger, --// allow to create standard db objects create sequence, create view, --// allow access to defining extended objects create procedure --// allow creating stored proc code to HRDB; In addition, you can decide on assign a profile of resources and specific roles and so on. In some cases, you can also leave the schema create types, synonyms and private database links, views materialized, etc.
Don't grant access. No access to the SYS code and objects. By default. Everything else is a security exception requiring a valid justification.
-
How to create a procedure for REF CURSOR output with any WHERE clause?
I have a requirement like this: I have a huge question that need to reuse in my code over 10 times. This SQL has about 50 lines. Here for these 10 odd times sometimes changes in WHERE clause (columns are the same). So I can't create a view as SQL is not static.
I thought to write a procedure with a para of WHERE_CLAUSE entry. I pulled out a refcursor sys by adding where clause. But I can't do it because you cannot add a clause like this where clause.
i.e.
The foregoing gives an error.PROCEDURE dynamyic_query (p_where_clause IN VARCHAR2, p_out_query OUT SYS_REFCURSOR ) IS BEGIN OPEN p_out_query FOR SELECT ......... FROM table WHERE || ' ' || p_where_clause; END;
How to handle such a situation? Any help would be greatly appreciated.Hello
Channa wrote:
... However, when I change the procedure like this:PROCEDURE FORMS_TEXT_DYN_SQL_TEST(p_where_cluase IN VARCHAR2, p_out_cursor OUT SYS_REFCURSOR) IS v_stmt VARCHAR2(1000); BEGIN v_stmt := 'SELECT tname FROM tab_test WHERE tname LIKE ''%ABS_V4%'' AND :y'; OPEN p_out_cursor FOR v_stmt using p_where_cluase; END;
And run this block of code:
declare v_tname varchar2(200); out_cursor sys_refcursor; begin forms_text_dyn_sql_test(' 1 = 1 ', out_cursor ); LOOP fetch out_cursor INTO v_tname; exit when out_cursor%NOTFOUND; DBMS_OUTPUT.PUT_LINE(v_tname); END LOOP; end; /
I get the error:
[1]: (Error): ORA-00920: invalid relational operator ORA-06512: at "ABS.FORMS_TEXT_DYN_SQL_TEST", line 6 ORA-06512: at line 5
Looks like you can only set column_name =: z, column_name =: values of type y. You can not it seems to replace it with no WHERE CLAUSE?
A bind variable, such as: it, represents a single value.
If: is the VARCHAR2 '1 = 1', thenSELECT tname FROM tab_test WHERE tname LIKE '%ABS_V4%' AND :y
takes the value
SELECT tname FROM tab_test WHERE tname LIKE '%ABS_V4%' AND '1 = 1'
I think you want something like this:
CREATE OR REPLACE PROCEDURE FORMS_TEXT_DYN_SQL_TEST ( p_where_clause IN VARCHAR2 , p_out_cursor OUT SYS_REFCURSOR ) IS v_stmt VARCHAR2(1000); BEGIN v_stmt := 'SELECT ename FROM scott.emp WHERE ename LIKE ''%A%'' AND ' || p_where_clause; OPEN p_out_cursor FOR v_stmt; END; / show errors SET SERVEROUTPUT ON declare v_tname varchar2(200); out_cursor sys_refcursor; begin forms_text_dyn_sql_test(' 1 = 1 ', out_cursor ); LOOP fetch out_cursor INTO v_tname; exit when out_cursor%NOTFOUND; DBMS_OUTPUT.PUT_LINE(v_tname); END LOOP; end; /
Output:
ALLEN WARD MARTIN BLAKE CLARK ADAMS JAMES
-
ORA-00942 - create a procedure
When I create this procedure
It's a return ORA-00942 on line 6, but I have the privilege to choose on dba_tables.
CREATE OR REPLACE PROCEDURE p_read_only
AS
BEGIN
FOR x IN (SELECT table_name
FROM dba_tables
Owner WHERE = 'MAN')
LOOP
RUN IMMEDIATELY ' GRANT SELECT ON SWH.»
|| x.table_name
|| "TO READ_ONLY.
END LOOP;
FOR x IN (SELECT view_name
FROM dba_views
Owner WHERE = 'MAN')
LOOP
RUN IMMEDIATELY ' GRANT SELECT ON SWH. "| x.view_name
|| "TO READ_ONLY.
END LOOP;
END;
/
Thank you
Published by: Jx on July 19. 2011 08:10In the future please check for errors before you post thereon. This error is with ORA-1031, PLS-201 and ORA-12514 error more popular on this forum, always because people post here never use online resources.
No, you do not have privilege. You have the privilege, thanks to a role and roles are disabled during the compilation of the procedures as roles can change on the fly.
You must
or the other(1) create or replace... AUTHID current_user
(2) grant select privileges directly on dba_tables.The last method is not preferable, because you will end up with a myriad of direct privileges which are not included in your export, they are owned by SYS and SYS is not exported.
Also in DDL in a procedure is generally considered bad because it has all kinds of side effects.
A regular SQL script should be sufficient.----------------
Sybrand Bakker
Senior Oracle DBA -
How to create a procedure to change random passwords
Hello
I am trying to create a procedure to change randomly the passwords for all users in a database. I need this after the cloning of the database. I have too many users to change manually...
Y at - it option to create a procedure that will extract all users in a database and edit a random password?
I wasn't able to find any clue.
Could you help me?
Thank youWelcome to the forum.
change randomly the passwords for all users in a database.
All users? Including SYS/SYSTEM? I hope not...
But you can use DBMS_RANDOM. STRING and ALL_USERS and dynamic SQL.
http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14258/d_random.htm#sthref4675
http://download.Oracle.com/docs/CD/B19306_01/server.102/b14237/statviews_2114.htm#REFRN20302
http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14261/dynamic.htm#LNPLS01101(easy to find when you do a quick search for http://www.oracle.com/pls/db102/homepage or http://www.oracle.com/pls/db112/homepage)
DBMS_RANDOM. CHAIN can give you a random password easily:
select dbms_random.string('x', 10) from dual connect by level <= 10;
Zo, you could do something like:
begin for rec in ( select t.username , dbms_random.string('x', 10) new_pass from all_users t -- where t.username not in (...) -- or -- where t.username in (...) ) loop --execute immediate ' alter user '||rec.username||' identified by '||rec.new_pass; dbms_output.put_line ('New password for user '||rec.username||' = '||rec.new_pass); end loop; end; /
You will have to fill in the where clause.
I also commented on the dynamic modify the statement of the user, since I don't know if you really want to reset the DDT for all users.
Also, rather than use dbms_output.put_line to verify the new password, you can insert them into a table or spool the output to a file. -
Computation of factorial by creating a procedure for her
Hello everyone
I tried to create a procedure for the calculation of the factorail of a number
but something's not right
I hope that you guys can drive the correct path
Here is my codecreate or replace procedure factorial(n in number) is v number; begin for i in reverse n..1 loop v :=v*i; end loop; dbms_output.put_line(v); end;
Why reverse?
1 create or replace procedure factorial(n in number) 2 is 3 v number :=1; 4 begin 5 for i in 1..n 6 loop 7 v :=v * i; 8 end loop; 9 dbms_output.put_line(v); 10* end; SQL> / Procedure created. SQL> SQL> begin 2 factorial(5); 3 end; 4 / 120 PL/SQL procedure successfully completed.
-
Why I can't use the procedure in the select statement
Why I can't use the procedure in the select statementAnd you may not usa a SQL function if it has out parameters
SQL> create function myfun(p1 in out number) return number is 2 begin 3 p1:=1; 4 return 2; 5 end; 6 / SQL> select myfun(5) from dual; select myfun(5) from dual * ERRORE alla riga 1: ORA-06572: Function MYFUN has out arguments
In fact, the problem is that an output parameter is passed 'ref' and not 'val '...
Max
-
Can we call a procedure in the select statement?
Can we call a procedure in the select statement?Hello
Raghu_appsdba wrote:
Can we call a procedure in the select statement?# You can call functions, but not procedures.
If the procedure does not change the State of the database (for example, it isn't updated all tables), then you can wrap it in a function, or re - write function.
Here is an example of wrapping.
CREATE OR REPLACE FUNCTION fun_x (in_txt IN VARCHAR2) RETURN VARCHAR2 IS BEGIN proc_y (in_txt); RETURN in_txt END fun_x;
-
Is there an alternative targeted more to "create a procedure?
Oracle 10.2.0.4
Solaris 10
I'm providing permissions for a 3rd party dev team, allowing them to create procedures in one of the database schemas (schema_x).
Our corporate security policy does not allow them to directly access this scheme (they don't have the DDT for her, still in development).
Each developer has his own account in the comic book. From this account, they run the ddl statements to create objects (procs, pkg, functs) in schema_x.
I got the "create any procedure" to a role (3rd_party_dev_role) and this role for each 3rd party developer.
QUESTION: Is there a technique more focused I should use (grant create proc on schema_x to 3rd_party_dev_role)?
Thank you all.
Published by: rocr on January 28, 2009 10:04You can't, unfortunately, grant permission to the user only to create procedures in a specified schema. You can choose between the ability to create procedures in their own schema compared to the ability to create procedures in all schemas.
Depending on how you source code control, you can assign things upwards so that developers can check their changes in the source control system, mark for development and then have a separate script that removes the change of control of source code and applies to the development database.
Justin
-
Hi, I created the procedure and its code is / / DELETE FROM <? = odiRef.getObjectName ("L", "TRG_SALES", "ORACLE_ORCL_LOCAL_SALES", "", "D")? > / / and when I'm running, the error appeared.
com.sunopsis.tools.core.exception.SnpsSimpleMessageException: ODI-17517: error in the interpretation of the task.
Task: 1
java.lang.Exception: the application script threw an exception: com.sunopsis.tools.core.exception.SnpsSimpleMessageException: Exception getObjectName ("L", "TRG_SALES", "ORACLE_ORCL_LOCAL_SALES", "DEVELOPMENT", "D"): SnpLSchema.getLSchemaByName (): SnpLschema is no information OSB: Delete_Tar_Sales on line: column 0: columnNo
at com.sunopsis.dwg.codeinterpretor.SnpCodeInterpretor.transform(SnpCodeInterpretor.java:489)
at com.sunopsis.dwg.dbobj.SnpSessStep.createTaskLogs(SnpSessStep.java:737)
at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:465)
at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:2128)
to oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$ 2.doAction(StartSessRequestProcessor.java:366)
at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:216)
at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.doProcessStartSessTask(StartSessRequestProcessor.java:300)
to oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.access$ 0 (StartSessRequestProcessor.java:292)
to oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$ StartSessTask.doExecute (StartSessRequestProcessor.java:855)
at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:126)
to oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$ 2.run(DefaultAgentTaskExecutor.java:82)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.Exception: the application script threw an exception: com.sunopsis.tools.core.exception.SnpsSimpleMessageException: Exception getObjectName ("L", "TRG_SALES", "ORACLE_ORCL_LOCAL_SALES", "DEVELOPMENT", "D"): SnpLSchema.getLSchemaByName (): SnpLschema is no information OSB: Delete_Tar_Sales on line: column 0: columnNo
at com.sunopsis.dwg.codeinterpretor.SnpCodeInterpretor.transform(SnpCodeInterpretor.java:476)
... 11 more
Caused by: org.apache.bsf.BSFException: the application script threw an exception: com.sunopsis.tools.core.exception.SnpsSimpleMessageException: Exception getObjectName ("L", "TRG_SALES", "ORACLE_ORCL_LOCAL_SALES", "DEVELOPMENT", "D"): SnpLSchema.getLSchemaByName (): SnpLschema is no information OSB: Delete_Tar_Sales on line: column 0: columnNo
at bsh.util.BeanShellBSFEngine.eval (unknown Source)
at bsh.util.BeanShellBSFEngine.exec (unknown Source)
at com.sunopsis.dwg.codeinterpretor.SnpCodeInterpretor.transform(SnpCodeInterpretor.java:471)
... 11 more
Text: REMOVE OF <? = odiRef.getObjectName ("L", "TRG_SALES", "ORACLE_ORCL_LOCAL_SALES", "", "D")? >.
at com.sunopsis.dwg.dbobj.SnpSessStep.createTaskLogs(SnpSessStep.java:764)
at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:465)
at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:2128)
to oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$ 2.doAction(StartSessRequestProcessor.java:366)
at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:216)
at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.doProcessStartSessTask(StartSessRequestProcessor.java:300)
to oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.access$ 0 (StartSessRequestProcessor.java:292)
to oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$ StartSessTask.doExecute (StartSessRequestProcessor.java:855)
at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:126)
to oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$ 2.run(DefaultAgentTaskExecutor.java:82)
at java.lang.Thread.run(Thread.java:662)
If you do this in a procedure, use the following syntax:
<%=odiRef.getObjectName("L", "TRG_SALES", "D")%>
and set the relevant logical schema in the options on the target tab of the procedure. Also, make sure you only select the correct technology type in the options on the target tab.
-
Can we call the procedure inside the function?
Hello
Can we call the procedure inside the function?
Thank you
Brij845712 wrote:
Can we call the procedure inside the function?
Strange question to ask.
Yes. This is the standard behavior in most (if not all) procedural and object oriented languages.
A procedure, function or a method is a unit of code.
You can call one of the other units. Units can call themselves (recursion). Technically, this means simply by pushing the battery current (to save the stack of the current device memory), the call to the new unit and then popping up battery when control is returned to the unity of the appellant.
There are very few exceptions to this. The only one that comes to mind programming languages I've used through the years, is natural 1 - could not call a new unit of code to replace the existing one in memory. If no call-and-return was possible.
Exactly what did you ask this question? Some newcomers to confused Oracle SQL and PL/SQL - two different languages aside server. And then also mistaken for PL/SQL client command vocabulary of SQL * more.
You will need to make sure that understand the basics of programming (applies to most current programming languages) and Oracle concepts.
-
Create the procedure to check existing data, then update, if not then insert.
Dear all,
Help, please
I create a procedure to check the current data are available or not tables, if not match, the row in the table will insert another table, if matched, data will be updated.
table source: Table_read;
check table: stor_matdata;
key to two table ID is (assy_no and t.produced_number).
Here's the code I create, but he still has an error...
---------------------------------------------------------------------
create or replace
procedure Matched
as
Start
Fusion in stor_matdata m using double on (m.assy_no = t.produced_number)
When not matched then insert into stor_matdata (sequence_id, assy_no, package, basic_type, materialnumber, factor, mattype)
Select rownum, t.producednumber, t.package_name, t.basic_type, t.consumed_number, t.factor, t.mattype FROM (select * from Table_read xxxx) t
when matched, then update package set = t.package_name, basic_type = t.basic_type, materialnumber = t.consumed_number, = t.factor, mattype = t.mattype, sequence_id = rownum factor;
end Matched;
Thank you and best regards,
HadiThere is a support missing after values
VALUES ( t.r ,t.producednumber ,t.package_name ,t.basic_type ,t.consumed_number ,t.factor ,t.mattype );
Concerning
Marcus
Maybe you are looking for
-
Downloaded copy e-mail on USB?
I need to copy my emails downloaded on a USB because my laptop will be worked by the manufacturer and the hard disk will be wiped. How can I do this (if possible)? Thank you!
-
Is there a way to click with the right button on a text link to add it to Favorites?
I can't find an add-on that allows me to do this or the other. If I highlight a text link, like the link shared on a youtube video, there is no option to bookmark this link directly. Why is it not possible to do?
-
Portege R600 - y at - it a radio available internal broadband?
Our previous laptops had internal radios from Sprint for access to broadband.Sprint will give us external modems for the R600, but it would be great if there was an internal option - one less gadget to drag around. Is there such a thing? Thank you!
-
I have multi test stations with a runing Windows XP PC, each configured with NI PCI-MXI-2 card. Each station has two chassis VXI, each with its own controller Slot-0, Garland to run from the same VXI system, which the system identifies as VXI0. When
-
Impossible to install Vista 64-bit SP2 as it says file doesn't have a digital signature?
Hi have tried to download this several times but it goes on to say that the file doesn't have a valid digital signature, whereby it seems weird as its on the microsoft Web site. Windows Update doesn't have the option to install from there, I had to