How to create procedure

hi
i have a little problem with creating procedure
i have a table
create table t
t_id int,
t_name varchar(22)
insert into t values(1,'AA');
and then i try to create procedure for insert into this table
create or replace procedure my_proc(pt_id int,pt_name varchar(22))
as begin
insert into t values(pt_id,pt_name);
end;
but i receive an error
please help me anybody

Diman wrote:
hi
i have a little problem with creating procedure
i have a table
create table t
t_id int,
t_name varchar(22)
insert into t values(1,'AA');Thanks for posting the CRATE TABLE and INSERT statements; that's very helpful!
and then i try to create procedure for insert into this table
create or replace procedure my_proc(pt_id int,pt_name varchar(22))
as begin
insert into t values(pt_id,pt_name);
end;
but i receive an errorWhy not post the error message?
please help me anybodyWhen you give the datatype of an argument, you can't qualify it with a length (like VARCHAR *(22)* ); just give the type (VARCHAR)
create or replace procedure     my_proc
(   pt_id       int
,   pt_name     varchar          -- no size
as begin
    insert into t (t_id,   t_name)
            values (pt_id,  pt_name);
end;By the way, it's a good idea to explicitly name the columns in an INSERT statement. It helps prevent bugs, and it keeps you procedure working if you forget to change it when you add columns to the table.

Similar Messages

  • How to create procedure to mail ORA-error

    hi all,
    anyone please tell me how to create a procedure to mail the ORA-error when ORA- error comes in alert.log

    Ok, I can't really do this for you. It's not hard, just a lot of back-and-forth testing needs to be done. To do it solely in PL/SQL you need to monitor the alter_<sid>.log file for changes and filter the changed records for ORA- errors.. So, first step is to create, or get the dba to create a directory for that bdump directory. This will allow you to open the file for reading in PL/SQL
    This is on an XE 10g database as SYSTEM user, with poly being the database user that is monitoring the file.
    select value from v$parameter where name like 'background_dump_dest';
    /usr/lib/oracle/xe/app/oracle/admin/XE/bdump
    SQL> CREATE DIRECTORY BDUMP_DIR AS '/usr/lib/oracle/xe/app/oracle/admin/XE/bdump';
    create directory succeeded.
    SQL> grant read on directory alert_dir to poly;
    grant read succeeded.After this, you need to read the file and search for ORA- messages. You use the UTL_FILE package to do this. The following subprograms in UTL_FILE will be useful to you.
    Function: UTL_FILE.FOPEN You use this to open the file in readonly mode. Please look at the UTL_FILE documentation examples.
    Procedure: UTL_FILE.GET_LINE You use this to read lines into PL/SQL
    Procedure: UTL_FILE.GETATTR You use this to get the filelength. If the filelength is different from your previous call, you know some writes occurred.
    Procedure UTL_FILE.FSEEK You use this to position the reading stream to the first byte of new data read. You've detected the file has grown in size and do something like utl_file.fseek(file_desc,last_file_length+1)
    Procedure UTL_FILE.FCLOSE Close file when done.
    Pseudologic:
    This logic assumes you have a table which stores the filelength from the last time you executed the procedure. This allows you to only process records that have not already been processed.
    1. Read last file length from persistent storage such as a table. Default to zero if no value.
    2. Get filelength using UTL_FILE.GETATTR
    3. Compare filelength. If equal to prior value, exit. If greater, than more lines added. If less, then dba must have rolled the log, reset prior filelength to zero to process entire new file.
    4. Use UTL_FILE.FSEEK to position reader to one byte past last file length. This is why we default it to zero, 0+1=1.
    5. Open file using UTL_FILE.FOPEN
    6. Loop while data is avaliable, read each line, use instr or whatever to detect ORA- messages, call SMTP mailer as needed. You may want to log each email into a log table.
    7. After loop, set persisted last file length (update a table and commit maybe) to value returned from UTL_FILE.FGETPOS.
    8. Sleep for some interval of time. Start back at step 1.
    You should consider using DBMS_SCHEDULER to set up this job.
    There are lots of other ways of doing this. Remember that it's possible for your database to crash and your procedure might not be able to send an email. If someone edits the alter file and adds lines anywhere other than at the end, your program may resend some messages.
    Edited by: david.sweet on Feb 19, 2011 10:16 AM: changed the word function to procedure for most of them

  • How to create procedure having delete statement with between function?

    I am very new in SQL Development, I want to create a procedure having two date variable start and end and these two variable i want to use in procedure body to delete data from a specific table between two date duration.
    Please guide
    Thanks,

    create procedure some_proc (start_date date, end_date date)
    as
    begin
         delete from your_table
                   where your_date_column between start_date and end_date;
    end some_proc;
    /

  • How to create procedure for header table and  item table

    Hi,
    Can anyone help me to understand how to write SQLscript procedure for looping item table inside header table?
    I fetch records from sales header table ( order number ) and using that order number to loop sales item table,thereafter I need to perform business logic.
    Any example similar above requirement would be helpful
    thanks
    Sourav

    Hi Folks,
    This is my use case
    1) Select fact records from tables (say A,B,C,D ) with suitable Joins and certain Where conditions
        SELECT ordid FROM TABLES A,B,C,D on join condition where ....
    2) Using above header records , I have to select each and every item level data from different tables ( say X,Y,Z ) and perform calculation to derive new columns to update a new table ( Zreport )
    UPDATE TABLE ZREPORT
    SET col1 = ( Select qty  FROM TABLE X WHERE ordid = A.ordid
    UPDATE TABLE ZREPORT
    SET col2 = ( Select price FROM TABLE y WHERE ordid = B.ordid.
    and so on for other columns..
    3) Zreport table will be used for reporting.
    I would like to know the best way to achieve this to gain performance.
    Appreciate the help!
    Thanks
    Sourav

  • How to create Procedure  send Notification to Email In Oracle Worfkflow

    Hi all!
    Now,I'm doing about oracle workflow and i want send my notification to email of my boss.
    I configured workflow mailer in my system and it cant send mail to any email address.
    I want when workflow running,it can send notification to my email of my boss but now it can't
    How i write procude send noticafiton to email?
    Please,tell me about it ?
    Thanks all

    Are you using the notification mailer within Oracle Applications (ebs)? If so, I would post to the Oracle Applications forum, someone there might be able to give you a better idea.

  • How to create a LOV based on a stored procedure returning a cursor

    Hello,
    I've tried to search the forum, but did not find much. We are facing a problem of large LOVs and creating large TMP files on the app server. Our whole application is drived by store procedures. LOVs are built manually by fetching data from cursors returned from stored procedures. That creates the issue when whole LOV needs to be stored in the memory and thus the TMP files.
    Is there anyway how to create LOV based on a procedure returning cursor ?
    Thank you,
    Radovan

    Hello,
    As of now we populate the record group by looping through the ref cursor and adding rows into it. Is there a better way? That forces the whole record group to be stored in a memory on the app server.
    Thank you,
    Radovan

  • 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 G

    1. 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 to create the pricing procedure for domestic & import.

    HI,
        Pls any body let me know how to create the pricing procedure for domestic & import.
    what is the use of the keys
    step condiiton condition type from   to  manual required statistic   subtotal requirement caltype basetype.
    how system will work based on this.

    Hi,
    Please see below WIKI for your reference:
    http://wiki.sdn.sap.com/wiki/display/ERPLO/16FieldsDescriptioninPricing+Procedure
    Regards,
    Ninad Kshirsagar

  • 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
    Nihar

    nihar 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 tables and views and procedures in other users as one

    HI to all,
    I am having a user named vijay and i am trying to create the tables in user srini as user vijay
    in user vijay i'm having tables
    1. company
    2. department
    i wrote one procedure
    create or replace procedure sp_createobjects{short_name in varchar2}
    {my openbracket key is not working so that i put open braces here}
    as
    cursor table_name is select object_name from dba_tables where object_type = 'TABLE';
    var_table_name varchar2{1000};
    begin
    open table_name;
    loop
    fetch table_name into var_table_name;
    execute immediate 'create table ' || short_name || '.' || var_table_name || ' as select * from '||var_table_name;
    end loop;
    end;
    the procedure is created sucessfully. but when i am trying to execute the procedure it is throwing the error as insufficient privileges.
    my 2nd question is how to create the procedures into the other user?
    Thanks in advance

    First of all, your query "from dba_tables where object_type = 'TABLE'" returns all tables, not just the tables of the user vijay.
    So there are two possibilities, you may be getting the error because you cannot select from another user's table or you may be getting the error because you cannot create a table under the user srini. To create tables in another schema you need the "create any table" privilege.

  • With create procedure, How to clear Shared pool

    Hi, I have a sql script file it contains
    more than 300,000 line code, I use this file
    to create procedure in the Oracle.
    When I execute this sql script file, I receive a error message " out of cursor". I know when I create procedure, the procedure's code is stores in the shared pool. So when the code is stores out of shared pool's size, I receive that error.
    But how can I clear shared pool? With commit statement, it won't be use.
    Thanks a lot.

    you may try:
    alter system flush shared_pool;
    null

  • How to create a stored procedure and use it in Crystal reports

    Hi All,
    Can anyone explain me how to create a stored procedure and use that stored procedure in Crystal reports. As I have few doubts in this process, It would be great if you can explain me with a small stored proc example.
    Thanks in advance.

    If you are using MSSQL SERVER then try creating a stored procedure like this
    create proc Name
    select * from Table
    by executing this in sql query analyzer will create a stored procedure that returns all the data from Table
    here is the syntax to create SP
    Syntax
    CREATE PROC [ EDURE ] procedure_name [ ; number ]
        [ { @parameter data_type }
            [ VARYING ] [ = default ] [ OUTPUT ]
        ] [ ,...n ]
    [ WITH
        { RECOMPILE | ENCRYPTION | RECOMPILE , ENCRYPTION } ]
    [ FOR REPLICATION ]
    AS sql_statement [ ...n ]
    Now Create new report and create new connection to your database and select stored procedure and add it to the report that shows all the columns and you can place the required fields in the report and refresh the report.
    Regards,
    Raghavendra
    Edited by: Raghavendra Gadhamsetty on Jun 11, 2009 1:45 AM

  • How to create stored procedures and use those in Crystal reports

    Hi All,
    Can anyone explain me how to create a stored procedure and use that stored procedure in Crystal reports. As I have few doubts in this process, It would be great if you can explain me with a small stored proc example.
    Thanks in advance.

    Hello,
    There is a document explainining how to use Oracle stored proc with Crystal reports.
    Check at:
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/1084c536-711e-2b10-e48a-924a60745253
    It is for older version but it should work and you can refer to it to get general idea how to start with it. It has a sample oracle stored proc and how to connect it from Crystal Reports.

  • Procedure to how to create a pop up in webdynpro

    hi all,
      will anybody guide me the procedure to how to create a pop up in webdynpro application..plz as am new to it and i had requirement of creating pop up window in starting the application.
    thanks in advance.

    hi suman,
    thanks for ur reply.
    i want my pop up when i clk on button ok on my 1st view.
    so i included the code in the method of ONACTION OK.
    but am not able to display any sort of pop up.
    my code is
    DATA lo_nd_node TYPE REF TO if_wd_context_node.
          data: lr_popup type ref to if_wd_window,
            lr_view_controller type ref to if_wd_view_controller.
    data lo_window_manager type ref to if_wd_window_manager.
    data lo_api_component  type ref to if_wd_component.
    data lo_window         type ref to if_wd_window.
    lo_api_component  = wd_comp_controller->wd_get_api( ).
    lo_window_manager = lo_api_component->get_window_manager( ).
    lo_window         = lo_window_manager->create_window(
                       window_name            = 'WW_POP'
                      title                  = 'my first message'
                      close_in_any_case      = abap_true
                       message_display_mode   = if_wd_window=>co_msg_display_mode_selected
                      close_button           = abap_true
                       button_kind            = if_wd_window=>co_buttons_ok
                       message_type           = if_wd_window=>co_msg_type_none
                       default_button         = if_wd_window=>co_button_ok
    lo_window->open( ).
    will u help me out in this.

  • 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

Maybe you are looking for

  • Error installing Oracle 10g on Windows XP SP2

    Hi I had an error message at the end of the setup. Error instantiating EM configuration files. Log about the error is below. thanks in advance for your help OS:windows xp sp2 C:\oracle\product\10.2.0\db_1\cfgtoollogs\dbca\orcl\emconfig.log Dec 7, 200

  • Trouble running MSS reports on thin clients

    Does anyone know if it is a known issue that Running reports in EP 6 might not work in thin clients?

  • ChaRM functionality in SOLMAN

    Hello ChaRM-experts! I have the following questions regarding ChaRM-Setup: 1) Do I always need to define a Maintenance Project or can I use tcode u201CSCMAu201D to use transport management/ChaRM for satellite systems in SOLMAN 2) Is it possible to us

  • How to add default tools in HTML panel?

    For my workflow in Photoshop I've created this panel: using Adobe Configurator. It has some scripts and those default PS tools. As you know in Configurator is just a matter of drag'n'drop and that's about that. Is there any way to include those tools

  • How to delete a cost center hierarchy

    Hi all,         We are having a issue regarding the cost centers. The cost centers have been assigned wrong cost center numbers. Now the client wants a set of new cost center numbers to be used in the system. In order for that to be done I thought ma