Sql statement for a table name with a space in between

Hi,
I just noticed that one of my tables for Access is consisted of two word. It is called "CURRENT CPL". How would I put this table name into an sql statement. When I did what I normally do, it only reads the CURRENT and thinks that's the table name.
Thanks
Feng

I just noticed that one of my tables for Access is
consisted of two word. It is called "CURRENT CPL".
How would I put this table name into an sql
statement. When I did what I normally do, it only
reads the CURRENT and thinks that's the table name.That is called a quoted identifier. The SQL (not java) for this would look like this....
select "my field" from "CURRENT CPL"
The double quote is the correct character to use. Note that quoted identifiers are case sensitive, normal SQL is not.

Similar Messages

  • Sql statement for join tables

    hi there..i need ur helps
    Here are my tables n column name for each tables
    a) rep_arrngt
    Name
    REP_ARRNGT_ID
    REP_ARRNGT_DESC
    REP_ARRNGT_TYPE
    ACCT_CAT
    DEF_INDUSTRY_CODE
    MEDIA_ID
    LANGUAGE_ID
    CURRENCY
    PAGE_ID
    b) bci_rep_arrng
    Name
    REP_ARRNGT_ID
    BCI
    SUB_SUM_CODE
    DP_SUB_SUM_CODE
    c) acct_rep_arrngt_link
    Name
    ACCT_NO
    REP_ARRNGT_ID
    DOC_TYPE
    LAST_BILL_DATE
    BILL_FREQUENCY
    SCALING
    EFF_FROM_DATE
    EFF_TO_DATE
    MEDIA_ID
    Actually, i want to get the unique value for sub_sum_code according to the bci..
    i already use join tables n here is my sql statement :
    SELECT T1.SUB_SUM_CODE,T1.BCI,T1.REP_ARRNGT_ID,T2.REP_ARRNGT_ID,T3.REP_ARRNGT_ID FROM BCI_REP_ARRNG T1, REP_ARRNGT T2, ACCT_REP_ARRNGT_LINK T3 WHERE T1.REP_ARRNGT_ID=T2.REP_ARRNGT_ID AND T2.REP_ARRNGT_ID=T3.REP_ARRNGT_ID AND BCI='TTA00F06'
    n my results is :
    SUB_SUM_CODE BCI REP_ARRNGT_ID
    TBGSR TTA00F06 R1
    TBGSR TTA00F06 R1
    TBGSR TTA00F06 R1
    TBGSR TTA00F06 R1
    I get the repeated results for sub_sum_code..
    so, what i need to do if i want only 1 row results like this :
    [u]SUB_SUM_CODE BCI REP_ARRNGT_ID
    TBGSR TTA00F06 R1
    i try to use group by, but i get the error..plz help me

    If you only want "to get the unique value for sub_sum_code according to the bci" then why are you joining the tables in the first place? Not knowing PKs etc you could just use DISTINCT in your select statement.
    SELECT DISTINCT T1.SUB_SUM_CODE,
                    T1.BCI
    FROM BCI_REP_ARRNG T1
    AND BCI='TTA00F06'

  • Problem with SQL Statement for Result Filtering

    Dear Visual Composer Experts,
    Here is another Question from me: I have a SQL Query that is working as the data service
    Select AB.AgingBandID, AB.AgingBand,
    Sum(Case when priority='Emergency' then '1' Else 0 End) as [Emergency],
    Sum(Case when priority='Ugent' then '1' Else 0 End) as Ugent,
    Sum(Case when priority='High' then '1' Else 0 End) as High,
    Sum(Case when priority='Medium' then '1' Else 0 End) as Medium,
    Sum(Case when priority='Low' then '1' Else 0 End) as Low
    from DimAgingBand AB left outer join
    (Select AgingBandID , priority , yeardesc
    from vNotifications where YearDesc = (select year(getdate())-1)) as vN
    on AB.AgingBandID=vN.AgingBandID
    where AB.AgingBandID<>'1'  
    Group by  AB.AgingBandID, AB.AgingBand
    Order by AB.AgingBandID
    That would return me a table as in the following:
         Agingband     E     U     H     M     L
         < 1week     0     0     0     0     1
         1 - 2 weeks     0     0     0     0     0
         2 - 4weeks     0     0     0     0     1
    > 1month     8     2     1     1     6
    Now that I would like to add some parameters to filter the result, so I modify the query and put it in the SQL Statement input port of the same data service. The query is like this:
         "Select AB.AgingBandID, AB.AgingBand,Sum(Case when priority='Emergency' then '1' Else 0 End) as [Emergency],Sum(Case when priority='Ugent' then '1' Else 0 End) as Ugent,Sum(Case when priority='High' then '1' Else 0 End) as High,Sum(Case when priority='Medium' then '1' Else 0 End) as Medium,Sum(Case when priority='Low' then '1' Else 0 End) as Low from DimAgingBand AB left outer join (Select AgingBandID , priority , yeardesc from vNotifications where YearDesc like '2009%' and Branch like '" & if(STORE@selectedBranch=='ALL', '%', STORE@selectedBranch) & "' and MainWorkCentre like '%') as vN on AB.AgingBandID=vN.AgingBandID where AB.AgingBandID<>'1' Group by AB.AgingBandID, AB.AgingBand Order by AB.AgingBandID"
    However this input port query keeps giving me error as NullPointerException. I have actually specified a condition where the query will run if only STORE@selectedBranch != u2018u2019.
    I have other filtering queries working but they are not as complicated query as this one. Could it be possible that query in the input port cannot handle left outer join?
    Could it be anything else?
    Help is very much appreciated.
    Thanks & Regard,
    Sarah

    Hi,
    Thank you very much for your replys. I've tested if the dynamic value of the condition is integer, it's OK
    But if the ClassID type is not integer, it's string, I write  a SQL Statement like:
    "Select DBADMIN.Class.ClassName from DBADMIN.Class where DBADMIN.Class.ClassID = '1' "
    or with dynamic condition:
    "Select DBADMIN.Class.ClassName from DBADMIN.Class where DBADMIN.Class.ClassID = '"&@ClassID&"'"
    or I write the SQL Statement for insert/update/delete data,
    I always have errors.
    I've tested if the dynamic value of the condition is integer, it's OK
    Do you know this problem ?
    Thank you very much & kindly regards,
    Tweety

  • Sql statement for retrieving the last update time of a table

    Hello all,
    Can somebody give me an example of sql statement for retrieving the last update time of an oracle table.
    Thank you
    Il

    Thanks for the fast replies. It works great when I test it as a sql statement but when trying to populate a datalist with it it raises the following exception:
    Exception Details: System.ArgumentException: SCN_TO_TIMESTAMP(MAX(ORA_ROWSCN is neither a DataColumn nor a DataRelation for table DefaultView
    Part of the Datalist Code:
    ItemTemplate>
    Line 12:             SCN_TO_TIMESTAMP(MAX(ORA_ROWSCN)):
    Line 13:             <asp:Label ID="SCN_TO_TIMESTAMP_MAX_ORA_ROWSCN__Label" runat="server" Text='<%# Eval("[SCN_TO_TIMESTAMP(MAX(ORA_ROWSCN))]") %>'>
    Line 14:             </asp:Label><br/>
    Line 15:             <br/>
    {code}
    Why is this happening? Any ideas?
    Il                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Sql statement for network version of JavaDB database

    Hi,
    Could somebody please tell is it a must to have double quote for field name inside the SQL statement for JavaDB
    I am developing the project using netbean 5.5.1 IDE
    integrating netwok version of JavaDB.
    example
    select "field1","field2" from table1
    instead of the simple sql like
    select field1,field2 from table1
    I find that simple select sql query could not work without having the double quotation eclosed for any of the fieldname called by the SQL statement.
    I am not sure is it only unique to netbeans IDE environment , in principle simple plain query should work , this is however not for netbeans IDE, wht is the reason behind?
    Thanks

    The Quotes around the fieldnames are normally only needed if the field is the same as a reserved word, or has a non-standard character in the field. Look at the JavaDB/Derby manual (specifically the one with the SQL reference) to find out what the reserved words and special characters are, then redefine your table.

  • Execute the sql statement stored in table

    friends i m in complication that, how can i execute sql statement which is stored in database table.
    how can i fetch that particular statement from table and make it execute!!!
    Thanks in advance

    I think we should stop at this point and have a little think.
    My understanding is that your plan is to do the following
    -Execute a Dynamic SQL statement which is constructed from values in several columns in a table (Bad idea to begin with)
    -The result of the execution is then loaded into PL/SQL.....not sure how you are handling different column lists but I'll assume you are not having to convert every column value to a VARCHAR2
    -The values returned are then used in an INSERT statement
    So basically your goal here is to take some data from one table and insert it into another table by moving data from SQL to PL/SQL then back to SQL in an elaborate, dynamic way. This is a costly waste of resources and will not scale (this is before we get to the problem of having to read the SQL statement from a table in the first place)
    I would recommend looking the INSERT SELECT statement here: http://psoug.org/reference/insert.html
    This will get the job done in one go. If you really do need it to be dynamic (which you don't, trust me) then you can still store this statement in your "dynamic SQL" table and execute it using EXECUTE IMMEDIATE although I can say for sure that you're going to run into more problems down the line with this architecture, it won't scale very well, and you'll probably waste at least *1* day of your time every week trying to fix a bug caused by the removal of a table, change to a column name etc.......
    However if you believe that storing SQL in a table is the best solution to your problem then go ahead.....at least when you find out that it isn't you'll have learned a valuable lesson.

  • Using a parameter for a table name?

    In SQL Server, can you use a parameter for a table name?  I'm working with Visual C# and want to do something like this:
    SELECT MAX(ItemID) FROM @TableName;
    Can this be done?
    (Basically, I have three separate methods within a class--one for each table I have; and each one will perform the above query but on different table names.  I'd like to see if there is a way that I can have just one method that will allow me to specify
    the table name.)

    As pointed out in other posts, you can. But a more relevant question is whether you should.
    A table in a relational database is supposed to model a unique entity, and each column in the table is supposed to model a unique attribute. This is not always how it is, but it is from this model a relational database is designed.
    From this angle, having a dynamic table name does not really make sense for application code. (Administrative actions is a different story.) Think of it this way: have you ever wanted to make the class name dynamic in C#?
    Admittedly, it is different in .NET, because everything inherits from System.Object, but in a relational database there is no inheritence.
    Anyway, if you are using stored procedures, you should have one stored procedure per table. Physically, in the plan cache, there will be one query plan per table, no matter how you do it.
    If you are submitting SQL statements from your application, it is a different matter. In this case, I find it difficult to object if you have a class that performs generic actions against tables. Then you build the SQL string in the client code.
    However, no matter how you do it, you need to be careful to avoid SQL injection. We had the example:
    DECLARE @TableName nvarchar(50),@sqlCommand nvarchar(max)
      SET @TableName = ' ItemInformation'
      SET @sqlCommand = 'SELECT MAX(ItemID) FROM ' + @TableName
    EXEC (@sqlCommand)
    But what if we have:
      SET @TableName = ' sys.objects; SHUTDOWN WITH NOWAIT; --'
    As long as we do it in T-SQL, we can (and we should do!) this to prevent SQL injection:
      SET @sqlCommand = 'SELECT MAX(ItemID) FROM ' + quotename(@TableName)
    If you build your SQL strings in C#, you will need to employ other checks. There is only an issue if the user can inject data somewhere, but your generic class will not have knowledge of this, and must assume the worst.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • How to find the column name and table name with a value

    Hi All
    How to find the column name and table name with "Value".
    For Example i have value named "Srikkanth" This value will be stored in one table and in one column i we dont know the table how to find the table name and column name
    Any help is highly appricatable
    Thanks & Regards
    Srikkanth.M

    2 solutions by Michaels (the latter is 11g upwards only)...
    michaels>  var val varchar2(5)
    michaels>  exec :val := 'as'
    PL/SQL procedure successfully completed.
    michaels>  select distinct substr (:val, 1, 11) "Searchword",
                    substr (table_name, 1, 14) "Table",
                    substr (t.column_value.getstringval (), 1, 50) "Column/Value"
               from cols,
                    table
                       (xmlsequence
                           (dbms_xmlgen.getxmltype ('select ' || column_name
                                                    || ' from ' || table_name
                                                    || ' where upper('
                                                    || column_name
                                                    || ') like upper(''%' || :val
                                                    || '%'')'
                                                   ).extract ('ROWSET/ROW/*')
                       ) t
    --        where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
           order by "Table"or
    SQL> select table_name,
           column_name,
           :search_string search_string,
           result
      from cols,
           xmltable(('ora:view("'||table_name||'")/ROW/'||column_name||'[ora:contains(text(),"%'|| :search_string || '%") > 0]')
           columns result varchar2(10) path '.'
    where table_name in ('EMP', 'DEPT')
    TABLE_NAME           COLUMN_NAME          SEARCH_STRING        RESULT   
    DEPT                 DNAME                ES                   RESEARCH 
    DEPT                 DNAME                ES                   SALES    
    EMP                  ENAME                ES                   JONES    
    EMP                  ENAME                ES                   JAMES    
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   PRESIDENT
    EMP                  JOB                  ES                   SALESMAN 
    9 rows selected.

  • Need help on SQL Statement for UDF

    Hi,
    as I am not so familiar with SQL statements on currently selected values, I urgently need help.
    The scenario looks as follows:
    I have defined two UDFs named Subgroup1 and Subgroup2 which represent the subgroups dependent on my article groups. So for example: When the user selects article group "pianos", he only sees the specific subgroups like "new pianos" and "used pianos" in field "Subgroup1". After he has selected one of these specific values, he sees only the specific sub-subgroups in field "Subgroup2", like "used grand pianos".
    I have defined UDTs for both UDFs. The UDT for field "Subgroup1" has a UDF called "ArticleGroup" which represents the relation to the article group codes. The UDT for field "Subgroup2" has a UDF called "Subgroup1" which represents the relation to the subgroups one level higher.
    The SQL statement for the formatted search in field "Subgroup1" looks as follows:
    SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP1]  T0 WHERE T0.[U_ArticleGroup]  = (SELECT $[OITM.ItmsGrpCod])
    It works fine.
    However, I cannot find the right statement for the formatted search in field "Subgroup2".
    Unfortunately this does NOT WORK:
    SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2]  T0 WHERE T0.[U_Subgroup1]  = (SELECT $[OITM.U_Subgroup1])
    I tried a lot of others that didn't work either.
    Then I tried the following one:
    SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2]  T0 WHERE T0.[U_Subgroup1] = (SELECT T1.[Code] FROM [dbo].[@B_SUBGROUP1] T1 WHERE T1.[U_ArticleGroup] = (SELECT $[OITM.ItmsGrpCod]))
    Unfortunately that only works as long as there is only one specific subgroup1 for the selected article group.
    I would be sooooo happy if there is anyone who can tell me the correct statement for my second UDF!
    Thanks so much in advance!!!!
    Edited by: Corinna Hochheim on Jan 18, 2010 10:16 PM
    Please ignore the "http://" in the above statements - it is certainly not part of my SQL.
    Please also ignore the strikes.

    Hello Dear,
    Use the below queries to get the values:
    Item Sub Group on the basis of Item Group
    SELECT T0.[Name] FROM [dbo].[@SUBGROUP]  T0 WHERE T0.[U_GroupCod] =$[OITM.ItmsGrpCod]
    Item Sub Group 1 on the basis of item sub group
    SELECT T0.[Name] FROM [dbo].[@SUBGROUP1]  T0 WHERE T0.[U_SubGrpCod]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP]  T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp])
    Sub group 2 on the basis of sub group 1
    SELECT T0.[Name] FROM [dbo].[@SUBGROUP2]  T0 WHERE T0.[U_SubGrpCod1]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP1]  T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp1])
    this will help you.
    regards,
    Neetu

  • Need SQL statement for this logic....

    Hi,
    I want a SQL statement for updating the following changed last number .
    Cuurently its:
    SELECT * FROM TEST;
    LAST NUMBER     CHANGED LAST NUMBER
    123518          
    12355265     
    123674659     
    9087648970     
    After updating with the required SQL statement table should look like
    LAST NUMBER     CHANGED LAST NUMBER
    123518          0000123518
    12355265     0012355265
    123674659     0123674659
    9087648970     9087648970
    the last number should be appended with ZEROs and the length of changed last number should be 10 always. Hope its clear.
    Appreciate your help.
    Thanks in advance
    Devender

    select last_number, lpad(to_char(last_number), 10 , '0') FROM test

  • SQL Statement for Composite Primary key

    Hi,
    I need a SQL statement for finding the Distinct values for combination of 2 Columns( Composite Primary key). I dont want to use Data Dictionary views.
    Table A
    c1 c2
    1 1
    1 2
    2 3
    Now for the above table combination of c1 and c2 is unique.
    Please advice.
    Cheers
    Ramkannan.A

    This?
    PRAZY@solarc> with tableA as
      2  (select 1 col1,2 col2 from dual
      3  union all
      4  select 1,1 from dual
      5  union all
      6  select 1,2 from dual
      7  union all
      8  select 2,3 from dual
      9  union all
    10  select 1,2 from dual
    11  union all
    12  select 2,3 from dual
    13  )
    14  select distinct col1, col2 from TableA
    15  /
          COL1       COL2
             2          3
             1          2
             1          1Regards,
    Prazy

  • Sql statement in a table not accepting variable

    I have the following problem on 10.1.0.3.0 with varialbe in an execute immediate statement
    here is the code that I am using
    declare
    remote_data_link varchar2(25) := 'UDE_DATATRANSFER_LINK';
    FROM_SCHEMA VARCHAR2(40) := 'UDE_OLTP';
    l_last_process_date date := to_date(to_char(sysdate,'mm-dd-yyyy hh:mi:ss'),'mm-dd-yyyy hh:mi:ss') - 1;
    stmt varchar2(4000) := 'MERGE into applicant_adverseaction_info theTarget USING (select * from '||FROM_SCHEMA||'.applicant_adverseaction_info@'||remote_data_link||' where last_activity > :l_last_process_date ) theSource ON(theTarget.applicant_id = theSource.applicant_id) WHEN MATCHED THEN UPDATE SET theTarget.cb_used = theSource.cb_used, theTarget.cb_address = theSource.cb_address, theTarget.scoredmodel_id = theSource.scoredmodel_id, theTarget.last_activity = theSource.last_activity WHEN NOT MATCHED THEN INSERT(CB_USED, CB_ADDRESS, SCOREDMODEL_ID, APPLICANT_ID, LAST_ACTIVITY) values(theSource.cb_used, theSource.cb_address, theSource.scoredmodel_id, theSource.applicant_id, theSource.last_activity)';
    stmt2 varchar2(4000) := 'MERGE into edm_application theTarget USING (select * from '||from_schema||'.edm_application@'||remote_data_link||' where last_activity > :l_last_process_date) theSource ON (theTarget.edm_appl_id = theSource.edm_appl_id) WHEN MATCHED THEN UPDATE SET theTarget.APP_REF_KEY = theSource.APP_REF_KEY, theTarget.IMPORT_REF_KEY = theSource.IMPORT_REF_KEY, theTarget.LAST_ACTIVITY = theSource.LAST_ACTIVITY WHEN NOT MATCHED THEN INSERT (EDM_APPL_ID, APP_REF_KEY, IMPORT_REF_KEY, LAST_ACTIVITY) values(theSource.EDM_APPL_ID, theSource.APP_REF_KEY, theSource.IMPORT_REF_KEY, theSource.LAST_ACTIVITY)';
    v_error varchar2(4000);
    T_MERGE VARCHAR2(4000);
    stmt3 varchar2(4000);
    BEGIN
    select merge_sql
    INTO T_MERGE
    from transfertables
    where table_name= 'edm_application';
    remote_data_link:= 'UDE_DATATRANSFER_LINK';
    FROM_SCHEMA := 'UDE_OLTP';
    --DBMS_OUTPUT.PUT_LINE(SUBSTR(stmt2,1,200));
    --STMT2 := T_MERGE;
    dbms_output.put_line(from_schema||' '||remote_data_link||' '||l_last_process_date);
    EXECUTE IMMEDIATE stmt2 using l_last_process_date;
    --execute immediate stmt3 ;
    dbms_output.put_line(from_schema||' '||remote_data_link||' '||l_last_process_date);
    dbms_output.put_line(substr(stmt2,1,200));
    commit;
    EXCEPTION
    WHEN OTHERS THEN
    V_ERROR := SQLCODE||' '||SQLERRM;
    v_ERROR := V_ERROR ||' '||SUBSTR(stmt2,1,200);
    DBMS_OUTPUT.PUT_LINE(V_ERROR);
    --dbms_output.put_line(substr(stmt2,1,200));
    END;
    This works perfectly
    but if I change it to get the same statement in a db table
    declare
    remote_data_link varchar2(25) := 'UDE_DATATRANSFER_LINK';
    FROM_SCHEMA VARCHAR2(40) := 'UDE_OLTP';
    l_last_process_date date := to_date(to_char(sysdate,'mm-dd-yyyy hh:mi:ss'),'mm-dd-yyyy hh:mi:ss') - 1;
    stmt varchar2(4000) := 'MERGE into applicant_adverseaction_info theTarget USING (select * from '||FROM_SCHEMA||'.applicant_adverseaction_info@'||remote_data_link||' where last_activity > :l_last_process_date ) theSource ON(theTarget.applicant_id = theSource.applicant_id) WHEN MATCHED THEN UPDATE SET theTarget.cb_used = theSource.cb_used, theTarget.cb_address = theSource.cb_address, theTarget.scoredmodel_id = theSource.scoredmodel_id, theTarget.last_activity = theSource.last_activity WHEN NOT MATCHED THEN INSERT(CB_USED, CB_ADDRESS, SCOREDMODEL_ID, APPLICANT_ID, LAST_ACTIVITY) values(theSource.cb_used, theSource.cb_address, theSource.scoredmodel_id, theSource.applicant_id, theSource.last_activity)';
    stmt2 varchar2(4000) := 'MERGE into edm_application theTarget USING (select * from '||from_schema||'.edm_application@'||remote_data_link||' where last_activity > :l_last_process_date) theSource ON (theTarget.edm_appl_id = theSource.edm_appl_id) WHEN MATCHED THEN UPDATE SET theTarget.APP_REF_KEY = theSource.APP_REF_KEY, theTarget.IMPORT_REF_KEY = theSource.IMPORT_REF_KEY, theTarget.LAST_ACTIVITY = theSource.LAST_ACTIVITY WHEN NOT MATCHED THEN INSERT (EDM_APPL_ID, APP_REF_KEY, IMPORT_REF_KEY, LAST_ACTIVITY) values(theSource.EDM_APPL_ID, theSource.APP_REF_KEY, theSource.IMPORT_REF_KEY, theSource.LAST_ACTIVITY)';
    v_error varchar2(4000);
    T_MERGE VARCHAR2(4000);
    stmt3 varchar2(4000);
    BEGIN
    select merge_sql
    INTO T_MERGE
    from transfertables
    where table_name= 'edm_application';
    remote_data_link:= 'UDE_DATATRANSFER_LINK';
    FROM_SCHEMA := 'UDE_OLTP';
    --DBMS_OUTPUT.PUT_LINE(SUBSTR(stmt2,1,200));
    STMT2 := T_MERGE;
    dbms_output.put_line(from_schema||' '||remote_data_link||' '||l_last_process_date);
    EXECUTE IMMEDIATE stmt2 using l_last_process_date;
    --execute immediate stmt3 ;
    dbms_output.put_line(from_schema||' '||remote_data_link||' '||l_last_process_date);
    dbms_output.put_line(substr(stmt2,1,200));
    commit;
    EXCEPTION
    WHEN OTHERS THEN
    V_ERROR := SQLCODE||' '||SQLERRM;
    v_ERROR := V_ERROR ||' '||SUBSTR(stmt2,1,200);
    DBMS_OUTPUT.PUT_LINE(V_ERROR);
    --dbms_output.put_line(substr(stmt2,1,200));
    END;
    I get ora-00900 invalid sql statement
    can somebody explain why this happens
    Thanks

    I agree with jan and anthony. Your post is too long and ill-formatted. However here's my understanding of your problem (with examples though slightly different ones).
    1- I have a function that returns number of records in a any given table.
      1  CREATE OR REPLACE FUNCTION get_count(p_table varchar2)
      2     RETURN NUMBER IS
      3     v_cnt number;
      4  BEGIN
      5    EXECUTE IMMEDIATE('SELECT count(*) FROM '||p_table) INTO v_cnt;
      6    RETURN v_cnt;
      7* END;
    SQL> /
    Function created.
    SQL> SELECT get_count('emp')
      2  FROM dual
      3  /
    GET_COUNT('EMP')
                  14
    2- I decide to move the statement to a database table and recreate my function.
    SQL> CREATE TABLE test
      2  (stmt varchar2(2000))
      3  /
    Table created.
    SQL> INSERT INTO test
      2  VALUES('SELECT count(*) FROM p_table');
    1 row created.
    SQL> CREATE OR REPLACE FUNCTION get_count(p_table varchar2)
      2     RETURN NUMBER IS
      3     v_cnt number;
      4     v_stmt varchar2(4000);
      5  BEGIN
      6     SELECT stmt INTO v_stmt
      7     FROM test;
      8     EXECUTE IMMEDIATE(v_stmt) INTO v_cnt;
      9     RETURN v_cnt;
    10  END;
    11  /
    Function created.
    SQL> SELECT get_count('emp')
      2  FROM dual
      3  /
    SELECT get_count('emp')
    ERROR at line 1:
    ORA-00942: table or view does not exist
    ORA-06512: at "SCOTT.GET_COUNT", line 8
    ORA-06512: at line 1
    --p_table in the column is a string and has nothing to do with p_table parameter in the function. And since there's no p_table table in my schema function returns error on execution. I suppose this is what you mean by "sql statement in a table not accepting variable"
    3- I rectify the problem by recreating the function.
      1  CREATE OR REPLACE FUNCTION get_count(p_table varchar2)
      2     RETURN NUMBER IS
      3     v_cnt number;
      4     v_stmt varchar2(4000);
      5  BEGIN
      6     SELECT replace(stmt,'p_table',p_table) INTO v_stmt
      7     FROM test;
      8     EXECUTE IMMEDIATE(v_stmt) INTO v_cnt;
      9     RETURN v_cnt;
    10* END;
    SQL> /
    Function created.
    SQL> SELECT get_count('emp')
      2  FROM dual
      3  /
    GET_COUNT('EMP')
                  14
    Hope this gives you some idea.-----------------------
    Anwar

  • Building a data flow task, within a foreach loop for dynamic table name, but ole db source not allowing variable

    In my control flow, I set up a variable for the table name, enumerated by SMO, following the instructions from the link here:
    http://www.bidn.com/blogs/mikedavis/ssis/156/using-a-for-each-loop-on-tables-ssis
    Now, I put a data flow task inside the foreach. I selected the OLE DB connection manger for my database, set the Data access mode to "Table name or view name variable", and selected my variable name from the drop down. So far so good. When I click on OK,
    it gives me an error 0x80040E37, basically saying it can't open the rowset for "my variable", Check that the object exists in the database.
    So, I assume I won't be able to do this "that' easily, and I will need to build a "SQL command from variable" or some such thing. Any advice on how to build this Source editor to dynamically name my columns from the variable?
    Thanks in advance!
    mpleaf

    Hi mpleaf,
    Please try to set "ValidateExternalData" to False in your OLE DB Source Properties and "DelayValidation" property to TRUE, please refer to similar threads:
    http://social.msdn.microsoft.com/Forums/en-US/sqlintegrationservices/thread/620557d9-41bc-4a40-86d5-0a8d2f910d8c/
    http://social.msdn.microsoft.com/Forums/en-US/sqlintegrationservices/thread/456f2201-447c-41b3-bf27-b3ba47e6b737
    Thanks,
    Eileen
    Eileen Zhao
    TechNet Community Support

  • How to increase the max character for a table name..!!

    Hi All,
    The maximum characters that supports for the table Name is 30
    How can I increase this so that I can have table names lengthier than 30
    This is required as I was doing a conversion of the database from SQL server 2005 to Oracle 9i
    Many thanks in advance...
    Best Regards..,

    So How can I make it possible..?!!If it not possible, you cannot make it possible.
    If you can create a synonym on more than 30 char., you cannot use it on more than 30 char :
    SQL> create synonym my_very_long_synonym_name_for_emp_table for emp;
    Synonym created.
    SQL> select count(*) from my_very_long_synonym_name_for_emp_table;
    select count(*) from my_very_long_synonym_name_for_emp_table
    ERROR at line 1:
    ORA-00972: identifier is too long
    SQL> select * from user_synonyms;
    SYNONYM_NAME                   TABLE_OWNER                    TABLE_NAME
    DB_LINK
    /91b591a7_MY_VERY_LONG_SYNONYM SCOTT                          EMP
    SQL> select count(*) from "/91b591a7_MY_VERY_LONG_SYNONYM";
      COUNT(*)
            14Nicolas.

  • How to write Sql statement for M:M relationship set?

    If theres two Entity sets "Department" and "Employee".....
    Department Entity contains this attribute dno,dname,address etc and
    "Employee" entity contain attribute like Empno,Empname,date,time etc
    and theres Many to Many relationship between Employee and Deapartment Entity set,i.e.each employee can work in any department, and each department has at least one employee (Many to Many relationship)
    What should be the SQL statement to create table for Many to Many relationship sets for Employee and Department set..
    Any helps will be appreciated.
    Femi

    create 3 tables: employee, department and empdept
    in the empdept table you reference foreign keys from the 2 other tables. so if my employee id was 42 and I work for departments 1,2 and 3, this table would look like this:
    emp_fk | dept_fk
    42           1
    42           2
    42           3

Maybe you are looking for