I have a SQL query (a store procedure ) that i want to convert to PLSQL I already conver most of the store procedure but i cant convert the following part :
DECLARE lookupTableRow CURSOR FOR
SELECT TableName FROM SYS_LookUpTable
OPEN lookupTableRow
FETCH NEXT FROM lookupTableRow INTO @tableName
WHILE @@FETCH_STATUS=0
BEGIN
SET @sql='SELECT * FROM '+@tableName
EXECUTE sp_executesql @sql
IF @counter=0
BEGIN
INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table', @tableName)
END
ELSE
BEGIN
INSERT INTO T_TABLE_MAPPING
VALUES( 'P_MAIN_METADATA',
'Table' + CONVERT(NVARCHAR(10),@counter),
@tableName)
END
SET @counter=@counter+1
FETCH NEXT FROM lookupTableRow INTO @tableName
END
CLOSE lookupTableRow
DEALLOCATE lookupTableRow
As i understand i can't use ORACLE dynamic sql (execute immediate) when the table name is a parameter.
Furthermore when i execute this dynamic query in my SQL store procedure each SELECT statement return me as a result the relevant table rows , those result are different in each loop .
Please advice for any solution * how can i use dynamic sql with table name as parameter ? * how can i use a "dynamic" cursor, in order to be able to display the dynamic results ?
Thanks for the advice
'Table' + CONVERT(NVARCHAR(10),@counter)
do on this code? – Jorge CamposSelect owner, table_name, 'Table' || to_char(rownum) from all_tables order by owner, table_name
– xQbertI have a SQL query (a store procedure )
SQL is programming language which is industry standard for many RDBMS. You probably mean Transact-SQL or T-SQL stored procedure which is part of MS SQL Server product. Please use proper terms to avoid confusion. – Yaroslav Shabalin