Dynamic SQL Help - Getting Errors

Basically I have a table with employee data, and I'm trying to create a dynamic PL / SQL block that creates a new table and copies over the data from employee table to the new one.
I'm teaching myself dynamic SQL so this is practice. Please don't offer "better solutions" because I'm sure there are plenty - I'm just looking to complete the code as is so I better understand this query language.
Here is my code:
set serveroutput on size 10000
declare
cursor c is
select table_name, tablespace_name
from user_tables where table_name = 'EMP';
cursor c2 is
select table_name, column_name, data_length, data_type, data_precision
from user_tab_cols where table_name = 'EMP';
cursor c3 is
select *
from emp;
counter number(3);
counter := 0;
begin
for i in c loop
if (counter = 0) then
create table emp2;
insert into emp2 table_name, tablespace_name;
for i in c2 loop
insert into emp2 table_name, column_name, data_length, data_type, data_precision;
counter := counter + 1;
end loop;
end loop;
for i in c3 loop
insert into emp2 empno, ename, job, mgr, hiredate, sal, comm, deptno;
end loop;
end;
Here are my errors:
Error starting at line 3 in command:
declare
cursor c is
select table_name, tablespace_name
from user_tables where table_name = 'EMP';
cursor c2 is
select table_name, column_name, data_length, data_type, data_precision
from user_tab_cols where table_name = 'EMP';
cursor c3 is
select *
from emp;
counter number(3);
counter := 0;
begin
for i in c loop
if (counter = 0) then
create table emp2;
insert into emp2 table_name, tablespace_name;
for i in c2 loop
insert into emp2 table_name, column_name, data_length, data_type, data_precision;
counter := counter + 1;
end loop;
end loop;
for i in c3 loop
insert into emp2 empno, ename, job, mgr, hiredate, sal, comm, deptno;
end loop;
end;
Error report:
ORA-06550: line 14, column 13:
PLS-00103: Encountered the symbol "=" when expecting one of the following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table long double ref
char time timestamp interval date binary national character
nchar
The symbol "<an identifier>" was substituted for "=" to continue.
ORA-06550: line 19, column 7:
PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
( begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifi
06550. 00000 - "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Start reading the Documents
There are basic errors in your code, some are pointed out below
declare
  cursor c is
    select table_name, tablespace_name
    from user_tables where table_name = 'EMP';
  cursor c2 is
    select table_name, column_name, data_length, data_type, data_precision
    from user_tab_cols where table_name = 'EMP';
  cursor c3 is
    select *
    from emp;
  counter number(3);
  counter := 0; --"You cannot initiate variable like this"
begin
  for i in c loop
   if (counter = 0) then
     create table emp2; --"You cannot create tables directly in PL/SQL. Need to use dynamic SQL.Syntax also wrong. "
     insert into emp2 table_name, tablespace_name; --"Values caluse missing"
     for i in c2 loop
        insert into emp2 table_name, column_name, --"Values caluse missing"
           data_length, data_type, data_precision; --"Record syntax not used"
        counter := counter + 1;
  end loop;
  end loop;
  for i in c3 loop
    insert into emp2 empno, ename,
     job, mgr, hiredate, sal, comm, deptno; --"Values caluse missing"
  end loop;
end;

Similar Messages

  • Connect by - sql help : getting error ORA-01489: result of string concatena

    here is an sql query and I am trying to cook a decode but since there are many columns invloved when I am trying to run this I am getting the following error:
    ORA-01489: result of string concatenation is too long
    Any kind of help is appreciated, I need to get this going otherwise I am dead :(
    Regards
    Rahul
    SQL:
    select sys_connect_by_path(c.decode_prep,'-') decode_prep
    from (select 'DECODE(BIAPPS_11.'||substr(b.all_cols,instr(b.all_cols,',',1,a.rn)+1,instr(b.all_cols,',',1,a.rn+1)-instr(b.all_cols,',',1,a.rn)-1)||','||'RAHULKALRA.'||substr(b.all_cols,instr(b.all_cols,',',1,a.rn)+1,instr(b.all_cols,',',1,a.rn+1)-instr(b.all_cols,',',1,a.rn)-1)||',''1'',''0'')' decode_prep, rownum curr, rownum -1 prev
    from (select rownum rn
    from dual connect by rownum <=
    (select (length('ROW_WID,COST_CENTER_NUM,COST_CENTER_NAME,COST_CENTER_DESC,CONTROL_AREA_NUM,CONTROL_AREA_NAME,CATEGORY_CODE,CATEGORY_NAME,CATEGORY_DESC,MANAGER_NAME,CURRENCY_CODE,CURRENCY_NAME,LANGUAGE_CODE,LANGUAGE_NAME,ST_ADDRESS1,ST_ADDRESS2,POST_OFFICE_BOX,CITY_NAME,STATE_CODE,STATE_NAME,REGION_CODE,REGION_NAME,COUNTRY_CODE,COUNTRY_NAME,POSTAL_CODE,PHONE_NUM,FAX_NUM,CSCN_HIER1_CODE,CSCN_HIER1_NAME,CSCN_HIER2_CODE,CSCN_HIER2_NAME,CSCN_HIER3_CODE,CSCN_HIER3_NAME,CSCN_HIER4_CODE,CSCN_HIER4_NAME,CSCN_HIER5_CODE,CSCN_HIER5_NAME,CSCN_HIER6_CODE,CSCN_HIER6_NAME,ACTIVE_FLG,CREATED_BY_WID,CHANGED_BY_WID,CREATED_ON_DT,CHANGED_ON_DT,AUX1_CHANGED_ON_DT,AUX2_CHANGED_ON_DT,AUX3_CHANGED_ON_DT,AUX4_CHANGED_ON_DT,SRC_EFF_FROM_DT,SRC_EFF_TO_DT,EFFECTIVE_FROM_DT,EFFECTIVE_TO_DT,DELETE_FLG,CURRENT_FLG,W_INSERT_DT,W_UPDATE_DT,DATASOURCE_NUM_ID,ETL_PROC_WID,INTEGRATION_ID,SET_ID,TENANT_ID,X_CUSTOM')
    - length(replace('ROW_WID,COST_CENTER_NUM,COST_CENTER_NAME,COST_CENTER_DESC,CONTROL_AREA_NUM,CONTROL_AREA_NAME,CATEGORY_CODE,CATEGORY_NAME,CATEGORY_DESC,MANAGER_NAME,CURRENCY_CODE,CURRENCY_NAME,LANGUAGE_CODE,LANGUAGE_NAME,ST_ADDRESS1,ST_ADDRESS2,POST_OFFICE_BOX,CITY_NAME,STATE_CODE,STATE_NAME,REGION_CODE,REGION_NAME,COUNTRY_CODE,COUNTRY_NAME,POSTAL_CODE,PHONE_NUM,FAX_NUM,CSCN_HIER1_CODE,CSCN_HIER1_NAME,CSCN_HIER2_CODE,CSCN_HIER2_NAME,CSCN_HIER3_CODE,CSCN_HIER3_NAME,CSCN_HIER4_CODE,CSCN_HIER4_NAME,CSCN_HIER5_CODE,CSCN_HIER5_NAME,CSCN_HIER6_CODE,CSCN_HIER6_NAME,ACTIVE_FLG,CREATED_BY_WID,CHANGED_BY_WID,CREATED_ON_DT,CHANGED_ON_DT,AUX1_CHANGED_ON_DT,AUX2_CHANGED_ON_DT,AUX3_CHANGED_ON_DT,AUX4_CHANGED_ON_DT,SRC_EFF_FROM_DT,SRC_EFF_TO_DT,EFFECTIVE_FROM_DT,EFFECTIVE_TO_DT,DELETE_FLG,CURRENT_FLG,W_INSERT_DT,W_UPDATE_DT,DATASOURCE_NUM_ID,ETL_PROC_WID,INTEGRATION_ID,SET_ID,TENANT_ID,X_CUSTOM',',')))+1 total_cols
    from dual)) a, (select ','||'ROW_WID,COST_CENTER_NUM,COST_CENTER_NAME,COST_CENTER_DESC,CONTROL_AREA_NUM,CONTROL_AREA_NAME,CATEGORY_CODE,CATEGORY_NAME,CATEGORY_DESC,MANAGER_NAME,CURRENCY_CODE,CURRENCY_NAME,LANGUAGE_CODE,LANGUAGE_NAME,ST_ADDRESS1,ST_ADDRESS2,POST_OFFICE_BOX,CITY_NAME,STATE_CODE,STATE_NAME,REGION_CODE,REGION_NAME,COUNTRY_CODE,COUNTRY_NAME,POSTAL_CODE,PHONE_NUM,FAX_NUM,CSCN_HIER1_CODE,CSCN_HIER1_NAME,CSCN_HIER2_CODE,CSCN_HIER2_NAME,CSCN_HIER3_CODE,CSCN_HIER3_NAME,CSCN_HIER4_CODE,CSCN_HIER4_NAME,CSCN_HIER5_CODE,CSCN_HIER5_NAME,CSCN_HIER6_CODE,CSCN_HIER6_NAME,ACTIVE_FLG,CREATED_BY_WID,CHANGED_BY_WID,CREATED_ON_DT,CHANGED_ON_DT,AUX1_CHANGED_ON_DT,AUX2_CHANGED_ON_DT,AUX3_CHANGED_ON_DT,AUX4_CHANGED_ON_DT,SRC_EFF_FROM_DT,SRC_EFF_TO_DT,EFFECTIVE_FROM_DT,EFFECTIVE_TO_DT,DELETE_FLG,CURRENT_FLG,W_INSERT_DT,W_UPDATE_DT,DATASOURCE_NUM_ID,ETL_PROC_WID,INTEGRATION_ID,SET_ID,TENANT_ID,X_CUSTOM'||',' all_cols from dual) b) c
    start with curr = 1
    connect by prior curr = prev
    order by length(sys_connect_by_path(c.decode_prep,'-')) desc
    same as above sql only difference is here I am pulling the first record from the result set which above query returns :
    select ltrim(replace(decode_prep,'-','||'),'||') decode_prep
    from (select sys_connect_by_path(c.decode_prep,'-') decode_prep
    from (select 'DECODE(BIAPPS_11.'||substr(b.all_cols,instr(b.all_cols,',',1,a.rn)+1,instr(b.all_cols,',',1,a.rn+1)-instr(b.all_cols,',',1,a.rn)-1)||','||'RAHULKALRA.'||substr(b.all_cols,instr(b.all_cols,',',1,a.rn)+1,instr(b.all_cols,',',1,a.rn+1)-instr(b.all_cols,',',1,a.rn)-1)||',''1'',''0'')' decode_prep, rownum curr, rownum -1 prev
    from (select rownum rn
    from dual connect by rownum <=
    (select (length('ROW_WID,COST_CENTER_NUM,COST_CENTER_NAME,COST_CENTER_DESC,CONTROL_AREA_NUM,CONTROL_AREA_NAME,CATEGORY_CODE,CATEGORY_NAME,CATEGORY_DESC,MANAGER_NAME,CURRENCY_CODE,CURRENCY_NAME,LANGUAGE_CODE,LANGUAGE_NAME,ST_ADDRESS1,ST_ADDRESS2,POST_OFFICE_BOX,CITY_NAME,STATE_CODE,STATE_NAME,REGION_CODE,REGION_NAME,COUNTRY_CODE,COUNTRY_NAME,POSTAL_CODE,PHONE_NUM,FAX_NUM,CSCN_HIER1_CODE,CSCN_HIER1_NAME,CSCN_HIER2_CODE,CSCN_HIER2_NAME,CSCN_HIER3_CODE,CSCN_HIER3_NAME,CSCN_HIER4_CODE,CSCN_HIER4_NAME,CSCN_HIER5_CODE,CSCN_HIER5_NAME,CSCN_HIER6_CODE,CSCN_HIER6_NAME,ACTIVE_FLG,CREATED_BY_WID,CHANGED_BY_WID,CREATED_ON_DT,CHANGED_ON_DT,AUX1_CHANGED_ON_DT,AUX2_CHANGED_ON_DT,AUX3_CHANGED_ON_DT,AUX4_CHANGED_ON_DT,SRC_EFF_FROM_DT,SRC_EFF_TO_DT,EFFECTIVE_FROM_DT,EFFECTIVE_TO_DT,DELETE_FLG,CURRENT_FLG,W_INSERT_DT,W_UPDATE_DT,DATASOURCE_NUM_ID,ETL_PROC_WID,INTEGRATION_ID,SET_ID,TENANT_ID,X_CUSTOM')
    - length(replace('ROW_WID,COST_CENTER_NUM,COST_CENTER_NAME,COST_CENTER_DESC,CONTROL_AREA_NUM,CONTROL_AREA_NAME,CATEGORY_CODE,CATEGORY_NAME,CATEGORY_DESC,MANAGER_NAME,CURRENCY_CODE,CURRENCY_NAME,LANGUAGE_CODE,LANGUAGE_NAME,ST_ADDRESS1,ST_ADDRESS2,POST_OFFICE_BOX,CITY_NAME,STATE_CODE,STATE_NAME,REGION_CODE,REGION_NAME,COUNTRY_CODE,COUNTRY_NAME,POSTAL_CODE,PHONE_NUM,FAX_NUM,CSCN_HIER1_CODE,CSCN_HIER1_NAME,CSCN_HIER2_CODE,CSCN_HIER2_NAME,CSCN_HIER3_CODE,CSCN_HIER3_NAME,CSCN_HIER4_CODE,CSCN_HIER4_NAME,CSCN_HIER5_CODE,CSCN_HIER5_NAME,CSCN_HIER6_CODE,CSCN_HIER6_NAME,ACTIVE_FLG,CREATED_BY_WID,CHANGED_BY_WID,CREATED_ON_DT,CHANGED_ON_DT,AUX1_CHANGED_ON_DT,AUX2_CHANGED_ON_DT,AUX3_CHANGED_ON_DT,AUX4_CHANGED_ON_DT,SRC_EFF_FROM_DT,SRC_EFF_TO_DT,EFFECTIVE_FROM_DT,EFFECTIVE_TO_DT,DELETE_FLG,CURRENT_FLG,W_INSERT_DT,W_UPDATE_DT,DATASOURCE_NUM_ID,ETL_PROC_WID,INTEGRATION_ID,SET_ID,TENANT_ID,X_CUSTOM',',')))+1 total_cols
    from dual)) a, (select ','||'ROW_WID,COST_CENTER_NUM,COST_CENTER_NAME,COST_CENTER_DESC,CONTROL_AREA_NUM,CONTROL_AREA_NAME,CATEGORY_CODE,CATEGORY_NAME,CATEGORY_DESC,MANAGER_NAME,CURRENCY_CODE,CURRENCY_NAME,LANGUAGE_CODE,LANGUAGE_NAME,ST_ADDRESS1,ST_ADDRESS2,POST_OFFICE_BOX,CITY_NAME,STATE_CODE,STATE_NAME,REGION_CODE,REGION_NAME,COUNTRY_CODE,COUNTRY_NAME,POSTAL_CODE,PHONE_NUM,FAX_NUM,CSCN_HIER1_CODE,CSCN_HIER1_NAME,CSCN_HIER2_CODE,CSCN_HIER2_NAME,CSCN_HIER3_CODE,CSCN_HIER3_NAME,CSCN_HIER4_CODE,CSCN_HIER4_NAME,CSCN_HIER5_CODE,CSCN_HIER5_NAME,CSCN_HIER6_CODE,CSCN_HIER6_NAME,ACTIVE_FLG,CREATED_BY_WID,CHANGED_BY_WID,CREATED_ON_DT,CHANGED_ON_DT,AUX1_CHANGED_ON_DT,AUX2_CHANGED_ON_DT,AUX3_CHANGED_ON_DT,AUX4_CHANGED_ON_DT,SRC_EFF_FROM_DT,SRC_EFF_TO_DT,EFFECTIVE_FROM_DT,EFFECTIVE_TO_DT,DELETE_FLG,CURRENT_FLG,W_INSERT_DT,W_UPDATE_DT,DATASOURCE_NUM_ID,ETL_PROC_WID,INTEGRATION_ID,SET_ID,TENANT_ID,X_CUSTOM'||',' all_cols from dual) b) c
    start with curr = 1
    connect by prior curr = prev
    order by length(sys_connect_by_path(c.decode_prep,'-')) desc)
    where rownum = 1
    Edited by: Mac_Freak_Rahul on Nov 28, 2012 1:31 AM : in the first sql ')'
    removed after desc in the last line so now this query will run and throw an error.

    Clearly your error is because the string concatenation you are doing with sys_connect_by_path is exceeding the 4000 bytes permitted by SQL.
    In that case you need to concatenate your data into a CLOB datatype, for which you'll need a CLOB aggregation function...
    create or replace type clobagg_type as object
      text clob,
      static function ODCIAggregateInitialize(sctx in out clobagg_type) return number,
      member function ODCIAggregateIterate(self in out clobagg_type, value in clob) return number,
      member function ODCIAggregateTerminate(self in clobagg_type, returnvalue out clob, flags in number) return number,
      member function ODCIAggregateMerge(self in out clobagg_type, ctx2 in clobagg_type) return number
    create or replace type body clobagg_type is
      static function ODCIAggregateInitialize(sctx in out clobagg_type) return number is
      begin
        sctx := clobagg_type(null) ;
        return ODCIConst.Success ;
      end;
      member function ODCIAggregateIterate(self in out clobagg_type, value in clob) return number is
      begin
        self.text := self.text || value ;
        return ODCIConst.Success;
      end;
      member function ODCIAggregateTerminate(self in clobagg_type, returnvalue out clob, flags in number) return number is
      begin
        returnValue := self.text;
        return ODCIConst.Success;
      end;
      member function ODCIAggregateMerge(self in out clobagg_type, ctx2 in clobagg_type) return number is
      begin
        self.text := self.text || ctx2.text;
        return ODCIConst.Success;
      end;
    end;
    create or replace function clobagg(input clob) return clob
      deterministic
      parallel_enable
      aggregate using clobagg_type;
    SQL> select trim(',' from clobagg(ename||',')) as enames from emp;
    ENAMES
    SMITH,ALLEN,WARD,JONES,MARTIN,BLAKE,CLARK,SCOTT,KING,TURNER,ADAMS,JAMES,FORD,MILLER
    SQL> ed
    Wrote file afiedt.buf
      1  with t as
      2    (select 'PFL' c1, 0 c2,110 c3 from dual union all
      3     select 'LHL', 0 ,111 from dual union all
      4     select 'PHL', 1, 111 from dual union all
      5     select 'CHL', 2, 111 from dual union all
      6     select 'DHL', 0, 112 from dual union all
      7     select 'VHL', 1, 112 from dual union all
      8     select 'CPHL', 0, 114 from dual union all
      9     select 'WDCL', 1, 114 from dual union all
    10     select 'AHL' ,2 ,114 from dual union all
    11     select 'NFDL', 3, 114 from dual)
    12  --
    13  -- end of test data
    14  --
    15  select trim(clobagg(c1||' ')) as c1, c3
    16  from (select * from t order by c3, c2)
    17  group by c3
    18* order by c3
    SQL> /
    C1                                     C3
    PFL                                   110
    LHL CHL PHL                           111
    DHL VHL                               112
    CPHL AHL NFDL WDCL                    114

  • Dynamic Change event getting error with cascading LOV's

    Hi all,
    In my application (v4.0.0), I have two sets of cascading drop-down select lists, these each make up a date (year, month, day) plus a time value (not cascading).
    I also have a dynamic action that gets the hours difference between the two dates set above. This fires on the change event.
    When I change, say the month drop-down, the day list is refreshed. But before it is refreshed, it looks to be emptied and the change event fires. I then get an error from the dynamic action because the day value passed to the query is empty (confirmed when looking at POST data).
    Can anyone think of a workaround idea for this? e.g. a way to set the dynamic action to conditional?
    Thanks!

    Hi Peter
    Thanks for the tip, I have tried this and it has helped, although not solved the problem. I was originally getting two errors appear ("AJAX call returned server error ORA-01843: not a valid month for Set Value.") and this has removed one of them...
    When looking in Firebug, it seems to me that although the dynamic actions (cascading update + set value) are running one before the other, the values aren't updated in order. e.g. the cascading update is not applied before the set value action is run.
    Could this be a bug with dynamic actions?

  • Dynamic SQL help!

    I'm trying to build a update statement with different operator which setup from a table and passed. Not sure how to build it. Please help
    PROCEDURE my_update
      p_id            IN NUMBER,
      p_var1          IN NUMBER,
      my_value        IN VARCHAR2,
      my_operator     IN VARCHAR2,
      x_return_status OUT VARCHAR2,
      x_errors        OUT VARCHAR2
    ) IS
      l_dynamic_string VARCHAR2(4000);
    BEGIN
    l_dynamic_string := table_b.col2 ||
                        rec.my_operator  /* value as: "=" OR "LIKE" */ ||
                        my_value /* VALUE AS "2233"  OR "900%" */
      UPDATE table_b
         SET col1 = ''
       WHERE id = p_id
         AND l_dynamic_string
         AND id = (SELECT table_a.id
                     FROM table_a
                    WHERE id = p_id
                      AND col_a = p_var1);
    EXCEPTION
      WHEN OTHERS THEN
        NULL;
    END my_update;

    Hi,
    What you posted can probably be done without dynamic SQL. If the expression after LIKE does not conatin a wild-card, then LIKE behaves just like =. You can probably arrange things so that the query always uses LIKE.
    If you need dynamic SQL, then use EXECUTE IMMEDIATE to perform it.
    I think you want something like this:
    PROCEDURE my_update
      p_id            IN NUMBER,
      p_var1          IN NUMBER,
      my_value        IN VARCHAR2,
      my_operator     IN VARCHAR2,
      x_return_status OUT VARCHAR2,
      x_errors        OUT VARCHAR2
    ) IS
      l_dynamic_string VARCHAR2 (4000);
      l_update_txt        VARCHAR2 (4000);
    BEGIN
        l_dynamic_string := table_b.col2 || ' '     -- If my_operator is LIKE you'll need a space here
                                        || my_operator               /* value as: "=" OR "LIKE" */
                             || Q'< '>'
                             || my_value            /* VALUE AS "2233"  OR "900%" */
                             || Q'<' >'
        l_update_txt := 'UPDATE table_b'
                    || '   SET col1 = NULL'
                  || ' WHERE id = p_id'
                    || '   AND ' || l_dynamic_string
                    || '   AND id = (SELECT table_a.id'
                     || '                     FROM table_a'
                     || '             WHERE id = p_id
                     || '               AND col_a = p_var1)';
        dbms_output.put_line (l_update_txt || ' = l_update_txt in my_update');
    --  EXECUTE IMMEDIATE  l_update_txt;
    --     No EXCEPTION hider
    END my_update;While writing dynamic SQL, it's a good idea to display the dynamic text. I used put_line to do that. Remember to comment out (or remove) the display code when testing is finished.
    Notice that the EXECUTE IMMEDIATE command is commented out. Only after you've tested some, and you think l_update_txt is correct, should you un-commnet that line.
    Never say "EXCEPTION WHEN OTHERS THEN NULL;"
    Error messages help you, especially duting development when you're likely to have lots of coding errors.
    If you really need to keep the program running after encountering certain errors, then it's okay to have an EXCEPTION block, but your use of either "WHEN OTHERS" or "THEN NULL" should be very limited, and you should not use both of them together.

  • Pl Dynamic sql help needed

    Hello Everyone
    I am using database 11g. Can someone pl suggest what are the rules for putting single quotes for dynamic sql like
    1) how many single quotes before/after a sql statement .
    2) Rules for putting single quotes if there exists i) a variable in the sql statement
    ii) a constant for e.g 100 in the sql statment.
    If you could give the answers with a simple select statement, it will be even better !!!
    Thanks and regards
    Gautam

    ms wrote:
    Hello Everyone
    I am using database 11g. Can someone pl suggest what are the rules for putting single quotes for dynamic sql like
    1) how many single quotes before/after a sql statement .
    2) Rules for putting single quotes if there exists i) a variable in the sql statement
    ii) a constant for e.g 100 in the sql statment.
    If you could give the answers with a simple select statement, it will be even better !!!
    Thanks and regards
    Gautamwrite the SQL statement as you would for any SQL client & enclose it using Q-quote
    http://askanantha.blogspot.com/2007/12/q-quote-operator-introduced-in-oracle.html
    Handle:     ms
    Status Level:     Newbie
    Registered:     Jun 3, 2007
    Total Posts:     46
    Total Questions:     17 (17 unresolved)
    WOW!
    *NEVER got any answer in 5+ years & still wasting time here again, still!
    You must be an eternal optimist.
    I hope I get credited for your FIRST answer.

  • Saving result from sp_executesql into a variable and using dynamic column name - getting error "Error converting data type varchar to numeric"

    Im getting an error when running a procedure that includes this code.
    I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql
    DECLARE @retval AS DECIMAL(12,2)
    DECLARE @MonthVal VARCHAR(20), @SpreadKeyVal INT
    DECLARE @sqlcmd AS NVARCHAR(150)
    DECLARE @paramdef NVARCHAR(150)
    SET @MonthVal = 'Month' + CAST(@MonthNumber AS VARCHAR(2) );
    SET @SpreadKeyVal = @SpreadKey; --CAST(@SpreadKey AS VARCHAR(10) );
    SET @sqlcmd = N' SELECT @retvalout = @MonthVal FROM dbo.CourseSpread WHERE CourseSpreadId = @SpreadKeyVal';
    SET @paramdef = N'@MonthVal VARCHAR(20), @SpreadKeyVal INT, @retvalout DECIMAL(12,2) OUTPUT'
    --default
    SET @retval = 0.0;
    EXECUTE sys.sp_executesql @sqlcmd,@paramdef, @MonthVal = 'Month4',@SpreadKeyVal = 1, @retvalout = @retval OUTPUT;
    SELECT @retval
    DECLARE @return_value DECIMAL(12,2)
    EXEC @return_value = [dbo].[GetSpreadValueByMonthNumber]
    @SpreadKey = 1,
    @MonthNumber = 4
    SELECT 'Return Value' = @return_value
    Msg 8114, Level 16, State 5, Line 1
    Error converting data type varchar to numeric.

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    >> I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql <<
    This is so very, very wrong! A column is an attribute of an entity. The idea that you are so screwed up that you have no idea if you want
    the shoe size, the phone number or something else at run time of this entity. 
    In Software Engineering we have a principle called cohesion that says a model should do one and only one task, have one and only one entry point, and one and only one exit point. 
    Hey, on a scale from 1 to 10, what color is your favorite letter of the alphabet? Yes, your mindset is that level of sillyity and absurdity. 
    Do you know that SQL is a declarative language? This family of languages does not use local variables! 
    Now think about “month_val” and what it means. A month is a temporal unit of measurement, so this is as silly as saying “liter_val” in your code. Why did you use “sp_” on a procedure? It has special meaning in T-SQL.  
    Think about how silly this is: 
     SET @month_val = 'Month' + CAST(@month_nbr AS VARCHAR(2));
    We do not do display formatting in a query. This is a violation of at the tiered architecture principle. We have a presentation layer. But more than that, the INTERVAL temporal data type is a {year-month} and never just a month. This is fundamental. 
    We need to see the DDL so we can re-write this mess. Want to fix it or not?
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Unable to generate the XML file through SQL script. getting error PLS-00306

    I am fetching the data from cursor and generating the xml output I am getting the below error.
    When I have checked the cursor query it is fetching the data in to single column.
    Input truncated to 1 characters
    Enter value for 7: EXEC FND_CONC_STAT.COLLECT;
    DBMS_LOB.append (tmp_file, r.core_xml);
    ERROR at line 95:
    ORA-06550: line 95, column 7:
    PLS-00306: wrong number or types of arguments in call to 'APPEND'
    ORA-06550: line 95, column 7:
    PL/SQL: Statement ignored

    Hi Alex,
    thanks for the responce..
    i have fixed the issue
    i have used XMLAttributes to get the value
    SELECT XMLELEMENT (
    NAME "TranACK",
    XMLAttributes ('1' as "TranNum",
    (select distinct to_char(SYSDATE,'yyyy-mm-dd')
    from DUAL) as "PrcDate"),
    XMLFOREST (
    a.PAYMENT_ID AS "PmtID"),
    XMLFOREST (
    a.ACK_TRANSACTION_RECEIVER AS "Name1"),
    XMLFOREST (
    to_char(a.VALUE_DATE,'yyyy-mm-dd') as "ValueDate" ),
    XMLFOREST (
    a.PAYMENT_AMOUNT AS "CurAmt"),
    XMLFOREST (
    a.CURRENCY_CODE AS "CurCode")
    ).getclobval ()
    AS line_xml
    FROM XXWAP_PAYMENT_LINE_TBL a
    where a.PAYMENT_BATCH_ID=P_batch_id;

  • Lync Powershell help -getting error "Management Object Not found"

    Hi,
    I want to reference a list of users in Lync that do not have a HostedVoicemailPolicy applied. Please can someone help me..
    I have a list of users that form a txt file I am referencing called $lynctest.
    User1
    User2
    User3
    NoSuchUser1
    NoSuchUser2
    I have the following and its not catching the error so that I can output to another file.
    try
    foreach($lyncuser in $lynctest)
        Get-CsUser -Identity $lyncuser | select displayname, hostedvoicemailpolicy
    catch
       write-host "$lyncuser user not found" > "c:\datatemp\listofusers.txt"

    Not super efficient, but quick and dirty.  If you're talking about thousands of users, this might be too slow and we can work something else out.  If you're talking about a handful, this might be fine.
    foreach($lyncuser in $lynctest) {
    $founduser=Get-CSUser|Where-Object {$_.samaccountname -match $lyncuser}
    if ($founduser) {
    "The user exists"
    else {
    "The user does not exist"
    Please remember, if you see a post that helped you please click "Vote As Helpful" and if it answered your question please click "Mark As Answer".
    SWC Unified Communications
    This forum post is based upon my personal experience and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

  • Insertin Data useing SQL Procedure Getting Error ORA-00942 and ORA-06512

    I have two Schemas ISYS and ISYSTWO
    I had created a Stored Procedure RECINC2 in Schema ISYS
    as
    procedure recinc2(cName IN CHAR,cWhere IN CHAR,cTable in CHAR)
    AS
    cQry VARCHAR2(1000);
    BEGIN
    cQry := 'INSERT INTO '||cName||'.'||cTable||' SELECT * FROM '||cTable|| ' WHERE ||cWhere;
    dbms_output.put_line(cqry);
    EXECUTE IMMEDIATE cQry;
    end;
    NOW WHEN in Run it gives error
    SQL> begin
    2 recinc2('ISYSTWO','CODE=4','AGENTS');
    3 end;
    4 /
    INSERT INTO ISYSTWO.AGENTS SELECT * FROM AGENTS WHERE CODE=4
    begin
    ERROR at line 1:
    ORA-00942: table or view does not exist
    ORA-06512: at "ISYS.RECINC2", line 8
    ORA-06512: at line 2
    BUT IF I EXECUTE
    the DBMS output
    INSERT INTO ISYSTWO.AGENTS SELECT * FROM AGENTS WHERE CODE=4
    it executes and gives fine result
    Please help
    Thanks
    Chaand kackria

    SQL> conn ISYSTWO/ISYSTWO
    Connected.
    SQL> grant all on agents to isys;
    Grant succeeded.
    SQL> conn isys/isys
    Connected.
    SQL> exec recinc2('ISYSTWO','CODE=4','AGENTS');
    INSERT INTO ISYSTWO.AGENTS SELECT * FROM AGENTS WHERE CODE=4
    PL/SQL procedure successfully completed.

  • Direct Path SQL Loader get error ORA-01555

    Hi All,
    11.2.0.1 DB
    Has anyone here used sqlloader direct path option?
    Is there special setting I need for the Undo TS?
    I am testing my sqlloader direct path but I got error : ORA-01555: snapshot too old: rollback segment number 10 with name "_SYSSMU10$" too small
    I am only testing 100 records and I shutdown the database. And I am only the one using it. :(
    Does dropping the Undo TS and creating new one help resolve my issue?
    Thanks a lot,
    Kinz
    Edited by: KinsaKaUy? on 07-Nov-2012 03:33

    I drop my UNDOTS1 and recreate it to resolve if there are framentation in the TS itself , but to no avail, the same error persist :(
    Record 1: Rejected - Error on table EMPLOYEE.
    ORA-00604: error occurred at recursive SQL level 1
    ORA-01555: snapshot too old: rollback segment number with name "" too small
    SYSTEM                         ONLINE
    _SYSSMU87_2780657351$          ONLINE
    _SYSSMU88_120427686$           ONLINE
    _SYSSMU89_1588874193$          ONLINE
    _SYSSMU90_2571046414$          ONLINE
    _SYSSMU91_1803654754$          ONLINE
    _SYSSMU92_2477693864$          ONLINE
    _SYSSMU93_1908993412$          ONLINE
    _SYSSMU94_985867735$           ONLINE
    _SYSSMU95_4165893730$          ONLINE
    _SYSSMU96_1502488804$          ONLINE
    _SYSSMU97_3533816217$          ONLINE
    _SYSSMU98_3954380786$          ONLINE
    _SYSSMU99_1314687851$          ONLINE
    _SYSSMU100_3542148152$         ONLINE
    _SYSSMU101_1249002234$         ONLINE
    _SYSSMU102_1520886654$         ONLINE
    _SYSSMU103_2785416951$         ONLINE
    _SYSSMU104_1530388055$         ONLINE
    _SYSSMU105_1995830672$         ONLINE
    _SYSSMU106_4584952$            ONLINE
    _SYSSMU107_1177768351$         ONLINE
    _SYSSMU108_3896986945$         ONLINE
    _SYSSMU109_2576315174$         ONLINE
    _SYSSMU110_2786589320$         ONLINE
    _SYSSMU111_1195961439$         ONLINE
    _SYSSMU112_2612035115$         ONLINE
    _SYSSMU113_1697198479$         ONLINE
    _SYSSMU114_3939726644$         ONLINE
    _SYSSMU115_467875145$          ONLINE
    _SYSSMU116_2826382876$         ONLINE
    _SYSSMU117_3650068864$         ONLINE
    _SYSSMU118_92260707$           ONLINE
    _SYSSMU119_2322108460$         ONLINE
    _SYSSMU120_2583709550$         ONLINE
    _SYSSMU121_1279604730$         ONLINE
    _SYSSMU122_2128414833$         ONLINE
    _SYSSMU123_1365970622$         ONLINE
    _SYSSMU124_1855929876$         ONLINE
    _SYSSMU125_1511578664$         ONLINE
    _SYSSMU126_3219352797$         ONLINE
    _SYSSMU127_2412556110$         ONLINE
    _SYSSMU128_2102547636$         ONLINE
    _SYSSMU129_447164998$          ONLINE
    _SYSSMU130_3851265156$         ONLINE
    _SYSSMU131_3046352603$         ONLINE
    _SYSSMU132_2987406815$         ONLINE
    _SYSSMU133_983809304$          ONLINE
    _SYSSMU134_928979873$          ONLINE
    _SYSSMU135_3248183819$         ONLINE
    _SYSSMU136_811112856$          ONLINE
    _SYSSMU137_1958351427$         ONLINE
    _SYSSMU138_2222543$            ONLINE
    _SYSSMU139_3962620689$         ONLINE
    _SYSSMU140_2711665463$         ONLINE
    _SYSSMU141_3724825495$         ONLINE
    _SYSSMU142_1818253355$         ONLINE
    _SYSSMU143_1370485269$         ONLINE
    _SYSSMU144_2442636386$         ONLINE
    59 rows selected.
    SQL>Is there something missing in my sqlloader parameter? but if I use "ordinary" path it will load successfully. But not with "direct" path :( Any ideas please

  • Help Getting error 1602 in itunes on the ipad

    HELP ME PLEASE everytime i try to update in itunes i get a 1602 error it gets stuck a the thrid verifying with apple and then after like three minutes it doesnt move i have tried everything to fix it right now it is just stuck on a black screen i can put it in dfu mode but thats it ...i have also tried differnet usb plugs but nothing i even tried two different computers i am currently running windows 7.. i dont know whats wrong if someone could help me that would be awesome i cant even put the device in recovery mode only dfu mode

    http://www.youtube.com/watch?v=AsWnZOCyt-0 here is a link to a video i uploaded that shows the exact problem that i am having

  • Dynamic SQL run with error 'ORA-29275: partial multibyte character'

    Hi All,
    In daily work, we use daynamic SQL to load data from another database through DB Link. However, even if I run the following simple statement in our DB, it will raise the error.
    CREATE TABLE TEST_TMP
    AS
    SELECT TRANSACTION_REASON
    FROM [email protected] --it is using db link.
    WHERE LAST_UPDATE_DATE>=TO_DATE('18-12-2012 22:01:58', 'dd-mm-yyyy hh24:mi:ss');
    This statement had been workng correctly before OCT-2012 and there was no change with the source. Afterwards, there was just a change which upgraded the DB version from 10g to 11g on our side. I have browsed my technical articles, but I still cannot find the root cause. Is it due to the updgrading of the DB which practice stricter sanity check?
    I don't know.
    I'd appreciate of you can give me suggestion if you know such case.
    Thanks,
    David

    David Paul wrote:
    Hi,
    Can you give me a full explaination about the DL http://vibhorkumar.wordpress.com/2011/02/27/fix-of-ora-29275-partial-multibyte-character/ you mentioned?
    I don't understand the query in it well.
    Thanks,
    DavidDon't confuse yourself... It's just saying to convert data into your local DB type...
    Check these queries -
    1] /* check this in both your LOCAL and REMOTE databases */
    select dump('a',1010) from dual;
    I got --
    Typ=96 Len=1 CharacterSet=AL32UTF8: 97
    So, my charset encoding is AL32UTF8. Similarly, find yours for both Local & Remote DBs.
    2]
    /* Then do */
    CONVERT(transaction_reason,'<local_charset>','<remote_charset>')Edited by: ranit B on Dec 22, 2012 5:46 PM

  • HELP--getting error message upon export attempt:

    WHile trying to export from AE CS5, I'm getting an error meassage which reads, " The directory originally specified
    in the selected output module no longer exists".
    I've tried rebooting and also, while re-launching after effects, I tried holding CTL, ALT, and shift (something i heard might work)...
    neither worked....
    What can i do????
    THANK YOU...
    ANOTHER bit of info----at the start of working on this project (it is a template project), i have the message
    ,"this project contains 1 reference to a missing effect.  Please install the following effect to restore this reference. ("Form")"....
    Could this have anything to do with my export issure?.....The project is working fine and looks great, so at first i didn't think
    not having "form" was an issure, but now i'm wondering............If this is connected, what is form and can i download it and add
    it for free???
    Thanks again..

    what is form and can i download it and add it for free???
    Trapcode Form. And no, it costs money.
    The directory originally specified in the selected output module no longer exists
    It's simply a leftover render item on the render queue pointing to a path that does not exist on your computer.
    Mylenium

  • From pl/sql table getting error - "ORA-01403: no data found"

    Hi All,
    i habe written package, and the spce define as -
    type F761RecType is RECORD (
    type F761TabType is TABLE of F761RecType INDEX BY BINARY_INTEGER;
    l_F761_table F761TabType;
    PROCEDURE modification1
    p_F761_table IN F761TabType,
    From button click of form i passed -
    DECLARE
    l_f761_table I743_PUC_MAPS_TREE_PKG.F761TabType;
    l_counter number;
    BEGIN
              LOOP
         l_counter :=l_counter+1;
              l_f761_table(l_counter).P_TABLE := :MAPS.P_table;
         EXIT WHEN      :SYSTEM.LAST_RECORD = 'TRUE' ;
    next_record;
    end loop;
    i743_puc_maps_tree_pkg.modification1(
                                            p_F761_table => l_f761_table,
    END;
    Now when I take table count (l_f761_table.count) in button click in form level I am getting value; but when I try to get the count in sid the package, it giving error "ORA-01403: no data found".
    Pls tell me where I am wrong ..!!
    BR,
    Subir

    Thaks all, probls has been solved..

  • Help Getting Errors in program

    I keep getting this error:
    Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
         at java.lang.String.compareTo(Unknown Source)
         at PasswordApplet.actionPerformed(PasswordApplet.java:54)
         at java.awt.Button.processActionEvent(Unknown Source)
         at java.awt.Button.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)Here's my code:
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    public class PasswordApplet extends Applet implements ActionListener
         String id, password;
         boolean success;
         String idArray[] = {"id", "pop"};
         String passwordArray[] = {"password", "snap"};
         Label headerLabel = new Label("Please type your ID and Password");
         Label idLabel = new Label("ID:");
              TextField idField = new TextField(8);
         Label passwordLabel = new Label("Password:");
              TextField passwordField = new TextField(8);
              Button loginButton = new Button("Login");
         public void init()
              setBackground(Color.orange);
              setLayout(new FlowLayout(FlowLayout.LEFT,50,30));
              add(headerLabel);
              add(idLabel);
                   add(idField);
                   idField.requestFocus();
              add(passwordLabel);
                   add(passwordField);
                   passwordField.setEchoChar('*');
              add(loginButton);
                   loginButton.addActionListener(this);
         public void actionPerformed(ActionEvent e)
              success = false;
              for (int i = 0; i<idArray.length;i++)
                   if((idArray.compareTo(id)==0) && (passwordArray[i].compareTo(password)==0))
                        success = true;
              if(success = true)
                   headerLabel.setText("Login Successful");
                   repaint();
              else
                   headerLabel.setText("Invalid. Try Again.");
                   clearFields();
         void clearFields()
              headerLabel.setText("Please type your ID and Password");
              idField.setText("");
              passwordField.setText("");

    Nevermind I got it But now I have a new problem: The program works but it's saying login successful whether the id and password are wrong or not. Any ideas on how to make it only say Login Successful when correct id and password are input?
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    public class PasswordApplet extends Applet implements ActionListener
         String id, password;
         boolean success;
         String idArray[] = {"id", "pop"};
         String passwordArray[] = {"password", "snap"};
         Label headerLabel = new Label("Please type your ID and Password");
         Label idLabel = new Label("ID:");
              TextField idField = new TextField(8);
         Label passwordLabel = new Label("Password:");
              TextField passwordField = new TextField(8);
              Button loginButton = new Button("Login");
              //password = passwordField;
         public void init()
              setBackground(Color.orange);
              setLayout(new FlowLayout(FlowLayout.LEFT,50,30));
              add(headerLabel);
              add(idLabel);
                   add(idField);
                   idField.requestFocus();
                   id = idField.toString();
              add(passwordLabel);
                   add(passwordField);
                   passwordField.setEchoChar('*');
                   password = passwordField.toString();
              add(loginButton);
                   loginButton.addActionListener(this);
         public void actionPerformed(ActionEvent e)
              success = false;     
              for (int i = 0; i<idArray.length;i++)
                   if((idArray.compareTo(id)==0) && (passwordArray[i].compareTo(password)==0))
                        success = true;
              if(success = true)
                   headerLabel.setText("Login Successful");
                   repaint();
              else
                   headerLabel.setText("Invalid. Try Again.");
                   clearFields();
         void clearFields()
              headerLabel.setText("Please type your ID and Password");
              idField.setText("");
              passwordField.setText("");
    Message was edited by:
    SancLunatic

Maybe you are looking for

  • Update tables in a view

    Is it possible to update the tables in a view?

  • Save real-time data

    Hello! I'm at the begin with LabView. I'd like to verify my signal with an oscilloscope. After this, when i active a light, the power of this signal must be save. I have found the oscilloscope VI. I'm tring to modify it in order to save, when it's ne

  • Outer join with BETWEEN clause

    Hi All, I have 2 tables (A and B) which i need to join. I need all records from table A and matching records from the table B. below is the structure. TABLE A (total rows = 10) ROW_WID GL_DATE LOCATION_CODE TABLE B (total = 7) ROW_WID START_DATE END_

  • Numbering To All Detail Sections

    Hi, Am developing a report in crystal report from visual studio. I need a help. In my report there are so many detail sections. Example : Every record i divided into 5 parts. One Record i divided into A,B,C,D and E every part is in a new detail secti

  • ORACLE APPLICATIONS AUDITTRAILS에 대한 이해

    제품 : AOL 작성날짜 : 2003-11-24 ORACLE APPLICATIONS AUDITTRAILS에 대한 이해 ======================================== PURPOSE I. AuditTrail은 무엇인가? II. AuditTrails 을 설정하는 방법 III. AuditTrail Shadow Tables, Triggers, Procedures, and Views IV. AuditTrail 사용을 위한 요구사