Calling a DDL in a procedure

I am setting up a job in the database (81741 on windows2000)as:
insert into orig_backup select * from orig;
truncate table orig;
Db wouldn't let me do this 'cause truncate is a DDL. And, delete (instead of truncate) wouldn't help me much because it just deletes the row, not shrink the size of the orig table. My main aim is to shrink the size of the table by moving the data to backup table & then truncate.
Any inputs would be appreciated.
Thanks.

You can use the Oracle supplied package DBMS_SQL to parse and run just about any DDL sql, such as creating, dropping and truncating tables. Here is a an example which I just used succesfully on Oracle 8.0.6...
CREATE OR REPLACE PROCEDURE TRUNCATE_TABLES (TABLE_NAME IN VARCHAR)
-- This function truncates the table with the name passed in.
-- Make sure that the variable to take in the return value is long enough to do so
IS
cur_id INTEGER;
rows_processed NUMBER;
BEGIN
cur_id := dbms_sql.OPEN_CURSOR;
dbms_sql.PARSE(cur_id, 'TRUNCATE TABLE ' || TABLE_NAME, dbms_sql.native);
rows_processed := dbms_sql.execute(cur_id);
dbms_sql.CLOSE_CURSOR(cur_id);
dbms_output.put_line('Truncated ' || TABLE_NAME);
EXCEPTION
WHEN OTHERS
THEN
dbms_sql.CLOSE_CURSOR(cur_id);
dbms_output.put_line('Failed to truncate ' || TABLE_NAME);
END;

Similar Messages

  • Calling SQL * LOADER  in stored procedure

    Hi Experts,
    Can we call sql*loader in stored procedures? . If yes , please let me know the syntax.
    Any help will be highly appreciated.
    Thanks.

    You can also use dbms_schedular to execute any shell or batch file - i guess ->
    BEGIN
      -- UNIX
      DBMS_SCHEDULER.create_job(
        job_name             => 'unix_command_job',
        job_type             => 'EXECUTABLE',
        number_of_arguments  => 1,
        job_action           => '/bin/ls',
        auto_drop            => FALSE,
        enabled              => FALSE);
      DBMS_SCHEDULER.set_job_argument_value('unix_command_job',1,'/tmp');
      DBMS_SCHEDULER.set_attribute('unix_command_job', 'credential_name', 'TIM_HALL_CREDENTIAL');
      DBMS_SCHEDULER.set_attribute('unix_command_job', 'destination', 'marge.localdomain:65001');
      DBMS_SCHEDULER.enable('unix_command_job');
    END;For details ->
    http://www.oracle-base.com/articles/11g/SchedulerEnhancements_11gR1.php
    http://www.oradev.com/dbms_scheduler.jsp
    http://www.psoug.org/reference/dbms_scheduler.html
    Regards.
    Satyaki De.

  • How to call sqlldr utility in stored procedure

    Hi,
    i want to call sqlldr exe from stored procedure.
    Regards,
    Tushar Josih

    user12044491 wrote:
    currently i am working on oracle release 10g R2.
    i am not very much sure whether all CTL option are available in the external table.Before you decide on the method you should clearly understand the following. SQL*Loader is client side tool while job and external table are server side tools. Therefore, unless you are connecting to oracle from database server or file you are loading is accessible from database server, neither job nor external table will help you. And now back to your question - yes, not all SQL*Loader features are available for external tables but most of the time there is a way around it.
    SY.

  • How to call PL-SQL script/stored procedure from Java?

    Assume I want to call a PL-SQL stored procedure from external Java program.
    How can I do this?
    Is there a simple "Hello world" example for this?
    Peter

    This forum is for Oracle only not for java
    Ug

  • How to call PL-SQL script/stored procedure from BPEL?

    Assume I want to call a PL-SQL stored procedure from BPEL.
    How can I do this?
    Is there a simple "Hello world" example for this?
    Peter

    The database adapter supports calling stored procedures. There is an example called "File2StoredProcedure" that you can use as a reference to get started.

  • Calling a Function inside a procedure

    Can you call a function inside a procedure?...if so....how?

    Not all built-in functions can be used directly in an assignment.
    SQL> CREATE PROCEDURE p (p_val IN VARCHAR2) AS
      2  l_v VARCHAR2(10);
      3  BEGIN
      4     l_v := DECODE(p_val,'YES','TRUE','FALSE');
      5  END;
      6  /
    Warning: Procedure created with compilation errors.
    SQL> show error
    Errors for PROCEDURE P:
    LINE/COL ERROR
    4/4      PL/SQL: Statement ignored
    4/11     PLS-00204: function or pseudo-column 'DECODE' may be used inside
             a SQL statement onlyTTFN
    John

  • Function called by what PL SQL procedure

    Hello.
    I want to see all the callers of a PL SQL function. I know it is called by some PL SQL procedures in a package. How do I see who calls the function?
    Thanks.

    i think you can try this : select * from
    user_dependencies where type = 'FUNCTION' actually, that what should what things are referenced by your function
    and you'd be better off with ALL_DEPENDENCIES, since references can cross schemas.
    select name, type from all_dependencies
    where referenced_owner= 'ME'
    and referenced_name= 'MY_FUNCTION'
    and referenced_type ='FUNCTION'
    this will show what other things are using your function. if it's used by a package, it will not show the exact procedure or function within that package.

  • How to call a sql server stored procedure from oracle

    Hi all,
    Please anybody tell me how to call a sql server stored procedure from oracle.
    I've made an hsodbc connection and i can do insert, update, fetch data in sql server from oracle. But calling SP gives error. when I tried an SP at oracle that has line like
    "dbo"."CreateReceipt"@hsa
    where CreateReceipt is the SP of sql server and hsa is the DSN, it gives the error that "dbo"."CreateReceipt" should be declared.
    my database version is 10g
    Please help me how can i call it... I need to pass some parameters too to the SP
    thanking you

    hi,
    thank you for the response.
    when i call the sp using DBMS_HS_PASSTHROUGH, without parameters it works successfully, but with parameters it gives the following error
    ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
    [Generic Connectivity Using ODBC][Microsoft][ODBC SQL Server Driver]Invalid parameter number[Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index (SQL State: S1093; SQL Code: 0)
    my code is,
    declare
    c INTEGER;
    nr INTEGER;
    begin
    c := DBMS_HS_PASSTHROUGH.OPEN_CURSOR@hsa;
    DBMS_HS_PASSTHROUGH.PARSE@hsa(c, 'Create_Receipt(?,?)');
    DBMS_HS_PASSTHROUGH.BIND_VARIABLE@hsa(c,1,'abc');
    DBMS_HS_PASSTHROUGH.BIND_VARIABLE@hsa(c,2,'xyz');
    nr:=DBMS_HS_PASSTHROUGH.EXECUTE_NON_QUERY@hsa(c);
    DBMS_HS_PASSTHROUGH.CLOSE_CURSOR@hsa(c);
    end;
    Create_Receipt is the sp which requires two parameters.
    please give me a solution
    thanking you
    sreejith

  • How to create a sequence DDL in a procedure

    Hello,
    i have a simple question but i dont find a solution here.
    How to create a sequence DDL in a procedure ?
    Thank 's

    Use Native Dynamic Sql. Look at the EXECUTE IMMEDIATE command.
    declare
    begin
       execute immediate 'create sequence xx_seq ';
    end;
    /Of course you need explicit permission to create a sequence. NOT through a ROLE.

  • Urgent : while calling a pl/sql stored procedure I am getting this error.

    Error iam getting like this:
    IDALException: ORA-06550: line 1, column 7: PLS-00201: identifier 'BORGPURCHASEDELEGATION_SEL' must be declared ORA-06550: line 1, column 7: PL/SQL: Statement ignored [ com.commerceone.ebs.infra.dal.idal.BasicSQL.oracleExceptionHandler(BasicSQL.java:863)]
    ADALException: Default Message[ com.commerceone.ebs.infra.dal.adal.Adal.execute(Adal.java:765)]
    ADALException: Default Message[ com.commerceone.ebs.infra.dal.adal.Adal.executeEbo(Adal.java:605)]
    BusinessFatalException: Default Message[ com.commerceone.ebs.wf.business.PurchaseBorgDelegation.getData(PurchaseBorgDelegation.java:483)]
    CommandException: Default Message[ com.commerceone.ebs.apps.profile.command.UserProfilePurchaseDelegationSaveCmd.execute(UserProfilePurchaseDelegationSaveCmd.java:124)]
    ActionException: Default Message[ com.commerceone.ebs.apps.base.action.ActionImpl.executeCommand(ActionImpl.java:107)]
    JobException: Default Message[ com.commerceone.ebs.apps.ui.WebJobImpl.executeAction(WebJobImpl.java:115)]
    JobException: Default Message[ com.commerceone.ebs.apps.ui.BuyerJob.executeAction(BuyerJob.java:750)]
    JobException: Default Message[ com.commerceone.ebs.apps.ui.BuyerJobWrapper.run(BuyerJobWrapper.java:64)]
    Thanks
    raji

    This has happened to me when I do not have the proper grants and/or synonyms set up. My JDev/J2EE connection user does not own the database objects so I need to grant access to the database object owner's database account and create synonyms available to the connection user's database account. If you are using the same database account in your JDev/J2EE connection object as you are using to run the stored proc in SQL*Plus, this is not your problem.
    I would test each part of the database involvement. For example, if you create a database view (with no additional grants or synonyms) in the user account that owns that stored procedure, can you create an ADF BC view object from that view in JDev and can you run the BC tester in JDev on it? If so, the connection user and object owner user accounts are probably the same.
    Another thing to try is, instead of executing the stored procedure, do something like this:
    stmt = "DECLARE v_dummy; BEGIN SELECT 1 INTO v_dummy FROM dual; END;";If that works, your calling mechanism for the stored procedure works.

  • Calling java classes from plsql procedures

    I'm attempting to call java classes from plsql procedures which will create cmsdk users, folders, groups etc, however when I attempt to load a java class into the oracle schema using the command:
    loadjava -user user/password@database -resolve classname.class
    It generates error messages to the effect that classes (cmsdk classes) required by the class cannot be found. The class is loaded and marked with the status "invalid". Is it therefore necessary for me to load the cmsdk packages into the schema?
    Cheers
    David

    Using CMSDK Java API within the database has never been supported
    (see Problems loading IFS's java class into database
    When we needed to invoke CMSDK code from our PL/SQL code, we used one of two approaches:
    (1) use advanced queues to send requests to an external Java program (the CMSDK code, running outside the database) and receive the results back (asynchronous choice); or
    (2) make an HTTP request to a Java servlet (the CMSDK code, running in some Java web container like iAS) and get the response back in some custom format (XML or something) (synchronous choice).
    It seems to me that the CMSDK Java API was designed to be used only in middle-tier, not in database tier.
    Regards,
    Daniel.

  • Obtaining HTML page by issuing a call from a PL/SQL procedure

    Is there any possibility to obtain HTMLDB -> HTML page from a user defined PL/SQL procedure ?
    For example I build an procedure which calls directly
    flows_010500.wwv_flow.show(null,p_flow_step_id=>'2',p_flow_id=>'104')
    and i try to read the result from htp.showpage, but I get a html response page with a security error.
    Maybe is necessary to initialize other parameters?
    Any help?

    Scott, I have got two pages in an application one is login page the other is welcome page. my login page will be process by store proceduer to validate the user based on users table that I have created on my schema. If the user login with username and password, if they exist on this table I will like to send them to welcome page. but I get http://htmldb.oracle.com/pls/otn/wwv_flow.accept.
    The page cannot be found
    The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.
    Please try the following:
    If you typed the page address in the Address bar, make sure that it is spelled correctly.
    Open the htmldb.oracle.com home page, and then look for links to the information you want.
    Click the Back button to try another link.
    Click Search to look for information on the Internet.
    HTTP 404 - File not found
    Internet Explorer
    the procedure is below:
    CREATE OR REPLACE PROCEDURE obj_pls_login_chk(p_UserName IN varchar2
    ,p_Password IN varchar2
    ,Login IN varchar2 ) IS
    l_usr_id number;
    l_url varchar2(2000);
    BEGIN
    l_url := 'http://htmldb.oracle.com/pls/otn/f?';
    select user_id into l_usr_id
    from s_cdm_users
    where upper(username) = upper(p_UserName)
    and upper(Password) = upper(p_Password);
    if l_usr_id is not null then
    l_url := l_url||'p=29921:2:4413779570974471450';
    --wwv_flow.show(null,p_flow_step_id=>'29921',p_flow_id=>'29921:2');
    --htp.print(p_UserName);
    end if;
    EXCEPTION
    when others then
    return;
    END

  • Call a pl/sql stored procedure from a report link

    Hello everyone:
    I have a report with a link in a column, which takes you to another page and passes values to that page, but also need the link, run a stored procedure before going to the other page.
    In the Forum I found cases similar to this, but none of the examples is clear to me how I do this. It seems that the target of the link should be URL, and also I have to call the stored procedure with a javascript function.
    My questions are:
    - Is this the best method to make what I need?
    - How should be the syntax of the link that takes me to another page and run the "stored procedure"
    - How and where I put the function "javascript" to run the "stored procedure"
    BDD: Oracle 11 g
    Apex version 4.1
    Best regards
    Gerard

    Hi,
    Change the link to call an apex.submit process. (javascript).
    Edit:
    I've set up a basic example.
    Region 1 (just so you can see the value getting set):
    select :P27_HIDDEN item_Value
    from dual
    Region 2:
    select rownum id, dbms_random.string('U', 12) sss
    from dual
    connect by level <= 20
    item attributes for ID:
    Target: URL
    URL: javascript:apex.submit({request:'NAVIGATE', set:{'P27_HIDDEN':#ID#}});
    (P27_HIDDEN is just a hidden item i created)
    http://apex.oracle.com/pls/apex/f?p=54920:27
    Edit2:
    In your case, then you can just have a page process based on conditions request = expression1, expression1: NAVIGATE..... then a page branch to go to the desired page, also with the same conditions
    Edit3:
    Im not sure what examples you are referring to , as you didn't supply any links; but you mention calling the stored procedure from javascript, so would likely involve some AJAX, but imo not necessary.

  • How can I call a function from a procedure

    I have a function named: f_calc_value which return the variable v_result. This function is part of a package.
    How can I call this function from a new procedure I am creating?
    Thanks

    or refer this theread....calling function from procedure

  • How can i call a shell script from procedure

    I have a shell script.now i am i a situation to call that shell script from one of my procedures and need to get a value from that script.
    can u suggest me that how can a call the shell script from pl/sql?

    Is the same question you asked here
    How to call Shell Script from pl/sql block
    -SK

Maybe you are looking for

  • How to reinstall Safari using Yosemite

    Safari is frozen after openingk with a constant "rainbow circle" spinning, How do I redownload Safafi? Do I have to reinstall Yosemite?

  • Webdynpro ABAP/Portal. Plugin HTTP connection issue on WaitingEventQueue.js

    Hello, We are experiencing a strange Portal Behavior with our Webdynpros. Our portal contains several iViews including some Webdynpro (ABAP) and some reporting transaction calls that use SAPgui for HTML. When portal is called for the first time and a

  • Is iphone JAVA-capable for Cingular Remote Monitoring?

    AT&T/Cingular has a service called Remote Monitor that lets you put up cameras, motion sensors etc at a site and monitor them remotely using the internet or a java-based application that you can download to a Cingular phone. Great for monitoring a 2n

  • Deactivated "Calculate Gross Profit"

    Hello everyone. I've searched in the notes and in the forum for this topic but couldn't find it. I would be happy to be redirected to answer of my question below: We have a client who migrated from 2007A to 8.8 PL 20. The "Calculate Gross Profit" was

  • E71 photo zoom, full screen & video full screen sh...

    anyone know any short key for this? my old nokia 6630 can zoom photo with pressing key #5. full screen photo with key *key, video full screen with pressing key #2. does E71 have these short key? Solved! Go to Solution.