To create a procedure in a procedure
Hi,
I am trying to do sth like this. I am trying to create a procedure within an anonymmous PL/SQL block and i am basically trying to execute the newly created procedure there.
This example (although wrong) would give a fair idea of what I am trying to do.
set serverout on;
declare
create or replace procedure test_1 is
begin
dbms_output.put_line('gaurav');
end;
begin
exec test_1;
end;
I tried using the 'execute immediate'...dynamic SQL but that doesnt seem to work.
The requirment is that we are processing a document in a SQL and in that document we have a call to a procedure...Generally we compile that procedure before we began processing the document..Now that is not we want to do anymore.
Please suggest a WorkAround.
TIA,
Gaurav
How do i ascertainthat the procedure is always created.It is not a controlled
instance and ppl may create object with the same name.executing dynamically created stored procedures in an uncontrolled environment? Oh boy, your application must be fun.
There are two scenarios:
(1)the existing object is a procedure
(2) the existing object is something else.
In scenario (2) your dynamic creation will fail whatever you do (unless teh object is an index or some such), so all you can do in your procedure is catch the ORA-00955 exception and report it.
In scenario (1) you have a choice. You can either CREATE PROCEDURE or CREATE OR REPLACE PROCEDURE. In the first case you object creation will fail, in the second it will succeeed. Which you choose depends upon whether it is legimiate for the rogue object to have been created by those "ppl".
Good luck, APC
Similar Messages
-
Create a Procedural ALV Report with editable fields and save the changes
Hi,
I am new to ABAP. I have created a Procedural ALV Report with 3 fields. I want to make 2 fields editable. When executed, if the fields are modified, I want to save the changes. All this I want to do without using OO concepts. Please help . Also, I checked out the forum and also the examples
BCALV_TEST_GRID_EDIT_01
BCALV_TEST_GRID_EDIT_02
BCALV_TEST_GRID_EDIT_04_FORMS
BCALV_TEST_GRID_EDITABLE
BCALV_EDIT_01
BCALV_EDIT_02
BCALV_EDIT_03
BCALV_EDIT_04
BCALV_EDIT_05
BCALV_EDIT_06
BCALV_EDIT_07
BCALV_EDIT_08
BCALV_FULLSCREEN_GRID_EDIT
But all these are using OO Concepts.
Please help.
Regards,
SmruthiTABLES: ekko.
TYPE-POOLS: slis. "ALV Declarations
*Data Declaration
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
statu TYPE ekpo-statu,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
line_color(4) TYPE c, "Used to store row color attributes
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko.
*ALV data declarations
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gd_tab_group TYPE slis_t_sp_group_alv,
gd_layout TYPE slis_layout_alv,
gd_repid LIKE sy-repid.
START-OF-SELECTION.
PERFORM data_retrieval.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM display_alv_report.
*& Form BUILD_FIELDCATALOG
Build Fieldcatalog for ALV Report
FORM build_fieldcatalog.
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 1.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'STATU'.
fieldcatalog-seltext_m = 'Status'.
fieldcatalog-col_pos = 2.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'AEDAT'.
fieldcatalog-seltext_m = 'Item change date'.
fieldcatalog-col_pos = 3.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 4.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'MENGE'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-edit = 'X'
fieldcatalog-col_pos = 5.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'MEINS'.
fieldcatalog-seltext_m = 'Order Unit'.
fieldcatalog-col_pos = 6.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
fieldcatalog-datatype = 'CURR'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'PEINH'.
fieldcatalog-seltext_m = 'Price Unit'.
fieldcatalog-col_pos = 8.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
ENDFORM. " BUILD_FIELDCATALOG
*& Form BUILD_LAYOUT
Build layout for ALV grid report
FORM build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).
gd_layout-info_fieldname = 'LINE_COLOR'.
ENDFORM. " BUILD_LAYOUT
*& Form DISPLAY_ALV_REPORT
Display report using ALV grid
FORM display_alv_report.
gd_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gd_repid
i_callback_pf_status_set = 'STATUS'
i_callback_top_of_page = 'TOP-OF-PAGE'
i_callback_user_command = 'USER_COMMAND'
i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
it_special_groups = gd_tabgroup
IT_EVENTS = GT_XEVENTS
i_save = 'X'
is_variant = z_template
TABLES
t_outtab = it_ekko
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. " DISPLAY_ALV_REPORT
*& Form DATA_RETRIEVAL
Retrieve data form EKPO table and populate itab it_ekko
FORM data_retrieval.
DATA: ld_color(1) TYPE c.
SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
UP TO 10 ROWS
FROM ekpo
INTO TABLE it_ekko.
LOOP AT it_ekko INTO wa_ekko.
ld_color = ld_color + 1.
IF ld_color = 8.
ld_color = 1.
ENDIF.
CONCATENATE 'C' ld_color '10' INTO wa_ekko-line_color.
MODIFY it_ekko FROM wa_ekko.
ENDLOOP.
ENDFORM. " DATA_RETRIEVAL
FORM top-of-page *
FORM top-of-page.
WRITE:/ 'This is First Line of the Page'.
ENDFORM.
FORM status *
FORM status USING rt_extab TYPE slis_t_extab. .
SET PF-STATUS 'ALV'.
ENDFORM.
FORM USER_COMMAND *
--> RF_UCOMM *
--> RS *
FORM user_command USING rf_ucomm LIKE sy-ucomm
rs TYPE slis_selfield.
DATA ref1 TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ref1.
CALL METHOD ref1->check_changed_data.
CASE rf_ucomm.
when 'SAVE'.
get all the modified entries and store them in an internal table and udpate them in to the required transaction or your custom table.
endcase.
endform.
ENDFORM.
here u need to 2 performs for PF status and USER_COMMAND in the ALV parameters.
create a custom PF status and create push buttons and assign your ok codes in your PF status.
if the field has to be edited in the ALV then pass EDIT = 'X' for that field in the fieldcatlog preparation.
Hope this will help you.
Regards,
phani. -
How to create a procedure in oracle to write the data into file
Hi All,
I am just wondered on how to create a procedure which will do following tasks:
1. Concat the field names
2. Union all the particular fields
3. Convert the date field into IST
4. Prepare the statement
5. write the data into a file
Basically what I am trying to achieve is to convert one mysql proc to oracle. MySQL Proc is as follows:
DELIMITER $$
USE `jioworld`$$
DROP PROCEDURE IF EXISTS `usersReport`$$
CREATE DEFINER=`root`@`%` PROCEDURE `usersReport`(IN pathFile VARCHAR(255),IN startDate TIMESTAMP,IN endDate TIMESTAMP )
BEGIN
SET @a= CONCAT("(SELECT 'User ID','Account ID','Gender','Birthdate','Account Registered On') UNION ALL (SELECT IFNULL(a.riluid,''),IFNULL(a.rilaccountid,''),IFNULL(a.gender,''),IFNULL(a.birthdate,''),IFNULL(CONVERT_TZ(a.creationDate,'+0:00','+5:30'),'') INTO OUTFILE '",pathFile,"' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\n' FROM account_ a where a.creationDate>='",startDate,"' and a.creationdate <='",endDate,"')");
PREPARE stmt FROM @a;
EXECUTE stmt;
DEALLOCATE PREPARE stmt ;
END$$
DELIMITER ;
Regards,
Vishal G1. Concat the field names
Double Pipe (||) is the concatenation operator in Oracle. There is also a function CONCAT for this purpose
2. Union all the particular fields
Not sure what do you mean by UNION ALL particular fields? UNION ALL is a set operation applied on two different result sets that have the same projection.
3. Convert the date field into IST
SQL> select systimestamp "Default Time"
2 , systimestamp at time zone 'Asia/Calcutta' "IST Time"
3 from dual;
Default Time IST Time
05-05-15 03:14:52.346099 AM -04:00 05-05-15 12:44:52.346099 PM ASIA/CALCUTTA
4. Prepare the statement
What do you mean by prepare the statement?
5. write the data into a file
You can use the API UTL_FILE to write to a file. -
How can I create stored procedure?
I am new in this field, I was reading in this web site on how to create stored procedure,and this is what I did :
SQL> CREATE PROCEDURE test.proc1 (n IN NUMBER)
2 AS BEGIN
3 select * from districts
4 where doe = n;
5 END;
6
Please direct me. I don't know if I am wrong or right, test is the name of the database, and proc1 is the stored procedure that I want to create, why when I hit Enter after END; I got the number 6.
How can I call this stored procedure, if it works.
Thanks in advance
nullSome reading and training might prove useful. Even if you are using Linux, this forum is no place for a question like that.
-
How to create a procedure to send a mail if the Database is down?
Hi,
I have created the below procedure to send a mail if the count is less than 1300. It scheduled daily @ 15 30 hrs. Its fine.
CREATE OR REPLACE procedure SCOTT.hrsmail
is
v_count number;
begin
Select count(*) into v_count from emp;
if v_count < 1300
then
UTL_MAIL.send(sender => '[email protected]',
recipients => '[email protected]',
cc => '[email protected]',
bcc => '[email protected]',
subject => 'Testing the UTL_MAIL Package',
message => 'If you get this, UTL_MAIL package
else
null; --what you want to do here
end if ;
end;
Sometime the Database is down, so the job is not running.
How to create a procedure to send a mail if the database is down?
Pls help me. Its highly appreciated.
Thanks
Niharnihar wrote:
How to create a procedure to send a mail if the database is down?And what if the database is up, but the network down? Or the database up and mail server down? Or mail server undergoing maintenance?
There are loads of "+What if's+" - and in that respect, playing "+What if database is down..+" in this case does not make any sense. You do not use the database to monitor its own up/down status. You do not rely just on SMTP as notification protocol that the database is down.
The correct approach would be using something like SNMP as the monitoring protocol. A monitoring system that can process SNMP and perform some basic root cause analysis (e.g. network to the database server down, database server status unknown). And this system supporting notification methods like SMTP, SMS and so on. -
HOW TO CREATE STORED PROCEDURE IN DATA INTEGRATOR
Hi to every one,
Can any one help in giving me a solution for creating stored procedure in Data Integrator.
I m new to this fieldHi nath,
Firstly are you using MYSQL or Oracle as the database,if its oracle database then follow this
http://obiee101.blogspot.com/2008/01/obiee-using-oracle-stored-procedure-to.html
http://oraclebizint.wordpress.com/2008/02/20/oracle-bi-ee-101332-executing-stored-proceduresfunctions-before-reports-before-report-triggers-and-global-temporary-tables/
EXEC [DATABASE_NAME].[SCHEMA_NAME].[PROCEDURE_NAME][DATABASE_NAME] --> is the database name your creating your procedure
[SCHEMA_NAME]-->is the user with which your creating
[PROCEDURE_NAME] --> the name given to procedure
You dont know how to get those run this SQL in TOAD and see select sys_context('userenv','db_name'), sys_context('userenv','session_user') from dual
(OR) open you connection pool properties window in RPD,you will get the DB name and the user name as the schema name
hope answered your question.
CHeers,
KK -
How can i create stored procedures dynamically?
I have tried to create a stored procedure building a string with the PL/SQL code needed to create the procedure. If i run the code using SQL+ works fine, but using the following code:
Public Sub CreateStoredProcedure()
Dim strSql As String
strSql = "CREATE OR REPLACE PACKAGE OPSPRUEBAS AS " & vbCrLf
strSql = strSql & vbTab & "PROCEDURE consulta (resultado OUT VARCHAR2); " & vbCrLf
strSql = strSql & "END OPSPRUEBAS; " & vbCrLf
strSql = strSql & "/ " & vbCrLf
strSql = strSql & ". " & vbCrLf
strSql = strSql & "CREATE OR REPLACE PACKAGE BODY OPSPRUEBAS AS " & vbCrLf
strSql = strSql & "PROCEDURE consulta (resultado OUT VARCHAR2) IS " & vbCrLf
strSql = strSql & "oc_ref" & vbTab & vbTab & "REF Content_Ontology; " & vbCrLf
strSql = strSql & "oc" & vbTab & vbTab & "Content_Ontology; " & vbCrLf
strSql = strSql & "ori" & vbTab & vbTab & "role_def; " & vbCrLf
strSql = strSql & "ori_ref" & vbTab & vbTab & "ref role_def; " & vbCrLf
strSql = strSql & "conce" & vbTab & vbTab & "concept; " & vbCrLf
strSql = strSql & "conce_ref" & vbTab & "REF concept; " & vbCrLf
strSql = strSql & "b" & vbTab & vbTab & "boolean; " & vbCrLf
strSql = strSql & "BEGIN " & vbCrLf
strSql = strSql & "b:=false; " & vbCrLf
strSql = strSql & "select REF(oi) into ori_ref from rol_table oi where oi.name='Playing'; " & vbCrLf
strSql = strSql & "select deref(ori_ref) into ori from dual; " & vbCrLf
strSql = strSql & "select REF(oi) into oc_ref from c_ontologies oi where oi.web_source_prop=websource('FilmContentOntology'); " & vbCrLf
strSql = strSql & "select deref(oc_ref) into oc from dual; " & vbCrLf
strSql = strSql & "if oc.if_has_co_class('Film')='TRUE' AND " & vbCrLf
strSql = strSql & "oc.if_has_co_class('theater')='TRUE' AND " & vbCrLf
strSql = strSql & "oc.if_has_co_relationship('is_scheduled')='TRUE' AND " & vbCrLf
strSql = strSql & "oc.if_has_co_attributes('Film', lista('is_scheduled', 'title', 'actor'))='TRUE' AND " & vbCrLf
strSql = strSql & "oc.if_has_co_attributes('theater', lista('theatername', 'address', 'email'))='TRUE' " & vbCrLf
strSql = strSql & "then resultado:='FilmContentOntology'; " & vbCrLf
strSql = strSql & "else resultado:='No Existe'; " & vbCrLf
strSql = strSql & "end if; " & vbCrLf
strSql = strSql & "END consulta; " & vbCrLf
strSql = strSql & "END OPSPRUEBAS; " & vbCrLf
strSql = strSql & "/ " & vbCrLf
strSql = strSql & ". " & vbCrLf
strSql = strSql & "COMMIT;" & vbCrLf
TextBox2.Text = strSql
'Dim myConnectionString As String = "User Id=system;Password=daniel;Data Source=websogo;"
'Dim oraConn As Oracle.DataAccess.Client.OracleConnection = New Oracle.DataAccess.Client.OracleConnection(myConnectionString)
Dim myCmd As New System.Data.OleDb.OleDbCommand()
Dim MyConnection As New System.Data.OleDb.OleDbConnection()
MyConnection.ConnectionString = "Provider=MSDAORA;Data Source=websogo;password=daniel;User ID=system"
MyConnection.Open()
'oraConn.Open()
myCmd.Connection = MyConnection
myCmd.CommandType = CommandType.Text
myCmd.CommandText = strSql
myCmd.ExecuteNonQuery()
'Dim e As Oracle.DataAccess.Client.OracleException
'Try
' myCmd.ExecuteNonQuery()
'Catch e
' Dim error1 As Oracle.DataAccess.Client.OracleError
' error1 = e.Errors.Item(0)
' Textbox3.Text = error1.Source & " " & error1.Message
'End Try
MyConnection.Close()
End Sub
I've tried using Microsoft ODP, OLEDB and Oracle's ODP.NET
Also tried to catch any error but there are no errors!
Has anybody achived a successful dynamically stored procedure creation using .net?
thanks in advance
DanI'm trying to create Stored Procedures via .NET and able to do so but when I look in Oracle Enterprise Manager Console, the Stored Procedures are marked as INVALID... If I edit the Stored Procedure (i.e. delete a space or something minor) and SAVE then it compiles fine.....
Any ideas ????
will be using this against 9i & 10g db -
How to create a procedure using program unit
Hai All
Ii have created a procedure like this
PROCEDURE Duty_calc
IS
procedure w_Time
is
begin
update dail_att set wtime= (select lpad((to_number(to_char(outtime,'hh24mi')-to_char(intime,'hh24mi'))),4,0) from dail_att where attend_date=f_date);
end w_time;
begin
if wtime >0830 then
update dail_att set etime= (select lpad(wtime-0830) from dail_att where attend_date=f_date);
else
null;
end if;
duty_calc;
end duty_calc;
And i have declare in the program unit as Duty_calc and while i am executing my procedure i had an error
is it must i need to declare a my inner procedure in my program unit
Regards
Srikkanth.Mthe same question you asked 2 month ago and same mistake you are doing
- Procedure name can only be one.
- Count proper BEGIN ENDs
PROCEDURE Duty_calc
IS
BEGIN
begin
update dail_att set wtime= (select lpad((to_number(to_char(outtime,'hh24mi')-to_char(intime,'hh24mi'))),4,0) from dail_att where attend_date=f_date);
end;
begin
if wtime >0830 then
update dail_att set etime= (select lpad(wtime-0830) from dail_att where attend_date=f_date);
else
null;
end if;
end;
END; -
How to create a procedure to change randomly passwords
Hello,
I am trying to create a procedure to change randomly passwords for all users in a database. I need this after the database cloning. I have too many users to alter in a manual way...
Is there any option to create a procedure which will fetch all users in a database and alter them by a random password?
I was not able to find any clue.
Could you help me?
ThanksWelcome to the forum.
change randomly passwords for all users in a database.All users? Including SYS/SYSTEM? I hope not...
But you could 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 from http://www.oracle.com/pls/db102/homepage or http://www.oracle.com/pls/db112/homepage)
DBMS_RANDOM.STRING 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'll have to fill in the where-clause yourself/
I also commented out the dynamic alter user statement, since I'm not sure if you really want to reset the pwd's for all users.
Also, instead of using dbms_output.put_line to check the new passwords, you could insert them in a table or spool the output to a file. -
How to create a procedure function with a return value of ref cursor?
Can anybody provide a sample about how to create a procedure function with a return value of REF CURSOR?
I heard if I can create a function to return a ref cursor, I can use VB to read its recordset.
Thanks a lot.http://osi.oracle.com/~tkyte/ResultSets/index.html
-
Help needed to create a Procedure
Can anyone help me with a small procedure I have to write?
Requirement to create Stored Procedure :
1. Create tables
A1
A2
B1
B2
----------- this is done------
Fill the data in those tables
------------this is also done----
Create "Source_table.tx"t file with table names and place them in any location.
------------this is also done----
write a procedure to read the above file "Source_table.txt" and it should read the tables name 1 by 1 which performs a simple operation inside SP -->
Select * from @Table_Name
Also, it should check if the .txt file is exisiting or not.
If exists then Read the file and execute the SP.
SP does this :
Select * from A1
Select * from A2
Select * from B1
Select * from B2
After that, write an output file with the counts of records to the same location where our Source_table.txt exists .
If doesnt exist then write to a .txt file that "File name and Location doesnt exist"What format is the data inside your .txt file?
If it's just some lines containing the names of the tables then you may as well just use the UTL_FILE package to:
a) check the existence of the file using the UTL_FILE.FGETATTR procedure
b) open and read the contents of the file using the UTL_FILE.FOPEN, UTL_FILE.GET_LINE and UTL_FILE.FCLOSE functions/procedures.
UTL_FILE
Alternatively you could set up an external table to read the .txt file as though it's a table.
Managing External Tables
Once you extract the table names from the .txt file, you'll then have to construct dynamic SQL queries to query the data from them. Are all of the tables of the same structure or do they change? If they change you'll have to use the DBMS_SQL package. If they don't you could do it more statically in PL/SQL code (at least in terms of the structures you're reading the data into), but you may still be better using DBMS_SQL for it. It depends what you're trying to do exactly and why these table names are being exported to a file and need to be read dynamically in this way. Often Dynamic coding indicates poor design, but without knowing exactly what you're doing, it's hard to tell if it's really necessary or not. -
Unable to create plsql procedure, fails at cursor
This was a working procedure which would take ID and then copy data from source parameter to destination parameter. Now I would like to have NAME as parameter, I have changed the code to accommodate the new parameters. But I am not able to create the procedure. I am getting 3 error at CURSOR (in bold red). I would like really appreciate if someone can take a look and let me know what is wrong.
Thanks in advance
3 ERRORs
1. PLS-00103: Encountered the symbol "CUR_V_HSP_COLUMN_DETAIL" when expecting one of the following:
:= . ( @ % ;
The symbol ":=" was substituted for "CUR_V_HSP_COLUMN_DETAIL" to continue.
2. PLS-00103: Encountered the symbol "NUMBER" when expecting one of the following:
The symbol "(" was substituted for "NUMBER" to continue.
3. PLS-00103: Encountered the symbol "NUMBER" when expecting one of the following:
CREATE OR REPLACE procedure EPM_PLAN_PLANSAMP.Copy_Details_test1 --Arguments
( in_From_Version_Name IN VARCHAR2, --HSP_object.OBJECT_NAME - Version From
in_From_Scenario_Name IN VARCHAR2 , --HSP_object.OBJECT_NAME - Scenarios From
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 To
in_To_Year_Name IN VARCHAR2 --HSP_object.OBJECT_NAME - Year To
IS
v_From_Object_Id number; -- Version From
s_From_Object_Id number; -- Scenarios From
y_From_Object_Id number; -- Year From
v_To_Object_Id number; -- Version To
s_To_Object_Id number; -- Scenarios To
y_To_Object_Id number; -- Year To
BEGIN
Select object_id into v_From_Object_Id
from hsp_object
where object_type = 35
and object_name = in_from_version_name;
Select object_id into s_From_Object_Id
from hsp_object
where object_type = 31
and object_name = in_from_scenario_name;
Select object_id into y_From_Object_Id
from hsp_object
where object_type = 38
and object_name = in_from_year_name;
Select object_id into v_To_Object_Id
from hsp_object
where object_type = 35
and object_name = in_to_version_name;
Select object_id into s_To_Object_Id
from hsp_object
where object_type = 31
and object_name = in_to_scenario_name;
Select object_id into y_To_Object_Id
from hsp_object
where object_type = 38
and object_name = in_to_year_name;
--Select Supporting Details for the current Version
CURSOR Cur_V_HSP_COLUMN_DETAIL (cV_From_Object_Id IN NUMBER, cS_From_Object_Id IN NUMBER) IS
Select DETAIL_ID From 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;
v_cnt number;
v_err varchar2(2000);
-----------------------------------------Begin Copy Version ---------------------------
BEGIN
-- Delete Next version if already exists
v_step_name := 'Delete on HSP_COLUMN_DETAIL_ITEM';
Delete from HSP_COLUMN_DETAIL_ITEM
Where DETAIL_ID in (Select DETAIL_ID from HSP_COLUMN_DETAIL
Where DIM5 = v_To_Object_Id AND DIM1 = s_To_Object_Id);
v_cnt := sql%rowcount;
insert into t_copy_supporting_dtls_log values (v_step_name, v_cnt,1,'Success',sysdate);
v_step_name := 'Delete on HSP_COLUMN_DETAIL';
Delete from HSP_COLUMN_DETAIL
where DIM5 = v_To_Object_Id AND DIM1 = s_To_Object_Id;
v_cnt := sql%rowcount;
insert into t_copy_supporting_dtls_log values (v_step_name, v_cnt,1,'Success',sysdate);
Open Cur_V_HSP_COLUMN_DETAIL(v_From_Object_Id, s_From_Object_Id);
v_step_name := 'Inserts ';
LOOP
FETCH Cur_V_HSP_COLUMN_DETAIL INTO li_DETAIL_ID;
EXIT WHEN Cur_V_HSP_COLUMN_DETAIL%NOTFOUND;
-- Find next detail_id
Select Max(DETAIL_ID) + 1 INTO Li_Next_DETAIL_ID From HSP_COLUMN_DETAIL;
-- Insert Into HSP_COLUMN_DETAIL Table
Insert Into HSP_COLUMN_DETAIL ( DETAIL_ID , PLAN_TYPE , DIM1 , DIM2 , DIM3 , DIM4 , DIM5 , DIM6 ,
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 , DIM6 ,
DIM7 , DIM8 , DIM9 , DIM10 , DIM11 , DIM12 , DIM13 , DIM14 , DIM15 ,
DIM16 , DIM17 , DIM18 , DIM19 , DIM20
From HSP_COLUMN_DETAIL
Where DETAIL_ID = li_DETAIL_ID;
v_rec_cnt := v_rec_cnt + sql%rowcount;
-- Insert Into HSP_COLUMN_DETAIL_ITEM Table
Insert Into HSP_COLUMN_DETAIL_ITEM ( DETAIL_ID , VALUE , POSITION , GENERATION , OPERATOR , LABEL)
Select Li_Next_DETAIL_ID , VALUE , POSITION , GENERATION , OPERATOR , 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,'Success',sysdate);
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;All the following statements should go into the declaration section (i.e. before the first begin)
CURSOR Cur_V_HSP_COLUMN_DETAIL (cV_From_Object_Id IN NUMBER, cS_From_Object_Id IN NUMBER) IS
Select DETAIL_ID From 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;
v_cnt number;
v_err varchar2(2000); -
I have created stored procedure with %rowtype as IN OUT parameter.I want to
i have created stored procedure with %rowtype as IN OUT parameter.I want to call it in java program
Hi Avi,
I have the same problem as the person asking before me, so I'll try and clarify:
I have a Java client and a PL/SQL database procedure that looks something along the lines of:
Create of Replace procedure myProc(myRow IN myTable%Rowtype)
It's very easy to pass a parameter into this procedure from another procedure within the database because creating another myTable%Rowtype is not a problem.
However, Java doesnt know what "Rowtype" is.
I was wondering how I would pass a "rowtype" from Java.
I was thinking along the lines of creating an object in the DB like that:
Create Type myObj AS myTable%Rowtype (<-- is that even allowed?)
And then create a procedure in the DB with the header:
Create of Replace procedure myProc(myRow IN myObj)
And then, in my Java,just create a STRUCT of my DB object and pass it to the DB:
myCallableStatement.setObject(1, myStruct);
Would that work?
Is there a better way?
Thanks,
Dan -
Create a Procedure that will accept a variable
Hi,
I'm new to pl/sql and I'm trying to create a procedure that will accept a variable. I want to use this sql to create restore points that can store the name of each batch job as it runs.
The code works fine on it's own, but if I try to create the procedure it asks me for a value for 1, how do I stop it doing that?
CREATE OR REPLACE PROCEDURE create_restore_point AS
DECLARE
pointno number(5);
pointname varchar2(128) := upper('&1');
dbname v$database.name%TYPE;
scn_time date;
scn number;
BEGIN
SELECT restore_point_seq.nextval into pointno from dual;
SELECT name into dbname from v$database;
SELECT sysdate into scn_time from dual;
SELECT dbms_flashback.get_system_change_number into scn from dual;
INSERT into restore_point
values
(pointno,pointname,dbname,scn_time,scn);
commit;
END create_restore_point;
Many thanks in advance,
Tom.It asks for value of 1 because you have &1 in your code. If you want to pass the value for pointname, then you can change your procedure like below.
CREATE OR REPLACE PROCEDURE create_restore_point (svar varchar2)AS
DECLARE
pointno number(5);
pointname varchar2(128) := upper(svar);
dbname v$database.name%TYPE;
scn_time date;
scn number;
BEGIN
SELECT restore_point_seq.nextval into pointno from dual;
SELECT name into dbname from v$database;
SELECT sysdate into scn_time from dual;
SELECT dbms_flashback.get_system_change_number into scn from dual;
INSERT into restore_point
values
(pointno,pointname,dbname,scn_time,scn);
commit;
END create_restore_point; -
In this practice, create a procedure to monitor whether employees have exceeded their average salary limits.
a. Add a column to the EMPLOYEES table by executing the following command:
ALTER TABLE employees
ADD (sal_limit_indicate VARCHAR2(3) DEFAULT 'NO'
CONSTRAINT emp_sallimit_ck CHECK (sal_limit_indicate IN ('YES', 'NO')));
a. Write a stored procedure called CHECK_AVG_SAL. This checks each employee's average salary limit from the JOBS table against the salary that this employee has in the EMPLOYEES table and updates the SAL_LIMIT_INDICATE column in the EMPLOYEES table when this employee has exceeded his or her average salary limit.
Create a cursor to hold employee IDs, salaries, and their average salary limit – lock the rows with the FOR UPDATE NOWAIT clause in your cursor definition.
Find the average salary limit possible for an employee's job from the JOBS table. The average salary limit is defined as (max salary + min salary)/2 . Compare the average salary limit possible for each employee to exact salaries and if the salary is more than the average salary limit, set the employee’s SAL_LIMIT_INDICATE column to YES; otherwise, set it to NO.
Add exception handling to account for a record being locked. This is the only exception you will need to check. This exception is Oracle non-predefined -0054. So you will need to associate it using the PRAGMA EXCEPTION_INIT. Then you can handle it with a standard WHEN clause in the EXCEPTION area of your program.
It might look like this in your declaration area:
e_resource_busy EXCEPTION;
PRAGMA EXCEPTION_INIT(e_resource_busy, -54);
c. Execute the procedure, and then test the results.
EXECUTE check_avg_sal
Now test the rows lock exception by starting another session executing the procedure again. Remember to SET SERVEROUTPUT ON. In this example I used the RAISE_APPLICATION_ERROR procedure in my exception section– this is what the output will look like. But you could also have printed a nice message using DBMS_OUTPUT.PUT_LINE. Your choice.
EXECUTE check_avg_sal
BEGIN check_avg_sal; END;
ERROR at line 1:
ORA-20001: Record is busy, try later.
ORA-06512: at "TEACH.CHECK_AVG_SAL", line 29
ORA-06512: at line 1
Query the EMPLOYEES table to view your modifications, and then commit the changes.
select e.employee_id, e.job_id, j.min_salary, e.salary, j.max_salary, e.sal_limit_indicate
from employees e , jobs j
WHERE e.job_id = j.job_id
EMPLOYEE_ID JOB_ID MIN_SALARY SALARY MAX_SALARY SAL
100 AD_PRES 20000 24000 40000 NO
101 AD_VP 15000 17000 30000 NO
102 AD_VP 15000 17000 30000 NO
200 AD_ASST 3000 4400 6000 NO
108 FI_MGR 8200 12000 16000 NO
109 FI_ACCOUNT 4200 9000 9000 YES
110 FI_ACCOUNT 4200 8200 9000 YES
111 FI_ACCOUNT 4200 7700 9000 YES
112 FI_ACCOUNT 4200 7800 9000 YES
113 FI_ACCOUNT 4200 6900 9000 YES
205 AC_MGR 8200 12000 16000 NO
206 AC_ACCOUNT 4200 8300 9000 YES
145 SA_MAN 10000 14000 20000 NO
146 SA_MAN 10000 13500 20000 NO
Commit
Commit complete.The below is what I have.. it is not working.. I am not sure what is wrong.
set server output on
---to add sal_limit_indicate column to employees table
ALTER TABLE employees
ADD (sal_limit_indicate VARCHAR2(3) DEFAULT 'NO'
CONSTRAINT emp_sallimit_ck CHECK (sal_limit_indicate IN ('YES', 'NO')));
--query employees table to make sure the column is added
select * from employees
----query to check average salary
select e.JOB_ID, e.SALARY,e.sal_limit_indicate,((min_salary+max_salary)/2) as avg_sal
from employees e, jobs
where e.job_id = jobs.job_id
---procedure to use in main procedure
create or replace procedure update_indicator
(emp_id employees.employee_id% type,
emp_sallimit employee.sal_limit_indicate% type)
is
begin
update employees
set sal_limit_indicate ='yes'
end update_indicator;
---procedure to update sal-limit_indicate to yes if salary is greater than average salary
create or replace procedure CHECK_AVG_SAL is
cursor sal_cursor is
select e.employee_id, e.SALARY ,e.sal_limit_indicate,j.avg_sal
from employees e, (select ((min_salary+max_salary)/2) as avg_sal, job_id from jobs)j
where e.job_id = j.job_id
and salary >avg_sal;
begin
for sal_rec in sal_cursor
loop
update_indicator(sal_rec.employee_id,sal_limit_indicate);
end loop;
end;
end CHECK_AVG_SAL; -
Can i create any procedure or function inside a oracle reserve package?
Hi!
Can i create any procedure or function inside a oracle reserve package. Suppose, I want to create a function called x in the dbms_output package. Can i do that? Or can i extend the features of this package and create/derived a function from it like we extend any class in JAVA. I'm not sure - whether this is at all possible. I'll be waiting for your reply.
Thanks in advance.
Satyaki De.No, but you can write a wrapper package and use that instead of using the Built-In package directly. So, instead of calling DBMS_OUTPUT, you call your own Package.
Steven Feuerstein wrote a wrapper for DBMS_OUTPUT, called P:
Re: DBMS_OUTPUT.PUT_LINE
Maybe you are looking for
-
HT1349 how do i find the serial number for my ipod if i lost it
I lost my ipod nano and i have not been able to find it all summer. I can't tell apple what the serial number is for it though because i can't remember it. What do i do now will they not be able to help me?
-
How to get a specific page's field values in pdf ?
I am using acrobat javascript to read a pdf file. Is there any way to read textfield values which are present in a specific page?
-
Reviewing the G5 manual, it says you can connect a stereo receiver to the Mac via the optical audio OUT port. Can you connect one to the audio IN port instead (to play LP's and run the music though the stereo to the Mac for conversion to digital)? I
-
Existing settings do not carry over on updating. ie: tabs below.
on updating firefox does not carry over and of the user adjusted settings. WTF in previous version I could hover over a thumnail with the curser and it would open to size in a new phantom window. was a great feature. I set firefox to check but not in
-
I want to edit the text within Captivate after importing slides from PowerPoint
Hi, Background: I import slides from a .pptx file. Once the slides are created inside of Captivate, I want to edit the text on the slide, but I can't; it's all become part of the background. So, I am left with two options: 1) open the .pptx file, edi