Alter Statement in Select

Can we write an alter statement in Select Query?

Dynamic sql
SQL> create table t_al (al number(10));
Table created.
SQL>
DECLARE
   v_al   VARCHAR2 (200);
BEGIN
    select 'alter table t_al modify al varchar2(20)' into v_al from dual;
execute immediate v_al;
end;
PL/SQL procedure successfully completed.
SQL> desc t_al;
  AL  VARCHAR2(20 CHAR)

Similar Messages

  • SQL Statement within alter statement

    Has anybody used a sql statement inside of an alter statement?
    example:
    alter index index_name rebuild;
    trying to get the index_name by doing the following:
    alter index '|| select index_name from user_ind_columns ||' rebuild;
    Thank you.

    Are you trying to generate a script ?
    I think it would be more like :-
    select 'alter index '||owner||'.'||index_name||' rebuild;' from dba_indexes where owner = 'MYUSER';

  • How to use the alter statement in Execute

    Hi All,
    Need your help to solve this issue.
    i want the call the alter statement in procedure to load data to the external table.
    As per our requirement location will be given as a input parameter.
    Created procedure as shown below
    CREATE OR REPLACE PROCEDURE apps.rda_cm_postaova_stmt_main (
    p_process_name IN VARCHAR2,
    p_file_name IN VARCHAR2,
    p_submit_option IN VARCHAR2
    AS
    BEGIN
    EXECUTE IMMEDIATE 'ALTER TABLE RDA_POSTOVA_BANK_STMT location' || (p_file_name);
    END;
    it compiled but while executing it end up in below error:
    ORA-01735: invalid ALTER TABLE option
    ORA-06512: at "APPS.RDA_CM_POSTAOVA_STMT_MAIN", line 8
    ORA-06512: at line 2
    Please help to solve this issue.
    Thanks
    Rajesh

    create or replace procedure reset_et_location
    ( p_table    in varchar2
    , p_filename in varchar2)
    is
    begin
      execute immediate 'alter table '||p_table||' location ('''||p_filename||''')';
    end reset_et_location;

  • In a SQL statement, the SELECT clause is used to

    In a SQL statement, the SELECT clause is used to select
    (a) columns
    (b) rows
    (c) tables
    (d) none of the above
    can any one help Immediately

    Is used to select rows of specified column...
    SELECT column_name(s) FROM table_name

  • How to convert update,delete statement into select stmt

    Hi all,
         I have a field called dml_stmt, i am getting the dml statement has input from the user.
         My requirement is, if user is giving "update set col_name = 'xyz' from table_name where codition = 'aa'", before updating the table, i need to get old values from the table and put it in the audit table
         For that,i need to convert those update statement into select stmt and need to execute the query to get the data and then i will put it in the audit table..
         can anyone guide how to convert the update or delete stmt into select(need to write in pl/sql)
    Please do needfull things ......
    Regards,
    Jame

    Maybe I'm missing something, but why would auditing help here? It sounds like the user wants to know the prior values of the data, not the SQL UPDATE statement that was issued. Auditing would tell you that a table was updated, fine-grained auditing would tell you what the UPDATE statement was, but you'd need something else to capture the state of the data prior to the update.
    Depending on why putting triggers on every table was discounted, you may also want to take a look at using Workspace Manager or Total Recall (in 11g) to track a history of data changes. But triggers would be the common solution to this sort of problem.
    Justin

  • Difference between "print" statements and "select" statements , TSQL

     What is the difference between "print" statements and "select" statements when it omces to debugging and watching varibles in the stored procs .....

    SELECT statement is part of the ANSI SQL language.
    PRINT command is not part of the SQL language, it is used for debugging in T-SQL.
    BOL:" Returns a user-defined message to the client.
    A message string can be up to 8,000 characters long if it is a non-Unicode string, and 4,000 characters long if it is a Unicode string. Longer strings are truncated. The
    varchar(max) and nvarchar(max) data types are truncated to data types that are no larger than
    varchar(8000) and nvarchar(4000).
    RAISERROR can also be used to return messages. RAISERROR has these advantages over PRINT:
    RAISERROR supports substituting arguments into an error message string using a mechanism modeled on the printf function of the C language standard library.
    RAISERROR can specify a unique error number, a severity, and a state code in addition to the text message.
    RAISERROR can be used to return user-defined messages created using the sp_addmessage system stored procedure."
    LINK: http://technet.microsoft.com/en-us/library/ms176047.aspx
    The SSMS (client software) returns SELECT output to Results and PRINT output to Messages.
    The SQLCMD -o (output file) option captures all outputs into one file mixed.
    Kalman Toth Database & OLAP Architect
    T-SQL Scripts at sqlusa.com
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Compare Model DDL Preview is greyed out for ALTER statement

    Hi,
    I imported data dictionary from SQL Server  and made change to the table. I would like to generate ALTER statement but it's greyd out like below.
    The modeler detects the changes made to the table and compares right but preview is just disabled. Anything I missed ?

    I'm afraid Data Modeler doesn't support generation of ALTER statements for SQL Server databases.
    David

  • PreparedStatement puts ticks around strings when doing ALTER statement

    Hi,
    I am trying to add a column to a table with a prepared statement:
    private static final String ALTER_TABLE = "ALTER TABLE scene_tags ADD ? BOOL DEFAULT FALSE";
    addNewTagCol = conn.prepareStatement(ALTER_TABLE);
    addNewTagCol.setString(1, newTagName.getText());
    addNewTagCol.executeUpdate();
    When I execute this in java I get a syntax error from mySQL:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''dd' BOOL DEFAULT FALSE' at line 1
    If I do:
    System.out.println(addNewTagCol.toString());
    I get:
    ALTER TABLE scene_tags ADD 'dd' BOOL DEFAULT FALSE
    The probem is the 'dd' which should be just dd.
    If I copy this into the command line it doesn't like the 'dd'.
    How do I stop the ticks ticking?
    Thanks,
    John

    Personally, I don't think that CREATE and ALTER statements should be executed in Java.
    The schema is usually in place when a Java app starts. The application then performs CRUD operations on a well-defined, static schema. Changing the schema means changing the application, something that you shouldn't be doing on the fly.
    If you think you have to alter a table in a Java app, I'm betting that you have a bad design that needs rethinking.
    Unless you're trying to write an admin tool from scratch, of course. In that case I'd refer you to an admin tool like SQL Squirrel.
    %

  • Statement AUDIT SELECT TABLE also audits update, delete and inserts

    Hi,
    Database Oracle 11g.
    After turning on AUDIT with these 2 statements:
    SQL> ALTER SYSTEM SET audit_trail = "DB_EXTENDED" SCOPE=SPFILE;
    SQL> AUDIT SELECT TABLE BY ACCESS;
    then insert, update and delete statements are recorded in sys.aud$ as well as select statements.
    My expectation was to see only select statements in sys.aud$.
    Please clarify :-)
    Best regards
    Erik

    it should not record other action apart from select,can you crosscheck audit configuration by
    select * from DBA_OBJ_AUDIT_OPTS;
    SELECT * FROM ALL_DEF_AUDIT_OPTS;

  • CONNECT and ALTER statements in a Procedure. COPY command in SQL*Plus

    Hi people,
    Is it possible to use the SQL commands, "CONNECT" and "ALTER TABLE" in a procedure, function or trigger?
    In one of my audit procedures, I need to connect to a financial database (FROM the applications database), and then proceed to alter a number of tables based on certain data. I'm sure I've done it before, but I can't remember how! Isn't there a command such as "EXEC_SQL" or something?
    Another question:
    I need to copy a table from one database ("OPS$TSLIVE") to another ("TRACKER"). Here is an excerpt of my code, as well as an error! I've never had this error before!
    JOHANN> copy from ops$tslive/pwd@cds to tracker/pwd@tracker create new_alerts using select * from alertcodesfile;
    Array fetch/bind size is 15. (arraysize is 15)
    Will commit when done. (copycommit is 0)
    Maximum long size is 80. (long is 80)
    select * from alertcodesfile
    Error in SELECT statement: ORA--1002: Message -1002 not found; product=RDBMS; facility=ORA
    Please help!
    Kind regards,
    Johann.

    You are refering to 'execute immediate' (>=8i). As far as I know it is not possible to do connects. Alter table perhaps, if it is in the local database (try it). If you want to perform dml in a remote database, create a database link and use that to perform you dml on. a DB link can also be used to call a remote procedure (That perhaps does the alters for you). Try it.
    The oracle doc says this about ORA-1002:
    ORA-01002 fetch out of sequence
    Cause: In a host language program, a FETCH call was issued out of sequence.
    A successful parse-and-execute call must be issued before a fetch. This can
    occur if an attempt was made to FETCH from an active set after all records have
    been fetched. This may be caused by fetching from a SELECT FOR UPDATE
    cursor after a commit. A PL/SQL cursor loop implicitly does fetches and may
    also cause this error.
    Action: Parse and execute a SQL statement before attempting to fetch the data.It looks like a bug, ask Oracle support.
    L.

  • IF Statement in Select

    I need to choose between value1 and value2 within a select statement.
    TableA
    Flag (char)
    Value1
    Value2
    ItemDesc
    pseudo code
    select ItemDesc, (if Flag = 'y' then Value1 else Value2) as Price from TableA;
    How can this be done?

    select   itemdesc,
             sum (case
                     when flag = 'y'
                        then (case
                                 when value1 < 10
                                    then value1 * 1.2
                                 else value1
                              end)
                     else value2
                  end
                 ) as price
        from tablea
    group by itemdesc;

  • If statement in select statement alias

    I have the following select statement. It has the alias Survivors, Deaths and "All Cases". Is it posible to use :P_LANGUAGE variable to say that -- IF :P_LANGUAGE = FRENCH THEN alias are Survivants for survivors, Décès for Deaths, Tous_les_cas for All Cases. Please advise
    SELECT ALL T_NTR_MULTIBAR.CAT, T_NTR_MULTIBAR.NUM_CASES_LEFTBAR AS Survivors,
    T_NTR_MULTIBAR.NUM_CASES_MIDDLEBAR AS Deaths, T_NTR_MULTIBAR.NUM_CASES_RIGHTBAR AS "All Cases"
    FROM T_NTR_MULTIBAR
    WHERE INSTANCE_NUM = :P_INSTANCENUM
    order by ORDERS

    You may not be able to add this condition inside the SQL Statement. But you can add this condition outside the statement, if you're using PL/SQL...
    IF :p_language = french THEN
    SELECT ALL t_ntr_multibar.cat,
      t_ntr_multibar.num_cases_leftbar AS survivors,
      t_ntr_multibar.num_cases_middlebar AS deaths,
      t_ntr_multibar.num_cases_rightbar AS "All Cases"
    ELSE
    END IF;

  • Decode statement in Select line of a View Object Query

    I attempted to create a view object in expert mode with a customized query.
    The query had a decode statement in the select line of the query. The view
    object compiled correctly but gave an error when run.
    ex: select .... decode(CrpSchools.SCHOOLS_ID,null,CrpCustSchools.SCHOOL_NAME,CrpSchools.SCHOOL_NAME) SCHOOL_VALUE, ...
    from ....
    where ....
    The error was that school_value does not exist in the statement. I got the error when
    doing a vo.executeQuery().
    When I removed the decode statement everything worked correctly. Does anyone know if
    the decode statement cannont be used in the select line of a query in a view object?
    Or maybe I was linking the query column (SCHOOLS_ID) up to the view attribute (SCHOOL_VALUE) incorrectly in the
    Attribute Mappings tab of the VO wizard?

    There should be no problem using a DECODE() statement, provided that you've aliases the column as you have done.
    At design time, if you click on the (Test) button, does your query test ok?
    Are you by chance applying a custom where clause at runtime?
    If so, are you saying:
    setWhereClause("yourtable.column_alias = ?";
    or are you doing:
    setWhereClause("column_alias = ?";
    for an expert-mode query, you'll need to use the latter syntax.

  • "If, Then" Statements Driving Selection

    I am creating a price list/order form and need some help with "If, Then" statements and how their result drives a price selection.
    I have a product that is priced differently based on both how many is purchased and how many colors it has. My variables are (a) one, two, three or four colors, and (b) 10 to 500 pieces in six tiers (10-24, 25-49, 50-99, 100-249, 250-499, 500+).
    I want to autopopulate a price field based on the color number and the quantity, making the pricing foolproof and the total order amount automatically calculated.
    Here's my situation:
      - Field A is Number of Colors (let's say 1-color)
      - Field B is Quantity (let's say it's 23, putting us in the 10-24 tier pricing)
      - Field C is Unit Price (1-color @ 23 qty would be $76.63 each)
      - Field D is Total Price (23 x $76.63)
    My statement would look like the following, but I don't know how to structure this in the form fields or where to put the quantity or pricing table for the software to calculate B or C:
    If A is 1-color, and B is 23, then C is $76.63.
    My Field D calculation is pretty straight-forward (Field C x Field D) if I can figure out a way to determine Field C's value.
    Help!

    Have a look at these tutorials:
    http://acrobatusers.com/tutorials/conditional-execution
    http://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations
    If you still need help afterwards, post here again.

  • Error while executing the Alter statement

    ORA-00604: error occurred at recursive SQL level 1
    ORA-01654: unable to extend index SYS.I_COL2 by 64 in tablespace SYSTEM
    Im facing the above issue , while executing the Alter . Any solution on this . How to Overcome this ...

    It would have been nice if you'd bothered to actually post the statement causing this error.
    However, I think it is simply that you have run out of room in the system tablespace.
    In which case, ask your DBA to increase the size of that tablespace.

Maybe you are looking for

  • How do I share files with other accounts on mac

    Under Lion public folders are hidden?  I turned on sharing, but can't see any public folders so I can share files between accounts on the same computer.  Any ideas.

  • SAP SRM Prod with Oracle DB and AIX 5.3 Performance Issue.

    Hi Basis Gurus, Today my SAP PRD system all of a sudden was running slow and users had difficulties executing TCodes as it took minutes before the screen appeared.My system is SAP SRM 4.00, Oracle Release 11.2.0.1.0 and AIX 5.3. From Basis point of v

  • Content Viewer Bugs?

    I'm having two strange scenarios with the newest version of the Adobe Content Viewer and multi-state objects.  Both situations below were in v27 folios, and they worked perfectly fine on the Desktop Viewer, but when loaded onto an iPad and viewed thr

  • CR XI's packaged JRC export to PDF, Wingdings2 font acts weirdly

    I have used Wingdings2 font for a certain template. I developed the template in Windows. In the production environment (Linux), we have put the font files in the jvm's font folder as instructed in Wingdings not exported correctly in PDF by Crystal Re

  • Printing Docs saved in Windows

    I am saving pages doc in Windows so I can send an attachment to a PC but then I can't print the doc either in WIndows or revert to Pages to print. Any suggestions? Please