Problem wile EXECUTE IMMEDIATE DDL statement in procedure

Hi ,
This is my procedure and it's getting compiled but while executing procedure getting this error,
can anyone please tell me how to fix this?
create or replace procedure construct_Table (name_table IN VARCHAR2)
IS
v_tab_name varchar2(40):=NULL;
v_sql_Stmt varchar2(32767) := NULL;
finalquery varchar2(32767) :=NULL;
cursor tp is
select COLUMN_NAME,DATA_TYPE,DATA_PRECISION,CHAR_LENGTH  from all_tab_cols where table_name=name_table;
BEGIN
begin
select TABLE_NAME into v_tab_name from user_tables where table_name=name_table;
EXCEPTION
WHEN no_Data_found
THEN
DBMS_OUTPUT.PUT_LINE('No such table exist');
end;
if(v_tab_name IS NOT NULL)then
finalquery := 'CREATE TABLE '||v_tab_name||'_DUMMY (';
   FOR I IN tp LOOP
   if(I.data_type='VARCHAR2') then
   v_sql_stmt := finalquery ||I.column_name||' '||I.data_type||'('||I.char_length||') ';
   elsif(I.data_type='NUMBER') then
   v_sql_stmt := finalquery ||I.column_name||' '||I.data_type||'('||I.DATA_PRECISION ||') ';
   else
   v_sql_stmt := finalquery ||I.column_name||' '||I.data_type ;
   end if;
   finalquery := v_sql_stmt || ',';
   END LOOP;
   finalquery := SUBSTR(finalquery,1,LENGTH(finalquery) - 1)||')';
   dbms_output.put_line(finalquery);
   EXECUTE IMMEDIATE'grant create any table to cmsuser';
   EXECUTE IMMEDIATE finalquery;
end if; 
END;
/This is the error I am getting
Error starting at line 1 in command:
begin
construct_Table ('EMP');
end;
Error report:
ORA-01031: insufficient privileges
ORA-06512: at "CMSUSER.CONSTRUCT_TABLE", line 30
ORA-06512: at line 2
01031. 00000 -  "insufficient privileges"
*Cause:    An attempt was made to change the current username or password
           without the appropriate privilege. This error also occurs if
           attempting to install a database without the necessary operating
           system privileges.
           When Trusted Oracle is configure in DBMS MAC, this error may occur
           if the user was granted the necessary privilege at a higher label
           than the current login.
*Action:   Ask the database administrator to perform the operation or grant
           the required privileges.
           For Trusted Oracle users getting this error although granted the
           the appropriate privilege at a higher label, ask the database
           administrator to regrant the privilege at the appropriate label.Thanks ,
Deekay.

Deekay,
If you grant create table privilege and create table in the same procedure, then how you will differentiate that which user you granted the privilege and in which schema, you are creating the table. Here, you are granting to "cmuser", but in the same schema, you are creating the table also. How can a user grant privilege to himself?
Login as DBA, grant create any table privilege to "cmuser" from dba. Then, you can execute you procedure in "cmuser" schema.

Similar Messages

  • Executing multiple DDL statements with OracleCommand

    hi..
    im having trouble executing multiple ddl statements with the the oracle command object. i have tried to enclose them within Begin.. End; block but with no use.
    this problem seems to occur only with DDL statements,.. as my DML like update, delete and Inserts seem to work fine when enclosed within the PL /SQL block.
    single DDL statements also seem to work fine. so im guessing this has nothing to do with priviledges. any ideas?
    my code as follows
    OracleCommand command = new OracleCommand();
    command.CommandType = CommandType.Text;
    command.CommandText = string.Format(@"{0}",script);
    conn.Open();
    command.Connection = conn;
    command.ExecuteNonQuery();
    the script is read from a file, and looks like this. (note : i have removed any line breaks or any other characters)
    BEGIN ALTER TABLE SYSTEMUSER DISABLE CONSTRAINT FK_USER_CLIENT; ALTER TRIGGER SET_SUBSCRIPTION_SUB_I DISABLE; END;
    this is the error i get.
    Oracle.DataAccess.Client.OracleException: ORA-06550: line 1, column 7:
    PLS-00103: Encountered the symbol "ALTER" when expecting one of the following:
    begin case declare exit for goto if loop mod null pragma
    raise return select update while with <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> <<
    close current delete fetch lock insert open rollback
    savepoint set sql execute commit forall merge pipe.

    If I'm not mistaken, we're not allowed to issue DDL inside anonymoue block (or stored procedure) since DDL has implicit commit in it. But you still can execute DDL using EXECUTE IMMEDIATE or using DBMS_SQL package. Try changing your CommandText like this,
    BEGIN
       EXECUTE IMMEDIATE 'ALTER TABLE SYSTEMUSER DISABLE CONSTRAINT FK_USER_CLIENT';
       EXECUTE IMMEDIATE 'ALTER TRIGGER SET_SUBSCRIPTION_SUB_I DISABLE';
    END;Hope this helps,
    [Nur Hidayat|http://nur-hidayat.net/]

  • How to know which user has executed which ddl statement

    Hi All,
    Last week i faced some problem, like some one has truncated the table , so luckily i have the schema backup so i restored it till the last backup taken.
    but i want to know who has executed this ddl statement.
    i know there are some utilities are avaible with oracle, so please describe me the easiest and quickest way to get this.
    Regards
    Asif

    In order of descending simplicity
    - Use the principle of least privilege to restrict the privileges users have in the database to ensure that they cannot do things like truncating a table
    - Enable auditing of potentially problematic statements. This has to be done before the damage is done, though
    - Create a DDL trigger that logs when users issue DDL. This also must be done before the damage is done.
    - Use LogMiner to go through the archived log files that were generated at the time the table was truncated. This assumes that the database is in ARCHIVELOG mode and that you have the archived logs from last week. Using LogMiner to track down the culprit is also likely to be relatively time-intensive
    Justin

  • Executing a DDL statement from java code

    Hi all,
    this is code from jdev11.1.1.3 version. I am trying to execute a DDL statement in oracle db from java code, but "ORA-00900: invalid SQL statement" error is coming.
    I am trying to create a table in same schema in same db by using 'Copy' command.
    Same DDL command is executing from sql command prompt & table is being created. Plz help me , as how to do from java?
            public String cmb_action() {
            // Add event code here...
            try {
                //getting source db connection
                InitialContext initialContext = new InitialContext();
                DataSource ds = (DataSource) initialContext.lookup("java:comp/env/jdbc/SourceConnDS");
                Connection sourceconn = ds.getConnection();
                sourceconn.setAutoCommit(false);
                String sql = "Copy from myschema/mypass@DB insert t_dept using select * from dept;"                       
                Statement stat = sourceconn.createStatement();
                stat.executeUpdate(sql);
                sourceconn.commit();
                System.out.println("done");
              catch (Exception ne) {
                // TODO: Add catch code
                ne.printStackTrace();
            return null;
        }

    I have a requirement to transfer data from one db to another db from Java Application Layer.Maybe, maye not. We get all sorts of weird "requirements" - which are nothing but thoughts or proposed solutions.
    But,
    Did the "requirement" mention whether the table existed already or not in the target database? - If not, did it tell you to create it - drop/create it?
    Did the "requirement" deliver some explanation to why this copying was neeeded? - Are we talking replication? - Or a one time cloning?
    Etc, etc,
    Personally I would always argue against a "reuirement" like that. - It just isn't the way to do it. Period.
    Regards
    Peter
    P.S: If you are satisfied with what COPY does, then you could let Java make an OS call and do it from there?

  • EXECUTE IMMEDIATE dynamic statement and return procedure value

    Hello guys,
    How can i return values from procedure using EXECUTE IMMEDIATE statment?
    I made easy example:
    CREATE OR REPLACE PACKAGE pac_test
    IS
    PROCEDURE pro_calc_average( p_age_1 IN NUMBER,
    p_age_2 IN NUMBER,
    p_age_3 IN NUMBER,
    v_out OUT NUMBER);
    PROCEDURE pro_calc(p_age_1 IN NUMBER,
    p_age_2 IN NUMBER,
    p_age_3 IN NUMBER);
    END;
    CREATE OR REPLACE PACKAGE BODY pac_test
    IS
    PROCEDURE pro_calc_average( p_age_1 IN NUMBER,
    p_age_2 IN NUMBER,
    p_age_3 IN NUMBER,
    v_out OUT NUMBER)
    IS
    BEGIN
    v_out:=(p_age_1+p_age_2+p_age_3)/3;
    END pro_calc_average;
    PROCEDURE pro_calc(p_age_1 IN NUMBER,
    p_age_2 IN NUMBER,
    p_age_3 IN NUMBER)
    IS
    x number;
    v_sql varchar2(4000);
    BEGIN
    v_sql:='pac_test.pro_calc_average('||p_age_1||','||p_age_2||','||p_age_3||',x)';
    dbms_output.put_line(v_sql);
    EXECUTE IMMEDIATE v_sql;
    dbms_output.put_line(' ====> '||x);
    END pro_calc;
    END;
    -- Run procedures [Faild]
    EXEC pac_test.pro_calc(2,9,19);
    When i run:
    DECLARE
    x number;
    BEGIN
    pac_test.pro_calc_average(2,9,9,x);
    dbms_output.put_line(' ====> '||x);
    END;
    It's works, but this is not what i am looking for.
    Thank you guys,
    Sam.

    Hi Sam,
    Like this?
    CREATE OR REPLACE PACKAGE pac_test
    IS
    pac_var number;  /* added new*/
    PROCEDURE pro_calc_average( p_age_1 IN NUMBER,
    p_age_2 IN NUMBER,
    p_age_3 IN NUMBER,
    v_out OUT NUMBER);
    PROCEDURE pro_calc(p_age_1 IN NUMBER,
    p_age_2 IN NUMBER,
    p_age_3 IN NUMBER);
    END;
    CREATE OR REPLACE PACKAGE BODY pac_test
    IS
    PROCEDURE pro_calc_average( p_age_1 IN NUMBER,
    p_age_2 IN NUMBER,
    p_age_3 IN NUMBER,
    v_out OUT NUMBER)
    IS
    BEGIN
    v_out:=(p_age_1+p_age_2+p_age_3)/3;
    END pro_calc_average;
    PROCEDURE pro_calc(p_age_1 IN NUMBER,
    p_age_2 IN NUMBER,
    p_age_3 IN NUMBER)
    IS
    pack_local_var number;
    v_sql varchar2(4000);
    BEGIN
    --v_sql:='pac_test.pro_calc_average('||p_age_1||','||p_age_2||','||p_age_3||',x)';
    v_sql:=' declare x number; begin pac_test.pro_calc_average('||p_age_1||','||p_age_2||','||p_age_3||',x);
    dbms_output.put_line(x);
    pac_test.pac_var:=x; /* added new*/
    end;';
    dbms_output.put_line(v_sql);
    EXECUTE IMMEDIATE v_sql;
    pack_local_var:=pac_var; /* added new*/
    dbms_output.put_line(pack_local_var); /* added new*/
    END pro_calc;
    END;Declared a package variable.
    But be aware this variable is accessible to everyone and they can read or change its value if they have the right privileges.
    REgards,
    Bhushan

  • **URGENT** Problem using execute immediate in a procedure ...

    Hi all,
    I am writing this procedure
    create or replace procedure pr_test is
    begin
    EXECUTE IMMEDIATE 'CREATE or replace view test1 as select * from table_name';
    end ;
    when I execute this procedure even in the same schema who owns this table it gives me this message.
    BEGIN pr_test; END;
    ERROR at line 1:
    ORA-01031: insufficient privileges
    ORA-06512: at "COLIS.PR_TEST", line 3
    ORA-06512: at line 1
    can any body lets me know the solution????
    Thanks in advance
    Take Care !
    Ghulam

    Thank you very much fellows.
    But I have reached at this point that one has to have create view privellege explicitly to create view using a dynamic sql statemetn. Actually I could create the view using SQL*Plus and every thing was working fine through SQL*Plus. But I granted the rights of create user from a user having DBA role.
    Anyways! Thank you very much for contributing this discussion. I really appreciate it.
    Ghulam Mustafa Butt

  • Single quotes problem with execute immediate

    Thanks for considering to solve the issue.
    [i]Situation:
    I am trying to create a procedure to perform a set of operations. As part of that, I am trying to create a table using execute immediate statement. This create table statement has a select sub query where p_LOB3 is the variable for the procedure of datatype varchar2.
    Problem :
    I need to pass the variable p_LOB3 as single quoted as it is of type Varchar2. Also I need to enclose the entire create table query within single quotes. How do I specify this as it is throwing an error when the PL/SQL engine is parsing the single quotes in the query used twice for different purposes as mention earlier.
    Query:
    execute immediate'create table test5 as select min(contract_number)as contract_number,contact_id,max(line_of_business) as line_of_business from mytable group by contact_id having min(contract_number) = max(contract_number) and max(Line_of_business) = 'p_LOB3' ';

    Thank you Todd,
    Is just worked fine.
    New issue is: I am not able to put 2 such statements in a single procedure and execute. Before I give parameters to the procedure, PL/SQL engine is actually creating a view of the mytable and naming is as test5, as a result I am not able to create a table as there is a view with the same name.
    Right now, the workaround I am using is to create three different procedures to create three such tables. I know this is not a good idea....can you please tell me if there is a better way.
    Procedure
    CREATE OR REPLACE PROCEDURE SP_CREATE_0_0(p_LOB1 IN varchar2, p_LOB2 IN varchar2)
    IS
    BEGIN
    execute immediate 'create table test5 as select min(contract_number) as
    contract_number,contact_id,max(line_of_business) as line_of_business from
    mytable group by contact_id having min(contract_number) = max(contract_number)
    and max(Line_of_business) = ' ' ' || p_LOB1 || ' ' ' ';
    execute immediate 'create table test5 as select min(contract_number) as
    contract_number,contact_id,max(line_of_business) as line_of_business from
    mytable group by contact_id having min(contract_number) = max(contract_number)
    and max(Line_of_business) = ' ' ' || p_LOB1 || ' ' ' ';
    END SP_CREATE_0_0;
    /

  • Problem using EXECUTE IMMEDIATE

    Hi,
    I am running the following procedure..
    table emp ( empno number,ename varchar2 , dept varchar2 )
    CREATE OR REPLACE PROCEDURE Sp_Test11 ( p_dept IN VARCHAR2 )
    IS
    m_count               NUMBER               :=     NULL;
    m_sql_query               VARCHAR2(32767) := 'SELECT COUNT(*) INTO m_count FROM emp WHERE dept = ';
    BEGIN
    m_sql_query := m_sql_query||''''||p_dept||''''||';';
         EXECUTE IMMEDIATE m_sql_query ;
    END Sp_Test11;
    I am getting the "Invalid character" error on execute immediate statement when i debug ..
    Please guide.

    venkata wrote:
    Use RETURN or RETURNING INTO Keywords in execute immediate statement.RETURNING INTO is used with INSERT/UPDATE/DELETE statements when there will be triggers that will populate something on the table after an insert or update etc. e.g. when you insert a new record and you want to return the primary key that is automatically generated from a sequence so you can use it in your code for something else.
    If you are SELECTing data then you would use the INTO keyword as Gj demonstrated.
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_cnt number;
      3  begin
      4    execute immediate 'select count(*) from x' returning into v_cnt;
      5* end;
    SQL> /
    declare
    ERROR at line 1:
    ORA-06547: RETURNING clause must be used with INSERT, UPDATE, or DELETE statements
    ORA-06512: at line 4
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_cnt number;
      3  begin
      4    execute immediate 'select count(*) from x' into v_cnt;
      5* end;
    SQL> /
    PL/SQL procedure successfully completed.
    SQL>It's amazing how many people are just jumping in here with wrong answers.

  • Problem in  EXECUTE IMMEDIATE

    I need to update certain columns of a table .
    But the columns are dynamic. i can update 1,20r 3 or more columns of that table.
    I tried executing with the Execute immediate statement.
    But i am getting the error (ORA-01747)
    :1(below in code) Contains the column name along with the values. (Example:Column2=Column2.value,Column3=Column3.value)
    There can be more than 3 or more columns to be updated.
    CREATE OR REPLACE PROCEDURE PR_Bulk_CA(pn_SSCA_ID_VARRAY          BULK_UPDATE_CA_VARRAY
                                          ,pv_set_string              Varchar2
                                          ,pn_success                 OUT number
                                          Is
    sql_stmt  VARCHAR2(32000);
    BEGIN
    sql_stmt:= 'update table_A
                   SET :1
               WHERE  ID IN (select ID from table_A ca
                       where  ca.status in (20700,20710,20720)
                         and  ca.id in (select * from table(:2)))';
    EXECUTE IMMEDIATE sql_stmt USING pv_set_string,pn_SSCA_ID_VARRAY;                     
    COMMIT;
    pn_success:=0;
    EXCEPTION
        WHEN OTHERS THEN
    pn_success:=-1;
    END PR_Bulk_CA;

    So?
    By concatenating the column-name-update-string to the rest of the dynamic statement you get what you want.
    if your pv_set_string has:
      column_a = 17, column_b = 15, column_c = 12in it, the statement generated will handle this...
    I did not state not to do dynamic sql but not to pass the column names using bind variables, as this will not work. The reason therefore is, that the parser need to know the names of the columns to figure out, whether you passed a syntactical correct statement. The parser will not know the content of a bind variable as this is not needed for the syntax (and access rights) check.
    hth

  • EXECUTE IMMEDIATE - DDL

    Can someone explain the reason for why oracle doesnt allow DDL statements to be executed directly in a PL/SQL block?

    DDL statements execute an implicit commit before the statement is executed, and the statement itself is also automatically committed.
    A pl/sql procedure typically should comprise one logical unit of work.
    Both executing DDL and committing every individual record must be considered extreemly poor practice, resulting from brainwashing by the Evil Empire, aka Microsoft, where this is required because the concurrency model is completely different (and unelegant).
    So, if you want to stop being a Ringwraith of Sauron, aka William H Gates III, or his amanuensis Saruman, aka Stephen Ballmer, please never ever issue DDL through a stored procedure.
    Sybrand Bakker
    Senior Oracle DBA

  • Q? Correct way to EXECUTE IMMEDIATE DDL

    Hi All,
    So I'm a little surprised to find that there isn't a builtin feature to "ALTER TABLE x DISABLE ALL CONSTRAINTS". So I'm trying to write a procedure that does that:
    procedure change_local_constraints(p_tablename USER_TABLES.TABLE_NAME%TYPE,
    p_desired_status status_t,
    p_exception_clause exception_t DEFAULT NULL) as
    begin
    <<table_constraints>>
    FOR constraint_rec IN (SELECT constraint_name
    FROM user_constraints
    WHERE table_name = p_tablename
    AND status <> p_desired_status) LOOP
    execute immediate 'ALTER TABLE :i_table :i_status CONSTRAINT :i_constraint :i_exception_clause'
    using p_tablename, p_desired_status, constraint_rec.constraint_name, p_exception_clause;
    END LOOP table_constraints;
    end change_local_constraints;
    Note: that I've defined a couple of subtypes earlier in my package:
    SUBTYPE status_t IS VARCHAR2(10);
    SUBTYPE exception_t IS VARCHAR2(100);
    Note: the exception parameter is for an " EXCEPTIONS INTO MY_EXCEPTION_TABLE " clause.
    When I try to run this I get an error:
    ORA-00903: invalid table name
    I don't want to concatenate my SQL command together as that opens everything up to SQL Injection attacks. On the other hand, it appears that bind variables can't be used in this situation. Or perhaps in any DDL. Does anyone know of a way to do this or see an error in my code?
    Thanks,
    Steven

    1- Concatenating table and constraint name in your code is not going to pose any risk, becuase if table name is incorrect like 'XYZ; DROP TABLE T;' (fear of intejection), for loop will never execute. And your constraint name is coming from the loop.
    2- For p_desired_status you can verify before EXECUTE IMMEDIATE that it contains appropriate keyword only:
    IF p_desired_status NOT IN('ENABLE','DIABLE') THEN
    raise_application_error(-20100,'Invalid syntax');
    END IF;
    3- EXCEPTIONS INTO MY_EXCEPTION_TABLE will always be there, so there's no need to accept it in a parameter. And if it does not always have to be there, you can treat it like p_desired_status.
    Anwar

  • Problem with execute immediate

    hi,
    Oracle gurus,
    when i execute the following statement in a procedure it is not getting executed and it is getting strucked,
    pls provide me some suggestions.
    This is very urgent.
    is there any proble with commented lines?
    EXECUTE IMMEDIATE          'select
                        oh.account_no,
                        p.ord_line_no,
                        o.ord_no,
                        p.lot ,
                        (pr1.each_qty/pr.each_qty),
                        :p_comp_id ,
                        p.cube,
                        sysdate,
                        SYSDATE,--p.pick_date,
                        SYSDATE,--pw.date_time_released,
                        pr.each_qty,
                        :p_ebiz_appown_no,
                        p.ord_cntrl_no,
                        oh.ord_cntrl_no,
                        nvl(p.prod_no,0),
                        :p_ebiz_user_no,
                        nvl(sl.wdth,0) * nvl(sl.dpth,0),
                        decode(s.haz_mat_class,null,''N'',''Y''),
                        ''N'',
                        p.ord_line_no,
                        p.loc,
                        p.lp,
                        (nvl(p.qty,0)/nvl(pr.each_qty,1)),
                        1,
                        (nvl(p.qty,1)/pr1.each_qty),--ceil(nvl(p.qty,1)/pr1.each_qty),
                        oh.ord_prio,
                        oh.ord_type,
                        o.ord_no ,
                        nvl(p.pkg_no,0),
                        :p_task_no,
                        p.pick_line,
                        pl.pickline_type,
                        to_char(nvl(p.transact_id,0)),
                        p.qty ,
                        oh.ord_type,
                        :p_site_id,
                        nvl(s.sku,''SKU ERROR''),
                        s.sku_desc1_35      ,
                        s.prod_fam ,
                        s.prod_cat,
                        o.prod_stat,
                        2 ,
                        SYSDATE,--nvl(p.pick_date,sysdate),
                        bt.task_desc ,
                        bt.task_type,
                        null,--p.pick_date,
                        sl.type_stor_equip ,
                        o.uom,
                        p.wght
                   from      [email protected] pr,
                        mast_abbtype bt,
                        mast_company bc,
                        [email protected] sl,
                        sku@'||l_dblink||' s,
                        picks@'||l_dblink||' p,
                        ordline'||l_dblink||' o,
                        ordhead@'||l_dblink||' oh,
                        prodqty@'||l_dblink||' pr1,
                        pickwave@'||l_dblink||' pw,
                        pickline@'||l_dblink||' pl
                   where      decode(bt.comp_id,null,:p_comp_id,bt.comp_id)=:p_comp_id
                        and decode(bt.site_id,null,:p_site_id,bt.site_id)=:p_site_id
                        and bt.task_type = ''PICK''--decode(null,''PICK'',''PIK'',''PIK'')
                        and bc.delete_flag=''N''
                        and bt.active_flag=''Y''
                        and bc.active_flag=''Y''
                        and bt.delete_flag=''N''                    --and nvl(bc.ebiz_appown_no,-1) = nvl(bt.ebiz_appown_no,-1)
         and nvl(bc.ebiz_appown_no,-1) =1nvl(p_ebiz_appown_no,-1)
                   and nvl(p.failed_pick_flg,''N'') != ''Y''
                   and (bt.site_id =:p_site_id or bt.site_id is null)
                        and p.cmpl_time is not null
                        and p.wave_no = pw.wave_no
                        and s.prod_no = p.prod_no
                   and pr.prod_no = s.prod_no
                        and pr.pkg_no = p.pkg_no
    --and p.ord_cntrl_no in (select ord_cntrl_no from [email protected]  where ord_no = nvl(NULL, ord_no))
    --nvl(p_ebiz_po_no, p.ord_cntrl_no)
    --     and p.ord_cntrl_no = nvl(p_rec_cntrl_no, p.ord_cntrl_no)
         and nvl(p.prod_no,0) = nvl(:p_ebiz_sku_no, nvl(p.prod_no,0))
                   and oh.ord_type = nvl(NULL, oh.ord_type)
                   and nvl(o.prod_stat, ''~'') = nvl(:p_sku_status, nvl(o.prod_stat, ''~''))
                   and p.lp = nvl(:p_lp, p.lp)
                   and nvl(p.lot, ''~'') = nvl(:p_batch_no, nvl(p.lot, ''~''))
                   and pr.logical_case_flg = ''Y''
                   --and nvl(bt.site_id,''~'') = nvl(bc.site_id,''~'')
                   and s.comp_code = p.comp_code
                   and sl.loc = p.loc
              --     and nvl(pick_time,0) != ''9898''
                   and p.ord_cntrl_no = o.ord_cntrl_no
                   and p.ord_line_no = o.ord_line_no
                   and o.ord_cntrl_no = oh.ord_cntrl_no
                   and trunc(p.pick_date) between trunc(nvl(sysdate-10000,p.pick_date)) and trunc(nvl(sysdate,p.pick_date))
                   and nvl(p.pick_date,sysdate)<= nvl(bc.effective_date,sysdate)
                   and p.ord_cntrl_no = decode(null,null,p.ord_cntrl_no,null)
                   and pr1.pkg_no = pr.pkg_no
                   and pr1.prod_no = pr.prod_no
                   and pr1.logical_plt_flg = ''Y'' '
                   --and p.pick_line = pl.line_id      '
         Bulk collect into
                   l_account_no,
                   l_asn_line_no,
                   l_asn_no,
                   l_batch_no,
                   l_cases_per_pallet,
                   l_comp_id,
                   l_cube,
                   l_currdate,
                   l_date_time_ended,
                   l_date_time_started,
                   l_eachs_per_case,
                   l_ebiz_appown_no,
                   l_ebiz_asn_no,
                   l_ebiz_cntrl_no,
                   l_ebiz_sku_no,
                   l_ebiz_user_no,
                   l_footage,
                   l_hazmat_flag,
                   l_intf_conf_flag,
                   l_line_no,
                   l_location,
                   l_lp,
                   l_no_of_cases,
                   l_no_of_units,
                   l_no_plts,
                   l_order_priority,
                   l_order_type,
                   l_ord_no,
                   l_packcode,
                   l_parent_task_no,
                   l_pickline_id,
                   l_pickline_type,
                   l_po_no,
                   l_qty,
                   l_rcv_type,
                   l_site_id,
                   l_sku,
                   l_skudesc1,
                   l_skufam,
                   l_skugroup,
                   l_sku_status,
                   l_status_flag,
                   l_task_date,
                   l_task_desc,
                   l_task_type,
                   l_time,
                   l_type_stor_equip,
                   l_uom_id,
                   l_wght
         using           p_comp_id,p_ebiz_appown_no,p_ebiz_user_no,p_task_no,
                   p_site_id,p_comp_id,p_comp_id,p_site_id,p_site_id,          p_site_id,p_ebiz_sku_no,p_sku_status,p_lp,p_batch_no;
    regards RR.

    hi,
    again iam sending the same query for ur easy reference.
    pls treat it urgent.
    EXECUTE IMMEDIATE 'select
    oh.account_no,p.ord_line_no,     o.ord_no,     p.lot ,
    (pr1.each_qty/pr.each_qty),     :p_comp_id ,p.cube,
    sysdate,     SYSDATE,--p.pick_date,     SYSDATE,--pw.date_time_released,
    r.each_qty,:p_ebiz_appown_no,     p.ord_cntrl_no,oh.ord_cntrl_no,
    nvl(p.prod_no,0),     :p_ebiz_user_no,nvl(sl.wdth,0) * nvl(sl.dpth,0),
    decode(s.haz_mat_class,null,''N'',''Y''),''N'',p.ord_line_no,p.loc,p.lp,
    (nvl(p.qty,0)/nvl(pr.each_qty,1)),     1,
    (nvl(p.qty,1)/pr1.each_qty),--ceil(nvl(p.qty,1)/pr1.each_qty),
    oh.ord_prio,     oh.ord_type,o.ord_no ,nvl(p.pkg_no,0),
    :p_task_no,p.pick_line,pl.pickline_type,     to_char(nvl(p.transact_id,0)),
    p.qty ,     oh.ord_type,:p_site_id,     nvl(s.sku,''SKU ERROR''),
    s.sku_desc1_35      ,     s.prod_fam ,     s.prod_cat,
    o.prod_stat,     2 ,     SYSDATE,--nvl(p.pick_date,sysdate),
    bt.task_desc ,bt.task_type,     null,--p.pick_date,sl.type_stor_equip ,
    o.uom,     p.wght
    FROM
    [email protected] pr,
    mast_abbtype bt,
    mast_company bc,
    [email protected] sl,
    sku@'||l_dblink||' s,
    picks@'||l_dblink||' p,
    ordline'||l_dblink||' o,
    ordhead@'||l_dblink||' oh,
    prodqty@'||l_dblink||' pr1,
    pickwave@'||l_dblink||' pw,
    pickline@'||l_dblink||' pl
    WHERE
    decode(bt.comp_id,null,:p_comp_id,bt.comp_id)=:p_comp_id
    and decode(bt.site_id,null,:p_site_id,bt.site_id)=:p_site_id
    and bt.task_type = ''PICK''--decode(null,''PICK'',''PIK'',''PIK'')
    and bc.delete_flag=''N''
    and bt.active_flag=''Y''
    and bc.active_flag=''Y''
    and bt.delete_flag=''N''
    and nvl(p.failed_pick_flg,''N'') != ''Y''
    and (bt.site_id =:p_site_id or bt.site_id is null)
    and p.cmpl_time is not null
    and p.wave_no = pw.wave_no
    and s.prod_no = p.prod_no
    and pr.prod_no = s.prod_no
    and pr.pkg_no = p.pkg_no
    and nvl(p.prod_no,0) = nvl(:p_ebiz_sku_no, nvl(p.prod_no,0))
    and oh.ord_type = nvl(NULL, oh.ord_type)
    and nvl(o.prod_stat, ''~'') = nvl(:p_sku_status, nvl(o.prod_stat, ''~''))
    and p.lp = nvl(:p_lp, p.lp)
    and nvl(p.lot, ''~'') = nvl(:p_batch_no, nvl(p.lot, ''~''))
    and pr.logical_case_flg = ''Y''
    and s.comp_code = p.comp_code
    and sl.loc = p.loc
    and p.ord_cntrl_no = o.ord_cntrl_no
    and p.ord_line_no = o.ord_line_no
    and o.ord_cntrl_no = oh.ord_cntrl_no
    and trunc(p.pick_date) between trunc(nvl(sysdate-10000,p.pick_date)) and trunc(nvlsysdate,p.pick_date))
    and nvl(p.pick_date,sysdate)<= nvl(bc.effective_date,sysdate)
    and p.ord_cntrl_no = decode(null,null,p.ord_cntrl_no,null)
    and pr1.pkg_no = pr.pkg_no
    and pr1.prod_no = pr.prod_no
    and pr1.logical_plt_flg = ''Y'' '
    Bulk collect into
    l_account_no,
    l_asn_line_no,
                   l_asn_no,
                   l_batch_no,
                   l_cases_per_pallet,
                   l_comp_id,
                   l_cube,
                   l_currdate,
                   l_date_time_ended,
                   l_date_time_started,
                   l_eachs_per_case,
                   l_ebiz_appown_no,
                   l_ebiz_asn_no,
                   l_ebiz_cntrl_no,
                   l_ebiz_sku_no,
                   l_ebiz_user_no,
                   l_footage,
                   l_hazmat_flag,
                   l_intf_conf_flag,
                   l_line_no,
                   l_location,
                   l_lp,
                   l_no_of_cases,
                   l_no_of_units,
                   l_no_plts,
                   l_order_priority,
                   l_order_type,
                   l_ord_no,
                   l_packcode,
                   l_parent_task_no,
                   l_pickline_id,
                   l_pickline_type,
                   l_po_no,
                   l_qty,
                   l_rcv_type,
                   l_site_id,
                   l_sku,
                   l_skudesc1,
                   l_skufam,
                   l_skugroup,
                   l_sku_status,
                   l_status_flag,
                   l_task_date,
                   l_task_desc,
                   l_task_type,
                   l_time,
                   l_type_stor_equip,
                   l_uom_id,
                   l_wght
         using           p_comp_id,p_ebiz_appown_no,p_ebiz_user_no,p_task_no,
         p_site_id,p_comp_id,p_comp_id,p_site_id,p_site_id,          p_site_id,p_ebiz_sku_no,p_sku_status,p_lp,p_batch_no;
    here l_dblink contains database link
    regards
    RR

  • Problem with execute immediate code

    I have the following anonymous block:
    declare
    v_id_char varchar2(50) := '2072018827821663';
    trace_flg number := 0;
    v_exe_imm varchar2(500) := 'univdb.EML_CAMPUS_200605(v_id_char, trace_flg)';
    v_exe_imm2 varchar2(500) := 'univdb.EML_CAMPUS_200605(:v_id_char, :trace_flg)';
    begin
    --1) execute immediate v_exe_imm;
    --2) execute immediate v_exe_imm2 using v_id_char, trace_flg);
    univdb.EML_CAMPUS_200605(v_id_char, trace_flg);
    end;
    The compiled procedure that is getting called is defined like this:
    CREATE OR REPLACE PROCEDURE univdb.eml_campus_200605(
    hist_str IN VARCHAR2,
    trace_flg IN NUMBER := 0) IS ...
    As you might expect, when I execute the block without execute immediate it works.
    But either of the execute immediate statements results in ORA-00900: invalid SQL statment.
    I want to use execute immediate because the procedure that gets called will need to be dynamic.
    Help appreciated,
    ...elsa

    For me, thats crude if you have a procedure thats
    getting created dynamically.
    anyway, you could try a
    execute immediate ' begin ' || your_funny_proc || '
    end;';But for sure the whole stuff is very error prone.Actually, the procedure itself isn't getting built dynamically, only which procedure to call. It's really quite clever in my opinion.
    Anyway, I tried you suggestion:
    declare
    v_id_char varchar2(50) := '2072018827821663';
    trace_flg number := 0;
    v_exe_imm varchar2(500) := 'univdb.EML_CAMPUS_200605(v_id_char, trace_flg)';
    v_exe_imm2 varchar2(500) := 'univdb.EML_CAMPUS_200605(:v_id_char, :trace_flg)';
    begin
    execute immediate 'BEGIN ' || v_exe_imm || '; END;';
    --execute immediate v_exe_imm2 using v_id_char, trace_flg);
    --univdb.EML_CAMPUS_200605(v_id_char, trace_flg);
    end;
    and got
    ORA-06550: line 1, column 32:
    PLS-00201: identifier 'V_ID_CHAR' must be declared
    Did I misunderstand what you were trying for?

  • Problems with execute immediate

    HELLO :
    How can I execute a procedure (with input , output parameters ) , in another schema??
    I have the following code :
    V_SENTENCIA:= 'begin '||v_schema_name|| .DAR_ID('||V_CODE||',:p1); END;';
    EXECUTE IMMEDIATE V_SENTENCIA INTO V_Num
    and the declaration on my proc is the following :
    CREATE PROCEDURE DAR_ID ( p_1 in varchar2 ,p_2 out NUMBER) IS
    NUM NUMBER (5,0);
    BEGIN
    SELECT count (id) INTO p_2 FROM Veh WHERE (Param1=p_1)
    END ;
    Can anyone help me please ?

    Hey,
    this one will work:
    SQL> create or replace procedure pp(p_arg in varchar2, p_res out number)
    2 is
    3 begin
    4 select 1 into p_res from dual where p_arg = '1';
    5 end;
    6 /
    Procedure created
    SQL> set serveroutput on
    SQL> declare
    2 l_ret number;
    3 begin
    4 execute immediate 'begin pp(:p_arg, :l_ret); end;' using
    5 in '1', out l_ret;
    6 dbms_output.put_line(l_ret);
    7 end;
    8 /
    1
    PL/SQL procedure successfully completed
    from a remote db:
    SQL> set serveroutput on;
    SQL>
    SQL> declare
    2 l_ret number;
    3 begin
    4 execute immediate 'begin pp@to_remote(:p_arg, :l_ret); end;'
    5 using in '1', out l_ret;
    6 dbms_output.put_line(l_ret);
    7 end;
    8 /
    1
    PL/SQL procedure successfully completed
    Amiel.

  • Maximum execute immediate commands in a procedure

    Hi All,
    I have written a procedure and my database size is 2 million records. i want to check for all special characters, as shown in my procedure. Is it possible to check for all special charachers like &39 to &255 checked within one single procedure. In that situation maximum immediate commands will be about 500.
    I am sending my procedure just for one of the charachters.
    CREATE or REPLACE PROCEDURE SPECIAL_YPOL1 (TABLENAME IN VARCHAR2,fieldname IN VARCHAR2)
    AUTHID CURRENT_USER
    IS
    TYPE YPOLCurTyp IS REF CURSOR;
    YPOL_cur      YPOLCurTyp;
    sqlSt      LONG;
    THEFIELD      VARCHAR2(250);
    BEGIN
    -- CHR(38)||39,
    SQLST:= 'SELECT ' || UPPER(fieldname) ||' FROM '|| UPPER(TABLENAME) ;
              SQLST:=SQLST ||' WHERE ' || UPPER(fieldname) ||' LIKE ''%'' || CHR(38)|| ''39,%''';
                   BEGIN
                        EXECUTE IMMEDIATE SQLST;
                        EXCEPTION WHEN OTHERS THEN
                        NULL;
                   END;
         OPEN YPOL_CUR FOR SQLST;
         LOOP
              FETCH YPOL_CUR INTO THEFIELD;
                   EXIT WHEN YPOL_cur%NOTFOUND OR YPOL_cur%NOTFOUND IS NULL;
                        SQLST:='UPDATE '||upper(UPPER(TABLENAME)) || ' SET '||UPPER(UPPER(fieldname)) ||' =REPLACE(' ||UPPER(fieldname)||','''||CHR(38) ||'39,'',CHR(39))';
                        SQLST:=SQLST||' WHERE '||UPPER(fieldname) ||' LIKE ''%'' ||CHR(38) || ''39,%''';
                   BEGIN
                        EXECUTE IMMEDIATE SQLST;
                        EXCEPTION
                             WHEN OTHERS THEN
                             DBMS_OUTPUT.PUT_LINE('ERROR2');
                   END;
         END LOOP;
    COMMIT;
    END SPECIAL_YPOL1;
    /

    You can use one more loop for that and catch all the special characters.
    SQL> ;
      1  begin
      2      for i in 38..255 loop
      3         dbms_output.put_line(chr(i));
      4      end loop;
      5* end;
    SQL> /
    +
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    <
    =
    >
    A
    B
    C
    D
    E
    F
    G
    H
    I
    J
    K
    L
    M
    N
    O
    P
    Q
    R
    S
    T
    U
    V
    W
    X
    Y
    Z
    ^
    `
    a
    b
    c
    d
    e
    f
    g
    h
    i
    j
    k
    l
    m
    n
    o
    p
    q
    r
    s
    t
    u
    v
    w
    x
    y
    z
    |
    ~
    PL/SQL procedure successfully completed.
    SQL> Cheers
    Sarma.

Maybe you are looking for

  • Missing Mail Rules after upgrade to 10.8.2 from 10.6.8

    The title says it all, really - I just upgraded to 10.8.2 via the App Store from 10.6.8, and, after a long period of re-indexing my email, Mail.app opened up and all of my sorting rules were gone  gone gone. There doesn't seem to be an easily findabl

  • Error messages in modem/router event log

    Share on facebook Share on twitter Share on email Share on print More Sharing Services 2  Hi folks.  Just purchased a new wireless cable modem/router from Telstra (Gateway Max - Netgear C6300BD-1TLAUS).  I've just noticed the following messages in th

  • How can I find a segment name from p1 and p2 value of v$session??

    Hi, all. A session is waiting with "gc cr request". The pvalue of the session are as followings. p1text p1 p2text p2 p3text p3 file# 15 block# 412 id# 33619969 I issued the following sql statement to find the segment name. select segment_name from db

  • Sales Order Punching Through Bapi

    Hi Experts, I have got an assignment of doing Salesorder punching in portal and through web dynpro. I have used BAPI_SALESORDER_GETLIST through RFC connection. But can you tell me what diffrent Bapi's will be required for my task and where relevant d

  • Can't add anything on top full motion clip

    I have several full motion clips in my simulation. Each has some sensitive information I want to block out by inserting a Highlight Box. I've done this on several of my full motion clips with no problem. However, I have one clip that simply will not