Create education dynamic table in SQL

Hello

I am trying to create a table in a select query via a using the dynamic SQL PL/SQL block. This is the query,

declare
stmt varchar2 (2000);
Start
stmt: = "' CREATE TABLE AS SELECT PATIENT_ID, name FROM employee output" ';
immediately execute stmt;
end;
/

It throws the following error.

declare
*
ERROR on line 1:
ORA-00900: invalid SQL statement
ORA-06512: at line 5

I tried to run the statement without the variable, and it runs very well. I mean

Start
run immediately "CREATE TABLE output AS SELECT PATIENT_ID, name OF the employee";
end;
/

works perfectly. Can you please help me with this.

Thank you

Hello

declare
stmt varchar2(2000);
begin
stmt := 'CREATE TABLE output AS SELECT PATIENT_ID, FIRST_NAME FROM employee';
execute immediate stmt;
end;

Nothing different from what Anurag has shown above.
But you will need to consider a few things.
(1) since it is possible it is not a must to use
(2) it is considered to be a poor design where in it need to create tables on the fly.
(3) whether it is absolutely mandatory. If you can give us an idea of your condition. I don't know that the gurus here can give you suggestions
(4) this kind of design will be will lead you into problems sooner or later for sure

Kind regards
Bobin

Tags: Database

Similar Questions

  • Dynamic table returns only a line

    Hello world

    I try to use a Recordset:

    "SOME concerts. EventDate, concerts. Location, concerts. Notes

    CONCERTS

    WHERE the concerts. "EventDate > = CURRENT_DATE.

    When I test the Recordset, I get 3 of the 5 records returned, which is exactly as it should.

    However, when I try to create a dynamic table to display the results - if I choose to show all records, or the default of 10 at a time, it shows the first line results from the Recordset.

    When I try to create a master-detail table and ask him to show one record at a time, it's there for that, but using the next/back navigation links, it takes me to other records, though one at a time.  That tells me that he doesn't know that there should be three records, but it only shows one.

    What am I doing wrong with the dynamic table, here?

    Thank you!

    I suggest that you start the page completely from scratch, because it seems that you made the rookie mistake classic to remove a dynamic object in Design view without realizing that any other PHP code is connected with it. When you work with dynamic objects, keep an eye on what is listed in the server behaviors panel. To remove a server behavior, select the referencing in the Panel and click the button "-" to remove it properly.

    In fact, you have two sets of records on the same page, that do the same thing. One is called to come, the other is called UpcomingShows. You get only a line showing in your table is because you use the recordset "to come". The Dreamweaver recordset code automatically retrieves the first record and then uses a do... while loop to create the region repeated in the table. What has happened is that your changes to the page have resulted in this line who appear before the repeat region:

    mysql_free_result($upcoming);
    

    This destroys the rest of the result of database before using it again. Therefore, only trace never appears.

    Dreamweaver always puts mysql_free_result() after the closing tag. Thus, it seems that your changes caused Dreamweaver to lose track of all the relevant parts of the server behavior. If you move this line to the bottom of the page, your table should work. However, as I said before, I think that it is better to start from scratch.

    One last thing: your SQL query contains the following WHERE clause:

    WHERE gigs.EventDate >= CURRENT_DATE
    

    It is an incorrect syntax for MySQL. It should be like this:

    WHERE gigs.EventDate >= CURRENT_DATE()
    

    CURRENT_DATE() is a MySQL function, not a constant.

    If all goes well, a little less head banging.

  • The dynamic LOV PL/SQL syntax help

    Hello

    I am trying to create a dynamic lov pl/sql Oracle Apex 3.2 on 11 g. I'm having some trouble with the syntax of the statements below and I would be grateful for any suggestion.
    DECLARE
    BEGIN
    
    IF :p3_current_a_workshop != 0 THEN
    RETURN
    'select distinct workshop_title ||':  '  || presenter_name ||'    $'|| workshop_fee display_value, workshop_id return_value 
    from WORKSHOP
    where session_time = 'A'
    and workshop_status = 'Open'
    or workshop_id = :p3_current_a_workshop
    order by 1';
    
    ELSE
    RETURN
    'select distinct workshop_title ||':  '  || presenter_name ||'    $'|| workshop_fee display_value, workshop_id return_value 
    from WORKSHOP
    where session_time = 'A'
    and workshop_status = 'Open'
    order by 1';
    
    END IF;
    EXCEPTION
            WHEN OTHERS THEN
                HTP.PRN('ERROR'||SQLERRM);          
    END;
    I'm trying to shape the code above out of the example given by apex:
    A function that returns a SQL query with two columns:
    
    IF :MY_ITEM='10' THEN
      RETURN 
      'SELECT ename, empno 
    FROM  emp 
    WHERE depno = 10 
    ORDER BY 1';
    ELSE
      RETURN 
      'SELECT ename, empno 
    FROM emp 
    WHERE depno = :my_item 
    ORDER BY 1';
    END IF;
    ~ Andrew Schultz

    How do you use this procedure?

    You can create and example on apex.oracle.com?

    Lev

    Published by: the January 12, 2011 14:10

  • dynamic table overlap other objects!

    Hello world


    I created a dynamic table with button to add a line


    Please can someone tell me how to avoid the overlapping of dynamic array objects below when several lines are created?


    what I wish is that the table bumps everything on its way like MSWord packaging option


    Please provide a flash tutorial if you can train a lot of people ask this topic

    Hello

    Use fluid page layout to avoid overlapping of table on other objects. This fluid layout must be set on the container parent (form/subform) of the table. Put also other objects in the same container. It results in dynamic container resizing, whenever the new row is added.

    Thank you.

    -

    Afonso

  • How to create a dynamic RTF report that creates dynamic columns based on the selection of dynamic columns in a table?

    Hi all

    Suppose I have table, whose structure changes frequently on a daily basis.

    For example. / / desc my_table gives you after the name of the column the day 1

    SQL > my_table DESC;

    Output

    Name

    Age

    Phone


    Day 2, two other columns are added, viz, address and salary.

    SQL > my_table DESC;

    Output

    Name

    Age

    Phone

    Address

    Salary


    Now, I want to create a Dynnamic RTF report which made extracting data from all columns from my_table daily. For this, I have defined a simultaneous program with XML output type and include in annex a data/definition of data model that takes XML as input and gives the final result of the conc program in EXCEL layout. I am able to do that for a constant number of columns, but don't know how to do it when the number of columns to display dynamically changes.

    For 1 day my XML file should be like this.

    <?xml version="1.0" encoding="UTF-8"?>
    <dataTemplate name="XYZ" description="iExpenses Report" Version="1.0">
    <dataQuery>
    <sqlStatement name="Q2">
    <![CDATA[
    SELECT Name
    ,Age
    ,Phone
    FROM my_table
    ]]>
    </sqlStatement>
    </dataQuery>
    <dataStructure>
    <group name="G_my_table" source="Q2">
      <element name="Name" value="Name" />
      <element name="Age" value="Age" />
      <element name="Phone" value="Phone" />
    </group>
    </dataStructure>
    </dataTemplate>
    
    

    And my day 1, EXCEL output RTF model should be like this.
    Name age phone

    Swapnill 23 12345

    For 2 days my XML file should be like this. With 2 new columns selected in the SELECT clause.

    <?xml version="1.0" encoding="UTF-8"?>
    <dataTemplate name="XYZ" description="iExpenses Report" Version="1.0">
    <dataQuery>
    <sqlStatement name="Q2">
    <![CDATA[
    SELECT Name
    ,Age
    ,Phone
    ,Address
    ,Salary
    FROM my_table
    ]]>
    </sqlStatement>
    </dataQuery>
    <dataStructure>
    <group name="G_my_table" source="Q2">
      <element name="Name" value="Name" />
      <element name="Age" value="Age" />
      <element name="Phone" value="Phone" />
      <element name="Address" value="Address" />
      <element name="Salary" value="Salary" />
    </group>
    </dataStructure>
    </dataTemplate>
    
    

    And my day 2, exit EXCEL model RTF should be like this.
    Name address telephone pay

    23 12345 Madrid 100000 Swapnill

    Now, I don't know below things.

    • Make the dynamic XML as we did in the day 1 there are 3 columns in the SELECT statement and the day 2, 5 columns. I want to create a dynamic XML which must not be changed if the new columns are added into my_table. I don't know how to create this query and also create their corresponding items below.
    • Make the RTF model dyanamic as day 1 there are 3 exit EXCEL columns and the day 2, 5 columns. I want to create a dynamic RTF model that would display all the columns selected in XML dynamic. I don't know how the RTF will create new XML tags and how it will know where to place them in the report. Means, I can create model RTF day 1, by loading the XML data for 3 columns and place 3 tags XML in the model. But how he will create and place the tags for the new columns the day 2?

    Hope so, you got my requirement, it's difficult. Please let me know how I can implement the necessary solution using the RTF dynamically without any manual intervention.

    Kind regards

    Patricia K.

    Post edited by: SwapnilK

    Hi guys,.

    I was able to solve above the requirement.

    I created a procedure that would create & update (attached to the data definition) XML file dynamically for each race. This dynamic XML contains the SQL statement for the data query that is built dynamically. I am updating this XML file using XDOLoader utility to the definition of data. Then run my program customized to generate the excel output.

    Exit excel retrieves correct number of columns dynamically (3 on Day1 and Day2 5), with corresponding data records.

    Kind regards

    Patricia K.

  • Why odi creates datetime2 (27) type of data and because of create table in sql server 2012 is a failure

    Hey

    I had a situation in the present case, I flat file and I want to load it into sql server 2012.

    In the flatfile I have 2 data types of columns date and I chose LKM FILE TO SQL, when I try to run it fails to create the work table.

    When I c the code in this step it shows

    create the table dev.dbo.C$ _0TES

    (

    ASN_BOL_NBR NUMERIC (7,0) NULL,

    ASN_CARTON NUMERIC (20.0) NULL,

    ASN_SHORT_SKU NUMERIC (7,0) NULL,

    ASN_SKU_CHECK_DIGIT NUMERIC (1.0) NULL,

    ASN_DESC VARCHAR (25) NULL,

    ASN_QUANTITY NUMERIC (7,0) NULL,

    ASN_LEAVE_DATE DATETIME2 (27) NULL,

    ASN_ARRIVAL_DATE DATETIME2 (27) NULL,

    ASN_MULT_PACK VARCHAR (1) NULL,

    ASN_MULT_SKU VARCHAR (1) NULL

    )

    MSG 1002, level 15, State 1, line 9

    Line 9: Specified scale 27 is not valid.

    DATETIME2 (27) the table of creative work is a failure because of the type of data

    ASN_LEAVE_DATE DATETIME2 (27)

    ASN_ARRIVAL_DATE DATETIME2 (27)

    Is there a way to avoid a DATETIME2 (27)?

    Thank you!

    Yes, I would certainly put the data on the source of the string type.

    Then in your mapping/interface, you can use the CONVERT function.

    For example, CONVERT (DATETIME, YOUR.) ASN_LEAVE_DATE, 101)

    In this example, 101 as a style means that your file contains a date in the format dd/mm/yyyy.

    See CAST and CONVERT (Transact-SQL) to find out what style you apply.

    Kind regards

    JeromeFr

  • How to create a dynamic lov inside the table?

    Hi all

    I use JDeveloper11.1.1.1.4.

    My scenario is that I have page with editable < af:table >. Table contains a < af:inputListOfValues > inside the column. I want to do this < af:inputListOfValues >

    as a dynamic. Because according to users, we have to get the chronogram different objects in different point of view. I tried with below link it works very well for forms.

    But editable tables, I'm not able to create the dynamic lov.

    ADF practice: dynamic linking LOV

    Thank you

    David.

    Hello David

    have you tried ADFbc lov switcher?

    See - Andrejus Baranovskis Blog: Groovy - multiple LOV by attribute in JDeveloper 11 g

    http://www.Oracle.com/technetwork/developer-tools/ADF/learnmore/89-adfbc-lov-switcher-454168.PDF

    Thank you

  • Workshop SQL-&gt; Tables-&gt; create the Lookup Table

    It is perhaps a SQL issue rather than an issue of Apex, but...

    With my experience of amateur to create database tables, I usually start with a parent table and create children and link them.

    While playing with Apex, I have the ability to create a Lookup Table of in any table.

    And, what is created is a new table that is, indeed, a parent.
    So I have been working from the bottom to the top.

    I understand that correctly?

    Thank you-
    Marion

    Marion...

    Yes...

    Lookup tables store data from reference and a link to your main table with a standard primary/foreign key relationship.

    This feature is particularly useful if you are creating your tables of data in the worksheet and you want to standardize it.
    Gus...

  • Attempt to create run time (dynamic) table and insert the data in this... The entrance is a flat file (txt file) which has the numbers and strings... I'm trying to convert them to a string and insert into the table. It is a matter of urgency for me please

    create or replace procedure Dynamic_Table AS

    iVal VARCHAR2 (32);

    iTemp varchar (200): = ";

    sql_stmt VARCHAR2 (200);

    l_file1 UTL_FILE. TYPE_DE_FICHIER;

    l_file utl_file.file_type;

    BEGIN

    l_file1: = UTL_FILE. FOPEN ('TEST', 'dinput.txt', 'R');

    EXECUTE IMMEDIATE ' CREATE TABLE baseline (Item_ID varchar2 (32))';

    Loop

    BEGIN

    UTL_FILE. GET_LINE (l_file1, iVal);

    EXECUTE IMMEDIATE ' insert into baseline values (: ival) "using ival;

    EXCEPTION

    WHEN No_Data_Found THEN EXIT;

    While some OTHER THEN dbms_output.put_line (SQLERRM); * /

    END;

    end loop;

    END;

    You are approaching this the wrong way.  Create an external table based on the file.  External tables are CSV, fixed width data in a queryable table.

    You will need to create an oracle directory to put the file in (MY_ORA_DIR) I leave it for you to do, and then perform the following...

    create table BASELINE)

    ITEM_ID varchar2 (32)

    )

    EXTERNAL ORGANIZATION

    (

    TYPE ORACLE_LOADER

    THE DEFAULT DIRECTORY MY_ORA_DIR

    ACCESS SETTINGS

    (

    RECORDS DELIMITED BY NEWLINE

    LOGFILE "dinput.log".

    BADFILE "dinput.bad."

    NODISCARDFILE

    FIELDS

    (

    ITEM_ID

    )

    )

    LOCATION ("dinput.txt")

    )

    REJECT LIMIT UNLIMITED

    /

    All the dubious records appear in dinput.bad. Dinput.log will give you information.

    External tables are read-only, so once you set up your file, you can create editable as a normal table.

    create table ITABLE_EDITABLE as

    Select * from BASELINE

    /

    Work done, a few lines of code.

  • Create a temporary table using EXECUTE IMMEDIATE

    Hello

    I need to create a report more complex which must have three different queries. I use a determined IF clause that the query that uses the report, according to the parameters.

    I want to write the output to a csv file, so I created a PROCEDURE.

    The first package of the procedure has the three SQL and the IF clause in order to determine the query that the report uses and stores the query code in a variable (v_sql), which is passed to the PROCEDURE that needs to write to the output of the report.

    I tried to create a table with data from the request in order to make a LOOP and exit, something like this:

    WRITE_FILE (errBUFF of the PROCEDUREOUT VARCHAR2,
    retCODEOUT VARCHAR2,
    v_sqlIN VARCHAR2)

    IS

    ContorNUMBER;

    BEGIN

    EXECUTE IMMEDIATE v_sql;
    SLIDE G
    IS
    Select * from XXROR_REG_MF_TBL;
    --
    -initialization
    --
    retCode: = 0;
    errBUFF: = NULL;
    Contor: = 0;
    --
    -cursor
    --

    FOR X IN G
    LOOP
    APPS. FND_FILE.
    PUT_LINE)
    APPS. FND_FILE. OUTPUT,
    ....)

    I should mention that v_sql is something like:

    CREATE GLOBAL TEMPORARY TABLE ACEs (SELECT * of the double);

    I can't really do that, so I was wondering if you have any suggestions

    Thank you

    Claudiu

    Hello

    I don't think you need a table at all. You can set the cursor based on the SQL passed as parameter

    https://docs.Oracle.com/database/121/LNPLS/dynamic.htm#LNPLS629

    Concerning

    Marcus

  • Can I create multiple dynamic entries during execution?

    Can I create multiple dynamic entries during execution?

    Oracle 11g
    Request Express 4.0.2.00.06

    Here's my problem:
    We have a table that contains metadata about the files (paper or electronic).
    We hope that we can need more columns in the table at some point and do not want to change the table or the application.

    So to do this I would like to create:

    A table called TBL_FILE with columns:
    NUMBER of TBL_FILE_ID (this will be the primary key)
    TBL_FILE_NAME VARCHAR2 (1000) (this will be the name of the file)

    A second table will be called TBL_FILE_META with columns:
    NUMBER of TBL_META_ID (this will be the primary key)
    NUMBER of TBL_FILE_ID (this will be the key to forign to the files table)
    TBL_META_COLUMN VARCHAR2 (30) (this is what would be the name of the column if it existed in TBL_FILE)
    TBL_META_VALUE VARCHAR2 (1000) (this is the value of this record and the column "would be")

    If a person can have as many meta data in the file to add columns to the table.
    The problem is how can I allow users to add as much data as they wish with them having to re develop page.

    Other things to note is that we would like this be on one page.
    I know how to add we can create inserts several rows using a SQL (editable report).
    However the TBL_META_VALUE in the TBL_FILE_META column will sometimes be a selection list and other times one text box or a numeric field.
    So I don't see now a SQL (editable report) would work for this and I can't create a table of elements on the page running I can?

    No idea how I might accomplish this? Is there a better way to do this?

    It is a term or a name for what I'm doing by creating these "virtual" columns in another table?
    I found this method looking at the workflow tables Oracles.

    Welcome to the Oracle Forums!
    >
    Can I create multiple dynamic entries during execution?

    Oracle 11g
    Request Express 4.0.2.00.06

    Here's my problem:
    We have a table that contains metadata about the files (paper or electronic).
    We hope that we can need more columns in the table at some point and do not want to change the table or the application.

    So to do this I would like to create:

    A table called TBL_FILE with columns:
    NUMBER of TBL_FILE_ID (this will be the primary key)
    TBL_FILE_NAME VARCHAR2 (1000) (this will be the name of the file)

    A second table will be called TBL_FILE_META with columns:
    NUMBER of TBL_META_ID (this will be the primary key)
    NUMBER of TBL_FILE_ID (this will be the key to forign to the files table)
    TBL_META_COLUMN VARCHAR2 (30) (this is what would be the name of the column if it existed in TBL_FILE)
    TBL_META_VALUE VARCHAR2 (1000) (this is the value of this record and the column "would be")

    If a person can have as many meta data in the file to add columns to the table.
    The problem is how can I allow users to add as much data as they wish with them having to re develop page.
    >
    Creation of dynamic Page elements is not available. You must create surplus items and hide/show, etc. But you cannot change the element Type. Overall, too many restrictions in this approach.
    >
    Other things to note is that we would like this be on one page.
    >
    The limit of 100 points will hit you if you go with extra page element. With the form of tables that should not be a limitation, unless you're exceeding the limit of 50 APEX_APPLICATION point. G_Fnn points and limitation of the 60 column of the region report with "(analyze the query executing only) use generic name column" in the dynamic region.
    >
    I know how to add we can create inserts several rows using a SQL (editable report).
    However the TBL_META_VALUE in the TBL_FILE_META column will sometimes be a selection list and other times one text box or a numeric field.
    >
    If the type if the item is variable, that doesn't mean that you have to type a way to store the item. Metadata of meta data.
    >
    So I don't see now a SQL (editable report) would work for this and I can't create a table of elements on the page running I can?
    >
    Yes, you can do it. Update report / query in a table can be built from the metadata using the SQL query that returns the PL/SQL function . It will be a bit of coding in PL/SQL where you use metadata and metadata of Meta data to restore your SELECTION with the right APEX_ITEMs. He might have a decrease in performance associated with it, but it will not be a serious degradation.
    >
    No idea how I might accomplish this? Is there a better way to do this?

    It is a term or a name for what I'm doing by creating these "virtual" columns in another table?
    I found this method looking at the workflow tables Oracles.
    >
    I guess it's just a good TNF. This is the master model / retail Design, sounding more modern? ;)

    Kind regards

  • creating a dynamic list of values

    Hello

    While I am trying to create a dynamic list of values on a table (table1) with h_id columns, the head_foot and the header. I gave the query to create the dynamic values as list

    Select d, r header header
    of g.fw_header_footer
    order by 1

    where d is the display value and r is the return value to get the error message

    "1 error has occurred."

    LOV query is not valid, a display and a return value is needed, the column names must be different. If your query contains a query online, the first CLAUSE in the SQL statement must not belong to the query online. »


    Can someone please suggest me if am wrong.


    Thanks in advance

    Hello

    I suggest that you check the permissions of your application of the analysis of schema has on your g.fw_header_footer table.

    It is a mistake to mislead, but I've just reproduced the same problem trying to select from a table that I didn't have SELECT permission.

    Scott

  • Dynamic table not displaying not data

    First of all, I have searched high and low and have not been able to find a lot of help.

    That said, I tried to create a simple search/results page in Dream Weaver, I'm using ASP and sql express.  Ive been following the adobe tutorial and everything works like it says it should be, except that when in reality, you do a search and click on submit, the results page shows that dynamic table headers, but no data.

    On the results page, when I create the Recordset, if I am controlled, the data is displayed correctly.  However, on the page itself, nothing shows upward.

    Here are some example screenshots:

    recordset.JPG

    searchresult.JPG

    You populate your variable with the value of querystring:

    Request.QueryString ("frmUserSearch").  Is the name of the shape, not the form with the user name field.

    Your form field's "name ="username"

    Replace all references in your 'frmUserSearch' script 'username '.

  • Create a new table from another table which are ussing a stored procedure

    Hello

    I want to know if it is posibble to create a new table from another table which are ussing a stored procedure. This new table is created from another table that exists in the DB.
    (in the following code the table tbl1 exist in the schema of the DB, but temp_tbl1 does not exist, it must be created by the procedure)

    create or replace procedute temp is
    temp_tbl1 tbl1% TYPE; the temp_tbl1 will have the same type of tbl1
    Start
    create the table temp_tbl1 as (select * from tbl1);
    time of the end;
    \


    Thank you very much

    Yes, it is possible to create a table using a procedure.
    Do everything that use dynamic SQL is

    Try this:

    ==================================================
    create or replace PROCEDURE Create Table as
    BEGIN
    EXECUTE IMMEDIATE ' CREATE TABLE testtable in select * from testingtable';
    END createtable;
    ==================================================

    Kind regards
    Ankur

  • How to make a table temporary sql

    Hello

    I would like to create a table temporary sql - «create table #tempTable...» »

    but I get the error

    Is it possible to do it with Labview DB connectivity toolkit?

    Thank you... Eran

    I know that you can create a stored procedure and run it since in LabVIEW.  And within the stored procedure, you can create temporary tables.  I like this method because you can easily change the SP code without recompiling your VI.  Hope this helps.

Maybe you are looking for