Ampersand substitution in create or replace procedure statement

Hi Guys,
I wonder why my ampersand substitution does not work in a create or replace stored procedure statement.
CREATE OR REPLACE PROCEDURE UPDATE_DIM_SALES AS
UNDEFINE DimSales;
UNDEFINE FactTable;
DEFINE DimSales = 'TESTTAB';
DEFINE FactTable = myfact;
BEGIN
Error(5,20): PLS-00103: Encountered the symbol "=" when expecting one of the following: := . ( @ % ; not null range default character
If I then assign the value with := I get the error "invalid table" later on for the INSERT statemnt:
CREATE OR REPLACE PROCEDURE UPDATE_DIM_SALES AS
UNDEFINE DimSales;
UNDEFINE FactTable;
DEFINE DimSales := 'x2';
DEFINE FactTable := 'x1';
BEGIN
INSERT INTO &DimSales  (column1, column2,...)
Why does ampersand substitution not work within a stored procedure?

Hi,
Thanks for the suggestion.
The IF---ELSE Logic I have to write is quite complex.
I dont think joins will not do the trick and limiting the collection size to smaller than 4000 seems not very practical. there
is no poin using a collection if I have to use X amout of them.
UNDEFINE DimSALES;
UNDEFINE FactTable;
DEFINE DimSALES = 'TESTTAB';
DEFINE FactTable = 'testfact';
--Collect all distinct SELLERNr into materialized views
CREATE MATERIALIZED VIEW v1 AS select distinct SELLERnr from &FactTable;
CREATE MATERIALIZED VIEW v2 AS select distinct SELLER_ID from &DimSALES;
DECLARE
v_SELLERNr VarChar(9);
CURSOR v1_cursor IS Select * from v1;
l_exists INTEGER;
BEGIN
OPEN v1_cursor;
LOOP
FETCH v1_cursor INTO v_SELLERNr;
EXIT WHEN v1_cursor%NOTFOUND;
SELECT COUNT(*) INTO l_exists FROM v2 WHERE SELLER_id =v_SELLERNr AND ROWNUM = 1;
IF l_exists <> 1 THEN
INSERT INTO &DimSALES (K_SALES,REG,BVL,DS, VS,RS,SELLER_ID,VK,VALID_FROM)
(SELECT SEQ_DIM_SALES.NEXTVAL ,REG, BVL,DS, VS,RS,SELLERNR,VK,sysdate from &FactTable where SELLERNR =v_SELLERNr);
commit;
ELSE
--Update old combination(s), invalidate (DATE)
UPDATE &DimSALES SET VALID_TO = SYSDATE -1 WHERE REG||BVL||DS||VS||RS||SELLERNR||VK IN(
--In case the SELLER and combinations exists and differs from what is in the dimension then invalidate old combinations and insert new ones
SELECT * FROM(
SELECT REG||BVL||DS||VS||RS||SELLERNR||VK WHERE SELLERNR = v_SELLERNr FROM &FactTable;
MINUS
SELECT REG||BVL||DS||VS||RS||SELLERNR||VK WHERE SELLERNR = v_SELLERNr FROM &DimSALES;)
commit;
--Insert new combination
INSERT INTO &DimSALES (K_SALES,REG,BVL,DS, VS,RS,SELLER_ID,VK,VALID_FROM)
(SELECT SEQ_DIM_SALES.NEXTVAL ,REG, BVL,DS, VS,RS,SELLERNR,VK,sysdate from &FactTable where SELLERNR =v_SELLERNr) subselect;
WHERE &DimSALES.SELLER_Id=v_SELLERNr AND subselect.REG||BVL||DS||VS||RS||SELLERNR||VK NOT IN &DimSALES.REG||BVL||DS||VS||RS||SELLERNR||VK
commit;
END IF;
END LOOP;
CLOSE v1_cursor;
END;
DROP MATERIALIZED VIEW v1;
DROP MATERIALIZED VIEW v2;
-----------------

Similar Messages

  • Executing create or replace procedure statement from plsql script

    Hi ,
    I want to execute create or replace procedure from pl/sql block without using execute immediate or dbms_sql, please let me know if feasible.
    Eg:
    declare
    begin
    create or replace procedure .....
    if v_temp = 4 then
    end if;
    end;
    Thanks for help.
    Regards,
    RK

    user588487 wrote:
    Actual requirement is I have .sql file which has Create procedure command in it
    and i have to conditionally execute the above .sql file so going for a pl/sql block.
    Eg:
    begin
    if variable1 <> variable2 then
    @xyz.sql -- contains create or replace procedure statement
    insert into tablexyz.....
    end if;
    end;
    Won't work. The PL/SQL code block (also called an anonymous block) is shipped from the client (e.g. SQL*Plus) to the database server. There it is parsed and executed.
    It cannot execute SQL*Plus code.
    There are 2 basic approaches to address this requirement.
    Method 1. Use PL/SQL and SQL to perform the conditional logic checks that SQL*Plus cannot. Use bind variables to "copy" the results between SQL*Plus and PL/SQL, use substitution variables to execute the conditional branch (as a script) in SQL*Plus.
    Basic example:
    SQL> --// bind variable for passing data to PL/SQL code and
    SQL> --// to receive data from PL/SQL code
    SQL> var status varchar2(100)
    SQL>
    SQL> declare
      2          function ExistsTable( tableName varchar2 ) return boolean is
      3                  i       integer;
      4          begin
      5                  select 1 into i
      6                  from    user_objects
      7                  where   object_type = 'TABLE'
      8                  and     object_name = tableName;
      9                  return( true );
    10          exception when NO_DATA_FOUND then
    11                  return( false );
    12          end;
    13  begin
    14          --// determine if table exists
    15          if not ExistsTable( 'FOOTAB' ) then
    16                  --// table does not exists and SQL*Plus client
    17                  --// needs to run the footab client script
    18                  :status := 'footab.sql';
    19          else
    20                  :status := 'do-nothing.sql';
    21          end if;
    22  end;
    23  /
    PL/SQL procedure successfully completed.
    SQL>
    SQL> --// use a substitution variable to determine what to do
    SQL> set define on
    SQL> col STATUS new_value SCRIPT
    SQL> select :status as STATUS from dual;
    STATUS
    footab.sql
    SQL>
    SQL> --// execute the relevant script (i.e. execute the conditional
    SQL> --// branch of the PL/SQL IF condition
    SQL> @ &SCRIPT
    SQL> --// file: footab.sql
    SQL>
    SQL> create table footab(
      2          id      number primary key,
      3          col1    number,
      4          col2    date
      5  ) organization index
      6  /
    Table created.
    SQL>
    SQL> --//eof
    // running the same steps when the table does exist
    SQL> --// bind variable for passing data to PL/SQL code and
    SQL> --// to receive data from PL/SQL code
    SQL> var status varchar2(100)
    SQL>
    SQL> declare
      2          function ExistsTable( tableName varchar2 ) return boolean is
      3                  i       integer;
      4          begin
      5                  select 1 into i
      6                  from    user_objects
      7                  where   object_type = 'TABLE'
      8                  and     object_name = tableName;
      9                  return( true );
    10          exception when NO_DATA_FOUND then
    11                  return( false );
    12          end;
    13  begin
    14          --// determine if table exists
    15          if not ExistsTable( 'FOOTAB' ) then
    16                  --// table does not exists and SQL*Plus client
    17                  --// needs to run the footab client script
    18                  :status := 'footab.sql';
    19          else
    20                  :status := 'do-nothing.sql';
    21          end if;
    22  end;
    23  /
    PL/SQL procedure successfully completed.
    SQL>
    SQL> --// use a substitution variable to determine what to do
    SQL> set define on
    SQL> col STATUS new_value SCRIPT
    SQL> select :status as STATUS from dual;
    STATUS
    do-nothing.sql
    SQL>
    SQL> --// execute the relevant script (i.e. execute the conditional
    SQL> --// branch of the PL/SQL IF condition
    SQL> @ &SCRIPT
    SQL> prompt Nothing to do...
    Nothing to do...
    SQL> Method 2. Move all "client scripting" to the server. You can still use .sql files. These need to contain valid DDL that can be parsed and executed. On the server, the .sql files are loaded into a table.
    This can be a physical load (e.g. using <i>DBMS_LOB.LoadFromFile()</i>). Or you can keep the .sql files on the server and use BFILE pointers instead to the files.
    You can now use execute immediate to execute the contents of a .sql file as a CLOB that was read from the table containing the .sql scripts.
    To be honest - I have used both methods extensively in the past and no longer bother using either. Table exists when running the table create script? So what. If the table should not exist, use server exceptions in SQL*Plus to cease processing and exit. If it does not matter whether the table exists or not, why be concern with running the script to create the table if the table already exists?

  • CREATE OR REPLACE PROCEDURE return data like SELECT statement

    "SELECT * FROM SEARCH_KEYWORD" is successfully done and return the data of the tables. Now, I want to run that on server side using PROCEDURE.
    I successfully executed the below scripts. Please teach me how to call the sp_test procedure. OR if you have other way or maybe my scripts are wrong.
    CREATE OR REPLACE PACKAGE GLOBALPKG
    AS
         TYPE RCT1 IS REF CURSOR;
         TRANCOUNT INTEGER := 0;
         IDENTITY INTEGER;
    END;
    CREATE OR REPLACE PROCEDURE LPG.sp_test
         RCT1 IN OUT      GLOBALPKG.RCT1
    AS
    BEGIN
         OPEN RCT1 FOR
         SELECT *
         FROM SEARCH_KEYWORD;
    END;
    Here is my table definition:
    CREATE TABLE LPG.SEARCH_KEYWORD
    FRACTION VARCHAR2(50),
    KEYWORD VARCHAR2(50),
    PURPOSE VARCHAR2(50),
    REMARKS VARCHAR2(50),
    DATE_INSERTED DATE DEFAULT sysdate
    PCTFREE 10
    PCTUSED 40
    MAXTRANS 255
    TABLESPACE SYSTEM
    STORAGE(INITIAL 64K MINEXTENTS 1 MAXEXTENTS 2147483645 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    NOCACHE
    LOGGING
    Eros
    Japan

    Wrong forum. You should ask this question in the SQL and PL/SQL forum.
    Couple of comments though. Oracle is not SQL-Server. So calling a procedure that returns a ref cursor is different from a T-SQL macro procedure that functions like a view.
    Also, there is no need to use the SQL-Server standard (and silly one at that) of prefixing stored procedures using the text "sp_". In fact, the whole concept of Hungarian-like notation is something of the past and has no place in today's paradigm of software engineering.
    As for calling a a proc that returns a ref cursor, from SQL*Plus it will look as follows:
    SQL> var c refcursor
    SQL>
    SQL> exec LPG.sp_test( :c )
    SQL> print c
    Ref cursor needs to be supported by the client language you use to make this call to Oracle.

  • CREATE OR REPLACE PROCEDURE dq_setAllCollOptionsForColl (srcCollId INT, s

    CREATE OR REPLACE PROCEDURE dq_setAllCollOptionsForColl
    (srcCollId INT,
    collId INT)
    AS
    BEGIN
    INSERT INTO dq_spidering_options
    SELECT collId, id_type, file_types, file_extns, sub_directories,
    max_files, min_file_size, max_file_size, protocols_to_fetch, reanalysis_option,
    page_download_timeout, page_download_retries, page_download_pause, thread_count FROM dq_spidering_options
    WHERE id = srcCollId AND id_type = 'S';
    INSERT INTO dq_exclude_includes
    SELECT collId, id_type, entity, type from dq_exclude_includes WHERE id = srcCollId AND id_type = 'S'
    EXEC dq_setSiteOptionsForSites srcCollId, collId
    END dq_setAllCollOptionsForColl;
    how do i fix this?

    how do i fix this? Well, for us to say how, you need to tell what's wrong?
    To start with, EXEC is a SQL*Plus command not to be used within stored procedures. also, you seem to be calling another stored procedure with two parameters. you need to change that line as:
    dq_setSiteOptionsForSites(srcCollId, collId) ;

  • Procedure hangs while create or replace!

    Dear All,
    My Database is Oracle 11g RAC.
    I did few changes in one of my procedure and wanted to re-create it using CREATE OR REPLACE procedure...
    The statement hangs for a long time and the concurrency in OEM raises up to a very high level. I tried to find the blocking sessions but for some time there was no blocking session.
    I also tried stopping the activities on the tables used in this procedure.
    Kindly suggest me what should I do in this situation. I have also tried running the query directly from the server.
    Regards, Imran

    Hi,
    check for any locks & kill it , execute on each instance or use gv$
    alter session set nls_date_format='dd-mon-yy hh24:mi:ss';
    select /*+ CHOOSE */ a.sid, a.serial#,vp.spid,a.last_call_et,a.logon_time,a.status,sw.event, a.username,a.osuser, a.status,
    a.program,a.MACHINE, a.type ptype,b.owner, b.object, b.type
    from v$session a, v$access b,v$session_wait sw, v$process vp
    where a.sid=b.sid and b.sid=sw.sid  and a.paddr=vp.addr
    and b.type<>'NON-EXISTENT'
    and (b.owner is not null) and (b.owner<>'SYSTEM')  and (b.owner<>'SYS')
    and upper(b.object) like '%&obj_name%'
    ORDER BY 3;Thanks,
    Ajay More
    http://moreajays.blogspot.com

  • Need help to create export table procedure

    Hi,
    I have created a procedure, which may use to do following things:
    1. first create a duplicate table of sys.aud$ records
    2. export that duplicate table
    here I am enclosing my code:
    1. create or replace procedure crt_tab
    2. is
    3. sqlstring varchar2(100);
    4. tablename varchar2(100);
    5. sys_date varchar2(100);
    6. h1 number;
    7. begin
    8. select to_char(sysdate,'DDMMYYYY_HH12MISSAM') into sys_date from dual;
    9. tablename :='AUDIT_RECORD_'||sys_date;
    10. sqlstring := 'create table ' || tablename|| ' as select * from sys.aud$';
    11. execute immediate sqlstring;
    12. h1 := dbms_datapump.open(operation=>'EXPORT',job_mode=>'TABLE',job_name=>NULL,version=>'COMPATIBLE');
    13. dbms_datapump.add_file(handle =>h1, filename =>tablename||'.dmp',directory =>'AUDIT_RECORD', filetype =>1);
    14. dbms_datapump.add_file(handle =>h1,filename =>tablename||'.log',directory =>'AUDIT_RECORD',filetype =>3);
    15. dbms_datapump.metadata_filter(h1,'NAME_LIST','(''tablename'')');
    16. dbms_datapump.start_job(h1);
    17. dbms_output.put_line('Data Pump job started successfully');
    18. end;
    Well, in line number 15. I am passing a variable tablename as a parameter to dbms_datapump.metadata_filter but it exporting an empty dump. Could you please let me know how to pass a variable value in this.
    looking forward to your early response.
    Regards,
    M.A.Bamboat
    [email protected]

    SQL> ed
    Wrote file afiedt.buf
      1  DECLARE
      2    l_dp_handle     NUMBER;
      3    l_last_job_state VARCHAR2(30) := 'UNDEFINED';
      4    l_job_state     VARCHAR2(30) := 'UNDEFINED';
      5    l_logfilename     VARCHAR2(20) := to_char(sysdate, 'DDMMRRRR') || '.log';
      6    l_expfilename     VARCHAR2(20) := to_char(sysdate, 'DDMMRRRR') || '.dmp';
      7    l_tbl_name     VARCHAR2(30) :='EMP';
      8  BEGIN
      9    l_dp_handle := DBMS_DATAPUMP.OPEN(operation   => 'EXPORT',
    10                          job_mode    => 'TABLE',
    11                          remote_link => NULL,
    12                          job_name    => 'SAUBHIK_EXPORT',
    13                          version     => 'COMPATIBLE');
    14    DBMS_DATAPUMP.ADD_FILE(handle     => l_dp_handle,
    15                     filename     => l_expfilename,
    16                     directory => 'SAUBHIK',
    17                     filetype     => DBMS_DATAPUMP.KU$_FILE_TYPE_DUMP_FILE);
    18    DBMS_DATAPUMP.ADD_FILE(handle     => l_dp_handle,
    19                     filename     => l_logfilename,
    20                     directory => 'SAUBHIK',
    21                     filetype     => DBMS_DATAPUMP.KU$_FILE_TYPE_LOG_FILE);
    22    dbms_datapump.metadata_filter(handle => l_dp_handle,
    23                         name   => 'NAME_EXPR',
    24                         value  =>'= '||''''||l_tbl_name||'''');
    25    dbms_datapump.start_job(l_dp_handle);
    26    dbms_datapump.detach(l_dp_handle);
    27  EXCEPTION
    28    WHEN OTHERS THEN
    29      dbms_datapump.stop_job(l_dp_handle);
    30      RAISE;
    31* END;
    SQL> /
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM user_datapump_jobs;
    JOB_NAME                 OPERATION                JOB_MODE                    STATE                    DEGREE ATTACHED_SESSIONS DATAPUMP_SESSIONS
    SAUBHIK_EXPORT                 EXPORT                     TABLE                    EXECUTING                         1       0           2
    SQL> /
    JOB_NAME                 OPERATION                JOB_MODE                    STATE                    DEGREE ATTACHED_SESSIONS DATAPUMP_SESSIONS
    SAUBHIK_EXPORT                 EXPORT                     TABLE                    NOT RUNNING                    0       0           0
    SQL> /
    no rows selected
    SQL>
    oracle@ubuntu-desktop:~/Documents$ pwd
    /home/oracle/Documents
    oracle@ubuntu-desktop:~/Documents$ ls -l 05092011*
    -rw-r----- 1 oracle oinstall 98304 2011-09-05 15:07 05092011.dmp
    -rw-r--r-- 1 oracle oinstall   928 2011-09-05 15:07 05092011.log
    oracle@ubuntu-desktop:~/Documents$

  • Create a stored procedure to convert a temp table to current table

    I have a current table in oracle called motor_assist2 with columns:
    NAME
    ADDRESS
    PHONE
    CITY
    STATE
    ZIP
    FRIENDLINESS
    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 another table(motor_assist9) in excel with similiar columns that i want to insert that data into my current table(motor_assist2) using a stored procedure but am not sure how to do it. Can anybody help me? Thanks
    Deanna

    so this is my procedure:
    create or replace procedure "PREVIOUS_MA_DATA"
    is
    BEGIN
    FOR var IN 1 ..3289 LOOP
    insert into MAV.MOTOR_ASSIST2
    (NAME,ADDRESS,PHONE,CITY,STATE,ZIP,
    FRIENDLINESS,SERVICE,WAIT_TIME,
    CONT_SERVICE,COMMENTS,DAY,CLOCK,TECHNICIAN1_RADIO,
    TECHNICIAN1_NAME,LOCATION,COUNTY_NAME,COUNTY_ABBR,
    MAV_TROOP,TECHNICIAN2_RADIO,TECHNICIAN2_NAME,FY,
    BEG_DATE,END_DATE,MONTH,YEAR,to_date(DAY||' '||CLOCK,'dd-mon-rr hh12:mi:ss')DATETIME
    from temp;
    END LOOP;
    END;
    when i try to compile it, it gives me the errors:
    Compilation failed,line 10 (13:20:46)
    PL/SQL: ORA-00917: missing commaCompilation failed,line 8 (13:20:46)
    PL/SQL: SQL Statement ignored
    Where am i missing a comma???

  • Create directory from procedure using IN parameter-Directory name with path

    Hi,
    I wrote a procedure which takes directory name(C:\temp) as IN parameter and create oracle directory using EXECUTE IMMEDIATE by the procedure. Proc compiled fine but when i try to execute it (exec prc_lx_e_m_fund_activty ('C:\interface','test1.txt','20040102') , i am getting the following error with the execute immediate statement mentioned below.
    create or replace
    PROCEDURE prc_lx_e_m_fund_activty
    i_output_dir IN VARCHAR2,
    i_output_file_name IN VARCHAR2,
    i_interface_date IN VARCHAR2
    AS
    EXECUTE IMMEDIATE 'CREATE OR REPLACE DIRECTORY OUTPUT_PATH AS ' || ''''||i_output_dir||'''' ||';'; -- Where i_output_dir=C:\temp (I am passing this parameter as IN)
    END
    ORA-01481: invalid number format model
    ORA-06512: at "DBO.PRC_LX_E_M_FUND_ACTIVTY", line 326
    ORA-00911: invalid character
    ORA-06512: at line 10
    Process exited.
    Regards,
    Nagarjun.

    You don't need to put it in a string first. Your actual problem was that you included a ";" on the end of your statement which you don't require with execute immediate.
    This would do the job...
    EXECUTE IMMEDIATE 'CREATE OR REPLACE DIRECTORY OUTPUT_PATH AS '''||i_output_dir||'''';or this (if you are on 10g upwards)
    EXECUTE IMMEDIATE q'[CREATE OR REPLACE DIRECTORY OUTPUT_PATH AS ''||i_output_dir||'']';However, I would seriously question why you are creating directories dynamically in code.
    The purpose of creating directories and granting permission to read and/or write to them is to maintain security over which users can access various places on the file system. If you give this flexibility of creating directories to users then effectively they can kill your database server and/or hack into information that they shouldn't.

  • Can't replace procedure

    Hi:
    I am using Squirrel as the client tool using JDBC RAC driver against Oracle 11.1. I am trying to replace an existing Oracle procedure with:
    CREATE OR REPLACE PROCEDURE MY_PROC
    AS
    BEGIN
    DELETE FROM table1 WHERE IEX_DATE >= (select max(idate) from table1) - 20;
    DELETE FROM table2 WHERE IEX_DATE >= (select max(idate) from table2) - 20;
    DELETE FROM table3 WHERE IEX_DATE >= (select max(idate) from table3) - 20;
    DELETE FROM table4 WHERE IEX_DATE >= (select max(idate) from table4) - 20;
    END;
    It fails with the error:
    Query 1 of 5, Rows read: 0, Elapsed time (seconds) - Total: 0.047, SQL query: 0.047, Building output: 0
    6,326 Row(s) Deleted
    Query 2 of 5, Rows read: 0, Elapsed time (seconds) - Total: 0.672, SQL query: 0.672, Building output: 0
    12,097 Row(s) Deleted
    Query 3 of 5, Rows read: 0, Elapsed time (seconds) - Total: 1.25, SQL query: 1.25, Building output: 0
    5,040 Row(s) Deleted
    Query 4 of 5, Rows read: 0, Elapsed time (seconds) - Total: 0.531, SQL query: 0.531, Building output: 0
    Error: ORA-00900: invalid SQL statement
    SQLState: 42000
    ErrorCode: 900
    Error occured in:
    END
    What am I doing wrong? I've tried different things but nothing seems to give me an executable procedure.

    Looks to me like Squirrel (whatever tool that is) processes SQL statements, so has performed the DELETE statements it's found, but doesn't know about PL/SQL code.
    What happens if you run the same create procedure statement through SQL*Plus instead?

  • How to create minimal stored procedure?

    What is the preferred way of creating stored procedures? Can I use SQL Developer or SQLPlus?
    I'm running version 11.2.0.1.0.
    Here is my attempt in SQLDeveloper:
    CREATE OR REPLACE PROCEDURE hello ()
    BEGIN
    dbms_output.put_line('Hello, World!');
    END;
    SET SERVEROUTPUT ON;
    SELECT hello() from DUAL;
    When I hit F5 it says
    Warning: execution completed with warning
    PROCEDURE hello Compiled.
    When I select the last line and hit F9 I get a dialog box that says:
    An error was encountered performing the requested operation:
    ORA-00904: "HELLO" invalid identifier
    00904.0000 - "%s: invalid identifier"
    *Cause:
    *Action:
    Vendor code 904 Error at line:8 column 7
    I tried using SQL plus but since I'm having trouble just logging in, I already posted my query in the SQLPlus forum.
    Thanks,
    siegfried

    user8816970 wrote:
    What is the preferred way of creating stored procedures? Can I use SQL Developer or SQLPlus? Yes.
    A "minimal" procedure would be:
    create or replace procedure TestProc as
    begin
      null;
    end;Also get the whole pascalcase, camelcase and lowercase correct. Do not code in uppercase - it not only looks stupid, it contravenes programming standards that existed since the 70's and are still applicable and used today. From Microsoft's .Net to Java and /C/C++ and Pascal/Delphi and Visual Basic and most other languages. It is just plain silly to code in uppercase. Cobol standards do not apply today and were intended for punch cards - which is why I find this whole code-reserve-words-in-uppercase approach used in PL/SQL, flawed and idiotic.
    When I select the last line and hit F9 I get a dialog box that says:
    An error was encountered performing the requested operation:That is because PL/SQL procedures need to be executed via an anonymous PL./SQL block. You need use (enter) the following code block on the client side to be send to Oracle for parsing and execution:
    begin
      Hello;
    end;Some clients, like SQL*Plus, supports a client EXEC command. This takes the parameter supplied to the EXEC command and wrap that into an anonymous block like above.
    You can only execute PL/SQL functions via the SQL language. Quite important that you do not confuse languages at this level. Some clients (like SQL*Plus) have their own client commands like EXEC and HOST and SPOOL. These client commands are not PL/SQL or SQL.
    PL/SQL and SQL are also two different languages. PL/SQL combines Programming Language with SQL in a very integrated and transparent way. However. PL is executed by the PL engine and SQL is executed by the SQL engine.
    Lastly, make sure you understand what DBMS_OUTPUT does. It does not write anything to the client's display device. It is server code running in a server process. It cannot hack across the network to do stuff on the client - like reading a file or displaying something.
    The put_line() procedure of DBMS_OUTPUT writes text data into a static PL/SQL variable. The more you write into it, the more expensive server memory is consumed by that server process. When the server process has completed the client call (SQL statement or PL/SQL call), the client can then interrogate this buffer variable, read it, display the contents itself, and clear the buffer variable.
    It's important to understand what client-server is and how it applies to what you are doing using Oracle as a server.

  • How to create a stored procedure that accepts an array of args from Java?

    I am to be creating a stored procedure that accepts an array of arguments from Java. How to create this? thanks
    Sam

    Not a PL/SQL question really, but a Java one. The client call is done via ThinJDBC/OCI to PL/SQL, This call must be valid and match the parameters and data types of the PL/SQL procedure.
    E.g. Let's say I define the following array (collection) structure in Oracle:
    SQL> create or replace type TStrings as table of varchar2(4000);
    Then I use this as dynamic array input for a PL/SQL proc:
    create or replace procedure foo( string_array IN TStrings )...
    The client making the call to PL/SQL needs to ensure that it passes a proper TStrings array structure.. The Oracle Call Interface (OCI) supports this on the client side - allowing the client to construct an OCI variable that can be passed as a TStrings data type to SQL. Unsure just what JDBC supports in this regard.
    An alternative method, and a bit of a dirty hack, is to construct the array dynamically - but as this does not use bind variables, it is not a great idea.
    E.g. the client does the call as follows: begin
      foo( TStrings( 'Tom', 'Dick', 'Harry' ) );
    end;Where the TStrings constructor is created by the client by stringing together variables to create a dynamic SQL statement. A bind var call would look like this instead (and scale much better on the Oracle server side):begin
      foo( :MYSTRINGS );
    end;I'm pretty sure these concepts are covered in the Oracle Java Developer manuals...

  • Create and select procedure

    Hello,
    i want to create and select procedure in SQL commands editor:
    CREATE OR REPLACE PROCEDURE SLEEP AS BEGIN DBMS_OUTPUT.PUT_LINE('a'); END; SELECT SLEEP() from dual;
    but i get error Error at line 1: PLS-00103
    that says it was founded SELECT...
    can u help me ? thanx..
    and, can i execute php code on this server ? thanx

    if I execute this code as one statement:
    CREATE OR REPLACE FUNCTION SLEEP RETURN VARCHAR2 IS
    BEGIN
    RETURN 'a';
    END;
    select sleep from dual;
    i get error which says, that SELECT was founded...
    if I execute first
    CREATE OR REPLACE FUNCTION SLEEP RETURN VARCHAR2 IS
    BEGIN
    RETURN 'a';
    END;
    and then
    select sleep from dual;
    i get error ORA-06575 Package or function SLEEP is in an invalid state
    1.) whats wrong?
    2.) is possioble to execute a creating function and the select it in one statement ?
    3.) can I use my own jsp or php on apex.oracle.com ?
    Thank you

  • Creating pl/sql procedure problems

    Dear all,
    I have problems with creating a procedure which select returns more then one row.
    CREATE OR REPLACE PROCEDURE ECM_DATA.check_padrones_datos
    IS
      v_padron_check   VARCHAR2(50);
      v_padron_number   VARCHAR2(50);
    BEGIN
       SELECT count(pd.estado)
       INTO v_padron_check
       FROM par6.padrones_datos pd, par6.padrones p, par6.FECHAS f
         where pd.estado not in ('2000','8000')
         AND PD.ARCHIVO = P.ARCHIVO
         AND P.FECHA = F.datum_s;
        DBMS_OUTPUT.PUT_LINE('Št. neuspešnih zapisov :  ' || v_padron_check);
        SELECT distinct pd.archivo
       INTO v_padron_number
       FROM par6.padrones_datos pd, par6.padrones p, par6.FECHAS f
         where pd.estado not in ('2000','8000')
         AND PD.ARCHIVO = P.ARCHIVO
         AND P.FECHA = F.datum_s;
        DBMS_OUTPUT.PUT_LINE('Padron št. :  ' || v_padron_number);
      EXCEPTION
        WHEN NO_DATA_FOUND THEN
         v_padron_number := 'Vsi padroni so OK';
         DBMS_OUTPUT.PUT_LINE('Padron št. :  ' || v_padron_number);
    END;
    Error ->  -01422: exact fetch returns more than requested number of rows
    Select returns 2 or more rows.
    SELECT distinct pd.archivo
        FROM par6.padrones_datos pd, par6.padrones p, par6.FECHAS f
         where pd.estado not in ('2000','8000')
         AND PD.ARCHIVO = P.ARCHIVO
         AND P.FECHA = F.datum_s;
    How to write correct syntax in pl/sql. I apologize in advance for rookie questions. Any help would be appreciated.
    Regards,
    Robert

    The exact implementation depends on the use case.
    You can loop through the results
    FOR r IN (
        SELECT  DISTINCT pd.archivo
        FROM    par6.padrones_datos pd
               ,par6.padrones p
               ,par6.fechas f
        WHERE   pd.estado not in ('2000','8000')
        AND     pd.archivo = p.archivo
        AND     p.fecha = F.datum_s
    LOOP
        dbms_output.put_line('Padron št. :  ' || r.archivo);
    END LOOP;
    Or maybe you can process all results in one step, e.g. if you want to update a table based on the select.
    Regards
    Marcus

  • Error after creating a stored procedure

    hi,
    i m planning to create the below stored procedure and created but i m unable to execute this procedure,
    please provide me the solution.
    SQL> create or replace procedure test is
    2 titl varchar(20);
    3 typ varchar(20);
    4 pric number(10);
    5 nprice number(10);
    6 begin
    7 SELECT
    8 title_id,
    9 type,
    10 price,
    11 CASE type
    12 WHEN 'history'
    13 THEN price + 110
    14 WHEN 'psychology'
    15 THEN price + 120
    16 WHEN 'computer'
    17 THEN price + 140
    18 ELSE price
    19 END
    20 AS "New price" into titl,typ,pric,nprice
    21 FROM book
    22 ORDER BY type ASC, title_id ASC;
    23 dbms_output.put_line(titl || typ || pric || nprice);
    24 end;
    25 /
    Procedure created.
    SQL> set serverout on
    SQL> exec test
    BEGIN test; END;
    ERROR at line 1:
    ORA-01422: exact fetch returns more than requested number of rows
    ORA-06512: at "SYS.TEST", line 8
    ORA-06512: at line 1
    SQL> show error
    No errors.
    thanks...

    Hi,
    Check you SQL query, Its returning mutiple rows which you are storing in variables.
    If your data returns mutiple row then use cursor to iterate through it.
    like
    create or replace procedure test is
    titl varchar(20);
    typ varchar(20);
    pric number(10);
    nprice number(10);
    cursor c is
    SELECT title_id, type, price, CASE type WHEN 'history' THEN price + 110
                                                           WHEN 'psychology' THEN price + 120
                                                           WHEN 'computer'   THEN price + 140
                                                           ELSE price END AS "New price"
    FROM book
    ORDER BY type ASC, title_id ASC;
    begin
    for r in c loop
    dbms_output.put_line(r.titl || r.typ || r.pric || r.nprice);
    end;Twinkle

  • How to create report using Procedure.

    Hi All,
    I want to create report in apex.But i do not have sql code.I have one procedure.Is it possible to create report using this procedure in apex.
    CREATE OR REPLACE PROCEDURE headcsv_prc2
    AS
       CURSOR cr_header
       IS
          SELECT ood.organization_code, fm.formula_no AS "FORMULA_NAME",
                   fm.formula_vers AS "FORMULA_VERSION",
                   fm.formula_desc1 AS "FORMULA_DESC",
                   DECODE (fm.formula_status,
                           100, 'New',
                           400, 'Approve for Laboratory Use',
                           700, 'Approve for General',
                           800, 'On Hold',
                           900, 'Frozen',
                           1000, 'Obsolete/Archived'
                          ) AS "FORMULA_STATUS",
                   DECODE (fd.line_type, '1', msib.segment1) product,
                   DECODE (fd.line_type, '-1', msib.segment1) ingrediant,
                   DECODE (fd.line_type, '2', msib.segment1) AS "BY_PRODUCT",
                   DECODE (by_product_type,
                           'W', 'Waste',
                           'R', 'Rework',
                           'Y', 'Yield',
                           'S', 'Sample',
                           NULL
                          ) AS "BY_PRODUCT_TYPE"
              FROM org_organization_definitions ood,
                   fm_form_mst fm,
                   fm_matl_dtl fd,
                   mtl_system_items_b msib
             WHERE ood.organization_id = fm.owner_organization_id
               AND fm.owner_organization_id = msib.organization_id
               AND msib.organization_id = fd.organization_id
               AND fd.organization_id = ood.organization_id
               AND fm.formula_id = fd.formula_id
               AND msib.inventory_item_id = fd.inventory_item_id
               -- and fm.FORMULA_NO like'%TEA%'
               AND fd.line_type IN ('1', '2', '-1')
          GROUP BY ood.organization_code,
                   fm.formula_no,
                   fm.formula_vers,
                   fm.formula_desc1,
                   fm.formula_status,
                   fd.line_type,
                   msib.segment1,
                   by_product_type
          ORDER BY fm.formula_no, fm.formula_vers;
    BEGIN
       DBMS_OUTPUT.put_line (   INITCAP ('ORGANIZATION CODE')
                             || ','
                             || INITCAP ('FORMULA NAME')
                             || ','
                             || INITCAP ('FORMULA VERSION')
                             || ','
                             || INITCAP ('FORMULA DESC')
                             || ','
                             || INITCAP ('FORMULA STATUS')
                             || ','
                             || INITCAP ('PRODUCT')
                             || ','
                             || INITCAP ('INGREDIANT')
                             || ','
                             || INITCAP ('BY PRODUCT')
                             || ','
                             || INITCAP ('BY PRODUCT TYPE')
       FOR ch IN cr_header
       LOOP
          DBMS_OUTPUT.put_line (   ch.organization_code
                                || ','
                                || ch.formula_name
                                || ','
                                || ch.formula_version
                                || ','
                                || '"'
                                || ch.formula_desc
                                || '"'
                                || ','
                                || ch.formula_status
                                || ','
                                || ch.product
                                || ','
                                || ch.ingrediant
                                || ','
                                || ch.by_product
                                || ','
                                || ch.by_product_type
       END LOOP;
    EXCEPTION
       WHEN OTHERS
       THEN
          DBMS_OUTPUT.put_line ('Error No: ' || SQLCODE || 'Error Msg: '
                                || SQLERRM
    END;
    EXEC HeadCSV_Prc2
    Thanks,
    Raghu

    RaghuVarma wrote:
    I created one report using sql code.(Ex: select * from emp).
    But my higher authorities want that for security purpose They will change the code into java.
    What "higher authorities"? What "security purpose"?
    In this process they changed my code as a procedure.Finally they give that java code.they tell to me please fix in apex.
    Do these "higher authorities" know anything about APEX? What does the Java code actually do? Have you asked them how their approach is to be integrated into APEX?
    There is no reason why a properly written Java stored program cannot be used in APEX, provided that whatever it is doing makes sense in an APEX/web context, and isn't some nonsense like using DBMS_OUTPUT to generate a CSV.
    I tried so many ways.But it is not fixed.Different Different errors will occurs.
    Tried what? Demonstrate what you have tried, preferably using examples on apex.oracle.com.
    How to solve this.
    How to solve what? No clearly defined problem or requirement has been identified.
    Describe the the problem/requirement (not your attempted solutions) in detail.
    How to ask questions
    Re: 2. How do I ask a question on the forums?
    Include as much relevant information with your question as possible, starting with:
    APEX version
    DB version, edition and host OS
    Web server architecture (EPG, OHS or APEX listener), platform, and host OS
    Browser(s)/version(s) used
    Theme
    Templates
    Region type(s)

Maybe you are looking for

  • Sales order - Schedule line or Availability check

    Dear friends, I have one requirement on sales order availability check or schedule line. When i enter material and quantity in sales order it should not determine stock from one storage location (0003 storage location for damaged goods) through avail

  • Oracle 11gr2 RAC

    hi, can i setup 2 node oracle RAC using vmware server in a single laptop..? cpu-intel i3 memory 4GB. thanks in advance, Sarathi

  • I have a program that I do not want to update, how do I turn off nags

    The Mac App Store keeps sending me reminders to update iMovie 10.   I am using the superior iMovie 06.  How can I tell the app store to stop notifying me about iMovie 10 updates. Thanks

  • Questions on PO attachments

    Hi Gurus, Is there any possibility to restrict the viewing or editing of attachments in PO, unless it belongs to the purchasing group. Is there any commands which will enable this in SAP? Thanks.

  • WEB WIDGETS SECURE?

    Don't know why I was directed here from the iWeb discussion forum, but I was. So, to humor the redirection, in the event there is some merit to asking here, I will ask. The question is about Adsense ads & security of web widgets in general when place