Results 1 to 5 of 5

Thread: stored procedures

  1. #1
    Junior Member
    Join Date
    Jun 2008
    Answers
    10

    stored procedures

    Hi all
    i have a table called dbo.priorites which contains 2 columns
    _codepriorite varchar (20) primary key
    _priorite varchar (50) null

    so i was asked to change _codepriorite varchar (20) into _codepriorite int(4)

    it worked with this script

    alter table dbo.priorites
    drop constraint pk_priorites
    go

    alter table dbo.priorites
    drop column _codepriorite
    go

    alter table dbo.priorites
    add _codepriorite int identity
    go

    alter table dbo.priorites
    add primary key (_codepriorite)
    go


    i wanna use this script from the compiler , like with stored procedures... I wanna call this script from the software im working with... Any ideas on how to do it? ill be thankful for some help...

    Last edited by ronaldrahme; 07-01-2008 at 07:47 AM.

  2. #2
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: stored procedures

    Do you want to write general script or script specific to this table only?

    If it is a general script pass table name and column name as parameter.

    You can't execute DDL statements directly in procedures. Use EXECUTE IMMEDIATE to execute above statemetns in procedure.


  3. #3
    Junior Member
    Join Date
    Jun 2008
    Answers
    10

    Re: stored procedures

    Thnks krishna for your help
    i made a stored proceduren i checked the syntax, it was okay:

    create procedure sp_priorites

    as
    execute immediate
    alter table dbo.priorites
    drop constraint pk_priorites
    go

    execute immediate
    alter table dbo.priorites
    drop column _codepriorite
    go

    execute immediate alter table dbo.priorites
    add _codepriorite int identity
    go

    execute immediate
    alter table dbo.priorites
    add primary key (_codepriorite)
    go

    do you think it might work this way?


  4. #4
    Junior Member
    Join Date
    Jun 2008
    Answers
    10

    Re: stored procedures

    oops its not workin, just another kst> how to use execute immediate? its not working for the above statements


  5. #5
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: stored procedures

    Here is the example

    Code:
     
    create or replace procedure test_proc as 
    string varchar2(100); 
    
    begin 
    string := ' alter table test_data add constraint test_data_pk primary key (x)'; 
    execute immediate string; 
    end; 
    /



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact